40
40
LIBVD_EXTERN(theora)
42
#include <theora/theora.h>
42
#include <theora/theoradec.h>
44
44
#define THEORA_NUM_HEADER_PACKETS 3
46
46
typedef struct theora_struct_st {
52
53
/** Convert Theora pixelformat to the corresponding IMGFMT_ */
53
static uint32_t theora_pixelformat2imgfmt(theora_pixelformat fmt){
54
static uint32_t theora_pixelformat2imgfmt(th_pixel_fmt fmt){
55
case OC_PF_420: return IMGFMT_YV12;
56
case OC_PF_422: return IMGFMT_422P;
57
case OC_PF_444: return IMGFMT_444P;
56
case TH_PF_420: return IMGFMT_YV12;
57
case TH_PF_422: return IMGFMT_422P;
58
case TH_PF_444: return IMGFMT_444P;
64
65
theora_struct_t *context = sh->context;
66
67
case VDCTRL_QUERY_FORMAT:
67
if (*(int*)arg == theora_pixelformat2imgfmt(context->inf.pixelformat))
68
if (*(int*)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt))
68
69
return CONTROL_TRUE;
69
70
return CONTROL_FALSE;
91
theora_info_init(&context->inf);
92
theora_comment_init(&context->cc);
92
th_info_init(&context->ti);
93
th_comment_init(&context->tc);
94
96
/* Read all header packets, pass them to theora_decode_header. */
95
97
for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
112
if ( (errorCode = theora_decode_header (&context->inf, &context->cc, &op)) )
114
if ( (errorCode = th_decode_headerin (&context->ti, &context->tc, &context->tsi, &op)) < 0)
114
116
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
119
121
/* now init codec */
120
errorCode = theora_decode_init (&context->st, &context->inf);
122
context->tctx = th_decode_alloc (&context->ti, context->tsi);
123
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed: %i \n", errorCode);
125
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed\n");
128
/* free memory used for decoder setup information */
129
th_setup_free(context->tsi);
127
if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
131
if(sh->aspect==0.0 && context->ti.aspect_denominator!=0)
129
sh->aspect = ((double)context->inf.aspect_numerator * context->inf.width)/
130
((double)context->inf.aspect_denominator * context->inf.height);
133
sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width)/
134
((double)context->ti.aspect_denominator * context->ti.frame_height);
133
137
mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Theora video init ok!\n");
134
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);
138
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);
136
return mpcodecs_config_vo (sh,context->inf.width,context->inf.height,theora_pixelformat2imgfmt(context->inf.pixelformat));
140
return mpcodecs_config_vo (sh,context->ti.frame_width,context->ti.frame_height,theora_pixelformat2imgfmt(context->ti.pixel_fmt));
153
theora_info_clear(&context->inf);
154
theora_comment_clear(&context->cc);
155
theora_clear (&context->st);
157
th_info_clear(&context->ti);
158
th_comment_clear(&context->tc);
159
th_decode_free (context->tctx);
177
181
op.packet = data;
178
182
op.granulepos = -1;
180
errorCode = theora_decode_packetin (&context->st, &op);
184
errorCode = th_decode_packetin (context->tctx, &op, NULL);
183
187
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
188
errorCode = theora_decode_YUVout (&context->st, &yuv);
192
errorCode = th_decode_ycbcr_out (context->tctx, ycbcrbuf);
191
195
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
196
mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, yuv.y_width, yuv.y_height);
200
mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, ycbcrbuf[0].width, ycbcrbuf[0].height);
197
201
if(!mpi) return NULL;
199
mpi->planes[0]=yuv.y;
200
mpi->stride[0]=yuv.y_stride;
201
mpi->planes[1]=yuv.u;
202
mpi->stride[1]=yuv.uv_stride;
203
mpi->planes[2]=yuv.v;
204
mpi->stride[2]=yuv.uv_stride;
203
mpi->planes[0]=ycbcrbuf[0].data;
204
mpi->stride[0]=ycbcrbuf[0].stride;
205
mpi->planes[1]=ycbcrbuf[1].data;
206
mpi->stride[1]=ycbcrbuf[1].stride;
207
mpi->planes[2]=ycbcrbuf[2].data;
208
mpi->stride[2]=ycbcrbuf[2].stride;