Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / patches / mplayer2-theora-fix.patch
1 Fix libtheora linking issue with modern theora versions.
2
3 Adapted from:
4 http://git.buildroot.net/buildroot/commit/?id=46b71cb0be27c0e6b7c93afb49fc80779bf310e3
5
6 --- a/libmpcodecs/vd_theora.c
7 +++ b/libmpcodecs/vd_theora.c
8 @@ -39,22 +39,23 @@
9
10 LIBVD_EXTERN(theora)
11
12 -#include <theora/theora.h>
13 +#include <theora/theoradec.h>
14
15 #define THEORA_NUM_HEADER_PACKETS 3
16
17 typedef struct theora_struct_st {
18 - theora_state st;
19 - theora_comment cc;
20 - theora_info inf;
21 + th_setup_info *tsi;
22 + th_dec_ctx *tctx;
23 + th_comment tc;
24 + th_info ti;
25 } theora_struct_t;
26
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){
30 switch(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;
37 }
38 return 0;
39 }
40 @@ -64,7 +65,7 @@
41 theora_struct_t *context = sh->context;
42 switch(cmd) {
43 case VDCTRL_QUERY_FORMAT:
44 - if (*(int*)arg == theora_pixelformat2imgfmt(context->inf.pixelformat))
45 + if (*(int*)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt))
46 return CONTROL_TRUE;
47 return CONTROL_FALSE;
48 }
49 @@ -88,8 +89,9 @@
50 if (!context)
51 goto err_out;
52
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;
58
59 /* Read all header packets, pass them to theora_decode_header. */
60 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
61 @@ -109,7 +111,7 @@
62 op.b_o_s = 1;
63 }
64
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)
67 {
68 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
69 goto err_out;
70 @@ -117,23 +119,25 @@
71 }
72
73 /* now init codec */
74 - errorCode = theora_decode_init (&context->st, &context->inf);
75 - if (errorCode)
76 + context->tctx = th_decode_alloc (&context->ti, context->tsi);
77 + if (!context->tctx)
78 {
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");
81 goto err_out;
82 }
83 + /* free memory used for decoder setup information */
84 + th_setup_free(context->tsi);
85
86 - if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
87 + if(sh->aspect==0.0 && context->ti.aspect_denominator!=0)
88 {
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);
93 }
94
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);
98
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));
101
102 err_out:
103 free(context);
104 @@ -150,9 +154,9 @@
105
106 if (context)
107 {
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);
114 free (context);
115 }
116 }
117 @@ -165,7 +169,7 @@
118 theora_struct_t *context = sh->context;
119 int errorCode = 0;
120 ogg_packet op;
121 - yuv_buffer yuv;
122 + th_ycbcr_buffer ycbcrbuf;
123 mp_image_t* mpi;
124
125 // no delayed frames
126 @@ -177,31 +181,31 @@
127 op.packet = data;
128 op.granulepos = -1;
129
130 - errorCode = theora_decode_packetin (&context->st, &op);
131 - if (errorCode)
132 + errorCode = th_decode_packetin (context->tctx, &op, NULL);
133 + if (errorCode < 0)
134 {
135 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
136 errorCode);
137 return NULL;
138 }
139
140 - errorCode = theora_decode_YUVout (&context->st, &yuv);
141 - if (errorCode)
142 + errorCode = th_decode_ycbcr_out (context->tctx, ycbcrbuf);
143 + if (errorCode < 0)
144 {
145 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
146 errorCode);
147 return NULL;
148 }
149
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;
153
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;
166
167 return mpi;
168 }
169 --- a/libmpdemux/demux_ogg.c
170 +++ b/libmpdemux/demux_ogg.c
171 @@ -49,21 +49,21 @@
172 #endif
173
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>
178 #endif
179
180 #define BLOCK_SIZE 4096
181
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?
186 */
187 #ifdef CONFIG_OGGTHEORA
188 typedef struct theora_struct_st {
189 - theora_state st;
190 - theora_comment cc;
191 - theora_info inf;
192 + th_setup_info *tsi;
193 + th_dec_ctx *tctx;
194 + th_comment tc;
195 + th_info ti;
196 } theora_struct_t;
197 #endif
198
199 @@ -116,7 +116,7 @@
200 float samplerate; /// granulpos 2 time
201 int64_t lastpos;
202 int32_t lastsize;
203 - int keyframe_frequency_force;
204 + int keyframe_granule_shift;
205
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
210 decoder. */
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;
215
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;
221 } else {
222 @@ -892,14 +891,15 @@
223 #ifdef CONFIG_OGGTHEORA
224 } else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) {
225 int errorCode = 0;
226 - theora_info inf;
227 - theora_comment cc;
228 + th_info ti;
229 + th_comment tc;
230 + th_setup_info *tsi = NULL;
231
232 - theora_info_init (&inf);
233 - theora_comment_init (&cc);
234 + th_info_init (&ti);
235 + th_comment_init (&tc);
236
237 - errorCode = theora_decode_header (&inf, &cc, &pack);
238 - if (errorCode) {
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);
243 } else {
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;
265 n_video++;
266 mp_msg(MSGT_DEMUX, MSGL_INFO,
267 "[Ogg] stream %d: video (Theora v%d.%d.%d), -vid %d\n",
268 ogg_d->num_sub,
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,
275 n_video - 1);
276 if (mp_msg_test(MSGT_HEADER, MSGL_V))
277 print_video_header(sh_v->bih, MSGL_V);
278 }
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);