comparison mpeg12.c @ 1890:a07406ac4725 libavcodec

mpeg12 fix 10l of aspect calucalations, return gop perser to print debug info, and make mpeg1_seq_header hot overwrite height/width
author iive
date Mon, 15 Mar 2004 16:41:15 +0000
parents 4bbe33eed9f0
children f403b3e286b3
comparison
equal deleted inserted replaced
1889:c9b2debe7b2b 1890:a07406ac4725
1838 1<<30); 1838 1<<30);
1839 //mpeg2 aspect 1839 //mpeg2 aspect
1840 if(s->aspect_ratio_info > 1){ 1840 if(s->aspect_ratio_info > 1){
1841 if( (s1->display_weight == 0 )||(s1->display_height == 0) ){ 1841 if( (s1->display_weight == 0 )||(s1->display_height == 0) ){
1842 s->avctx->sample_aspect_ratio= 1842 s->avctx->sample_aspect_ratio=
1843 mpeg2_aspect[s->aspect_ratio_info]; 1843 av_div_q(
1844 mpeg2_aspect[s->aspect_ratio_info],
1845 (AVRational){s->width, s->height}
1846 );
1844 }else{ 1847 }else{
1845 s->avctx->sample_aspect_ratio= 1848 s->avctx->sample_aspect_ratio=
1846 av_div_q( 1849 av_div_q(
1847 mpeg2_aspect[s->aspect_ratio_info], 1850 mpeg2_aspect[s->aspect_ratio_info],
1848 (AVRational){s1->display_weight, s1->display_height} 1851 (AVRational){s1->display_weight, s1->display_height}
1849 ); 1852 );
1850 } 1853 }
1851 }else{ 1854 }else{
1852 s->avctx->sample_aspect_ratio= 1855 s->avctx->sample_aspect_ratio=
1853 av_div_q( 1856 mpeg2_aspect[s->aspect_ratio_info];
1854 mpeg2_aspect[s->aspect_ratio_info],
1855 (AVRational){s->width, s->height}
1856 );
1857 } 1857 }
1858 }//mpeg2 1858 }//mpeg2
1859 1859
1860 if(avctx->xvmc_acceleration){ 1860 if(avctx->xvmc_acceleration){
1861 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); 1861 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
2480 static int mpeg1_decode_sequence(AVCodecContext *avctx, 2480 static int mpeg1_decode_sequence(AVCodecContext *avctx,
2481 const uint8_t *buf, int buf_size) 2481 const uint8_t *buf, int buf_size)
2482 { 2482 {
2483 Mpeg1Context *s1 = avctx->priv_data; 2483 Mpeg1Context *s1 = avctx->priv_data;
2484 MpegEncContext *s = &s1->mpeg_enc_ctx; 2484 MpegEncContext *s = &s1->mpeg_enc_ctx;
2485 int width,height;
2485 int i, v, j; 2486 int i, v, j;
2486 2487
2487 init_get_bits(&s->gb, buf, buf_size*8); 2488 init_get_bits(&s->gb, buf, buf_size*8);
2488 2489
2489 s->width = get_bits(&s->gb, 12); 2490 width = get_bits(&s->gb, 12);
2490 s->height = get_bits(&s->gb, 12); 2491 height = get_bits(&s->gb, 12);
2492 if (width <= 0 || height <= 0 ||
2493 (width % 2) != 0 || (height % 2) != 0)
2494 return -1;
2491 s->aspect_ratio_info= get_bits(&s->gb, 4); 2495 s->aspect_ratio_info= get_bits(&s->gb, 4);
2492 if (s->aspect_ratio_info == 0) 2496 if (s->aspect_ratio_info == 0)
2493 return -1; 2497 return -1;
2494 s->frame_rate_index = get_bits(&s->gb, 4); 2498 s->frame_rate_index = get_bits(&s->gb, 4);
2495 if (s->frame_rate_index == 0 || s->frame_rate_index > 13) 2499 if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
2496 return -1; 2500 return -1;
2497 s->bit_rate = get_bits(&s->gb, 18) * 400; 2501 s->bit_rate = get_bits(&s->gb, 18) * 400;
2498 if (get_bits1(&s->gb) == 0) /* marker */ 2502 if (get_bits1(&s->gb) == 0) /* marker */
2499 return -1; 2503 return -1;
2500 if (s->width <= 0 || s->height <= 0) 2504 s->width = width;
2501 return -1; 2505 s->height = height;
2502 2506
2503 s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16; 2507 s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
2504 skip_bits(&s->gb, 1); 2508 skip_bits(&s->gb, 1);
2505 2509
2506 /* get matrix */ 2510 /* get matrix */
2660 avctx->dtg_active_format = p[0] & 0x0f; 2664 avctx->dtg_active_format = p[0] & 0x0f;
2661 } 2665 }
2662 } 2666 }
2663 } 2667 }
2664 2668
2669 static void mpeg_decode_gop(AVCodecContext *avctx,
2670 const uint8_t *buf, int buf_size){
2671 Mpeg1Context *s1 = avctx->priv_data;
2672 MpegEncContext *s = &s1->mpeg_enc_ctx;
2673
2674 int drop_frame_flag;
2675 int time_code_hours, time_code_minutes;
2676 int time_code_seconds, time_code_pictures;
2677 int broken_link;
2678
2679 init_get_bits(&s->gb, buf, buf_size*8);
2680
2681 drop_frame_flag = get_bits1(&s->gb);
2682
2683 time_code_hours=get_bits(&s->gb,5);
2684 time_code_minutes = get_bits(&s->gb,6);
2685 skip_bits1(&s->gb);//marker bit
2686 time_code_seconds = get_bits(&s->gb,6);
2687 time_code_pictures = get_bits(&s->gb,6);
2688
2689 /*broken_link indicate that after editing the
2690 reference frames of the first B-Frames after GOP I-Frame
2691 are missing (open gop)*/
2692 broken_link = get_bits1(&s->gb);
2693
2694 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
2695 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n",
2696 time_code_hours, time_code_minutes, time_code_seconds,
2697 time_code_pictures, broken_link);
2698 }
2665 /** 2699 /**
2666 * finds the end of the current frame in the bitstream. 2700 * finds the end of the current frame in the bitstream.
2667 * @return the position of the first byte of the next frame, or -1 2701 * @return the position of the first byte of the next frame, or -1
2668 */ 2702 */
2669 static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ 2703 static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
2798 mpeg_decode_user_data(avctx, 2832 mpeg_decode_user_data(avctx,
2799 buf_ptr, input_size); 2833 buf_ptr, input_size);
2800 break; 2834 break;
2801 case GOP_START_CODE: 2835 case GOP_START_CODE:
2802 s2->first_field=0; 2836 s2->first_field=0;
2837 mpeg_decode_gop(avctx,
2838 buf_ptr, input_size);
2803 break; 2839 break;
2804 default: 2840 default:
2805 if (start_code >= SLICE_MIN_START_CODE && 2841 if (start_code >= SLICE_MIN_START_CODE &&
2806 start_code <= SLICE_MAX_START_CODE) { 2842 start_code <= SLICE_MAX_START_CODE) {
2807 int mb_y= start_code - SLICE_MIN_START_CODE; 2843 int mb_y= start_code - SLICE_MIN_START_CODE;