~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to libmpcodecs/vd_theora.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
LIBVD_EXTERN(theora)
41
41
 
42
 
#include <theora/theora.h>
 
42
#include <theora/theoradec.h>
43
43
 
44
44
#define THEORA_NUM_HEADER_PACKETS 3
45
45
 
46
46
typedef struct theora_struct_st {
47
 
    theora_state st;
48
 
    theora_comment cc;
49
 
    theora_info inf;
 
47
    th_setup_info *tsi;
 
48
    th_dec_ctx    *tctx;
 
49
    th_comment     tc;
 
50
    th_info        ti;
50
51
} theora_struct_t;
51
52
 
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){
54
55
    switch(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;
58
59
    }
59
60
    return 0;
60
61
}
64
65
    theora_struct_t *context = sh->context;
65
66
    switch(cmd) {
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;
70
71
    }
88
89
    if (!context)
89
90
        goto err_out;
90
91
 
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
    context->tsi = NULL;
93
95
 
94
96
    /* Read all header packets, pass them to theora_decode_header. */
95
97
    for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
109
111
            op.b_o_s = 1;
110
112
        }
111
113
 
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)
113
115
        {
114
116
            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
115
117
            goto err_out;
117
119
    }
118
120
 
119
121
    /* now init codec */
120
 
    errorCode = theora_decode_init (&context->st, &context->inf);
121
 
    if (errorCode)
 
122
    context->tctx = th_decode_alloc (&context->ti, context->tsi);
 
123
    if (!context->tctx)
122
124
    {
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");
124
126
        goto err_out;
125
127
    }
 
128
    /* free memory used for decoder setup information */
 
129
    th_setup_free(context->tsi);
126
130
 
127
 
    if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
 
131
    if(sh->aspect==0.0 && context->ti.aspect_denominator!=0)
128
132
    {
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);
131
135
    }
132
136
 
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);
135
139
 
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));
137
141
 
138
142
err_out:
139
143
    free(context);
150
154
 
151
155
   if (context)
152
156
   {
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);
156
160
      free (context);
157
161
   }
158
162
}
165
169
   theora_struct_t *context = sh->context;
166
170
   int errorCode = 0;
167
171
   ogg_packet op;
168
 
   yuv_buffer yuv;
 
172
   th_ycbcr_buffer ycbcrbuf;
169
173
   mp_image_t* mpi;
170
174
 
171
175
   // no delayed frames
177
181
   op.packet = data;
178
182
   op.granulepos = -1;
179
183
 
180
 
   errorCode = theora_decode_packetin (&context->st, &op);
181
 
   if (errorCode)
 
184
   errorCode = th_decode_packetin (context->tctx, &op, NULL);
 
185
   if (errorCode < 0)
182
186
   {
183
187
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
184
188
             errorCode);
185
189
      return NULL;
186
190
   }
187
191
 
188
 
   errorCode = theora_decode_YUVout (&context->st, &yuv);
189
 
   if (errorCode)
 
192
   errorCode = th_decode_ycbcr_out (context->tctx, ycbcrbuf);
 
193
   if (errorCode < 0)
190
194
   {
191
195
      mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode YUVout failed: %i \n",
192
196
             errorCode);
193
197
      return NULL;
194
198
   }
195
199
 
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;
198
202
 
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;
205
209
 
206
210
    return mpi;
207
211
}