00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028
00029 #include "avcodec.h"
00030 #include "dsputil.h"
00031 #include "mpegvideo.h"
00032
00033 #include "mpeg12.h"
00034 #include "mpeg12data.h"
00035 #include "mpeg12decdata.h"
00036 #include "bytestream.h"
00037
00038
00039
00040
00041
00042 #define DC_VLC_BITS 9
00043 #define MV_VLC_BITS 9
00044 #define MBINCR_VLC_BITS 9
00045 #define MB_PAT_VLC_BITS 9
00046 #define MB_PTYPE_VLC_BITS 6
00047 #define MB_BTYPE_VLC_BITS 6
00048 #define TEX_VLC_BITS 9
00049
00050 static inline int mpeg1_decode_block_inter(MpegEncContext *s,
00051 DCTELEM *block,
00052 int n);
00053 static inline int mpeg1_decode_block_intra(MpegEncContext *s,
00054 DCTELEM *block,
00055 int n);
00056 static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n);
00057 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
00058 DCTELEM *block,
00059 int n);
00060 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
00061 DCTELEM *block,
00062 int n);
00063 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
00064 static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n);
00065 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
00066 static void exchange_uv(MpegEncContext *s);
00067
00068 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx);
00069 extern int XVMC_field_end(MpegEncContext *s);
00070 extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp);
00071 extern void XVMC_init_block(MpegEncContext *s);
00072
00073 static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,-1};
00074 static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1};
00075 static const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1};
00076 static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
00077 PIX_FMT_XVMC_MPEG2_IDCT,
00078 PIX_FMT_XVMC_MPEG2_MC,
00079 -1};
00080
00081 uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
00082
00083 static void init_2d_vlc_rl(RLTable *rl, int use_static)
00084 {
00085 int i;
00086
00087 init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2,
00088 &rl->table_vlc[0][1], 4, 2,
00089 &rl->table_vlc[0][0], 4, 2, use_static);
00090
00091 if(use_static)
00092 rl->rl_vlc[0]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
00093 else
00094 rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
00095
00096 for(i=0; i<rl->vlc.table_size; i++){
00097 int code= rl->vlc.table[i][0];
00098 int len = rl->vlc.table[i][1];
00099 int level, run;
00100
00101 if(len==0){
00102 run= 65;
00103 level= MAX_LEVEL;
00104 }else if(len<0){
00105 run= 0;
00106 level= code;
00107 }else{
00108 if(code==rl->n){
00109 run= 65;
00110 level= 0;
00111 }else if(code==rl->n+1){
00112 run= 0;
00113 level= 127;
00114 }else{
00115 run= rl->table_run [code] + 1;
00116 level= rl->table_level[code];
00117 }
00118 }
00119 rl->rl_vlc[0][i].len= len;
00120 rl->rl_vlc[0][i].level= level;
00121 rl->rl_vlc[0][i].run= run;
00122 }
00123 }
00124
00125 void ff_mpeg12_common_init(MpegEncContext *s)
00126 {
00127
00128 s->y_dc_scale_table=
00129 s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision];
00130
00131 }
00132
00133 void ff_mpeg1_clean_buffers(MpegEncContext *s){
00134 s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
00135 s->last_dc[1] = s->last_dc[0];
00136 s->last_dc[2] = s->last_dc[0];
00137 memset(s->last_mv, 0, sizeof(s->last_mv));
00138 }
00139
00140
00141
00142
00143
00144 static VLC dc_lum_vlc;
00145 static VLC dc_chroma_vlc;
00146 static VLC mv_vlc;
00147 static VLC mbincr_vlc;
00148 static VLC mb_ptype_vlc;
00149 static VLC mb_btype_vlc;
00150 static VLC mb_pat_vlc;
00151
00152 static void init_vlcs(void)
00153 {
00154 static int done = 0;
00155
00156 if (!done) {
00157 done = 1;
00158
00159 init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12,
00160 ff_mpeg12_vlc_dc_lum_bits, 1, 1,
00161 ff_mpeg12_vlc_dc_lum_code, 2, 2, 1);
00162 init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12,
00163 ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
00164 ff_mpeg12_vlc_dc_chroma_code, 2, 2, 1);
00165 init_vlc(&mv_vlc, MV_VLC_BITS, 17,
00166 &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
00167 &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 1);
00168 init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36,
00169 &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
00170 &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 1);
00171 init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
00172 &ff_mpeg12_mbPatTable[0][1], 2, 1,
00173 &ff_mpeg12_mbPatTable[0][0], 2, 1, 1);
00174
00175 init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
00176 &table_mb_ptype[0][1], 2, 1,
00177 &table_mb_ptype[0][0], 2, 1, 1);
00178 init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
00179 &table_mb_btype[0][1], 2, 1,
00180 &table_mb_btype[0][0], 2, 1, 1);
00181 init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
00182 init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
00183
00184 init_2d_vlc_rl(&ff_rl_mpeg1, 1);
00185 init_2d_vlc_rl(&ff_rl_mpeg2, 1);
00186 }
00187 }
00188
00189 static inline int get_dmv(MpegEncContext *s)
00190 {
00191 if(get_bits1(&s->gb))
00192 return 1 - (get_bits1(&s->gb) << 1);
00193 else
00194 return 0;
00195 }
00196
00197 static inline int get_qscale(MpegEncContext *s)
00198 {
00199 int qscale = get_bits(&s->gb, 5);
00200 if (s->q_scale_type) {
00201 return non_linear_qscale[qscale];
00202 } else {
00203 return qscale << 1;
00204 }
00205 }
00206
00207
00208 #define MT_FIELD 1
00209 #define MT_FRAME 2
00210 #define MT_16X8 2
00211 #define MT_DMV 3
00212
00213 static int mpeg_decode_mb(MpegEncContext *s,
00214 DCTELEM block[12][64])
00215 {
00216 int i, j, k, cbp, val, mb_type, motion_type;
00217 const int mb_block_count = 4 + (1<< s->chroma_format);
00218
00219 dprintf(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
00220
00221 assert(s->mb_skipped==0);
00222
00223 if (s->mb_skip_run-- != 0) {
00224 if (s->pict_type == P_TYPE) {
00225 s->mb_skipped = 1;
00226 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
00227 } else {
00228 int mb_type;
00229
00230 if(s->mb_x)
00231 mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
00232 else
00233 mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1];
00234 if(IS_INTRA(mb_type))
00235 return -1;
00236
00237 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
00238 mb_type | MB_TYPE_SKIP;
00239
00240
00241 if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0)
00242 s->mb_skipped = 1;
00243 }
00244
00245 return 0;
00246 }
00247
00248 switch(s->pict_type) {
00249 default:
00250 case I_TYPE:
00251 if (get_bits1(&s->gb) == 0) {
00252 if (get_bits1(&s->gb) == 0){
00253 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
00254 return -1;
00255 }
00256 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
00257 } else {
00258 mb_type = MB_TYPE_INTRA;
00259 }
00260 break;
00261 case P_TYPE:
00262 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
00263 if (mb_type < 0){
00264 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
00265 return -1;
00266 }
00267 mb_type = ptype2mb_type[ mb_type ];
00268 break;
00269 case B_TYPE:
00270 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
00271 if (mb_type < 0){
00272 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
00273 return -1;
00274 }
00275 mb_type = btype2mb_type[ mb_type ];
00276 break;
00277 }
00278 dprintf(s->avctx, "mb_type=%x\n", mb_type);
00279
00280 if (IS_INTRA(mb_type)) {
00281 s->dsp.clear_blocks(s->block[0]);
00282
00283 if(!s->chroma_y_shift){
00284 s->dsp.clear_blocks(s->block[6]);
00285 }
00286
00287
00288 if (s->picture_structure == PICT_FRAME &&
00289 !s->frame_pred_frame_dct) {
00290 s->interlaced_dct = get_bits1(&s->gb);
00291 }
00292
00293 if (IS_QUANT(mb_type))
00294 s->qscale = get_qscale(s);
00295
00296 if (s->concealment_motion_vectors) {
00297
00298 if (s->picture_structure != PICT_FRAME)
00299 skip_bits1(&s->gb);
00300
00301 s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
00302 mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
00303 s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
00304 mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
00305
00306 skip_bits1(&s->gb);
00307 }else
00308 memset(s->last_mv, 0, sizeof(s->last_mv));
00309 s->mb_intra = 1;
00310 #ifdef HAVE_XVMC
00311
00312 if(s->avctx->xvmc_acceleration > 1){
00313 XVMC_pack_pblocks(s,-1);
00314 if(s->swap_uv){
00315 exchange_uv(s);
00316 }
00317 }
00318 #endif
00319
00320 if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
00321 if(s->flags2 & CODEC_FLAG2_FAST){
00322 for(i=0;i<6;i++) {
00323 mpeg2_fast_decode_block_intra(s, s->pblocks[i], i);
00324 }
00325 }else{
00326 for(i=0;i<mb_block_count;i++) {
00327 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0)
00328 return -1;
00329 }
00330 }
00331 } else {
00332 for(i=0;i<6;i++) {
00333 if (mpeg1_decode_block_intra(s, s->pblocks[i], i) < 0)
00334 return -1;
00335 }
00336 }
00337 } else {
00338 if (mb_type & MB_TYPE_ZERO_MV){
00339 assert(mb_type & MB_TYPE_CBP);
00340
00341 s->mv_dir = MV_DIR_FORWARD;
00342 if(s->picture_structure == PICT_FRAME){
00343 if(!s->frame_pred_frame_dct)
00344 s->interlaced_dct = get_bits1(&s->gb);
00345 s->mv_type = MV_TYPE_16X16;
00346 }else{
00347 s->mv_type = MV_TYPE_FIELD;
00348 mb_type |= MB_TYPE_INTERLACED;
00349 s->field_select[0][0]= s->picture_structure - 1;
00350 }
00351
00352 if (IS_QUANT(mb_type))
00353 s->qscale = get_qscale(s);
00354
00355 s->last_mv[0][0][0] = 0;
00356 s->last_mv[0][0][1] = 0;
00357 s->last_mv[0][1][0] = 0;
00358 s->last_mv[0][1][1] = 0;
00359 s->mv[0][0][0] = 0;
00360 s->mv[0][0][1] = 0;
00361 }else{
00362 assert(mb_type & MB_TYPE_L0L1);
00363
00364
00365 if (s->frame_pred_frame_dct)
00366 motion_type = MT_FRAME;
00367 else{
00368 motion_type = get_bits(&s->gb, 2);
00369 if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
00370 s->interlaced_dct = get_bits1(&s->gb);
00371 }
00372
00373 if (IS_QUANT(mb_type))
00374 s->qscale = get_qscale(s);
00375
00376
00377 s->mv_dir= (mb_type>>13)&3;
00378 dprintf(s->avctx, "motion_type=%d\n", motion_type);
00379 switch(motion_type) {
00380 case MT_FRAME:
00381 if (s->picture_structure == PICT_FRAME) {
00382 mb_type |= MB_TYPE_16x16;
00383 s->mv_type = MV_TYPE_16X16;
00384 for(i=0;i<2;i++) {
00385 if (USES_LIST(mb_type, i)) {
00386
00387 s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
00388 mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
00389 s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
00390 mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
00391
00392 if (s->full_pel[i]){
00393 s->mv[i][0][0] <<= 1;
00394 s->mv[i][0][1] <<= 1;
00395 }
00396 }
00397 }
00398 } else {
00399 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
00400 s->mv_type = MV_TYPE_16X8;
00401 for(i=0;i<2;i++) {
00402 if (USES_LIST(mb_type, i)) {
00403
00404 for(j=0;j<2;j++) {
00405 s->field_select[i][j] = get_bits1(&s->gb);
00406 for(k=0;k<2;k++) {
00407 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
00408 s->last_mv[i][j][k]);
00409 s->last_mv[i][j][k] = val;
00410 s->mv[i][j][k] = val;
00411 }
00412 }
00413 }
00414 }
00415 }
00416 break;
00417 case MT_FIELD:
00418 s->mv_type = MV_TYPE_FIELD;
00419 if (s->picture_structure == PICT_FRAME) {
00420 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
00421 for(i=0;i<2;i++) {
00422 if (USES_LIST(mb_type, i)) {
00423 for(j=0;j<2;j++) {
00424 s->field_select[i][j] = get_bits1(&s->gb);
00425 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
00426 s->last_mv[i][j][0]);
00427 s->last_mv[i][j][0] = val;
00428 s->mv[i][j][0] = val;
00429 dprintf(s->avctx, "fmx=%d\n", val);
00430 val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
00431 s->last_mv[i][j][1] >> 1);
00432 s->last_mv[i][j][1] = val << 1;
00433 s->mv[i][j][1] = val;
00434 dprintf(s->avctx, "fmy=%d\n", val);
00435 }
00436 }
00437 }
00438 } else {
00439 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
00440 for(i=0;i<2;i++) {
00441 if (USES_LIST(mb_type, i)) {
00442 s->field_select[i][0] = get_bits1(&s->gb);
00443 for(k=0;k<2;k++) {
00444 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
00445 s->last_mv[i][0][k]);
00446 s->last_mv[i][0][k] = val;
00447 s->last_mv[i][1][k] = val;
00448 s->mv[i][0][k] = val;
00449 }
00450 }
00451 }
00452 }
00453 break;
00454 case MT_DMV:
00455 s->mv_type = MV_TYPE_DMV;
00456 for(i=0;i<2;i++) {
00457 if (USES_LIST(mb_type, i)) {
00458 int dmx, dmy, mx, my, m;
00459 mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
00460 s->last_mv[i][0][0]);
00461 s->last_mv[i][0][0] = mx;
00462 s->last_mv[i][1][0] = mx;
00463 dmx = get_dmv(s);
00464 my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
00465 s->last_mv[i][0][1] >> 1);
00466 dmy = get_dmv(s);
00467
00468
00469 s->last_mv[i][0][1] = my<<1;
00470 s->last_mv[i][1][1] = my<<1;
00471
00472 s->mv[i][0][0] = mx;
00473 s->mv[i][0][1] = my;
00474 s->mv[i][1][0] = mx;
00475 s->mv[i][1][1] = my;
00476
00477 if (s->picture_structure == PICT_FRAME) {
00478 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
00479
00480
00481 m = s->top_field_first ? 1 : 3;
00482
00483
00484 s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
00485 s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
00486 m = 4 - m;
00487 s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
00488 s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
00489 } else {
00490 mb_type |= MB_TYPE_16x16;
00491
00492 s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
00493 s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
00494 if(s->picture_structure == PICT_TOP_FIELD)
00495 s->mv[i][2][1]--;
00496 else
00497 s->mv[i][2][1]++;
00498 }
00499 }
00500 }
00501 break;
00502 default:
00503 av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
00504 return -1;
00505 }
00506 }
00507
00508 s->mb_intra = 0;
00509 if (HAS_CBP(mb_type)) {
00510 s->dsp.clear_blocks(s->block[0]);
00511
00512 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
00513 if(mb_block_count > 6){
00514 cbp<<= mb_block_count-6;
00515 cbp |= get_bits(&s->gb, mb_block_count-6);
00516 s->dsp.clear_blocks(s->block[6]);
00517 }
00518 if (cbp <= 0){
00519 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
00520 return -1;
00521 }
00522
00523 #ifdef HAVE_XVMC
00524
00525 if(s->avctx->xvmc_acceleration > 1){
00526 XVMC_pack_pblocks(s,cbp);
00527 if(s->swap_uv){
00528 exchange_uv(s);
00529 }
00530 }
00531 #endif
00532
00533 if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
00534 if(s->flags2 & CODEC_FLAG2_FAST){
00535 for(i=0;i<6;i++) {
00536 if(cbp & 32) {
00537 mpeg2_fast_decode_block_non_intra(s, s->pblocks[i], i);
00538 } else {
00539 s->block_last_index[i] = -1;
00540 }
00541 cbp+=cbp;
00542 }
00543 }else{
00544 cbp<<= 12-mb_block_count;
00545
00546 for(i=0;i<mb_block_count;i++) {
00547 if ( cbp & (1<<11) ) {
00548 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
00549 return -1;
00550 } else {
00551 s->block_last_index[i] = -1;
00552 }
00553 cbp+=cbp;
00554 }
00555 }
00556 } else {
00557 if(s->flags2 & CODEC_FLAG2_FAST){
00558 for(i=0;i<6;i++) {
00559 if (cbp & 32) {
00560 mpeg1_fast_decode_block_inter(s, s->pblocks[i], i);
00561 } else {
00562 s->block_last_index[i] = -1;
00563 }
00564 cbp+=cbp;
00565 }
00566 }else{
00567 for(i=0;i<6;i++) {
00568 if (cbp & 32) {
00569 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0)
00570 return -1;
00571 } else {
00572 s->block_last_index[i] = -1;
00573 }
00574 cbp+=cbp;
00575 }
00576 }
00577 }
00578 }else{
00579 for(i=0;i<12;i++)
00580 s->block_last_index[i] = -1;
00581 }
00582 }
00583
00584 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
00585
00586 return 0;
00587 }
00588
00589
00590 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
00591 {
00592 int code, sign, val, l, shift;
00593
00594 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
00595 if (code == 0) {
00596 return pred;
00597 }
00598 if (code < 0) {
00599 return 0xffff;
00600 }
00601
00602 sign = get_bits1(&s->gb);
00603 shift = fcode - 1;
00604 val = code;
00605 if (shift) {
00606 val = (val - 1) << shift;
00607 val |= get_bits(&s->gb, shift);
00608 val++;
00609 }
00610 if (sign)
00611 val = -val;
00612 val += pred;
00613
00614
00615 l= INT_BIT - 5 - shift;
00616 val = (val<<l)>>l;
00617 return val;
00618 }
00619
00620 static inline int decode_dc(GetBitContext *gb, int component)
00621 {
00622 int code, diff;
00623
00624 if (component == 0) {
00625 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2);
00626 } else {
00627 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2);
00628 }
00629 if (code < 0){
00630 av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n");
00631 return 0xffff;
00632 }
00633 if (code == 0) {
00634 diff = 0;
00635 } else {
00636 diff = get_xbits(gb, code);
00637 }
00638 return diff;
00639 }
00640
00641 static inline int mpeg1_decode_block_intra(MpegEncContext *s,
00642 DCTELEM *block,
00643 int n)
00644 {
00645 int level, dc, diff, i, j, run;
00646 int component;
00647 RLTable *rl = &ff_rl_mpeg1;
00648 uint8_t * const scantable= s->intra_scantable.permutated;
00649 const uint16_t *quant_matrix= s->intra_matrix;
00650 const int qscale= s->qscale;
00651
00652
00653 component = (n <= 3 ? 0 : n - 4 + 1);
00654 diff = decode_dc(&s->gb, component);
00655 if (diff >= 0xffff)
00656 return -1;
00657 dc = s->last_dc[component];
00658 dc += diff;
00659 s->last_dc[component] = dc;
00660 block[0] = dc<<3;
00661 dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff);
00662 i = 0;
00663 {
00664 OPEN_READER(re, &s->gb);
00665
00666 for(;;) {
00667 UPDATE_CACHE(re, &s->gb);
00668 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
00669
00670 if(level == 127){
00671 break;
00672 } else if(level != 0) {
00673 i += run;
00674 j = scantable[i];
00675 level= (level*qscale*quant_matrix[j])>>4;
00676 level= (level-1)|1;
00677 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
00678 LAST_SKIP_BITS(re, &s->gb, 1);
00679 } else {
00680
00681 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
00682 UPDATE_CACHE(re, &s->gb);
00683 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
00684 if (level == -128) {
00685 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);
00686 } else if (level == 0) {
00687 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
00688 }
00689 i += run;
00690 j = scantable[i];
00691 if(level<0){
00692 level= -level;
00693 level= (level*qscale*quant_matrix[j])>>4;
00694 level= (level-1)|1;
00695 level= -level;
00696 }else{
00697 level= (level*qscale*quant_matrix[j])>>4;
00698 level= (level-1)|1;
00699 }
00700 }
00701 if (i > 63){
00702 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
00703 return -1;
00704 }
00705
00706 block[j] = level;
00707 }
00708 CLOSE_READER(re, &s->gb);
00709 }
00710 s->block_last_index[n] = i;
00711 return 0;
00712 }
00713
00714 static inline int mpeg1_decode_block_inter(MpegEncContext *s,
00715 DCTELEM *block,
00716 int n)
00717 {
00718 int level, i, j, run;
00719 RLTable *rl = &ff_rl_mpeg1;
00720 uint8_t * const scantable= s->intra_scantable.permutated;
00721 const uint16_t *quant_matrix= s->inter_matrix;
00722 const int qscale= s->qscale;
00723
00724 {
00725 OPEN_READER(re, &s->gb);
00726 i = -1;
00727
00728 UPDATE_CACHE(re, &s->gb);
00729 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
00730 level= (3*qscale*quant_matrix[0])>>5;
00731 level= (level-1)|1;
00732 if(GET_CACHE(re, &s->gb)&0x40000000)
00733 level= -level;
00734 block[0] = level;
00735 i++;
00736 SKIP_BITS(re, &s->gb, 2);
00737 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00738 goto end;
00739 }
00740 #if MIN_CACHE_BITS < 19
00741 UPDATE_CACHE(re, &s->gb);
00742 #endif
00743
00744 for(;;) {
00745 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
00746
00747 if(level != 0) {
00748 i += run;
00749 j = scantable[i];
00750 level= ((level*2+1)*qscale*quant_matrix[j])>>5;
00751 level= (level-1)|1;
00752 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
00753 SKIP_BITS(re, &s->gb, 1);
00754 } else {
00755
00756 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
00757 UPDATE_CACHE(re, &s->gb);
00758 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
00759 if (level == -128) {
00760 level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
00761 } else if (level == 0) {
00762 level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
00763 }
00764 i += run;
00765 j = scantable[i];
00766 if(level<0){
00767 level= -level;
00768 level= ((level*2+1)*qscale*quant_matrix[j])>>5;
00769 level= (level-1)|1;
00770 level= -level;
00771 }else{
00772 level= ((level*2+1)*qscale*quant_matrix[j])>>5;
00773 level= (level-1)|1;
00774 }
00775 }
00776 if (i > 63){
00777 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
00778 return -1;
00779 }
00780
00781 block[j] = level;
00782 #if MIN_CACHE_BITS < 19
00783 UPDATE_CACHE(re, &s->gb);
00784 #endif
00785 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00786 break;
00787 #if MIN_CACHE_BITS >= 19
00788 UPDATE_CACHE(re, &s->gb);
00789 #endif
00790 }
00791 end:
00792 LAST_SKIP_BITS(re, &s->gb, 2);
00793 CLOSE_READER(re, &s->gb);
00794 }
00795 s->block_last_index[n] = i;
00796 return 0;
00797 }
00798
00799 static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n)
00800 {
00801 int level, i, j, run;
00802 RLTable *rl = &ff_rl_mpeg1;
00803 uint8_t * const scantable= s->intra_scantable.permutated;
00804 const int qscale= s->qscale;
00805
00806 {
00807 OPEN_READER(re, &s->gb);
00808 i = -1;
00809
00810 UPDATE_CACHE(re, &s->gb);
00811 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
00812 level= (3*qscale)>>1;
00813 level= (level-1)|1;
00814 if(GET_CACHE(re, &s->gb)&0x40000000)
00815 level= -level;
00816 block[0] = level;
00817 i++;
00818 SKIP_BITS(re, &s->gb, 2);
00819 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00820 goto end;
00821 }
00822 #if MIN_CACHE_BITS < 19
00823 UPDATE_CACHE(re, &s->gb);
00824 #endif
00825
00826
00827 for(;;) {
00828 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
00829
00830 if(level != 0) {
00831 i += run;
00832 j = scantable[i];
00833 level= ((level*2+1)*qscale)>>1;
00834 level= (level-1)|1;
00835 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
00836 SKIP_BITS(re, &s->gb, 1);
00837 } else {
00838
00839 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
00840 UPDATE_CACHE(re, &s->gb);
00841 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
00842 if (level == -128) {
00843 level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);
00844 } else if (level == 0) {
00845 level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
00846 }
00847 i += run;
00848 j = scantable[i];
00849 if(level<0){
00850 level= -level;
00851 level= ((level*2+1)*qscale)>>1;
00852 level= (level-1)|1;
00853 level= -level;
00854 }else{
00855 level= ((level*2+1)*qscale)>>1;
00856 level= (level-1)|1;
00857 }
00858 }
00859
00860 block[j] = level;
00861 #if MIN_CACHE_BITS < 19
00862 UPDATE_CACHE(re, &s->gb);
00863 #endif
00864 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00865 break;
00866 #if MIN_CACHE_BITS >= 19
00867 UPDATE_CACHE(re, &s->gb);
00868 #endif
00869 }
00870 end:
00871 LAST_SKIP_BITS(re, &s->gb, 2);
00872 CLOSE_READER(re, &s->gb);
00873 }
00874 s->block_last_index[n] = i;
00875 return 0;
00876 }
00877
00878
00879 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
00880 DCTELEM *block,
00881 int n)
00882 {
00883 int level, i, j, run;
00884 RLTable *rl = &ff_rl_mpeg1;
00885 uint8_t * const scantable= s->intra_scantable.permutated;
00886 const uint16_t *quant_matrix;
00887 const int qscale= s->qscale;
00888 int mismatch;
00889
00890 mismatch = 1;
00891
00892 {
00893 OPEN_READER(re, &s->gb);
00894 i = -1;
00895 if (n < 4)
00896 quant_matrix = s->inter_matrix;
00897 else
00898 quant_matrix = s->chroma_inter_matrix;
00899
00900
00901 UPDATE_CACHE(re, &s->gb);
00902 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
00903 level= (3*qscale*quant_matrix[0])>>5;
00904 if(GET_CACHE(re, &s->gb)&0x40000000)
00905 level= -level;
00906 block[0] = level;
00907 mismatch ^= level;
00908 i++;
00909 SKIP_BITS(re, &s->gb, 2);
00910 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00911 goto end;
00912 }
00913 #if MIN_CACHE_BITS < 19
00914 UPDATE_CACHE(re, &s->gb);
00915 #endif
00916
00917
00918 for(;;) {
00919 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
00920
00921 if(level != 0) {
00922 i += run;
00923 j = scantable[i];
00924 level= ((level*2+1)*qscale*quant_matrix[j])>>5;
00925 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
00926 SKIP_BITS(re, &s->gb, 1);
00927 } else {
00928
00929 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
00930 UPDATE_CACHE(re, &s->gb);
00931 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
00932
00933 i += run;
00934 j = scantable[i];
00935 if(level<0){
00936 level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
00937 level= -level;
00938 }else{
00939 level= ((level*2+1)*qscale*quant_matrix[j])>>5;
00940 }
00941 }
00942 if (i > 63){
00943 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
00944 return -1;
00945 }
00946
00947 mismatch ^= level;
00948 block[j] = level;
00949 #if MIN_CACHE_BITS < 19
00950 UPDATE_CACHE(re, &s->gb);
00951 #endif
00952 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00953 break;
00954 #if MIN_CACHE_BITS >= 19
00955 UPDATE_CACHE(re, &s->gb);
00956 #endif
00957 }
00958 end:
00959 LAST_SKIP_BITS(re, &s->gb, 2);
00960 CLOSE_READER(re, &s->gb);
00961 }
00962 block[63] ^= (mismatch & 1);
00963
00964 s->block_last_index[n] = i;
00965 return 0;
00966 }
00967
00968 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
00969 DCTELEM *block,
00970 int n)
00971 {
00972 int level, i, j, run;
00973 RLTable *rl = &ff_rl_mpeg1;
00974 uint8_t * const scantable= s->intra_scantable.permutated;
00975 const int qscale= s->qscale;
00976 OPEN_READER(re, &s->gb);
00977 i = -1;
00978
00979
00980 UPDATE_CACHE(re, &s->gb);
00981 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
00982 level= (3*qscale)>>1;
00983 if(GET_CACHE(re, &s->gb)&0x40000000)
00984 level= -level;
00985 block[0] = level;
00986 i++;
00987 SKIP_BITS(re, &s->gb, 2);
00988 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
00989 goto end;
00990 }
00991 #if MIN_CACHE_BITS < 19
00992 UPDATE_CACHE(re, &s->gb);
00993 #endif
00994
00995
00996 for(;;) {
00997 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
00998
00999 if(level != 0) {
01000 i += run;
01001 j = scantable[i];
01002 level= ((level*2+1)*qscale)>>1;
01003 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01004 SKIP_BITS(re, &s->gb, 1);
01005 } else {
01006
01007 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
01008 UPDATE_CACHE(re, &s->gb);
01009 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
01010
01011 i += run;
01012 j = scantable[i];
01013 if(level<0){
01014 level= ((-level*2+1)*qscale)>>1;
01015 level= -level;
01016 }else{
01017 level= ((level*2+1)*qscale)>>1;
01018 }
01019 }
01020
01021 block[j] = level;
01022 #if MIN_CACHE_BITS < 19
01023 UPDATE_CACHE(re, &s->gb);
01024 #endif
01025 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
01026 break;
01027 #if MIN_CACHE_BITS >=19
01028 UPDATE_CACHE(re, &s->gb);
01029 #endif
01030 }
01031 end:
01032 LAST_SKIP_BITS(re, &s->gb, 2);
01033 CLOSE_READER(re, &s->gb);
01034 s->block_last_index[n] = i;
01035 return 0;
01036 }
01037
01038
01039 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
01040 DCTELEM *block,
01041 int n)
01042 {
01043 int level, dc, diff, i, j, run;
01044 int component;
01045 RLTable *rl;
01046 uint8_t * const scantable= s->intra_scantable.permutated;
01047 const uint16_t *quant_matrix;
01048 const int qscale= s->qscale;
01049 int mismatch;
01050
01051
01052 if (n < 4){
01053 quant_matrix = s->intra_matrix;
01054 component = 0;
01055 }else{
01056 quant_matrix = s->chroma_intra_matrix;
01057 component = (n&1) + 1;
01058 }
01059 diff = decode_dc(&s->gb, component);
01060 if (diff >= 0xffff)
01061 return -1;
01062 dc = s->last_dc[component];
01063 dc += diff;
01064 s->last_dc[component] = dc;
01065 block[0] = dc << (3 - s->intra_dc_precision);
01066 dprintf(s->avctx, "dc=%d\n", block[0]);
01067 mismatch = block[0] ^ 1;
01068 i = 0;
01069 if (s->intra_vlc_format)
01070 rl = &ff_rl_mpeg2;
01071 else
01072 rl = &ff_rl_mpeg1;
01073
01074 {
01075 OPEN_READER(re, &s->gb);
01076
01077 for(;;) {
01078 UPDATE_CACHE(re, &s->gb);
01079 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
01080
01081 if(level == 127){
01082 break;
01083 } else if(level != 0) {
01084 i += run;
01085 j = scantable[i];
01086 level= (level*qscale*quant_matrix[j])>>4;
01087 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01088 LAST_SKIP_BITS(re, &s->gb, 1);
01089 } else {
01090
01091 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
01092 UPDATE_CACHE(re, &s->gb);
01093 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
01094 i += run;
01095 j = scantable[i];
01096 if(level<0){
01097 level= (-level*qscale*quant_matrix[j])>>4;
01098 level= -level;
01099 }else{
01100 level= (level*qscale*quant_matrix[j])>>4;
01101 }
01102 }
01103 if (i > 63){
01104 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
01105 return -1;
01106 }
01107
01108 mismatch^= level;
01109 block[j] = level;
01110 }
01111 CLOSE_READER(re, &s->gb);
01112 }
01113 block[63]^= mismatch&1;
01114
01115 s->block_last_index[n] = i;
01116 return 0;
01117 }
01118
01119 static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
01120 DCTELEM *block,
01121 int n)
01122 {
01123 int level, dc, diff, j, run;
01124 int component;
01125 RLTable *rl;
01126 uint8_t * scantable= s->intra_scantable.permutated;
01127 const uint16_t *quant_matrix;
01128 const int qscale= s->qscale;
01129
01130
01131 if (n < 4){
01132 quant_matrix = s->intra_matrix;
01133 component = 0;
01134 }else{
01135 quant_matrix = s->chroma_intra_matrix;
01136 component = (n&1) + 1;
01137 }
01138 diff = decode_dc(&s->gb, component);
01139 if (diff >= 0xffff)
01140 return -1;
01141 dc = s->last_dc[component];
01142 dc += diff;
01143 s->last_dc[component] = dc;
01144 block[0] = dc << (3 - s->intra_dc_precision);
01145 if (s->intra_vlc_format)
01146 rl = &ff_rl_mpeg2;
01147 else
01148 rl = &ff_rl_mpeg1;
01149
01150 {
01151 OPEN_READER(re, &s->gb);
01152
01153 for(;;) {
01154 UPDATE_CACHE(re, &s->gb);
01155 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
01156
01157 if(level == 127){
01158 break;
01159 } else if(level != 0) {
01160 scantable += run;
01161 j = *scantable;
01162 level= (level*qscale*quant_matrix[j])>>4;
01163 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01164 LAST_SKIP_BITS(re, &s->gb, 1);
01165 } else {
01166
01167 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
01168 UPDATE_CACHE(re, &s->gb);
01169 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
01170 scantable += run;
01171 j = *scantable;
01172 if(level<0){
01173 level= (-level*qscale*quant_matrix[j])>>4;
01174 level= -level;
01175 }else{
01176 level= (level*qscale*quant_matrix[j])>>4;
01177 }
01178 }
01179
01180 block[j] = level;
01181 }
01182 CLOSE_READER(re, &s->gb);
01183 }
01184
01185 s->block_last_index[n] = scantable - s->intra_scantable.permutated;
01186 return 0;
01187 }
01188
01189 typedef struct Mpeg1Context {
01190 MpegEncContext mpeg_enc_ctx;
01191 int mpeg_enc_ctx_allocated;
01192 int repeat_field;
01193 AVPanScan pan_scan;
01194 int slice_count;
01195 int swap_uv;
01196 int save_aspect_info;
01197 int save_width, save_height;
01198 AVRational frame_rate_ext;
01199
01200 } Mpeg1Context;
01201
01202 static int mpeg_decode_init(AVCodecContext *avctx)
01203 {
01204 Mpeg1Context *s = avctx->priv_data;
01205 MpegEncContext *s2 = &s->mpeg_enc_ctx;
01206 int i;
01207
01208
01209
01210
01211 for(i=0;i<64;i++)
01212 s2->dsp.idct_permutation[i]=i;
01213
01214 MPV_decode_defaults(s2);
01215
01216 s->mpeg_enc_ctx.avctx= avctx;
01217 s->mpeg_enc_ctx.flags= avctx->flags;
01218 s->mpeg_enc_ctx.flags2= avctx->flags2;
01219 ff_mpeg12_common_init(&s->mpeg_enc_ctx);
01220 init_vlcs();
01221
01222 s->mpeg_enc_ctx_allocated = 0;
01223 s->mpeg_enc_ctx.picture_number = 0;
01224 s->repeat_field = 0;
01225 s->mpeg_enc_ctx.codec_id= avctx->codec->id;
01226 return 0;
01227 }
01228
01229 static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
01230 const uint8_t *new_perm){
01231 uint16_t temp_matrix[64];
01232 int i;
01233
01234 memcpy(temp_matrix,matrix,64*sizeof(uint16_t));
01235
01236 for(i=0;i<64;i++){
01237 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
01238 }
01239 }
01240
01241
01242
01243 static int mpeg_decode_postinit(AVCodecContext *avctx){
01244 Mpeg1Context *s1 = avctx->priv_data;
01245 MpegEncContext *s = &s1->mpeg_enc_ctx;
01246 uint8_t old_permutation[64];
01247
01248 if (
01249 (s1->mpeg_enc_ctx_allocated == 0)||
01250 avctx->coded_width != s->width ||
01251 avctx->coded_height != s->height||
01252 s1->save_width != s->width ||
01253 s1->save_height != s->height ||
01254 s1->save_aspect_info != s->aspect_ratio_info||
01255 0)
01256 {
01257
01258 if (s1->mpeg_enc_ctx_allocated) {
01259 ParseContext pc= s->parse_context;
01260 s->parse_context.buffer=0;
01261 MPV_common_end(s);
01262 s->parse_context= pc;
01263 }
01264
01265 if( (s->width == 0 )||(s->height == 0))
01266 return -2;
01267
01268 avcodec_set_dimensions(avctx, s->width, s->height);
01269 avctx->bit_rate = s->bit_rate;
01270 s1->save_aspect_info = s->aspect_ratio_info;
01271 s1->save_width = s->width;
01272 s1->save_height = s->height;
01273
01274
01275
01276 avctx->has_b_frames = !(s->low_delay);
01277
01278 if(avctx->sub_id==1){
01279
01280 avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
01281 avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
01282
01283 avctx->sample_aspect_ratio= av_d2q(
01284 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
01285
01286 }else{
01287
01288 av_reduce(
01289 &s->avctx->time_base.den,
01290 &s->avctx->time_base.num,
01291 ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
01292 ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
01293 1<<30);
01294
01295 if(s->aspect_ratio_info > 1){
01296 if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){
01297 s->avctx->sample_aspect_ratio=
01298 av_div_q(
01299 ff_mpeg2_aspect[s->aspect_ratio_info],
01300 (AVRational){s->width, s->height}
01301 );
01302 }else{
01303 s->avctx->sample_aspect_ratio=
01304 av_div_q(
01305 ff_mpeg2_aspect[s->aspect_ratio_info],
01306 (AVRational){s1->pan_scan.width, s1->pan_scan.height}
01307 );
01308 }
01309 }else{
01310 s->avctx->sample_aspect_ratio=
01311 ff_mpeg2_aspect[s->aspect_ratio_info];
01312 }
01313 }
01314
01315 if(avctx->xvmc_acceleration){
01316 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
01317 }else{
01318 if(s->chroma_format < 2){
01319 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
01320 }else
01321 if(s->chroma_format == 2){
01322 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_422);
01323 }else
01324 if(s->chroma_format > 2){
01325 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_444);
01326 }
01327 }
01328
01329 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
01330 if( avctx->idct_algo == FF_IDCT_AUTO )
01331 avctx->idct_algo = FF_IDCT_SIMPLE;
01332
01333
01334
01335 memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
01336
01337 if (MPV_common_init(s) < 0)
01338 return -2;
01339
01340 quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation);
01341 quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation);
01342 quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation);
01343 quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation);
01344
01345 s1->mpeg_enc_ctx_allocated = 1;
01346 }
01347 return 0;
01348 }
01349
01350 static int mpeg1_decode_picture(AVCodecContext *avctx,
01351 const uint8_t *buf, int buf_size)
01352 {
01353 Mpeg1Context *s1 = avctx->priv_data;
01354 MpegEncContext *s = &s1->mpeg_enc_ctx;
01355 int ref, f_code, vbv_delay;
01356
01357 if(mpeg_decode_postinit(s->avctx) < 0)
01358 return -2;
01359
01360 init_get_bits(&s->gb, buf, buf_size*8);
01361
01362 ref = get_bits(&s->gb, 10);
01363 s->pict_type = get_bits(&s->gb, 3);
01364 if(s->pict_type == 0 || s->pict_type > 3)
01365 return -1;
01366
01367 vbv_delay= get_bits(&s->gb, 16);
01368 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
01369 s->full_pel[0] = get_bits1(&s->gb);
01370 f_code = get_bits(&s->gb, 3);
01371 if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
01372 return -1;
01373 s->mpeg_f_code[0][0] = f_code;
01374 s->mpeg_f_code[0][1] = f_code;
01375 }
01376 if (s->pict_type == B_TYPE) {
01377 s->full_pel[1] = get_bits1(&s->gb);
01378 f_code = get_bits(&s->gb, 3);
01379 if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
01380 return -1;
01381 s->mpeg_f_code[1][0] = f_code;
01382 s->mpeg_f_code[1][1] = f_code;
01383 }
01384 s->current_picture.pict_type= s->pict_type;
01385 s->current_picture.key_frame= s->pict_type == I_TYPE;
01386
01387 if(avctx->debug & FF_DEBUG_PICT_INFO)
01388 av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
01389
01390 s->y_dc_scale = 8;
01391 s->c_dc_scale = 8;
01392 s->first_slice = 1;
01393 return 0;
01394 }
01395
01396 static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
01397 {
01398 MpegEncContext *s= &s1->mpeg_enc_ctx;
01399 int horiz_size_ext, vert_size_ext;
01400 int bit_rate_ext;
01401
01402 skip_bits(&s->gb, 1);
01403 s->avctx->profile= get_bits(&s->gb, 3);
01404 s->avctx->level= get_bits(&s->gb, 4);
01405 s->progressive_sequence = get_bits1(&s->gb);
01406 s->chroma_format = get_bits(&s->gb, 2);
01407 horiz_size_ext = get_bits(&s->gb, 2);
01408 vert_size_ext = get_bits(&s->gb, 2);
01409 s->width |= (horiz_size_ext << 12);
01410 s->height |= (vert_size_ext << 12);
01411 bit_rate_ext = get_bits(&s->gb, 12);
01412 s->bit_rate += (bit_rate_ext << 18) * 400;
01413 skip_bits1(&s->gb);
01414 s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
01415
01416 s->low_delay = get_bits1(&s->gb);
01417 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
01418
01419 s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
01420 s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
01421
01422 dprintf(s->avctx, "sequence extension\n");
01423 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
01424 s->avctx->sub_id = 2;
01425
01426 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
01427 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
01428 s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
01429
01430 }
01431
01432 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
01433 {
01434 MpegEncContext *s= &s1->mpeg_enc_ctx;
01435 int color_description, w, h;
01436
01437 skip_bits(&s->gb, 3);
01438 color_description= get_bits1(&s->gb);
01439 if(color_description){
01440 skip_bits(&s->gb, 8);
01441 skip_bits(&s->gb, 8);
01442 skip_bits(&s->gb, 8);
01443 }
01444 w= get_bits(&s->gb, 14);
01445 skip_bits(&s->gb, 1);
01446 h= get_bits(&s->gb, 14);
01447 skip_bits(&s->gb, 1);
01448
01449 s1->pan_scan.width= 16*w;
01450 s1->pan_scan.height=16*h;
01451
01452 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
01453 av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
01454 }
01455
01456 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
01457 {
01458 MpegEncContext *s= &s1->mpeg_enc_ctx;
01459 int i,nofco;
01460
01461 nofco = 1;
01462 if(s->progressive_sequence){
01463 if(s->repeat_first_field){
01464 nofco++;
01465 if(s->top_field_first)
01466 nofco++;
01467 }
01468 }else{
01469 if(s->picture_structure == PICT_FRAME){
01470 nofco++;
01471 if(s->repeat_first_field)
01472 nofco++;
01473 }
01474 }
01475 for(i=0; i<nofco; i++){
01476 s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16);
01477 skip_bits(&s->gb, 1);
01478 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16);
01479 skip_bits(&s->gb, 1);
01480 }
01481
01482 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
01483 av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n",
01484 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
01485 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
01486 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
01487 );
01488 }
01489
01490 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
01491 {
01492 int i, v, j;
01493
01494 dprintf(s->avctx, "matrix extension\n");
01495
01496 if (get_bits1(&s->gb)) {
01497 for(i=0;i<64;i++) {
01498 v = get_bits(&s->gb, 8);
01499 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01500 s->intra_matrix[j] = v;
01501 s->chroma_intra_matrix[j] = v;
01502 }
01503 }
01504 if (get_bits1(&s->gb)) {
01505 for(i=0;i<64;i++) {
01506 v = get_bits(&s->gb, 8);
01507 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01508 s->inter_matrix[j] = v;
01509 s->chroma_inter_matrix[j] = v;
01510 }
01511 }
01512 if (get_bits1(&s->gb)) {
01513 for(i=0;i<64;i++) {
01514 v = get_bits(&s->gb, 8);
01515 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01516 s->chroma_intra_matrix[j] = v;
01517 }
01518 }
01519 if (get_bits1(&s->gb)) {
01520 for(i=0;i<64;i++) {
01521 v = get_bits(&s->gb, 8);
01522 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01523 s->chroma_inter_matrix[j] = v;
01524 }
01525 }
01526 }
01527
01528 static void mpeg_decode_picture_coding_extension(MpegEncContext *s)
01529 {
01530 s->full_pel[0] = s->full_pel[1] = 0;
01531 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
01532 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
01533 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
01534 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
01535 s->intra_dc_precision = get_bits(&s->gb, 2);
01536 s->picture_structure = get_bits(&s->gb, 2);
01537 s->top_field_first = get_bits1(&s->gb);
01538 s->frame_pred_frame_dct = get_bits1(&s->gb);
01539 s->concealment_motion_vectors = get_bits1(&s->gb);
01540 s->q_scale_type = get_bits1(&s->gb);
01541 s->intra_vlc_format = get_bits1(&s->gb);
01542 s->alternate_scan = get_bits1(&s->gb);
01543 s->repeat_first_field = get_bits1(&s->gb);
01544 s->chroma_420_type = get_bits1(&s->gb);
01545 s->progressive_frame = get_bits1(&s->gb);
01546
01547 if(s->picture_structure == PICT_FRAME){
01548 s->first_field=0;
01549 s->v_edge_pos= 16*s->mb_height;
01550 }else{
01551 s->first_field ^= 1;
01552 s->v_edge_pos= 8*s->mb_height;
01553 memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
01554 }
01555
01556 if(s->alternate_scan){
01557 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
01558 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
01559 }else{
01560 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
01561 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
01562 }
01563
01564
01565 dprintf(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
01566 dprintf(s->avctx, "picture_structure=%d\n", s->picture_structure);
01567 dprintf(s->avctx, "top field first=%d\n", s->top_field_first);
01568 dprintf(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
01569 dprintf(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
01570 dprintf(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
01571 dprintf(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
01572 dprintf(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
01573 dprintf(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
01574 }
01575
01576 static void mpeg_decode_extension(AVCodecContext *avctx,
01577 const uint8_t *buf, int buf_size)
01578 {
01579 Mpeg1Context *s1 = avctx->priv_data;
01580 MpegEncContext *s = &s1->mpeg_enc_ctx;
01581 int ext_type;
01582
01583 init_get_bits(&s->gb, buf, buf_size*8);
01584
01585 ext_type = get_bits(&s->gb, 4);
01586 switch(ext_type) {
01587 case 0x1:
01588 mpeg_decode_sequence_extension(s1);
01589 break;
01590 case 0x2:
01591 mpeg_decode_sequence_display_extension(s1);
01592 break;
01593 case 0x3:
01594 mpeg_decode_quant_matrix_extension(s);
01595 break;
01596 case 0x7:
01597 mpeg_decode_picture_display_extension(s1);
01598 break;
01599 case 0x8:
01600 mpeg_decode_picture_coding_extension(s);
01601 break;
01602 }
01603 }
01604
01605 static void exchange_uv(MpegEncContext *s){
01606 short * tmp = s->pblocks[4];
01607 s->pblocks[4] = s->pblocks[5];
01608 s->pblocks[5] = tmp;
01609 }
01610
01611 static int mpeg_field_start(MpegEncContext *s){
01612 AVCodecContext *avctx= s->avctx;
01613 Mpeg1Context *s1 = (Mpeg1Context*)s;
01614
01615
01616 if(s->first_field || s->picture_structure==PICT_FRAME){
01617 if(MPV_frame_start(s, avctx) < 0)
01618 return -1;
01619
01620 ff_er_frame_start(s);
01621
01622
01623 s->current_picture_ptr->repeat_pict = 0;
01624 if (s->repeat_first_field) {
01625 if (s->progressive_sequence) {
01626 if (s->top_field_first)
01627 s->current_picture_ptr->repeat_pict = 4;
01628 else
01629 s->current_picture_ptr->repeat_pict = 2;
01630 } else if (s->progressive_frame) {
01631 s->current_picture_ptr->repeat_pict = 1;
01632 }
01633 }
01634
01635 *s->current_picture_ptr->pan_scan= s1->pan_scan;
01636 }else{
01637 int i;
01638
01639 if(!s->current_picture_ptr){
01640 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
01641 return -1;
01642 }
01643
01644 for(i=0; i<4; i++){
01645 s->current_picture.data[i] = s->current_picture_ptr->data[i];
01646 if(s->picture_structure == PICT_BOTTOM_FIELD){
01647 s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
01648 }
01649 }
01650 }
01651 #ifdef HAVE_XVMC
01652
01653
01654 if(s->avctx->xvmc_acceleration)
01655 XVMC_field_start(s,avctx);
01656 #endif
01657
01658 return 0;
01659 }
01660
01661 #define DECODE_SLICE_ERROR -1
01662 #define DECODE_SLICE_OK 0
01663
01669 static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
01670 const uint8_t **buf, int buf_size)
01671 {
01672 MpegEncContext *s = &s1->mpeg_enc_ctx;
01673 AVCodecContext *avctx= s->avctx;
01674 const int field_pic= s->picture_structure != PICT_FRAME;
01675 const int lowres= s->avctx->lowres;
01676
01677 s->resync_mb_x=
01678 s->resync_mb_y= -1;
01679
01680 if (mb_y<<field_pic >= s->mb_height){
01681 av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height);
01682 return -1;
01683 }
01684
01685 init_get_bits(&s->gb, *buf, buf_size*8);
01686
01687 ff_mpeg1_clean_buffers(s);
01688 s->interlaced_dct = 0;
01689
01690 s->qscale = get_qscale(s);
01691
01692 if(s->qscale == 0){
01693 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
01694 return -1;
01695 }
01696
01697
01698 while (get_bits1(&s->gb) != 0) {
01699 skip_bits(&s->gb, 8);
01700 }
01701
01702 s->mb_x=0;
01703
01704 for(;;) {
01705 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
01706 if (code < 0){
01707 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
01708 return -1;
01709 }
01710 if (code >= 33) {
01711 if (code == 33) {
01712 s->mb_x += 33;
01713 }
01714
01715 } else {
01716 s->mb_x += code;
01717 break;
01718 }
01719 }
01720 if(s->mb_x >= (unsigned)s->mb_width){
01721 av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
01722 return -1;
01723 }
01724
01725 s->resync_mb_x= s->mb_x;
01726 s->resync_mb_y= s->mb_y= mb_y;
01727 s->mb_skip_run= 0;
01728 ff_init_block_index(s);
01729
01730 if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
01731 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
01732 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
01733 s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
01734 s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
01735 s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
01736 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
01737 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
01738 }
01739 }
01740
01741 for(;;) {
01742 #ifdef HAVE_XVMC
01743
01744 if(s->avctx->xvmc_acceleration > 1)
01745 XVMC_init_block(s);
01746 #endif
01747
01748 if(mpeg_decode_mb(s, s->block) < 0)
01749 return -1;
01750
01751 if(s->current_picture.motion_val[0] && !s->encoding){
01752 const int wrap = field_pic ? 2*s->b8_stride : s->b8_stride;
01753 int xy = s->mb_x*2 + s->mb_y*2*wrap;
01754 int motion_x, motion_y, dir, i;
01755 if(field_pic && !s->first_field)
01756 xy += wrap/2;
01757
01758 for(i=0; i<2; i++){
01759 for(dir=0; dir<2; dir++){
01760 if (s->mb_intra || (dir==1 && s->pict_type != B_TYPE)) {
01761 motion_x = motion_y = 0;
01762 }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
01763 motion_x = s->mv[dir][0][0];
01764 motion_y = s->mv[dir][0][1];
01765 } else {
01766 motion_x = s->mv[dir][i][0];
01767 motion_y = s->mv[dir][i][1];
01768 }
01769
01770 s->current_picture.motion_val[dir][xy ][0] = motion_x;
01771 s->current_picture.motion_val[dir][xy ][1] = motion_y;
01772 s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
01773 s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
01774 s->current_picture.ref_index [dir][xy ]=
01775 s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i];
01776 assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
01777 }
01778 xy += wrap;
01779 }
01780 }
01781
01782 s->dest[0] += 16 >> lowres;
01783 s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
01784 s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
01785
01786 MPV_decode_mb(s, s->block);
01787
01788 if (++s->mb_x >= s->mb_width) {
01789 const int mb_size= 16>>s->avctx->lowres;
01790
01791 ff_draw_horiz_band(s, mb_size*s->mb_y, mb_size);
01792
01793 s->mb_x = 0;
01794 s->mb_y++;
01795
01796 if(s->mb_y<<field_pic >= s->mb_height){
01797 int left= s->gb.size_in_bits - get_bits_count(&s->gb);
01798 int is_d10= s->chroma_format==2 && s->pict_type==I_TYPE && avctx->profile==0 && avctx->level==5
01799 && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0
01800 && s->progressive_frame == 0 ;
01801
01802 if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
01803 || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){
01804 av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
01805 return -1;
01806 }else
01807 goto eos;
01808 }
01809
01810 ff_init_block_index(s);
01811 }
01812
01813
01814 if (s->mb_skip_run == -1) {
01815
01816 s->mb_skip_run = 0;
01817 for(;;) {
01818 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
01819 if (code < 0){
01820 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
01821 return -1;
01822 }
01823 if (code >= 33) {
01824 if (code == 33) {
01825 s->mb_skip_run += 33;
01826 }else if(code == 35){
01827 if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
01828 av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
01829 return -1;
01830 }
01831 goto eos;
01832 }
01833
01834 } else {
01835 s->mb_skip_run += code;
01836 break;
01837 }
01838 }
01839 if(s->mb_skip_run){
01840 int i;
01841 if(s->pict_type == I_TYPE){
01842 av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
01843 return -1;
01844 }
01845
01846
01847 s->mb_intra = 0;
01848 for(i=0;i<12;i++)
01849 s->block_last_index[i] = -1;
01850 if(s->picture_structure == PICT_FRAME)
01851 s->mv_type = MV_TYPE_16X16;
01852 else
01853 s->mv_type = MV_TYPE_FIELD;
01854 if (s->pict_type == P_TYPE) {
01855
01856 s->mv_dir = MV_DIR_FORWARD;
01857 s->mv[0][0][0] = s->mv[0][0][1] = 0;
01858 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
01859 s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
01860 s->field_select[0][0]= s->picture_structure - 1;
01861 } else {
01862
01863 s->mv[0][0][0] = s->last_mv[0][0][0];
01864 s->mv[0][0][1] = s->last_mv[0][0][1];
01865 s->mv[1][0][0] = s->last_mv[1][0][0];
01866 s->mv[1][0][1] = s->last_mv[1][0][1];
01867 }
01868 }
01869 }
01870 }
01871 eos:
01872 *buf += get_bits_count(&s->gb)/8 - 1;
01873
01874 return 0;
01875 }
01876
01877 static int slice_decode_thread(AVCodecContext *c, void *arg){
01878 MpegEncContext *s= arg;
01879 const uint8_t *buf= s->gb.buffer;
01880 int mb_y= s->start_mb_y;
01881
01882 s->error_count= 3*(s->end_mb_y - s->start_mb_y)*s->mb_width;
01883
01884 for(;;){
01885 uint32_t start_code;
01886 int ret;
01887
01888 ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
01889 emms_c();
01890
01891
01892 if(ret < 0){
01893 if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
01894 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
01895 }else{
01896 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
01897 }
01898
01899 if(s->mb_y == s->end_mb_y)
01900 return 0;
01901
01902 start_code= -1;
01903 buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
01904 mb_y= start_code - SLICE_MIN_START_CODE;
01905 if(mb_y < 0 || mb_y >= s->end_mb_y)
01906 return -1;
01907 }
01908
01909 return 0;
01910 }
01911
01916 static int slice_end(AVCodecContext *avctx, AVFrame *pict)
01917 {
01918 Mpeg1Context *s1 = avctx->priv_data;
01919 MpegEncContext *s = &s1->mpeg_enc_ctx;
01920
01921 if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
01922 return 0;
01923
01924 #ifdef HAVE_XVMC
01925 if(s->avctx->xvmc_acceleration)
01926 XVMC_field_end(s);
01927 #endif
01928
01929 if ( !s->first_field) {
01930
01931
01932 s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
01933
01934 ff_er_frame_end(s);
01935
01936 MPV_frame_end(s);
01937
01938 if (s->pict_type == B_TYPE || s->low_delay) {
01939 *pict= *(AVFrame*)s->current_picture_ptr;
01940 ff_print_debug_info(s, pict);
01941 } else {
01942 s->picture_number++;
01943
01944
01945 if (s->last_picture_ptr != NULL) {
01946 *pict= *(AVFrame*)s->last_picture_ptr;
01947 ff_print_debug_info(s, pict);
01948 }
01949 }
01950
01951 return 1;
01952 } else {
01953 return 0;
01954 }
01955 }
01956
01957 static int mpeg1_decode_sequence(AVCodecContext *avctx,
01958 const uint8_t *buf, int buf_size)
01959 {
01960 Mpeg1Context *s1 = avctx->priv_data;
01961 MpegEncContext *s = &s1->mpeg_enc_ctx;
01962 int width,height;
01963 int i, v, j;
01964
01965 init_get_bits(&s->gb, buf, buf_size*8);
01966
01967 width = get_bits(&s->gb, 12);
01968 height = get_bits(&s->gb, 12);
01969 if (width <= 0 || height <= 0 ||
01970 (width % 2) != 0 || (height % 2) != 0)
01971 return -1;
01972 s->aspect_ratio_info= get_bits(&s->gb, 4);
01973 if (s->aspect_ratio_info == 0)
01974 return -1;
01975 s->frame_rate_index = get_bits(&s->gb, 4);
01976 if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
01977 return -1;
01978 s->bit_rate = get_bits(&s->gb, 18) * 400;
01979 if (get_bits1(&s->gb) == 0)
01980 return -1;
01981 s->width = width;
01982 s->height = height;
01983
01984 s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
01985 skip_bits(&s->gb, 1);
01986
01987
01988 if (get_bits1(&s->gb)) {
01989 for(i=0;i<64;i++) {
01990 v = get_bits(&s->gb, 8);
01991 if(v==0){
01992 av_log(s->avctx, AV_LOG_ERROR, "intra matrix damaged\n");
01993 return -1;
01994 }
01995 j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01996 s->intra_matrix[j] = v;
01997 s->chroma_intra_matrix[j] = v;
01998 }
01999 #ifdef DEBUG
02000 dprintf(s->avctx, "intra matrix present\n");
02001 for(i=0;i<64;i++)
02002 dprintf(s->avctx, " %d", s->intra_matrix[s->dsp.idct_permutation[i]]);
02003 dprintf(s->avctx, "\n");
02004 #endif
02005 } else {
02006 for(i=0;i<64;i++) {
02007 j = s->dsp.idct_permutation[i];
02008 v = ff_mpeg1_default_intra_matrix[i];
02009 s->intra_matrix[j] = v;
02010 s->chroma_intra_matrix[j] = v;
02011 }
02012 }
02013 if (get_bits1(&s->gb)) {
02014 for(i=0;i<64;i++) {
02015 v = get_bits(&s->gb, 8);
02016 if(v==0){
02017 av_log(s->avctx, AV_LOG_ERROR, "inter matrix damaged\n");
02018 return -1;
02019 }
02020 j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
02021 s->inter_matrix[j] = v;
02022 s->chroma_inter_matrix[j] = v;
02023 }
02024 #ifdef DEBUG
02025 dprintf(s->avctx, "non intra matrix present\n");
02026 for(i=0;i<64;i++)
02027 dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]);
02028 dprintf(s->avctx, "\n");
02029 #endif
02030 } else {
02031 for(i=0;i<64;i++) {
02032 int j= s->dsp.idct_permutation[i];
02033 v = ff_mpeg1_default_non_intra_matrix[i];
02034 s->inter_matrix[j] = v;
02035 s->chroma_inter_matrix[j] = v;
02036 }
02037 }
02038
02039 if(show_bits(&s->gb, 23) != 0){
02040 av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
02041 return -1;
02042 }
02043
02044
02045 s->progressive_sequence = 1;
02046 s->progressive_frame = 1;
02047 s->picture_structure = PICT_FRAME;
02048 s->frame_pred_frame_dct = 1;
02049 s->chroma_format = 1;
02050 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
02051 avctx->sub_id = 1;
02052 s->out_format = FMT_MPEG1;
02053 s->swap_uv = 0;
02054 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
02055
02056 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
02057 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
02058 s->avctx->rc_buffer_size, s->bit_rate);
02059
02060 return 0;
02061 }
02062
02063 static int vcr2_init_sequence(AVCodecContext *avctx)
02064 {
02065 Mpeg1Context *s1 = avctx->priv_data;
02066 MpegEncContext *s = &s1->mpeg_enc_ctx;
02067 int i, v;
02068
02069
02070 s->out_format = FMT_MPEG1;
02071 if (s1->mpeg_enc_ctx_allocated) {
02072 MPV_common_end(s);
02073 }
02074 s->width = avctx->coded_width;
02075 s->height = avctx->coded_height;
02076 avctx->has_b_frames= 0;
02077 s->low_delay= 1;
02078
02079 if(avctx->xvmc_acceleration){
02080 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
02081 }else{
02082 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420);
02083 }
02084
02085 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
02086 if( avctx->idct_algo == FF_IDCT_AUTO )
02087 avctx->idct_algo = FF_IDCT_SIMPLE;
02088
02089 if (MPV_common_init(s) < 0)
02090 return -1;
02091 exchange_uv(s);
02092 s->swap_uv = 1;
02093 s1->mpeg_enc_ctx_allocated = 1;
02094
02095 for(i=0;i<64;i++) {
02096 int j= s->dsp.idct_permutation[i];
02097 v = ff_mpeg1_default_intra_matrix[i];
02098 s->intra_matrix[j] = v;
02099 s->chroma_intra_matrix[j] = v;
02100
02101 v = ff_mpeg1_default_non_intra_matrix[i];
02102 s->inter_matrix[j] = v;
02103 s->chroma_inter_matrix[j] = v;
02104 }
02105
02106 s->progressive_sequence = 1;
02107 s->progressive_frame = 1;
02108 s->picture_structure = PICT_FRAME;
02109 s->frame_pred_frame_dct = 1;
02110 s->chroma_format = 1;
02111 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
02112 avctx->sub_id = 2;
02113 return 0;
02114 }
02115
02116
02117 static void mpeg_decode_user_data(AVCodecContext *avctx,
02118 const uint8_t *buf, int buf_size)
02119 {
02120 const uint8_t *p;
02121 int len, flags;
02122 p = buf;
02123 len = buf_size;
02124
02125
02126 if (len >= 5 &&
02127 p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
02128 flags = p[4];
02129 p += 5;
02130 len -= 5;
02131 if (flags & 0x80) {
02132
02133 if (len < 2)
02134 return;
02135 p += 2;
02136 len -= 2;
02137 }
02138 if (flags & 0x40) {
02139 if (len < 1)
02140 return;
02141 avctx->dtg_active_format = p[0] & 0x0f;
02142 }
02143 }
02144 }
02145
02146 static void mpeg_decode_gop(AVCodecContext *avctx,
02147 const uint8_t *buf, int buf_size){
02148 Mpeg1Context *s1 = avctx->priv_data;
02149 MpegEncContext *s = &s1->mpeg_enc_ctx;
02150
02151 int drop_frame_flag;
02152 int time_code_hours, time_code_minutes;
02153 int time_code_seconds, time_code_pictures;
02154 int broken_link;
02155
02156 init_get_bits(&s->gb, buf, buf_size*8);
02157
02158 drop_frame_flag = get_bits1(&s->gb);
02159
02160 time_code_hours=get_bits(&s->gb,5);
02161 time_code_minutes = get_bits(&s->gb,6);
02162 skip_bits1(&s->gb);
02163 time_code_seconds = get_bits(&s->gb,6);
02164 time_code_pictures = get_bits(&s->gb,6);
02165
02166
02167
02168
02169 broken_link = get_bits1(&s->gb);
02170
02171 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
02172 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n",
02173 time_code_hours, time_code_minutes, time_code_seconds,
02174 time_code_pictures, broken_link);
02175 }
02180 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
02181 {
02182 int i;
02183 uint32_t state= pc->state;
02184
02185 i=0;
02186 if(!pc->frame_start_found){
02187 for(i=0; i<buf_size; i++){
02188 i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
02189 if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
02190 i++;
02191 pc->frame_start_found=1;
02192 break;
02193 }
02194 if(state == SEQ_END_CODE){
02195 pc->state=-1;
02196 return i+1;
02197 }
02198 }
02199 }
02200
02201 if(pc->frame_start_found){
02202
02203 if (buf_size == 0)
02204 return 0;
02205 for(; i<buf_size; i++){
02206 i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
02207 if((state&0xFFFFFF00) == 0x100){
02208 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
02209 pc->frame_start_found=0;
02210 pc->state=-1;
02211 return i-3;
02212 }
02213 }
02214 }
02215 }
02216 pc->state= state;
02217 return END_NOT_FOUND;
02218 }
02219
02220
02221 static int mpeg_decode_frame(AVCodecContext *avctx,
02222 void *data, int *data_size,
02223 const uint8_t *buf, int buf_size)
02224 {
02225 Mpeg1Context *s = avctx->priv_data;
02226 const uint8_t *buf_end;
02227 const uint8_t *buf_ptr;
02228 uint32_t start_code;
02229 int ret, input_size;
02230 AVFrame *picture = data;
02231 MpegEncContext *s2 = &s->mpeg_enc_ctx;
02232 dprintf(avctx, "fill_buffer\n");
02233
02234 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
02235
02236 if (s2->low_delay==0 && s2->next_picture_ptr) {
02237 *picture= *(AVFrame*)s2->next_picture_ptr;
02238 s2->next_picture_ptr= NULL;
02239
02240 *data_size = sizeof(AVFrame);
02241 }
02242 return buf_size;
02243 }
02244
02245 if(s2->flags&CODEC_FLAG_TRUNCATED){
02246 int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size);
02247
02248 if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
02249 return buf_size;
02250 }
02251
02252 buf_ptr = buf;
02253 buf_end = buf + buf_size;
02254
02255 #if 0
02256 if (s->repeat_field % 2 == 1) {
02257 s->repeat_field++;
02258
02259
02260 if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {
02261 *data_size = sizeof(AVPicture);
02262 goto the_end;
02263 }
02264 }
02265 #endif
02266
02267 if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2"))
02268 vcr2_init_sequence(avctx);
02269
02270 s->slice_count= 0;
02271
02272 for(;;) {
02273
02274 start_code = -1;
02275 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
02276 if (start_code > 0x1ff){
02277 if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
02278 if(avctx->thread_count > 1){
02279 int i;
02280
02281 avctx->execute(avctx, slice_decode_thread, (void**)&(s2->thread_context[0]), NULL, s->slice_count);
02282 for(i=0; i<s->slice_count; i++)
02283 s2->error_count += s2->thread_context[i]->error_count;
02284 }
02285 if (slice_end(avctx, picture)) {
02286 if(s2->last_picture_ptr || s2->low_delay)
02287 *data_size = sizeof(AVPicture);
02288 }
02289 }
02290 return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
02291 }
02292
02293 input_size = buf_end - buf_ptr;
02294
02295 if(avctx->debug & FF_DEBUG_STARTCODE){
02296 av_log(avctx, AV_LOG_DEBUG, "%3X at %zd left %d\n", start_code, buf_ptr-buf, input_size);
02297 }
02298
02299
02300 switch(start_code) {
02301 case SEQ_START_CODE:
02302 mpeg1_decode_sequence(avctx, buf_ptr,
02303 input_size);
02304 break;
02305
02306 case PICTURE_START_CODE:
02307
02308 mpeg1_decode_picture(avctx,
02309 buf_ptr, input_size);
02310 break;
02311 case EXT_START_CODE:
02312 mpeg_decode_extension(avctx,
02313 buf_ptr, input_size);
02314 break;
02315 case USER_START_CODE:
02316 mpeg_decode_user_data(avctx,
02317 buf_ptr, input_size);
02318 break;
02319 case GOP_START_CODE:
02320 s2->first_field=0;
02321 mpeg_decode_gop(avctx,
02322 buf_ptr, input_size);
02323 break;
02324 default:
02325 if (start_code >= SLICE_MIN_START_CODE &&
02326 start_code <= SLICE_MAX_START_CODE) {
02327 int mb_y= start_code - SLICE_MIN_START_CODE;
02328
02329 if(s2->last_picture_ptr==NULL){
02330
02331 if(s2->pict_type==B_TYPE) break;
02332 }
02333 if(s2->next_picture_ptr==NULL){
02334
02335 if(s2->pict_type==P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break;
02336 }
02337
02338 if(avctx->hurry_up && s2->pict_type==B_TYPE) break;
02339 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==B_TYPE)
02340 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=I_TYPE)
02341 || avctx->skip_frame >= AVDISCARD_ALL)
02342 break;
02343
02344 if(avctx->hurry_up>=5) break;
02345
02346 if (!s->mpeg_enc_ctx_allocated) break;
02347
02348 if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
02349 if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
02350 break;
02351 }
02352
02353 if(s2->first_slice){
02354 s2->first_slice=0;
02355 if(mpeg_field_start(s2) < 0)
02356 return -1;
02357 }
02358 if(!s2->current_picture_ptr){
02359 av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
02360 return -1;
02361 }
02362
02363 if(avctx->thread_count > 1){
02364 int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
02365 if(threshold <= mb_y){
02366 MpegEncContext *thread_context= s2->thread_context[s->slice_count];
02367
02368 thread_context->start_mb_y= mb_y;
02369 thread_context->end_mb_y = s2->mb_height;
02370 if(s->slice_count){
02371 s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
02372 ff_update_duplicate_context(thread_context, s2);
02373 }
02374 init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
02375 s->slice_count++;
02376 }
02377 buf_ptr += 2;
02378 }else{
02379 ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
02380 emms_c();
02381
02382 if(ret < 0){
02383 if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
02384 ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
02385 }else{
02386 ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END);
02387 }
02388 }
02389 }
02390 break;
02391 }
02392 }
02393 }
02394
02395 static int mpeg_decode_end(AVCodecContext *avctx)
02396 {
02397 Mpeg1Context *s = avctx->priv_data;
02398
02399 if (s->mpeg_enc_ctx_allocated)
02400 MPV_common_end(&s->mpeg_enc_ctx);
02401 return 0;
02402 }
02403
02404 AVCodec mpeg1video_decoder = {
02405 "mpeg1video",
02406 CODEC_TYPE_VIDEO,
02407 CODEC_ID_MPEG1VIDEO,
02408 sizeof(Mpeg1Context),
02409 mpeg_decode_init,
02410 NULL,
02411 mpeg_decode_end,
02412 mpeg_decode_frame,
02413 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
02414 .flush= ff_mpeg_flush,
02415 };
02416
02417 AVCodec mpeg2video_decoder = {
02418 "mpeg2video",
02419 CODEC_TYPE_VIDEO,
02420 CODEC_ID_MPEG2VIDEO,
02421 sizeof(Mpeg1Context),
02422 mpeg_decode_init,
02423 NULL,
02424 mpeg_decode_end,
02425 mpeg_decode_frame,
02426 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
02427 .flush= ff_mpeg_flush,
02428 };
02429
02430
02431 AVCodec mpegvideo_decoder = {
02432 "mpegvideo",
02433 CODEC_TYPE_VIDEO,
02434 CODEC_ID_MPEG2VIDEO,
02435 sizeof(Mpeg1Context),
02436 mpeg_decode_init,
02437 NULL,
02438 mpeg_decode_end,
02439 mpeg_decode_frame,
02440 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
02441 .flush= ff_mpeg_flush,
02442 };
02443
02444 #ifdef HAVE_XVMC
02445 static int mpeg_mc_decode_init(AVCodecContext *avctx){
02446 Mpeg1Context *s;
02447
02448 if( avctx->thread_count > 1)
02449 return -1;
02450 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
02451 return -1;
02452 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
02453 dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
02454 }
02455 mpeg_decode_init(avctx);
02456 s = avctx->priv_data;
02457
02458 avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
02459 avctx->xvmc_acceleration = 2;
02460
02461 return 0;
02462 }
02463
02464 AVCodec mpeg_xvmc_decoder = {
02465 "mpegvideo_xvmc",
02466 CODEC_TYPE_VIDEO,
02467 CODEC_ID_MPEG2VIDEO_XVMC,
02468 sizeof(Mpeg1Context),
02469 mpeg_mc_decode_init,
02470 NULL,
02471 mpeg_decode_end,
02472 mpeg_decode_frame,
02473 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
02474 .flush= ff_mpeg_flush,
02475 };
02476
02477 #endif
02478
02479
02480
02481
02482 #include "mdec.c"