Mercurial > libavcodec.hg
comparison mpeg12.c @ 1598:932d306bf1dc libavcodec
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
author | michael |
---|---|
date | Mon, 03 Nov 2003 13:26:22 +0000 |
parents | b69b086f5570 |
children | 721a76648a4b |
comparison
equal
deleted
inserted
replaced
1597:4c9165372ab3 | 1598:932d306bf1dc |
---|---|
992 | 992 |
993 assert(s->mb_skiped==0); | 993 assert(s->mb_skiped==0); |
994 | 994 |
995 if (s->mb_skip_run-- != 0) { | 995 if (s->mb_skip_run-- != 0) { |
996 if(s->pict_type == I_TYPE){ | 996 if(s->pict_type == I_TYPE){ |
997 fprintf(stderr, "skiped MB in I frame at %d %d\n", s->mb_x, s->mb_y); | 997 av_log(s->avctx, AV_LOG_ERROR, "skiped MB in I frame at %d %d\n", s->mb_x, s->mb_y); |
998 return -1; | 998 return -1; |
999 } | 999 } |
1000 | 1000 |
1001 /* skip mb */ | 1001 /* skip mb */ |
1002 s->mb_intra = 0; | 1002 s->mb_intra = 0; |
1032 switch(s->pict_type) { | 1032 switch(s->pict_type) { |
1033 default: | 1033 default: |
1034 case I_TYPE: | 1034 case I_TYPE: |
1035 if (get_bits1(&s->gb) == 0) { | 1035 if (get_bits1(&s->gb) == 0) { |
1036 if (get_bits1(&s->gb) == 0){ | 1036 if (get_bits1(&s->gb) == 0){ |
1037 fprintf(stderr, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); | 1037 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); |
1038 return -1; | 1038 return -1; |
1039 } | 1039 } |
1040 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; | 1040 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; |
1041 } else { | 1041 } else { |
1042 mb_type = MB_TYPE_INTRA; | 1042 mb_type = MB_TYPE_INTRA; |
1043 } | 1043 } |
1044 break; | 1044 break; |
1045 case P_TYPE: | 1045 case P_TYPE: |
1046 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); | 1046 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); |
1047 if (mb_type < 0){ | 1047 if (mb_type < 0){ |
1048 fprintf(stderr, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); | 1048 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); |
1049 return -1; | 1049 return -1; |
1050 } | 1050 } |
1051 mb_type = ptype2mb_type[ mb_type ]; | 1051 mb_type = ptype2mb_type[ mb_type ]; |
1052 break; | 1052 break; |
1053 case B_TYPE: | 1053 case B_TYPE: |
1054 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); | 1054 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); |
1055 if (mb_type < 0){ | 1055 if (mb_type < 0){ |
1056 fprintf(stderr, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); | 1056 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); |
1057 return -1; | 1057 return -1; |
1058 } | 1058 } |
1059 mb_type = btype2mb_type[ mb_type ]; | 1059 mb_type = btype2mb_type[ mb_type ]; |
1060 break; | 1060 break; |
1061 } | 1061 } |
1266 s->mb_intra = 0; | 1266 s->mb_intra = 0; |
1267 | 1267 |
1268 if (IS_PAT(mb_type)) { | 1268 if (IS_PAT(mb_type)) { |
1269 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); | 1269 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); |
1270 if (cbp < 0){ | 1270 if (cbp < 0){ |
1271 fprintf(stderr, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); | 1271 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); |
1272 return -1; | 1272 return -1; |
1273 } | 1273 } |
1274 cbp++; | 1274 cbp++; |
1275 | 1275 |
1276 #ifdef HAVE_XVMC | 1276 #ifdef HAVE_XVMC |
1354 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2); | 1354 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2); |
1355 } else { | 1355 } else { |
1356 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); | 1356 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); |
1357 } | 1357 } |
1358 if (code < 0){ | 1358 if (code < 0){ |
1359 fprintf(stderr, "invalid dc code at\n"); | 1359 av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n"); |
1360 return 0xffff; | 1360 return 0xffff; |
1361 } | 1361 } |
1362 if (code == 0) { | 1362 if (code == 0) { |
1363 diff = 0; | 1363 diff = 0; |
1364 } else { | 1364 } else { |
1426 level= (level*qscale*quant_matrix[j])>>3; | 1426 level= (level*qscale*quant_matrix[j])>>3; |
1427 level= (level-1)|1; | 1427 level= (level-1)|1; |
1428 } | 1428 } |
1429 } | 1429 } |
1430 if (i > 63){ | 1430 if (i > 63){ |
1431 fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1431 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
1432 return -1; | 1432 return -1; |
1433 } | 1433 } |
1434 | 1434 |
1435 block[j] = level; | 1435 block[j] = level; |
1436 } | 1436 } |
1502 level= ((level*2+1)*qscale*quant_matrix[j])>>4; | 1502 level= ((level*2+1)*qscale*quant_matrix[j])>>4; |
1503 level= (level-1)|1; | 1503 level= (level-1)|1; |
1504 } | 1504 } |
1505 } | 1505 } |
1506 if (i > 63){ | 1506 if (i > 63){ |
1507 fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1507 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
1508 return -1; | 1508 return -1; |
1509 } | 1509 } |
1510 | 1510 |
1511 block[j] = level; | 1511 block[j] = level; |
1512 } | 1512 } |
1580 }else{ | 1580 }else{ |
1581 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | 1581 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
1582 } | 1582 } |
1583 } | 1583 } |
1584 if (i > 63){ | 1584 if (i > 63){ |
1585 fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1585 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
1586 return -1; | 1586 return -1; |
1587 } | 1587 } |
1588 | 1588 |
1589 mismatch ^= level; | 1589 mismatch ^= level; |
1590 block[j] = level; | 1590 block[j] = level; |
1660 }else{ | 1660 }else{ |
1661 level= (level*qscale*quant_matrix[j])>>4; | 1661 level= (level*qscale*quant_matrix[j])>>4; |
1662 } | 1662 } |
1663 } | 1663 } |
1664 if (i > 63){ | 1664 if (i > 63){ |
1665 fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | 1665 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
1666 return -1; | 1666 return -1; |
1667 } | 1667 } |
1668 | 1668 |
1669 mismatch^= level; | 1669 mismatch^= level; |
1670 block[j] = level; | 1670 block[j] = level; |
1808 (AVRational){s->width, s->height} | 1808 (AVRational){s->width, s->height} |
1809 ); | 1809 ); |
1810 } | 1810 } |
1811 | 1811 |
1812 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | 1812 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
1813 printf("profile: %d, level: %d \n", profile, level); | 1813 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d \n", profile, level); |
1814 } | 1814 } |
1815 | 1815 |
1816 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1) | 1816 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1) |
1817 { | 1817 { |
1818 MpegEncContext *s= &s1->mpeg_enc_ctx; | 1818 MpegEncContext *s= &s1->mpeg_enc_ctx; |
1839 mpeg2_aspect[s->aspect_ratio_info], | 1839 mpeg2_aspect[s->aspect_ratio_info], |
1840 (AVRational){w, h} | 1840 (AVRational){w, h} |
1841 ); | 1841 ); |
1842 | 1842 |
1843 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | 1843 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
1844 printf("sde w:%d, h:%d\n", w, h); | 1844 av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h); |
1845 } | 1845 } |
1846 | 1846 |
1847 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) | 1847 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) |
1848 { | 1848 { |
1849 MpegEncContext *s= &s1->mpeg_enc_ctx; | 1849 MpegEncContext *s= &s1->mpeg_enc_ctx; |
1855 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); | 1855 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); |
1856 skip_bits(&s->gb, 1); //marker | 1856 skip_bits(&s->gb, 1); //marker |
1857 } | 1857 } |
1858 | 1858 |
1859 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | 1859 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
1860 printf("pde (%d,%d) (%d,%d) (%d,%d)\n", | 1860 av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n", |
1861 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], | 1861 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], |
1862 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], | 1862 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], |
1863 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1] | 1863 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1] |
1864 ); | 1864 ); |
1865 } | 1865 } |
2012 s->resync_mb_x= s->mb_x = | 2012 s->resync_mb_x= s->mb_x = |
2013 s->resync_mb_y= s->mb_y = -1; | 2013 s->resync_mb_y= s->mb_y = -1; |
2014 | 2014 |
2015 start_code = (start_code - 1) & 0xff; | 2015 start_code = (start_code - 1) & 0xff; |
2016 if (start_code >= s->mb_height){ | 2016 if (start_code >= s->mb_height){ |
2017 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height); | 2017 av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", start_code, s->mb_height); |
2018 return -1; | 2018 return -1; |
2019 } | 2019 } |
2020 | 2020 |
2021 ff_mpeg1_clean_buffers(s); | 2021 ff_mpeg1_clean_buffers(s); |
2022 s->interlaced_dct = 0; | 2022 s->interlaced_dct = 0; |
2045 *s->current_picture_ptr->pan_scan= s1->pan_scan; | 2045 *s->current_picture_ptr->pan_scan= s1->pan_scan; |
2046 | 2046 |
2047 //printf("%d\n", s->current_picture_ptr->repeat_pict); | 2047 //printf("%d\n", s->current_picture_ptr->repeat_pict); |
2048 | 2048 |
2049 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | 2049 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
2050 printf("qp:%d fc:%2d%2d%2d%2d %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n", | 2050 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n", |
2051 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], | 2051 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], |
2052 s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")), | 2052 s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")), |
2053 s->progressive_sequence ? "pro" :"", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", | 2053 s->progressive_sequence ? "pro" :"", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", |
2054 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, | 2054 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, |
2055 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); | 2055 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); |
2056 } | 2056 } |
2057 }else{ //second field | 2057 }else{ //second field |
2058 int i; | 2058 int i; |
2059 | 2059 |
2060 if(!s->current_picture_ptr){ | 2060 if(!s->current_picture_ptr){ |
2061 fprintf(stderr, "first field missing\n"); | 2061 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n"); |
2062 return -1; | 2062 return -1; |
2063 } | 2063 } |
2064 | 2064 |
2065 for(i=0; i<4; i++){ | 2065 for(i=0; i<4; i++){ |
2066 s->current_picture.data[i] = s->current_picture_ptr->data[i]; | 2066 s->current_picture.data[i] = s->current_picture_ptr->data[i]; |
2080 | 2080 |
2081 init_get_bits(&s->gb, *buf, buf_size*8); | 2081 init_get_bits(&s->gb, *buf, buf_size*8); |
2082 | 2082 |
2083 s->qscale = get_qscale(s); | 2083 s->qscale = get_qscale(s); |
2084 if(s->qscale == 0){ | 2084 if(s->qscale == 0){ |
2085 fprintf(stderr, "qscale == 0\n"); | 2085 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n"); |
2086 return -1; | 2086 return -1; |
2087 } | 2087 } |
2088 | 2088 |
2089 /* extra slice info */ | 2089 /* extra slice info */ |
2090 while (get_bits1(&s->gb) != 0) { | 2090 while (get_bits1(&s->gb) != 0) { |
2094 s->mb_x=0; | 2094 s->mb_x=0; |
2095 | 2095 |
2096 for(;;) { | 2096 for(;;) { |
2097 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | 2097 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); |
2098 if (code < 0){ | 2098 if (code < 0){ |
2099 fprintf(stderr, "first mb_incr damaged\n"); | 2099 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); |
2100 return -1; | 2100 return -1; |
2101 } | 2101 } |
2102 if (code >= 33) { | 2102 if (code >= 33) { |
2103 if (code == 33) { | 2103 if (code == 33) { |
2104 s->mb_x += 33; | 2104 s->mb_x += 33; |
2171 if(s->mb_y<<field_pic >= s->mb_height){ | 2171 if(s->mb_y<<field_pic >= s->mb_height){ |
2172 int left= s->gb.size_in_bits - get_bits_count(&s->gb); | 2172 int left= s->gb.size_in_bits - get_bits_count(&s->gb); |
2173 | 2173 |
2174 if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23))) | 2174 if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23))) |
2175 || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){ | 2175 || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){ |
2176 fprintf(stderr, "end missmatch left=%d\n", left); | 2176 av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d\n", left); |
2177 return -1; | 2177 return -1; |
2178 }else | 2178 }else |
2179 goto eos; | 2179 goto eos; |
2180 } | 2180 } |
2181 | 2181 |
2187 /* read again increment */ | 2187 /* read again increment */ |
2188 s->mb_skip_run = 0; | 2188 s->mb_skip_run = 0; |
2189 for(;;) { | 2189 for(;;) { |
2190 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | 2190 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); |
2191 if (code < 0){ | 2191 if (code < 0){ |
2192 fprintf(stderr, "mb incr damaged\n"); | 2192 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n"); |
2193 return -1; | 2193 return -1; |
2194 } | 2194 } |
2195 if (code >= 33) { | 2195 if (code >= 33) { |
2196 if (code == 33) { | 2196 if (code == 33) { |
2197 s->mb_skip_run += 33; | 2197 s->mb_skip_run += 33; |
2198 }else if(code == 35){ | 2198 }else if(code == 35){ |
2199 if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){ | 2199 if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){ |
2200 fprintf(stderr, "slice missmatch\n"); | 2200 av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n"); |
2201 return -1; | 2201 return -1; |
2202 } | 2202 } |
2203 goto eos; /* end of slice */ | 2203 goto eos; /* end of slice */ |
2204 } | 2204 } |
2205 /* otherwise, stuffing, nothing to do */ | 2205 /* otherwise, stuffing, nothing to do */ |
2562 } | 2562 } |
2563 | 2563 |
2564 input_size = buf_end - buf_ptr; | 2564 input_size = buf_end - buf_ptr; |
2565 | 2565 |
2566 if(avctx->debug & FF_DEBUG_STARTCODE){ | 2566 if(avctx->debug & FF_DEBUG_STARTCODE){ |
2567 printf("%3X at %d left %d\n", start_code, buf_ptr-buf, input_size); | 2567 av_log(avctx, AV_LOG_DEBUG, "%3X at %d left %d\n", start_code, buf_ptr-buf, input_size); |
2568 } | 2568 } |
2569 | 2569 |
2570 /* prepare data for next start code */ | 2570 /* prepare data for next start code */ |
2571 switch(start_code) { | 2571 switch(start_code) { |
2572 case SEQ_START_CODE: | 2572 case SEQ_START_CODE: |