History

Move code shared between libdirac and libschroedinger to libschroedinger.

This also involves making some function static and changing the name prefixes of some functions and structures.

Diego Biurrun committed 14 years ago

Commit 9cef0661 parent 8134faf7 files · +180 −247Browse files

Unified · Split

7 files
  1. libavcodec/Makefile +2 −4
  2. libavcodec/libdirac_libschro.c +0 −113
  3. libavcodec/libdirac_libschro.h +0 −105
  4. libavcodec/libschroedinger.c +88 −3
  5. libavcodec/libschroedinger.h +70 −0
  6. libavcodec/libschroedingerdec.c +10 −11
  7. libavcodec/libschroedingerenc.c +10 −11
libavcodec/Makefile+2−4
@@ -601,11 +601,9 @@ OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o · 600 unmodified lines
601601 OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o
602602 OBJS-$(CONFIG_LIBOPENJPEG_DECODER) += libopenjpeg.o
603603 OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER) += libschroedingerdec.o \
604− libschroedinger.o \
605− libdirac_libschro.o
604+ libschroedinger.o
606605 OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \
607− libschroedinger.o \
608− libdirac_libschro.o
606+ libschroedinger.o
609607 OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
610608 OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o audio_frame_queue.o
611609 OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
libavcodec/libdirac_libschro.c+0−113
@@ -1,113 +0,0 @@
1−/*
2− * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
3− *
4− * This file is part of Libav.
5− *
6− * Libav is free software; you can redistribute it and/or
7− * modify it under the terms of the GNU Lesser General Public
8− * License as published by the Free Software Foundation; either
9− * version 2.1 of the License, or (at your option) any later version.
10− *
11− * Libav is distributed in the hope that it will be useful,
12− * but WITHOUT ANY WARRANTY; without even the implied warranty of
13− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14− * Lesser General Public License for more details.
15− *
16− * You should have received a copy of the GNU Lesser General Public
17− * License along with Libav; if not, write to the Free Software
18− * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19− */
20−
21−/**
22−* @file
23−* functions common to libdirac and libschroedinger
24−*/
25−
26−#include "libdirac_libschro.h"
27−
28−static const DiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = {
29− { 640, 480, 24000, 1001},
30− { 176, 120, 15000, 1001},
31− { 176, 144, 25, 2 },
32− { 352, 240, 15000, 1001},
33− { 352, 288, 25, 2 },
34− { 704, 480, 15000, 1001},
35− { 704, 576, 25, 2 },
36− { 720, 480, 30000, 1001},
37− { 720, 576, 25, 1 },
38− { 1280, 720, 60000, 1001},
39− { 1280, 720, 50, 1 },
40− { 1920, 1080, 30000, 1001},
41− { 1920, 1080, 25, 1 },
42− { 1920, 1080, 60000, 1001},
43− { 1920, 1080, 50, 1 },
44− { 2048, 1080, 24, 1 },
45− { 4096, 2160, 24, 1 },
46−};
47−
48−unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext)
49−{
50− unsigned int ret_idx = 0;
51− unsigned int idx;
52− unsigned int num_formats = sizeof(ff_dirac_schro_video_format_info) /
53− sizeof(ff_dirac_schro_video_format_info[0]);
54−
55− for (idx = 1; idx < num_formats; ++idx) {
56− const DiracSchroVideoFormatInfo *vf = &ff_dirac_schro_video_format_info[idx];
57− if (avccontext->width == vf->width &&
58− avccontext->height == vf->height) {
59− ret_idx = idx;
60− if (avccontext->time_base.den == vf->frame_rate_num &&
61− avccontext->time_base.num == vf->frame_rate_denom)
62− return idx;
63− }
64− }
65− return ret_idx;
66−}
67−
68−void ff_dirac_schro_queue_init(DiracSchroQueue *queue)
69−{
70− queue->p_head = queue->p_tail = NULL;
71− queue->size = 0;
72−}
73−
74−void ff_dirac_schro_queue_free(DiracSchroQueue *queue,
75− void (*free_func)(void *))
76−{
77− while (queue->p_head)
78− free_func(ff_dirac_schro_queue_pop(queue));
79−}
80−
81−int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data)
82−{
83− DiracSchroQueueElement *p_new = av_mallocz(sizeof(DiracSchroQueueElement));
84−
85− if (!p_new)
86− return -1;
87−
88− p_new->data = p_data;
89−
90− if (!queue->p_head)
91− queue->p_head = p_new;
92− else
93− queue->p_tail->next = p_new;
94− queue->p_tail = p_new;
95−
96− ++queue->size;
97− return 0;
98−}
99−
100−void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue)
101−{
102− DiracSchroQueueElement *top = queue->p_head;
103−
104− if (top) {
105− void *data = top->data;
106− queue->p_head = queue->p_head->next;
107− --queue->size;
108− av_freep(&top);
109− return data;
110− }
111−
112− return NULL;
113−}
libavcodec/libdirac_libschro.h+0−105
@@ -1,105 +0,0 @@
1−/*
2− * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
3− *
4− * This file is part of Libav.
5− *
6− * Libav is free software; you can redistribute it and/or
7− * modify it under the terms of the GNU Lesser General Public
8− * License as published by the Free Software Foundation; either
9− * version 2.1 of the License, or (at your option) any later version.
10− *
11− * Libav is distributed in the hope that it will be useful,
12− * but WITHOUT ANY WARRANTY; without even the implied warranty of
13− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14− * Lesser General Public License for more details.
15− *
16− * You should have received a copy of the GNU Lesser General Public
17− * License along with Libav; if not, write to the Free Software
18− * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19− */
20−
21−/**
22−* @file
23−* data structures common to libdirac and libschroedinger
24−*/
25−
26−#ifndef AVCODEC_LIBDIRAC_LIBSCHRO_H
27−#define AVCODEC_LIBDIRAC_LIBSCHRO_H
28−
29−#include "avcodec.h"
30−
31−typedef struct {
32− uint16_t width;
33− uint16_t height;
34− uint16_t frame_rate_num;
35− uint16_t frame_rate_denom;
36−} DiracSchroVideoFormatInfo;
37−
38−/**
39−* Returns the index into the Dirac Schro common video format info table
40−*/
41−unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext);
42−
43−/**
44−* contains a single encoded frame returned from Dirac or Schroedinger
45−*/
46−typedef struct DiracSchroEncodedFrame {
47− /** encoded frame data */
48− uint8_t *p_encbuf;
49−
50− /** encoded frame size */
51− uint32_t size;
52−
53− /** encoded frame number. Will be used as pts */
54− uint32_t frame_num;
55−
56− /** key frame flag. 1 : is key frame , 0 : in not key frame */
57− uint16_t key_frame;
58−} DiracSchroEncodedFrame;
59−
60−/**
61−* queue element
62−*/
63−typedef struct DiracSchroQueueElement {
64− /** Data to be stored in queue*/
65− void *data;
66− /** Pointer to next element queue */
67− struct DiracSchroQueueElement *next;
68−} DiracSchroQueueElement;
69−
70−
71−/**
72−* A simple queue implementation used in libdirac and libschroedinger
73−*/
74−typedef struct DiracSchroQueue {
75− /** Pointer to head of queue */
76− DiracSchroQueueElement *p_head;
77− /** Pointer to tail of queue */
78− DiracSchroQueueElement *p_tail;
79− /** Queue size*/
80− int size;
81−} DiracSchroQueue;
82−
83−/**
84−* Initialise the queue
85−*/
86−void ff_dirac_schro_queue_init(DiracSchroQueue *queue);
87−
88−/**
89−* Add an element to the end of the queue
90−*/
91−int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data);
92−
93−/**
94−* Return the first element in the queue
95−*/
96−void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue);
97−
98−/**
99−* Free the queue resources. free_func is a function supplied by the caller to
100−* free any resources allocated by the caller. The data field of the queue
101−* element is passed to it.
102−*/
103−void ff_dirac_schro_queue_free(DiracSchroQueue *queue,
104− void (*free_func)(void *));
105−#endif /* AVCODEC_LIBDIRAC_LIBSCHRO_H */
libavcodec/libschroedinger.c+88−3
@@ -23,12 +23,97 @@ · 22 unmodified lines
2323 * function definitions common to libschroedinger decoder and encoder
2424 */
2525
26−#include "libdirac_libschro.h"
2726 #include "libschroedinger.h"
2827
28+static const SchroVideoFormatInfo ff_schro_video_format_info[] = {
29+ { 640, 480, 24000, 1001},
30+ { 176, 120, 15000, 1001},
31+ { 176, 144, 25, 2 },
32+ { 352, 240, 15000, 1001},
33+ { 352, 288, 25, 2 },
34+ { 704, 480, 15000, 1001},
35+ { 704, 576, 25, 2 },
36+ { 720, 480, 30000, 1001},
37+ { 720, 576, 25, 1 },
38+ { 1280, 720, 60000, 1001},
39+ { 1280, 720, 50, 1 },
40+ { 1920, 1080, 30000, 1001},
41+ { 1920, 1080, 25, 1 },
42+ { 1920, 1080, 60000, 1001},
43+ { 1920, 1080, 50, 1 },
44+ { 2048, 1080, 24, 1 },
45+ { 4096, 2160, 24, 1 },
46+};
47+
48+static unsigned int get_video_format_idx(AVCodecContext *avccontext)
49+{
50+ unsigned int ret_idx = 0;
51+ unsigned int idx;
52+ unsigned int num_formats = sizeof(ff_schro_video_format_info) /
53+ sizeof(ff_schro_video_format_info[0]);
54+
55+ for (idx = 1; idx < num_formats; ++idx) {
56+ const SchroVideoFormatInfo *vf = &ff_schro_video_format_info[idx];
57+ if (avccontext->width == vf->width &&
58+ avccontext->height == vf->height) {
59+ ret_idx = idx;
60+ if (avccontext->time_base.den == vf->frame_rate_num &&
61+ avccontext->time_base.num == vf->frame_rate_denom)
62+ return idx;
63+ }
64+ }
65+ return ret_idx;
66+}
67+
68+void ff_schro_queue_init(FFSchroQueue *queue)
69+{
70+ queue->p_head = queue->p_tail = NULL;
71+ queue->size = 0;
72+}
73+
74+void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *))
75+{
76+ while (queue->p_head)
77+ free_func(ff_schro_queue_pop(queue));
78+}
79+
80+int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data)
81+{
82+ FFSchroQueueElement *p_new = av_mallocz(sizeof(FFSchroQueueElement));
83+
84+ if (!p_new)
85+ return -1;
86+
87+ p_new->data = p_data;
88+
89+ if (!queue->p_head)
90+ queue->p_head = p_new;
91+ else
92+ queue->p_tail->next = p_new;
93+ queue->p_tail = p_new;
94+
95+ ++queue->size;
96+ return 0;
97+}
98+
99+void *ff_schro_queue_pop(FFSchroQueue *queue)
100+{
101+ FFSchroQueueElement *top = queue->p_head;
102+
103+ if (top) {
104+ void *data = top->data;
105+ queue->p_head = queue->p_head->next;
106+ --queue->size;
107+ av_freep(&top);
108+ return data;
109+ }
110+
111+ return NULL;
112+}
113+
29114 /**
30115 * Schroedinger video preset table. Ensure that this tables matches up correctly
31−* with the ff_dirac_schro_video_format_info table in libdirac_libschro.c.
116+* with the ff_schro_video_format_info table.
32117 */
33118 static const SchroVideoFormatEnum ff_schro_video_formats[]={
34119 SCHRO_VIDEO_FORMAT_CUSTOM ,
@@ -55,7 +140,7 @@ SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext · 20 unmodified lines
55140 unsigned int num_formats = sizeof(ff_schro_video_formats) /
56141 sizeof(ff_schro_video_formats[0]);
57142
58− unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext);
143+ unsigned int idx = get_video_format_idx(avccontext);
59144
60145 return (idx < num_formats) ? ff_schro_video_formats[idx] :
61146 SCHRO_VIDEO_FORMAT_CUSTOM;
libavcodec/libschroedinger.h+70−0
@@ -28,8 +28,78 @@ · 27 unmodified lines
2828
2929 #include <schroedinger/schrobitstream.h>
3030 #include <schroedinger/schroframe.h>
31+
3132 #include "avcodec.h"
3233
34+typedef struct {
35+ uint16_t width;
36+ uint16_t height;
37+ uint16_t frame_rate_num;
38+ uint16_t frame_rate_denom;
39+} SchroVideoFormatInfo;
40+
41+/**
42+* contains a single encoded frame returned from Dirac or Schroedinger
43+*/
44+typedef struct FFSchroEncodedFrame {
45+ /** encoded frame data */
46+ uint8_t *p_encbuf;
47+
48+ /** encoded frame size */
49+ uint32_t size;
50+
51+ /** encoded frame number. Will be used as pts */
52+ uint32_t frame_num;
53+
54+ /** key frame flag. 1 : is key frame , 0 : in not key frame */
55+ uint16_t key_frame;
56+} FFSchroEncodedFrame;
57+
58+/**
59+* queue element
60+*/
61+typedef struct FFSchroQueueElement {
62+ /** Data to be stored in queue*/
63+ void *data;
64+ /** Pointer to next element queue */
65+ struct FFSchroQueueElement *next;
66+} FFSchroQueueElement;
67+
68+
69+/**
70+* A simple queue implementation used in libschroedinger
71+*/
72+typedef struct FFSchroQueue {
73+ /** Pointer to head of queue */
74+ FFSchroQueueElement *p_head;
75+ /** Pointer to tail of queue */
76+ FFSchroQueueElement *p_tail;
77+ /** Queue size*/
78+ int size;
79+} FFSchroQueue;
80+
81+/**
82+* Initialise the queue
83+*/
84+void ff_schro_queue_init(FFSchroQueue *queue);
85+
86+/**
87+* Add an element to the end of the queue
88+*/
89+int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data);
90+
91+/**
92+* Return the first element in the queue
93+*/
94+void *ff_schro_queue_pop(FFSchroQueue *queue);
95+
96+/**
97+* Free the queue resources. free_func is a function supplied by the caller to
98+* free any resources allocated by the caller. The data field of the queue
99+* element is passed to it.
100+*/
101+void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *));
102+
33103 static const struct {
34104 enum PixelFormat ff_pix_fmt;
35105 SchroChromaFormat schro_pix_fmt;
libavcodec/libschroedingerdec.c+10−11
@@ -29,7 +29,6 @@ · 28 unmodified lines
2929
3030 #include "libavutil/imgutils.h"
3131 #include "avcodec.h"
32−#include "libdirac_libschro.h"
3332 #include "libschroedinger.h"
3433
3534 #undef NDEBUG
@@ -52,7 +51,7 @@ typedef struct SchroDecoderParams { · 16 unmodified lines
5251 SchroDecoder* decoder;
5352
5453 /** queue storing decoded frames */
55− DiracSchroQueue dec_frame_queue;
54+ FFSchroQueue dec_frame_queue;
5655
5756 /** end of sequence signalled */
5857 int eos_signalled;
@@ -155,7 +154,7 @@ static av_cold int libschroedinger_decode_init(AVCodecContext *avccontext) · 96 unmodified lines
155154 return -1;
156155
157156 /* Initialize the decoded frame queue. */
158− ff_dirac_schro_queue_init(&p_schro_params->dec_frame_queue);
157+ ff_schro_queue_init(&p_schro_params->dec_frame_queue);
159158 return 0;
160159 }
161160
@@ -267,8 +266,8 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, · 105 unmodified lines
267266 frame = schro_decoder_pull(decoder);
268267
269268 if (frame)
270− ff_dirac_schro_queue_push_back(&p_schro_params->dec_frame_queue,
271− frame);
269+ ff_schro_queue_push_back(&p_schro_params->dec_frame_queue,
270+ frame);
272271 break;
273272 case SCHRO_DECODER_EOS:
274273 go = 0;
@@ -285,7 +284,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext, · 10 unmodified lines
285284 } while (outer);
286285
287286 /* Grab next frame to be returned from the top of the queue. */
288− frame = ff_dirac_schro_queue_pop(&p_schro_params->dec_frame_queue);
287+ frame = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
289288
290289 if (frame) {
291290 memcpy(p_schro_params->dec_pic.data[0],
@@ -324,8 +323,8 @@ static av_cold int libschroedinger_decode_close(AVCodecContext *avccontext) · 32 unmodified lines
324323 avpicture_free(&p_schro_params->dec_pic);
325324
326325 /* Free data in the output frame queue. */
327− ff_dirac_schro_queue_free(&p_schro_params->dec_frame_queue,
328− libschroedinger_decode_frame_free);
326+ ff_schro_queue_free(&p_schro_params->dec_frame_queue,
327+ libschroedinger_decode_frame_free);
329328
330329 return 0;
331330 }
@@ -337,10 +336,10 @@ static void libschroedinger_flush(AVCodecContext *avccontext) · 5 unmodified lines
337336 SchroDecoderParams *p_schro_params = avccontext->priv_data;
338337
339338 /* Free data in the output frame queue. */
340− ff_dirac_schro_queue_free(&p_schro_params->dec_frame_queue,
341− libschroedinger_decode_frame_free);
339+ ff_schro_queue_free(&p_schro_params->dec_frame_queue,
340+ libschroedinger_decode_frame_free);
342341
343− ff_dirac_schro_queue_init(&p_schro_params->dec_frame_queue);
342+ ff_schro_queue_init(&p_schro_params->dec_frame_queue);
344343 schro_decoder_reset(p_schro_params->decoder);
345344 p_schro_params->eos_pulled = 0;
346345 p_schro_params->eos_signalled = 0;
libavcodec/libschroedingerenc.c+10−11
@@ -36,7 +36,6 @@ · 35 unmodified lines
3636
3737 #include "avcodec.h"
3838 #include "internal.h"
39−#include "libdirac_libschro.h"
4039 #include "libschroedinger.h"
4140 #include "bytestream.h"
4241
@@ -65,7 +64,7 @@ typedef struct SchroEncoderParams { · 22 unmodified lines
6564 int enc_buf_size;
6665
6766 /** queue storing encoded frames */
68− DiracSchroQueue enc_frame_queue;
67+ FFSchroQueue enc_frame_queue;
6968
7069 /** end of sequence signalled */
7170 int eos_signalled;
@@ -236,7 +235,7 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext) · 164 unmodified lines
236235 schro_encoder_start(p_schro_params->encoder);
237236
238237 /* Initialize the encoded frame queue. */
239− ff_dirac_schro_queue_init(&p_schro_params->enc_frame_queue);
238+ ff_schro_queue_init(&p_schro_params->enc_frame_queue);
240239 return 0;
241240 }
242241
@@ -261,7 +260,7 @@ static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext, · 18 unmodified lines
261260
262261 static void SchroedingerFreeFrame(void *data)
263262 {
264− DiracSchroEncodedFrame *enc_frame = data;
263+ FFSchroEncodedFrame *enc_frame = data;
265264
266265 av_freep(&enc_frame->p_encbuf);
267266 av_free(enc_frame);
@@ -273,7 +272,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk · 5 unmodified lines
273272 int enc_size = 0;
274273 SchroEncoderParams *p_schro_params = avccontext->priv_data;
275274 SchroEncoder *encoder = p_schro_params->encoder;
276− struct DiracSchroEncodedFrame *p_frame_output = NULL;
275+ struct FFSchroEncodedFrame *p_frame_output = NULL;
277276 int go = 1;
278277 SchroBuffer *enc_buf;
279278 int presentation_frame;
@@ -333,7 +332,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk · 53 unmodified lines
333332 }
334333
335334 /* Create output frame. */
336− p_frame_output = av_mallocz(sizeof(DiracSchroEncodedFrame));
335+ p_frame_output = av_mallocz(sizeof(FFSchroEncodedFrame));
337336 /* Set output data. */
338337 p_frame_output->size = p_schro_params->enc_buf_size;
339338 p_frame_output->p_encbuf = p_schro_params->enc_buf;
@@ -345,8 +344,8 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk · 5 unmodified lines
345344 * through 17 represesent the frame number. */
346345 p_frame_output->frame_num = AV_RB32(enc_buf->data + 13);
347346
348− ff_dirac_schro_queue_push_back(&p_schro_params->enc_frame_queue,
349− p_frame_output);
347+ ff_schro_queue_push_back(&p_schro_params->enc_frame_queue,
348+ p_frame_output);
350349 p_schro_params->enc_buf_size = 0;
351350 p_schro_params->enc_buf = NULL;
352351
@@ -373,7 +372,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk · 20 unmodified lines
373372 p_schro_params->eos_pulled)
374373 last_frame_in_sequence = 1;
375374
376− p_frame_output = ff_dirac_schro_queue_pop(&p_schro_params->enc_frame_queue);
375+ p_frame_output = ff_schro_queue_pop(&p_schro_params->enc_frame_queue);
377376
378377 if (!p_frame_output)
379378 return 0;
@@ -425,8 +424,8 @@ static int libschroedinger_encode_close(AVCodecContext *avccontext) · 45 unmodified lines
425424 schro_encoder_free(p_schro_params->encoder);
426425
427426 /* Free data in the output frame queue. */
428− ff_dirac_schro_queue_free(&p_schro_params->enc_frame_queue,
429− SchroedingerFreeFrame);
427+ ff_schro_queue_free(&p_schro_params->enc_frame_queue,
428+ SchroedingerFreeFrame);
430429
431430
432431 /* Free the encoder buffer. */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t