comparison mpeg12.c @ 7629:1d04f38681bd libavcodec

cosmetics: comment spelling/grammar fixes
author diego
date Wed, 20 Aug 2008 16:59:26 +0000
parents 0bd920dcb7a5
children d6390123201d
comparison
equal deleted inserted replaced
7628:2f5ed95d1039 7629:1d04f38681bd
1 /* 1 /*
2 * MPEG1/2 decoder 2 * MPEG-1/2 decoder
3 * Copyright (c) 2000,2001 Fabrice Bellard. 3 * Copyright (c) 2000,2001 Fabrice Bellard.
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 * 5 *
6 * This file is part of FFmpeg. 6 * This file is part of FFmpeg.
7 * 7 *
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 21 */
22 22
23 /** 23 /**
24 * @file mpeg12.c 24 * @file mpeg12.c
25 * MPEG1/2 decoder 25 * MPEG-1/2 decoder
26 */ 26 */
27 27
28 //#define DEBUG 28 //#define DEBUG
29 #include "avcodec.h" 29 #include "avcodec.h"
30 #include "dsputil.h" 30 #include "dsputil.h"
201 } else { 201 } else {
202 return qscale << 1; 202 return qscale << 1;
203 } 203 }
204 } 204 }
205 205
206 /* motion type (for mpeg2) */ 206 /* motion type (for MPEG-2) */
207 #define MT_FIELD 1 207 #define MT_FIELD 1
208 #define MT_FRAME 2 208 #define MT_FRAME 2
209 #define MT_16X8 2 209 #define MT_16X8 2
210 #define MT_DMV 3 210 #define MT_DMV 3
211 211
227 int mb_type; 227 int mb_type;
228 228
229 if(s->mb_x) 229 if(s->mb_x)
230 mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]; 230 mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
231 else 231 else
232 mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in mpeg at all, 232 mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all
233 if(IS_INTRA(mb_type)) 233 if(IS_INTRA(mb_type))
234 return -1; 234 return -1;
235 235
236 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= 236 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
237 mb_type | MB_TYPE_SKIP; 237 mb_type | MB_TYPE_SKIP;
281 281
282 if(!s->chroma_y_shift){ 282 if(!s->chroma_y_shift){
283 s->dsp.clear_blocks(s->block[6]); 283 s->dsp.clear_blocks(s->block[6]);
284 } 284 }
285 285
286 /* compute dct type */ 286 /* compute DCT type */
287 if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? 287 if (s->picture_structure == PICT_FRAME && //FIXME add an interlaced_dct coded var?
288 !s->frame_pred_frame_dct) { 288 !s->frame_pred_frame_dct) {
289 s->interlaced_dct = get_bits1(&s->gb); 289 s->interlaced_dct = get_bits1(&s->gb);
290 } 290 }
291 291
292 if (IS_QUANT(mb_type)) 292 if (IS_QUANT(mb_type))
305 skip_bits1(&s->gb); /* marker */ 305 skip_bits1(&s->gb); /* marker */
306 }else 306 }else
307 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ 307 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
308 s->mb_intra = 1; 308 s->mb_intra = 1;
309 #ifdef HAVE_XVMC 309 #ifdef HAVE_XVMC
310 //one 1 we memcpy blocks in xvmcvideo 310 //if 1, we memcpy blocks in xvmcvideo
311 if(s->avctx->xvmc_acceleration > 1){ 311 if(s->avctx->xvmc_acceleration > 1){
312 XVMC_pack_pblocks(s,-1);//inter are always full blocks 312 XVMC_pack_pblocks(s,-1);//inter are always full blocks
313 if(s->swap_uv){ 313 if(s->swap_uv){
314 exchange_uv(s); 314 exchange_uv(s);
315 } 315 }
385 /* MT_FRAME */ 385 /* MT_FRAME */
386 s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] = 386 s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
387 mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); 387 mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
388 s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] = 388 s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
389 mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]); 389 mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
390 /* full_pel: only for mpeg1 */ 390 /* full_pel: only for MPEG-1 */
391 if (s->full_pel[i]){ 391 if (s->full_pel[i]){
392 s->mv[i][0][0] <<= 1; 392 s->mv[i][0][0] <<= 1;
393 s->mv[i][0][1] <<= 1; 393 s->mv[i][0][1] <<= 1;
394 } 394 }
395 } 395 }
518 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); 518 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
519 return -1; 519 return -1;
520 } 520 }
521 521
522 #ifdef HAVE_XVMC 522 #ifdef HAVE_XVMC
523 //on 1 we memcpy blocks in xvmcvideo 523 //if 1, we memcpy blocks in xvmcvideo
524 if(s->avctx->xvmc_acceleration > 1){ 524 if(s->avctx->xvmc_acceleration > 1){
525 XVMC_pack_pblocks(s,cbp); 525 XVMC_pack_pblocks(s,cbp);
526 if(s->swap_uv){ 526 if(s->swap_uv){
527 exchange_uv(s); 527 exchange_uv(s);
528 } 528 }
583 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type; 583 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
584 584
585 return 0; 585 return 0;
586 } 586 }
587 587
588 /* as h263, but only 17 codes */ 588 /* as H.263, but only 17 codes */
589 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) 589 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
590 { 590 {
591 int code, sign, val, l, shift; 591 int code, sign, val, l, shift;
592 592
593 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); 593 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
625 RLTable *rl = &ff_rl_mpeg1; 625 RLTable *rl = &ff_rl_mpeg1;
626 uint8_t * const scantable= s->intra_scantable.permutated; 626 uint8_t * const scantable= s->intra_scantable.permutated;
627 const uint16_t *quant_matrix= s->intra_matrix; 627 const uint16_t *quant_matrix= s->intra_matrix;
628 const int qscale= s->qscale; 628 const int qscale= s->qscale;
629 629
630 /* DC coef */ 630 /* DC coefficient */
631 component = (n <= 3 ? 0 : n - 4 + 1); 631 component = (n <= 3 ? 0 : n - 4 + 1);
632 diff = decode_dc(&s->gb, component); 632 diff = decode_dc(&s->gb, component);
633 if (diff >= 0xffff) 633 if (diff >= 0xffff)
634 return -1; 634 return -1;
635 dc = s->last_dc[component]; 635 dc = s->last_dc[component];
638 block[0] = dc<<3; 638 block[0] = dc<<3;
639 dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff); 639 dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff);
640 i = 0; 640 i = 0;
641 { 641 {
642 OPEN_READER(re, &s->gb); 642 OPEN_READER(re, &s->gb);
643 /* now quantify & encode AC coefs */ 643 /* now quantify & encode AC coefficients */
644 for(;;) { 644 for(;;) {
645 UPDATE_CACHE(re, &s->gb); 645 UPDATE_CACHE(re, &s->gb);
646 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 646 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
647 647
648 if(level == 127){ 648 if(level == 127){
700 const int qscale= s->qscale; 700 const int qscale= s->qscale;
701 701
702 { 702 {
703 OPEN_READER(re, &s->gb); 703 OPEN_READER(re, &s->gb);
704 i = -1; 704 i = -1;
705 /* special case for the first coef. no need to add a second vlc table */ 705 // special case for first coefficient, no need to add second VLC table
706 UPDATE_CACHE(re, &s->gb); 706 UPDATE_CACHE(re, &s->gb);
707 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { 707 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
708 level= (3*qscale*quant_matrix[0])>>5; 708 level= (3*qscale*quant_matrix[0])>>5;
709 level= (level-1)|1; 709 level= (level-1)|1;
710 if(GET_CACHE(re, &s->gb)&0x40000000) 710 if(GET_CACHE(re, &s->gb)&0x40000000)
716 goto end; 716 goto end;
717 } 717 }
718 #if MIN_CACHE_BITS < 19 718 #if MIN_CACHE_BITS < 19
719 UPDATE_CACHE(re, &s->gb); 719 UPDATE_CACHE(re, &s->gb);
720 #endif 720 #endif
721 /* now quantify & encode AC coefs */ 721 /* now quantify & encode AC coefficients */
722 for(;;) { 722 for(;;) {
723 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 723 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
724 724
725 if(level != 0) { 725 if(level != 0) {
726 i += run; 726 i += run;
782 const int qscale= s->qscale; 782 const int qscale= s->qscale;
783 783
784 { 784 {
785 OPEN_READER(re, &s->gb); 785 OPEN_READER(re, &s->gb);
786 i = -1; 786 i = -1;
787 /* special case for the first coef. no need to add a second vlc table */ 787 // special case for first coefficient, no need to add second VLC table
788 UPDATE_CACHE(re, &s->gb); 788 UPDATE_CACHE(re, &s->gb);
789 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { 789 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
790 level= (3*qscale)>>1; 790 level= (3*qscale)>>1;
791 level= (level-1)|1; 791 level= (level-1)|1;
792 if(GET_CACHE(re, &s->gb)&0x40000000) 792 if(GET_CACHE(re, &s->gb)&0x40000000)
799 } 799 }
800 #if MIN_CACHE_BITS < 19 800 #if MIN_CACHE_BITS < 19
801 UPDATE_CACHE(re, &s->gb); 801 UPDATE_CACHE(re, &s->gb);
802 #endif 802 #endif
803 803
804 /* now quantify & encode AC coefs */ 804 /* now quantify & encode AC coefficients */
805 for(;;) { 805 for(;;) {
806 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 806 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
807 807
808 if(level != 0) { 808 if(level != 0) {
809 i += run; 809 i += run;
873 if (n < 4) 873 if (n < 4)
874 quant_matrix = s->inter_matrix; 874 quant_matrix = s->inter_matrix;
875 else 875 else
876 quant_matrix = s->chroma_inter_matrix; 876 quant_matrix = s->chroma_inter_matrix;
877 877
878 /* special case for the first coef. no need to add a second vlc table */ 878 // special case for first coefficient, no need to add second VLC table
879 UPDATE_CACHE(re, &s->gb); 879 UPDATE_CACHE(re, &s->gb);
880 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { 880 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
881 level= (3*qscale*quant_matrix[0])>>5; 881 level= (3*qscale*quant_matrix[0])>>5;
882 if(GET_CACHE(re, &s->gb)&0x40000000) 882 if(GET_CACHE(re, &s->gb)&0x40000000)
883 level= -level; 883 level= -level;
890 } 890 }
891 #if MIN_CACHE_BITS < 19 891 #if MIN_CACHE_BITS < 19
892 UPDATE_CACHE(re, &s->gb); 892 UPDATE_CACHE(re, &s->gb);
893 #endif 893 #endif
894 894
895 /* now quantify & encode AC coefs */ 895 /* now quantify & encode AC coefficients */
896 for(;;) { 896 for(;;) {
897 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 897 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
898 898
899 if(level != 0) { 899 if(level != 0) {
900 i += run; 900 i += run;
952 uint8_t * const scantable= s->intra_scantable.permutated; 952 uint8_t * const scantable= s->intra_scantable.permutated;
953 const int qscale= s->qscale; 953 const int qscale= s->qscale;
954 OPEN_READER(re, &s->gb); 954 OPEN_READER(re, &s->gb);
955 i = -1; 955 i = -1;
956 956
957 /* special case for the first coef. no need to add a second vlc table */ 957 // special case for first coefficient, no need to add second VLC table
958 UPDATE_CACHE(re, &s->gb); 958 UPDATE_CACHE(re, &s->gb);
959 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { 959 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
960 level= (3*qscale)>>1; 960 level= (3*qscale)>>1;
961 if(GET_CACHE(re, &s->gb)&0x40000000) 961 if(GET_CACHE(re, &s->gb)&0x40000000)
962 level= -level; 962 level= -level;
968 } 968 }
969 #if MIN_CACHE_BITS < 19 969 #if MIN_CACHE_BITS < 19
970 UPDATE_CACHE(re, &s->gb); 970 UPDATE_CACHE(re, &s->gb);
971 #endif 971 #endif
972 972
973 /* now quantify & encode AC coefs */ 973 /* now quantify & encode AC coefficients */
974 for(;;) { 974 for(;;) {
975 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 975 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
976 976
977 if(level != 0) { 977 if(level != 0) {
978 i += run; 978 i += run;
1024 uint8_t * const scantable= s->intra_scantable.permutated; 1024 uint8_t * const scantable= s->intra_scantable.permutated;
1025 const uint16_t *quant_matrix; 1025 const uint16_t *quant_matrix;
1026 const int qscale= s->qscale; 1026 const int qscale= s->qscale;
1027 int mismatch; 1027 int mismatch;
1028 1028
1029 /* DC coef */ 1029 /* DC coefficient */
1030 if (n < 4){ 1030 if (n < 4){
1031 quant_matrix = s->intra_matrix; 1031 quant_matrix = s->intra_matrix;
1032 component = 0; 1032 component = 0;
1033 }else{ 1033 }else{
1034 quant_matrix = s->chroma_intra_matrix; 1034 quant_matrix = s->chroma_intra_matrix;
1049 else 1049 else
1050 rl = &ff_rl_mpeg1; 1050 rl = &ff_rl_mpeg1;
1051 1051
1052 { 1052 {
1053 OPEN_READER(re, &s->gb); 1053 OPEN_READER(re, &s->gb);
1054 /* now quantify & encode AC coefs */ 1054 /* now quantify & encode AC coefficients */
1055 for(;;) { 1055 for(;;) {
1056 UPDATE_CACHE(re, &s->gb); 1056 UPDATE_CACHE(re, &s->gb);
1057 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 1057 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
1058 1058
1059 if(level == 127){ 1059 if(level == 127){
1103 RLTable *rl; 1103 RLTable *rl;
1104 uint8_t * scantable= s->intra_scantable.permutated; 1104 uint8_t * scantable= s->intra_scantable.permutated;
1105 const uint16_t *quant_matrix; 1105 const uint16_t *quant_matrix;
1106 const int qscale= s->qscale; 1106 const int qscale= s->qscale;
1107 1107
1108 /* DC coef */ 1108 /* DC coefficient */
1109 if (n < 4){ 1109 if (n < 4){
1110 quant_matrix = s->intra_matrix; 1110 quant_matrix = s->intra_matrix;
1111 component = 0; 1111 component = 0;
1112 }else{ 1112 }else{
1113 quant_matrix = s->chroma_intra_matrix; 1113 quant_matrix = s->chroma_intra_matrix;
1125 else 1125 else
1126 rl = &ff_rl_mpeg1; 1126 rl = &ff_rl_mpeg1;
1127 1127
1128 { 1128 {
1129 OPEN_READER(re, &s->gb); 1129 OPEN_READER(re, &s->gb);
1130 /* now quantify & encode AC coefs */ 1130 /* now quantify & encode AC coefficients */
1131 for(;;) { 1131 for(;;) {
1132 UPDATE_CACHE(re, &s->gb); 1132 UPDATE_CACHE(re, &s->gb);
1133 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); 1133 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
1134 1134
1135 if(level == 127){ 1135 if(level == 127){
1181 { 1181 {
1182 Mpeg1Context *s = avctx->priv_data; 1182 Mpeg1Context *s = avctx->priv_data;
1183 MpegEncContext *s2 = &s->mpeg_enc_ctx; 1183 MpegEncContext *s2 = &s->mpeg_enc_ctx;
1184 int i; 1184 int i;
1185 1185
1186 //we need some parmutation to store 1186 /* we need some permutation to store matrices,
1187 //matrixes, until MPV_common_init() 1187 * until MPV_common_init() sets the real permutation. */
1188 //set the real permutatuon
1189 for(i=0;i<64;i++) 1188 for(i=0;i<64;i++)
1190 s2->dsp.idct_permutation[i]=i; 1189 s2->dsp.idct_permutation[i]=i;
1191 1190
1192 MPV_decode_defaults(s2); 1191 MPV_decode_defaults(s2);
1193 1192
1214 for(i=0;i<64;i++){ 1213 for(i=0;i<64;i++){
1215 matrix[new_perm[i]] = temp_matrix[old_perm[i]]; 1214 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1216 } 1215 }
1217 } 1216 }
1218 1217
1219 //Call this function when we know all parameters 1218 /* Call this function when we know all parameters.
1220 //it may be called in different places for mpeg1 and mpeg2 1219 * It may be called in different places for MPEG-1 and MPEG-2. */
1221 static int mpeg_decode_postinit(AVCodecContext *avctx){ 1220 static int mpeg_decode_postinit(AVCodecContext *avctx){
1222 Mpeg1Context *s1 = avctx->priv_data; 1221 Mpeg1Context *s1 = avctx->priv_data;
1223 MpegEncContext *s = &s1->mpeg_enc_ctx; 1222 MpegEncContext *s = &s1->mpeg_enc_ctx;
1224 uint8_t old_permutation[64]; 1223 uint8_t old_permutation[64];
1225 1224
1247 avctx->bit_rate = s->bit_rate; 1246 avctx->bit_rate = s->bit_rate;
1248 s1->save_aspect_info = s->aspect_ratio_info; 1247 s1->save_aspect_info = s->aspect_ratio_info;
1249 s1->save_width = s->width; 1248 s1->save_width = s->width;
1250 s1->save_height = s->height; 1249 s1->save_height = s->height;
1251 1250
1252 //low_delay may be forced, in this case we will have B frames 1251 /* low_delay may be forced, in this case we will have B-frames
1253 //that behave like P frames 1252 * that behave like P-frames. */
1254 avctx->has_b_frames = !(s->low_delay); 1253 avctx->has_b_frames = !(s->low_delay);
1255 1254
1256 if(avctx->sub_id==1){//s->codec_id==avctx->codec_id==CODEC_ID 1255 if(avctx->sub_id==1){//s->codec_id==avctx->codec_id==CODEC_ID
1257 //mpeg1 fps 1256 //MPEG-1 fps
1258 avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num; 1257 avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
1259 avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den; 1258 avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
1260 //mpeg1 aspect 1259 //MPEG-1 aspect
1261 avctx->sample_aspect_ratio= av_d2q( 1260 avctx->sample_aspect_ratio= av_d2q(
1262 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); 1261 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
1263 1262
1264 }else{//mpeg2 1263 }else{//MPEG-2
1265 //mpeg2 fps 1264 //MPEG-2 fps
1266 av_reduce( 1265 av_reduce(
1267 &s->avctx->time_base.den, 1266 &s->avctx->time_base.den,
1268 &s->avctx->time_base.num, 1267 &s->avctx->time_base.num,
1269 ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num, 1268 ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num,
1270 ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, 1269 ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
1271 1<<30); 1270 1<<30);
1272 //mpeg2 aspect 1271 //MPEG-2 aspect
1273 if(s->aspect_ratio_info > 1){ 1272 if(s->aspect_ratio_info > 1){
1274 if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){ 1273 if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){
1275 s->avctx->sample_aspect_ratio= 1274 s->avctx->sample_aspect_ratio=
1276 av_div_q( 1275 av_div_q(
1277 ff_mpeg2_aspect[s->aspect_ratio_info], 1276 ff_mpeg2_aspect[s->aspect_ratio_info],
1286 } 1285 }
1287 }else{ 1286 }else{
1288 s->avctx->sample_aspect_ratio= 1287 s->avctx->sample_aspect_ratio=
1289 ff_mpeg2_aspect[s->aspect_ratio_info]; 1288 ff_mpeg2_aspect[s->aspect_ratio_info];
1290 } 1289 }
1291 }//mpeg2 1290 }//MPEG-2
1292 1291
1293 if(avctx->xvmc_acceleration){ 1292 if(avctx->xvmc_acceleration){
1294 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); 1293 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
1295 }else{ 1294 }else{
1296 if(s->chroma_format < 2){ 1295 if(s->chroma_format < 2){
1306 //until then pix_fmt may be changed right after codec init 1305 //until then pix_fmt may be changed right after codec init
1307 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) 1306 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
1308 if( avctx->idct_algo == FF_IDCT_AUTO ) 1307 if( avctx->idct_algo == FF_IDCT_AUTO )
1309 avctx->idct_algo = FF_IDCT_SIMPLE; 1308 avctx->idct_algo = FF_IDCT_SIMPLE;
1310 1309
1311 //quantization matrixes may need reordering 1310 /* Quantization matrices may need reordering
1312 //if dct permutation is changed 1311 * if DCT permutation is changed. */
1313 memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t)); 1312 memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
1314 1313
1315 if (MPV_common_init(s) < 0) 1314 if (MPV_common_init(s) < 0)
1316 return -2; 1315 return -2;
1317 1316
1375 { 1374 {
1376 MpegEncContext *s= &s1->mpeg_enc_ctx; 1375 MpegEncContext *s= &s1->mpeg_enc_ctx;
1377 int horiz_size_ext, vert_size_ext; 1376 int horiz_size_ext, vert_size_ext;
1378 int bit_rate_ext; 1377 int bit_rate_ext;
1379 1378
1380 skip_bits(&s->gb, 1); /* profil and level esc*/ 1379 skip_bits(&s->gb, 1); /* profile and level esc*/
1381 s->avctx->profile= get_bits(&s->gb, 3); 1380 s->avctx->profile= get_bits(&s->gb, 3);
1382 s->avctx->level= get_bits(&s->gb, 4); 1381 s->avctx->level= get_bits(&s->gb, 4);
1383 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ 1382 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
1384 s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */ 1383 s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
1385 horiz_size_ext = get_bits(&s->gb, 2); 1384 horiz_size_ext = get_bits(&s->gb, 2);
1397 s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1; 1396 s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
1398 s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1; 1397 s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
1399 1398
1400 dprintf(s->avctx, "sequence extension\n"); 1399 dprintf(s->avctx, "sequence extension\n");
1401 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; 1400 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
1402 s->avctx->sub_id = 2; /* indicates mpeg2 found */ 1401 s->avctx->sub_id = 2; /* indicates MPEG-2 found */
1403 1402
1404 if(s->avctx->debug & FF_DEBUG_PICT_INFO) 1403 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
1405 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n", 1404 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
1406 s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate); 1405 s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
1407 1406
1716 } 1715 }
1717 } 1716 }
1718 1717
1719 for(;;) { 1718 for(;;) {
1720 #ifdef HAVE_XVMC 1719 #ifdef HAVE_XVMC
1721 //one 1 we memcpy blocks in xvmcvideo 1720 //If 1, we memcpy blocks in xvmcvideo.
1722 if(s->avctx->xvmc_acceleration > 1) 1721 if(s->avctx->xvmc_acceleration > 1)
1723 XVMC_init_block(s);//set s->block 1722 XVMC_init_block(s);//set s->block
1724 #endif 1723 #endif
1725 1724
1726 if(mpeg_decode_mb(s, s->block) < 0) 1725 if(mpeg_decode_mb(s, s->block) < 0)
1788 ff_init_block_index(s); 1787 ff_init_block_index(s);
1789 } 1788 }
1790 1789
1791 /* skip mb handling */ 1790 /* skip mb handling */
1792 if (s->mb_skip_run == -1) { 1791 if (s->mb_skip_run == -1) {
1793 /* read again increment */ 1792 /* read increment again */
1794 s->mb_skip_run = 0; 1793 s->mb_skip_run = 0;
1795 for(;;) { 1794 for(;;) {
1796 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); 1795 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
1797 if (code < 0){ 1796 if (code < 0){
1798 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n"); 1797 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
1886 1885
1887 return 0; //not reached 1886 return 0; //not reached
1888 } 1887 }
1889 1888
1890 /** 1889 /**
1891 * handles slice ends. 1890 * Handles slice ends.
1892 * @return 1 if it seems to be the last slice of 1891 * @return 1 if it seems to be the last slice
1893 */ 1892 */
1894 static int slice_end(AVCodecContext *avctx, AVFrame *pict) 1893 static int slice_end(AVCodecContext *avctx, AVFrame *pict)
1895 { 1894 {
1896 Mpeg1Context *s1 = avctx->priv_data; 1895 Mpeg1Context *s1 = avctx->priv_data;
1897 MpegEncContext *s = &s1->mpeg_enc_ctx; 1896 MpegEncContext *s = &s1->mpeg_enc_ctx;
1916 if (s->pict_type == FF_B_TYPE || s->low_delay) { 1915 if (s->pict_type == FF_B_TYPE || s->low_delay) {
1917 *pict= *(AVFrame*)s->current_picture_ptr; 1916 *pict= *(AVFrame*)s->current_picture_ptr;
1918 ff_print_debug_info(s, pict); 1917 ff_print_debug_info(s, pict);
1919 } else { 1918 } else {
1920 s->picture_number++; 1919 s->picture_number++;
1921 /* latency of 1 frame for I and P frames */ 1920 /* latency of 1 frame for I- and P-frames */
1922 /* XXX: use another variable than picture_number */ 1921 /* XXX: use another variable than picture_number */
1923 if (s->last_picture_ptr != NULL) { 1922 if (s->last_picture_ptr != NULL) {
1924 *pict= *(AVFrame*)s->last_picture_ptr; 1923 *pict= *(AVFrame*)s->last_picture_ptr;
1925 ff_print_debug_info(s, pict); 1924 ff_print_debug_info(s, pict);
1926 } 1925 }
2000 j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; 1999 j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
2001 s->inter_matrix[j] = v; 2000 s->inter_matrix[j] = v;
2002 s->chroma_inter_matrix[j] = v; 2001 s->chroma_inter_matrix[j] = v;
2003 } 2002 }
2004 #ifdef DEBUG 2003 #ifdef DEBUG
2005 dprintf(s->avctx, "non intra matrix present\n"); 2004 dprintf(s->avctx, "non-intra matrix present\n");
2006 for(i=0;i<64;i++) 2005 for(i=0;i<64;i++)
2007 dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]); 2006 dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]);
2008 dprintf(s->avctx, "\n"); 2007 dprintf(s->avctx, "\n");
2009 #endif 2008 #endif
2010 } else { 2009 } else {
2019 if(show_bits(&s->gb, 23) != 0){ 2018 if(show_bits(&s->gb, 23) != 0){
2020 av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n"); 2019 av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
2021 return -1; 2020 return -1;
2022 } 2021 }
2023 2022
2024 /* we set mpeg2 parameters so that it emulates mpeg1 */ 2023 /* we set MPEG-2 parameters so that it emulates MPEG-1 */
2025 s->progressive_sequence = 1; 2024 s->progressive_sequence = 1;
2026 s->progressive_frame = 1; 2025 s->progressive_frame = 1;
2027 s->picture_structure = PICT_FRAME; 2026 s->picture_structure = PICT_FRAME;
2028 s->frame_pred_frame_dct = 1; 2027 s->frame_pred_frame_dct = 1;
2029 s->chroma_format = 1; 2028 s->chroma_format = 1;
2030 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO; 2029 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
2031 avctx->sub_id = 1; /* indicates mpeg1 */ 2030 avctx->sub_id = 1; /* indicates MPEG-1 */
2032 s->out_format = FMT_MPEG1; 2031 s->out_format = FMT_MPEG1;
2033 s->swap_uv = 0;//AFAIK VCR2 don't have SEQ_HEADER 2032 s->swap_uv = 0;//AFAIK VCR2 does not have SEQ_HEADER
2034 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; 2033 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
2035 2034
2036 if(s->avctx->debug & FF_DEBUG_PICT_INFO) 2035 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
2037 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n", 2036 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
2038 s->avctx->rc_buffer_size, s->bit_rate); 2037 s->avctx->rc_buffer_size, s->bit_rate);
2044 { 2043 {
2045 Mpeg1Context *s1 = avctx->priv_data; 2044 Mpeg1Context *s1 = avctx->priv_data;
2046 MpegEncContext *s = &s1->mpeg_enc_ctx; 2045 MpegEncContext *s = &s1->mpeg_enc_ctx;
2047 int i, v; 2046 int i, v;
2048 2047
2049 /* start new mpeg1 context decoding */ 2048 /* start new MPEG-1 context decoding */
2050 s->out_format = FMT_MPEG1; 2049 s->out_format = FMT_MPEG1;
2051 if (s1->mpeg_enc_ctx_allocated) { 2050 if (s1->mpeg_enc_ctx_allocated) {
2052 MPV_common_end(s); 2051 MPV_common_end(s);
2053 } 2052 }
2054 s->width = avctx->coded_width; 2053 s->width = avctx->coded_width;
2087 s->progressive_frame = 1; 2086 s->progressive_frame = 1;
2088 s->picture_structure = PICT_FRAME; 2087 s->picture_structure = PICT_FRAME;
2089 s->frame_pred_frame_dct = 1; 2088 s->frame_pred_frame_dct = 1;
2090 s->chroma_format = 1; 2089 s->chroma_format = 1;
2091 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; 2090 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
2092 avctx->sub_id = 2; /* indicates mpeg2 */ 2091 avctx->sub_id = 2; /* indicates MPEG-2 */
2093 return 0; 2092 return 0;
2094 } 2093 }
2095 2094
2096 2095
2097 static void mpeg_decode_user_data(AVCodecContext *avctx, 2096 static void mpeg_decode_user_data(AVCodecContext *avctx,
2153 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n", 2152 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n",
2154 time_code_hours, time_code_minutes, time_code_seconds, 2153 time_code_hours, time_code_minutes, time_code_seconds,
2155 time_code_pictures, closed_gop, broken_link); 2154 time_code_pictures, closed_gop, broken_link);
2156 } 2155 }
2157 /** 2156 /**
2158 * finds the end of the current frame in the bitstream. 2157 * Finds the end of the current frame in the bitstream.
2159 * @return the position of the first byte of the next frame, or -1 2158 * @return the position of the first byte of the next frame, or -1
2160 */ 2159 */
2161 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) 2160 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
2162 { 2161 {
2163 int i; 2162 int i;
2276 const uint8_t *buf_ptr = buf; 2275 const uint8_t *buf_ptr = buf;
2277 const uint8_t *buf_end = buf + buf_size; 2276 const uint8_t *buf_end = buf + buf_size;
2278 int ret, input_size; 2277 int ret, input_size;
2279 2278
2280 for(;;) { 2279 for(;;) {
2281 /* find start next code */ 2280 /* find next start code */
2282 uint32_t start_code = -1; 2281 uint32_t start_code = -1;
2283 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); 2282 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
2284 if (start_code > 0x1ff){ 2283 if (start_code > 0x1ff){
2285 if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ 2284 if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
2286 if(avctx->thread_count > 1){ 2285 if(avctx->thread_count > 1){
2310 mpeg1_decode_sequence(avctx, buf_ptr, 2309 mpeg1_decode_sequence(avctx, buf_ptr,
2311 input_size); 2310 input_size);
2312 break; 2311 break;
2313 2312
2314 case PICTURE_START_CODE: 2313 case PICTURE_START_CODE:
2315 /* we have a complete image : we try to decompress it */ 2314 /* we have a complete image: we try to decompress it */
2316 mpeg1_decode_picture(avctx, 2315 mpeg1_decode_picture(avctx,
2317 buf_ptr, input_size); 2316 buf_ptr, input_size);
2318 break; 2317 break;
2319 case EXT_START_CODE: 2318 case EXT_START_CODE:
2320 mpeg_decode_extension(avctx, 2319 mpeg_decode_extension(avctx,
2337 if(s2->last_picture_ptr==NULL){ 2336 if(s2->last_picture_ptr==NULL){
2338 /* Skip B-frames if we do not have reference frames. */ 2337 /* Skip B-frames if we do not have reference frames. */
2339 if(s2->pict_type==FF_B_TYPE) break; 2338 if(s2->pict_type==FF_B_TYPE) break;
2340 } 2339 }
2341 if(s2->next_picture_ptr==NULL){ 2340 if(s2->next_picture_ptr==NULL){
2342 /* Skip P-frames if we do not have reference frame no valid header. */ 2341 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */
2343 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; 2342 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break;
2344 } 2343 }
2345 /* Skip B-frames if we are in a hurry. */ 2344 /* Skip B-frames if we are in a hurry. */
2346 if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; 2345 if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break;
2347 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) 2346 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE)
2380 ff_update_duplicate_context(thread_context, s2); 2379 ff_update_duplicate_context(thread_context, s2);
2381 } 2380 }
2382 init_get_bits(&thread_context->gb, buf_ptr, input_size*8); 2381 init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
2383 s->slice_count++; 2382 s->slice_count++;
2384 } 2383 }
2385 buf_ptr += 2; //FIXME add minimum num of bytes per slice 2384 buf_ptr += 2; //FIXME add minimum number of bytes per slice
2386 }else{ 2385 }else{
2387 ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size); 2386 ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
2388 emms_c(); 2387 emms_c();
2389 2388
2390 if(ret < 0){ 2389 if(ret < 0){