1 Fix libtheora linking issue with modern theora versions.
4 http://git.buildroot.net/buildroot/commit/?id=46b71cb0be27c0e6b7c93afb49fc80779bf310e3
6 --- a/libmpcodecs/vd_theora.c
7 +++ b/libmpcodecs/vd_theora.c
12 -#include <theora/theora.h>
13 +#include <theora/theoradec.h>
15 #define THEORA_NUM_HEADER_PACKETS 3
17 typedef struct theora_struct_st {
27 /** Convert Theora pixelformat to the corresponding IMGFMT_ */
28 -static uint32_t theora_pixelformat2imgfmt(theora_pixelformat fmt){
29 +static uint32_t theora_pixelformat2imgfmt(th_pixel_fmt fmt){
31 - case OC_PF_420: return IMGFMT_YV12;
32 - case OC_PF_422: return IMGFMT_422P;
33 - case OC_PF_444: return IMGFMT_444P;
34 + case TH_PF_420: return IMGFMT_YV12;
35 + case TH_PF_422: return IMGFMT_422P;
36 + case TH_PF_444: return IMGFMT_444P;
41 theora_struct_t *context = sh->context;
43 case VDCTRL_QUERY_FORMAT:
44 - if (*(int*)arg == theora_pixelformat2imgfmt(context->inf.pixelformat))
45 + if (*(int*)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt))
53 - theora_info_init(&context->inf);
54 - theora_comment_init(&context->cc);
55 + th_info_init(&context->ti);
56 + th_comment_init(&context->tc);
57 + context->tsi = NULL;
59 /* Read all header packets, pass them to theora_decode_header. */
60 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
65 - if ( (errorCode = theora_decode_header (&context->inf, &context->cc, &op)) )
66 + if ( (errorCode = th_decode_headerin (&context->ti, &context->tc, &context->tsi, &op)) < 0)
68 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
74 - errorCode = theora_decode_init (&context->st, &context->inf);
76 + context->tctx = th_decode_alloc (&context->ti, context->tsi);
79 - mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed: %i \n", errorCode);
80 + mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed\n");
83 + /* free memory used for decoder setup information */
84 + th_setup_free(context->tsi);
86 - if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
87 + if(sh->aspect==0.0 && context->ti.aspect_denominator!=0)
89 - sh->aspect = ((double)context->inf.aspect_numerator * context->inf.width)/
90 - ((double)context->inf.aspect_denominator * context->inf.height);
91 + sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width)/
92 + ((double)context->ti.aspect_denominator * context->ti.frame_height);
95 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Theora video init ok!\n");
96 - mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Frame: %dx%d, Picture %dx%d, Offset [%d,%d]\n", context->inf.width, context->inf.height, context->inf.frame_width, context->inf.frame_height, context->inf.offset_x, context->inf.offset_y);
97 + mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Frame: %dx%d, Picture %dx%d, Offset [%d,%d]\n", context->ti.frame_width, context->ti.frame_height, context->ti.pic_width, context->ti.pic_height, context->ti.pic_x, context->ti.pic_y);
99 - return mpcodecs_config_vo (sh,context->inf.width,context->inf.height,theora_pixelformat2imgfmt(context->inf.pixelformat));
100 + return mpcodecs_config_vo (sh,context->ti.frame_width,context->ti.frame_height,theora_pixelformat2imgfmt(context->ti.pixel_fmt));
108 - theora_info_clear(&context->inf);
109 - theora_comment_clear(&context->cc);
110 - theora_clear (&context->st);
111 + th_info_clear(&context->ti);
112 + th_comment_clear(&context->tc);
113 + th_decode_free (context->tctx);
118 theora_struct_t *context = sh->context;
122 + th_ycbcr_buffer ycbcrbuf;
126 @@ -177,31 +181,31 @@
130 - errorCode = theora_decode_packetin (&context->st, &op);
132 + errorCode = th_decode_packetin (context->tctx, &op, NULL);
135 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
140 - errorCode = theora_decode_YUVout (&context->st, &yuv);
142 + errorCode = th_decode_ycbcr_out (context->tctx, ycbcrbuf);
145 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
150 - mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, yuv.y_width, yuv.y_height);
151 + mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, ycbcrbuf[0].width, ycbcrbuf[0].height);
152 if(!mpi) return NULL;
154 - mpi->planes[0]=yuv.y;
155 - mpi->stride[0]=yuv.y_stride;
156 - mpi->planes[1]=yuv.u;
157 - mpi->stride[1]=yuv.uv_stride;
158 - mpi->planes[2]=yuv.v;
159 - mpi->stride[2]=yuv.uv_stride;
160 + mpi->planes[0]=ycbcrbuf[0].data;
161 + mpi->stride[0]=ycbcrbuf[0].stride;
162 + mpi->planes[1]=ycbcrbuf[1].data;
163 + mpi->stride[1]=ycbcrbuf[1].stride;
164 + mpi->planes[2]=ycbcrbuf[2].data;
165 + mpi->stride[2]=ycbcrbuf[2].stride;
169 --- a/libmpdemux/demux_ogg.c
170 +++ b/libmpdemux/demux_ogg.c
174 #ifdef CONFIG_OGGTHEORA
175 -#include <theora/theora.h>
176 -int _ilog (unsigned int); /* defined in many places in theora/lib/ */
177 +#include <theora/theoradec.h>
180 #define BLOCK_SIZE 4096
182 /* Theora decoder context : we won't be able to interpret granule positions
183 - * without using theora_granule_time with the theora_state of the stream.
184 + * without using th_granule_time with the th_dec_ctx of the stream.
185 * This is duplicated in `vd_theora.c'; put this in a common header?
187 #ifdef CONFIG_OGGTHEORA
188 typedef struct theora_struct_st {
192 + th_setup_info *tsi;
200 float samplerate; /// granulpos 2 time
203 - int keyframe_frequency_force;
204 + int keyframe_granule_shift;
206 // Logical stream state
207 ogg_stream_state stream;
208 @@ -299,11 +299,10 @@
209 have theora_state st, until all header packets were passed to the
211 if (!pack->bytes || !(*data&0x80)) {
212 - int keyframe_granule_shift = _ilog(os->keyframe_frequency_force - 1);
213 - int64_t iframemask = (1 << keyframe_granule_shift) - 1;
214 + int64_t iframemask = (1 << os->keyframe_granule_shift) - 1;
216 if (pack->granulepos >= 0) {
217 - os->lastpos = pack->granulepos >> keyframe_granule_shift;
218 + os->lastpos = pack->granulepos >> os->keyframe_granule_shift;
219 os->lastpos += pack->granulepos & iframemask;
220 *flags = (pack->granulepos & iframemask) == 0;
222 @@ -892,14 +891,15 @@
223 #ifdef CONFIG_OGGTHEORA
224 } else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) {
230 + th_setup_info *tsi = NULL;
232 - theora_info_init (&inf);
233 - theora_comment_init (&cc);
234 + th_info_init (&ti);
235 + th_comment_init (&tc);
237 - errorCode = theora_decode_header (&inf, &cc, &pack);
239 + errorCode = th_decode_headerin(&ti, &tc, &tsi, &pack);
240 + if (errorCode < 0) {
241 mp_msg(MSGT_DEMUX, MSGL_ERR,
242 "Theora header parsing failed: %i \n", errorCode);
244 @@ -908,30 +908,32 @@
245 sh_v->bih = calloc(1, sizeof(*sh_v->bih));
246 sh_v->bih->biSize = sizeof(*sh_v->bih);
247 sh_v->bih->biCompression = sh_v->format = FOURCC_THEORA;
248 - sh_v->fps = ((double)inf.fps_numerator) / (double)inf.fps_denominator;
249 - sh_v->frametime = ((double)inf.fps_denominator) / (double)inf.fps_numerator;
250 - sh_v->disp_w = sh_v->bih->biWidth = inf.frame_width;
251 - sh_v->disp_h = sh_v->bih->biHeight = inf.frame_height;
252 + sh_v->fps = ((double)ti.fps_numerator) / (double)ti.fps_denominator;
253 + sh_v->frametime = ((double)ti.fps_denominator) / (double)ti.fps_numerator;
254 + sh_v->i_bps = ti.target_bitrate / 8;
255 + sh_v->disp_w = sh_v->bih->biWidth = ti.frame_width;
256 + sh_v->disp_h = sh_v->bih->biHeight = ti.frame_height;
257 sh_v->bih->biBitCount = 24;
258 sh_v->bih->biPlanes = 3;
259 sh_v->bih->biSizeImage = ((sh_v->bih->biBitCount / 8) * sh_v->bih->biWidth * sh_v->bih->biHeight);
260 ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps;
261 ogg_d->subs[ogg_d->num_sub].theora = 1;
262 - ogg_d->subs[ogg_d->num_sub].keyframe_frequency_force = inf.keyframe_frequency_force;
263 + ogg_d->subs[ogg_d->num_sub].keyframe_granule_shift = ti.keyframe_granule_shift;
264 ogg_d->subs[ogg_d->num_sub].id = n_video;
266 mp_msg(MSGT_DEMUX, MSGL_INFO,
267 "[Ogg] stream %d: video (Theora v%d.%d.%d), -vid %d\n",
269 - (int)inf.version_major,
270 - (int)inf.version_minor,
271 - (int)inf.version_subminor,
272 + (int)ti.version_major,
273 + (int)ti.version_minor,
274 + (int)ti.version_subminor,
276 if (mp_msg_test(MSGT_HEADER, MSGL_V))
277 print_video_header(sh_v->bih, MSGL_V);
279 - theora_comment_clear(&cc);
280 - theora_info_clear(&inf);
281 + th_comment_clear(&tc);
282 + th_info_clear(&ti);
283 + th_setup_free(tsi);
284 #endif /* CONFIG_OGGTHEORA */
285 } else if (pack.bytes >= 4 && !strncmp (&pack.packet[0], "fLaC", 4)) {
286 sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);