View | Details | Raw Unified | Return to bug 198901 | Differences between
and this patch

Collapse All | Expand All

(-)libmpcodecs/vd_theora.c (-35 / +40 lines)
Lines 39-60 Link Here
39
39
40
LIBVD_EXTERN(theora)
40
LIBVD_EXTERN(theora)
41
41
42
#include <theora/theora.h>
42
#include <theora/theoradec.h>
43
43
44
#define THEORA_NUM_HEADER_PACKETS 3
44
#define THEORA_NUM_HEADER_PACKETS 3
45
45
46
typedef struct theora_struct_st {
46
typedef struct theora_struct_st {
47
    theora_state st;
47
    th_setup_info *tsi;
48
    theora_comment cc;
48
    th_dec_ctx    *tctx;
49
    theora_info inf;
49
    th_comment     tc;
50
    th_info        ti;	
50
} theora_struct_t;
51
} theora_struct_t;
51
52
52
/** Convert Theora pixelformat to the corresponding IMGFMT_ */
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){
54
    switch(fmt) {
55
    switch(fmt) {
55
       case OC_PF_420: return IMGFMT_YV12;
56
       case TH_PF_420: return IMGFMT_YV12;
56
       case OC_PF_422: return IMGFMT_422P;
57
       case TH_PF_422: return IMGFMT_422P;
57
       case OC_PF_444: return IMGFMT_444P;
58
       case TH_PF_444: return IMGFMT_444P;
58
    }
59
    }
59
    return 0;
60
    return 0;
60
}
61
}
Lines 64-70 Link Here
64
    theora_struct_t *context = sh->context;
65
    theora_struct_t *context = sh->context;
65
    switch(cmd) {
66
    switch(cmd) {
66
    case VDCTRL_QUERY_FORMAT:
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
	    return CONTROL_TRUE;
69
	    return CONTROL_TRUE;
69
	return CONTROL_FALSE;
70
	return CONTROL_FALSE;
70
    }
71
    }
Lines 88-95 Link Here
88
    if (!context)
89
    if (!context)
89
        goto err_out;
90
        goto err_out;
90
91
91
    theora_info_init(&context->inf);
92
    th_info_init(&context->ti);
92
    theora_comment_init(&context->cc);
93
    th_comment_init(&context->tc);
94
    context->tsi = NULL;
95
	
93
96
94
    /* Read all header packets, pass them to theora_decode_header. */
97
    /* Read all header packets, pass them to theora_decode_header. */
95
    for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
98
    for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
Lines 109-115 Link Here
109
            op.b_o_s = 1;
112
            op.b_o_s = 1;
110
        }
113
        }
111
114
112
        if ( (errorCode = theora_decode_header (&context->inf, &context->cc, &op)) )
115
        if ( (errorCode = th_decode_headerin (&context->ti, &context->tc, &context->tsi, &op)) < 0)
113
        {
116
        {
114
            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
117
            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
115
            goto err_out;
118
            goto err_out;
Lines 117-139 Link Here
117
    }
120
    }
118
121
119
    /* now init codec */
122
    /* now init codec */
120
    errorCode = theora_decode_init (&context->st, &context->inf);
123
    context->tctx = th_decode_alloc (&context->ti, &context->tsi);
121
    if (errorCode)
124
    if (!context->tctx)
122
    {
125
    {
123
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed: %i \n", errorCode);
126
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed\n");
124
        goto err_out;
127
        goto err_out;
125
    }
128
    }
129
    /* free memory used for decoder setup information */
130
    th_setup_free(context->tsi);		
126
131
127
    if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
132
    if(sh->aspect==0.0 && context->ti.aspect_denominator!=0)
128
    {
133
    {
129
       sh->aspect = ((double)context->inf.aspect_numerator * context->inf.width)/
134
       sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width)/
130
          ((double)context->inf.aspect_denominator * context->inf.height);
135
          ((double)context->ti.aspect_denominator * context->ti.frame_height);
131
    }
136
    }
132
137
133
    mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Theora video init ok!\n");
138
    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);
139
    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);
135
140
136
    return mpcodecs_config_vo (sh,context->inf.width,context->inf.height,theora_pixelformat2imgfmt(context->inf.pixelformat));
141
    return mpcodecs_config_vo (sh,context->ti.frame_width,context->ti.frame_height,theora_pixelformat2imgfmt(context->ti.pixel_fmt));
137
142
138
err_out:
143
err_out:
139
    free(context);
144
    free(context);
Lines 150-158 Link Here
150
155
151
   if (context)
156
   if (context)
152
   {
157
   {
153
      theora_info_clear(&context->inf);
158
      th_info_clear(&context->ti);
154
      theora_comment_clear(&context->cc);
159
      th_comment_clear(&context->tc);
155
      theora_clear (&context->st);
160
      th_decode_free (context->tctx);
156
      free (context);
161
      free (context);
157
   }
162
   }
158
}
163
}
Lines 165-171 Link Here
165
   theora_struct_t *context = sh->context;
170
   theora_struct_t *context = sh->context;
166
   int errorCode = 0;
171
   int errorCode = 0;
167
   ogg_packet op;
172
   ogg_packet op;
168
   yuv_buffer yuv;
173
   th_ycbcr_buffer ycbcrbuf;
169
   mp_image_t* mpi;
174
   mp_image_t* mpi;
170
175
171
   // no delayed frames
176
   // no delayed frames
Lines 177-207 Link Here
177
   op.packet = data;
182
   op.packet = data;
178
   op.granulepos = -1;
183
   op.granulepos = -1;
179
184
180
   errorCode = theora_decode_packetin (&context->st, &op);
185
   errorCode = th_decode_packetin (context->tctx, &op, NULL);
181
   if (errorCode)
186
   if (errorCode < 0)
182
   {
187
   {
183
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
188
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
184
	     errorCode);
189
	     errorCode);
185
      return NULL;
190
      return NULL;
186
   }
191
   }
187
192
188
   errorCode = theora_decode_YUVout (&context->st, &yuv);
193
   errorCode = th_decode_ycbcr_out (context->tctx, ycbcrbuf);
189
   if (errorCode)
194
   if (errorCode < 0)
190
   {
195
   {
191
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
196
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
192
	     errorCode);
197
	     errorCode);
193
      return NULL;
198
      return NULL;
194
   }
199
   }
195
200
196
    mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, yuv.y_width, yuv.y_height);
201
    mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, ycbcrbuf[0].width, ycbcrbuf[0].height);
197
    if(!mpi) return NULL;
202
    if(!mpi) return NULL;
198
203
199
    mpi->planes[0]=yuv.y;
204
    mpi->planes[0]=ycbcrbuf[0].data;
200
    mpi->stride[0]=yuv.y_stride;
205
    mpi->stride[0]=ycbcrbuf[0].stride;
201
    mpi->planes[1]=yuv.u;
206
    mpi->planes[1]=ycbcrbuf[1].data;
202
    mpi->stride[1]=yuv.uv_stride;
207
    mpi->stride[1]=ycbcrbuf[1].stride;
203
    mpi->planes[2]=yuv.v;
208
    mpi->planes[2]=ycbcrbuf[2].data;
204
    mpi->stride[2]=yuv.uv_stride;
209
    mpi->stride[2]=ycbcrbuf[2].stride;
205
210
206
    return mpi;
211
    return mpi;
207
}
212
}

Return to bug 198901