Mercurial > libavcodec.hg
comparison mpeg12.c @ 2979:bfabfdf9ce55 libavcodec
COSMETICS: tabs --> spaces, some prettyprinting
author | diego |
---|---|
date | Thu, 22 Dec 2005 01:10:11 +0000 |
parents | ef2149182f1c |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2978:403183bbb505 | 2979:bfabfdf9ce55 |
---|---|
33 //#undef NDEBUG | 33 //#undef NDEBUG |
34 //#include <assert.h> | 34 //#include <assert.h> |
35 | 35 |
36 | 36 |
37 /* Start codes. */ | 37 /* Start codes. */ |
38 #define SEQ_END_CODE 0x000001b7 | 38 #define SEQ_END_CODE 0x000001b7 |
39 #define SEQ_START_CODE 0x000001b3 | 39 #define SEQ_START_CODE 0x000001b3 |
40 #define GOP_START_CODE 0x000001b8 | 40 #define GOP_START_CODE 0x000001b8 |
41 #define PICTURE_START_CODE 0x00000100 | 41 #define PICTURE_START_CODE 0x00000100 |
42 #define SLICE_MIN_START_CODE 0x00000101 | 42 #define SLICE_MIN_START_CODE 0x00000101 |
43 #define SLICE_MAX_START_CODE 0x000001af | 43 #define SLICE_MAX_START_CODE 0x000001af |
44 #define EXT_START_CODE 0x000001b5 | 44 #define EXT_START_CODE 0x000001b5 |
45 #define USER_START_CODE 0x000001b2 | 45 #define USER_START_CODE 0x000001b2 |
46 | 46 |
47 #define DC_VLC_BITS 9 | 47 #define DC_VLC_BITS 9 |
48 #define MV_VLC_BITS 9 | 48 #define MV_VLC_BITS 9 |
49 #define MBINCR_VLC_BITS 9 | 49 #define MBINCR_VLC_BITS 9 |
50 #define MB_PAT_VLC_BITS 9 | 50 #define MB_PAT_VLC_BITS 9 |
87 const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1}; | 87 const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1}; |
88 const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1}; | 88 const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,-1}; |
89 const enum PixelFormat pixfmt_xvmc_mpg2_420[] = { | 89 const enum PixelFormat pixfmt_xvmc_mpg2_420[] = { |
90 PIX_FMT_XVMC_MPEG2_IDCT, | 90 PIX_FMT_XVMC_MPEG2_IDCT, |
91 PIX_FMT_XVMC_MPEG2_MC, | 91 PIX_FMT_XVMC_MPEG2_MC, |
92 -1}; | 92 -1}; |
93 #ifdef CONFIG_ENCODERS | 93 #ifdef CONFIG_ENCODERS |
94 static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL; | 94 static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL; |
95 static uint8_t fcode_tab[MAX_MV*2+1]; | 95 static uint8_t fcode_tab[MAX_MV*2+1]; |
96 | 96 |
97 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2]; | 97 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2]; |
164 code= 111; /*rl->n*/ | 164 code= 111; /*rl->n*/ |
165 else | 165 else |
166 code= rl->index_run[0][run] + alevel - 1; | 166 code= rl->index_run[0][run] + alevel - 1; |
167 | 167 |
168 if (code < 111 /* rl->n */) { | 168 if (code < 111 /* rl->n */) { |
169 /* store the vlc & sign at once */ | 169 /* store the vlc & sign at once */ |
170 len= mpeg1_vlc[code][1]+1; | 170 len= mpeg1_vlc[code][1]+1; |
171 bits= (mpeg1_vlc[code][0]<<1) + sign; | 171 bits= (mpeg1_vlc[code][0]<<1) + sign; |
172 } else { | 172 } else { |
173 len= mpeg1_vlc[111/*rl->n*/][1]+6; | 173 len= mpeg1_vlc[111/*rl->n*/][1]+6; |
174 bits= mpeg1_vlc[111/*rl->n*/][0]<<6; | 174 bits= mpeg1_vlc[111/*rl->n*/][0]<<6; |
762 common_init(s); | 762 common_init(s); |
763 | 763 |
764 if(!done){ | 764 if(!done){ |
765 int f_code; | 765 int f_code; |
766 int mv; | 766 int mv; |
767 int i; | 767 int i; |
768 | 768 |
769 done=1; | 769 done=1; |
770 init_rl(&rl_mpeg1, 1); | 770 init_rl(&rl_mpeg1, 1); |
771 | 771 |
772 for(i=0; i<64; i++) | 772 for(i=0; i<64; i++) |
773 { | 773 { |
774 mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; | 774 mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; |
775 mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; | 775 mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; |
776 } | 776 } |
777 | 777 |
778 init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_bits, uni_mpeg1_ac_vlc_len); | 778 init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_bits, uni_mpeg1_ac_vlc_len); |
779 | 779 |
780 /* build unified dc encoding tables */ | 780 /* build unified dc encoding tables */ |
781 for(i=-255; i<256; i++) | 781 for(i=-255; i<256; i++) |
782 { | 782 { |
783 int adiff, index; | 783 int adiff, index; |
784 int bits, code; | 784 int bits, code; |
785 int diff=i; | 785 int diff=i; |
786 | 786 |
787 adiff = ABS(diff); | 787 adiff = ABS(diff); |
788 if(diff<0) diff--; | 788 if(diff<0) diff--; |
789 index = av_log2(2*adiff); | 789 index = av_log2(2*adiff); |
790 | 790 |
791 bits= vlc_dc_lum_bits[index] + index; | 791 bits= vlc_dc_lum_bits[index] + index; |
792 code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)); | 792 code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)); |
793 mpeg1_lum_dc_uni[i+255]= bits + (code<<8); | 793 mpeg1_lum_dc_uni[i+255]= bits + (code<<8); |
794 | 794 |
795 bits= vlc_dc_chroma_bits[index] + index; | 795 bits= vlc_dc_chroma_bits[index] + index; |
796 code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)); | 796 code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)); |
797 mpeg1_chr_dc_uni[i+255]= bits + (code<<8); | 797 mpeg1_chr_dc_uni[i+255]= bits + (code<<8); |
798 } | 798 } |
799 | 799 |
800 mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); | 800 mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); |
801 | 801 |
802 for(f_code=1; f_code<=MAX_FCODE; f_code++){ | 802 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
803 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ | 803 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
871 (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1))); | 871 (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1))); |
872 } | 872 } |
873 }else{ | 873 }else{ |
874 if (component == 0) { | 874 if (component == 0) { |
875 put_bits( | 875 put_bits( |
876 &s->pb, | 876 &s->pb, |
877 mpeg1_lum_dc_uni[diff+255]&0xFF, | 877 mpeg1_lum_dc_uni[diff+255]&0xFF, |
878 mpeg1_lum_dc_uni[diff+255]>>8); | 878 mpeg1_lum_dc_uni[diff+255]>>8); |
879 } else { | 879 } else { |
880 put_bits( | 880 put_bits( |
881 &s->pb, | 881 &s->pb, |
882 mpeg1_chr_dc_uni[diff+255]&0xFF, | 882 mpeg1_chr_dc_uni[diff+255]&0xFF, |
883 mpeg1_chr_dc_uni[diff+255]>>8); | 883 mpeg1_chr_dc_uni[diff+255]>>8); |
884 } | 884 } |
885 } | 885 } |
886 } | 886 } |
887 | 887 |
888 static void mpeg1_encode_block(MpegEncContext *s, | 888 static void mpeg1_encode_block(MpegEncContext *s, |
944 sign&=1; | 944 sign&=1; |
945 | 945 |
946 // code = get_rl_index(rl, 0, run, alevel); | 946 // code = get_rl_index(rl, 0, run, alevel); |
947 if (alevel <= mpeg1_max_level[0][run]){ | 947 if (alevel <= mpeg1_max_level[0][run]){ |
948 code= mpeg1_index_run[0][run] + alevel - 1; | 948 code= mpeg1_index_run[0][run] + alevel - 1; |
949 /* store the vlc & sign at once */ | 949 /* store the vlc & sign at once */ |
950 put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign); | 950 put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign); |
951 } else { | 951 } else { |
952 /* escape seems to be pretty rare <5% so i dont optimize it */ | 952 /* escape seems to be pretty rare <5% so i dont optimize it */ |
953 put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]); | 953 put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]); |
954 /* escape: only clip in this case */ | 954 /* escape: only clip in this case */ |
955 put_bits(&s->pb, 6, run); | 955 put_bits(&s->pb, 6, run); |
956 if(s->codec_id == CODEC_ID_MPEG1VIDEO){ | 956 if(s->codec_id == CODEC_ID_MPEG1VIDEO){ |
957 if (alevel < 128) { | 957 if (alevel < 128) { |
1374 if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){ | 1374 if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){ |
1375 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); | 1375 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); |
1376 return -1; | 1376 return -1; |
1377 } | 1377 } |
1378 if(mb_block_count > 6){ | 1378 if(mb_block_count > 6){ |
1379 cbp<<= mb_block_count-6; | 1379 cbp<<= mb_block_count-6; |
1380 cbp |= get_bits(&s->gb, mb_block_count-6); | 1380 cbp |= get_bits(&s->gb, mb_block_count-6); |
1381 } | 1381 } |
1382 | 1382 |
1383 #ifdef HAVE_XVMC | 1383 #ifdef HAVE_XVMC |
1384 //on 1 we memcpy blocks in xvmcvideo | 1384 //on 1 we memcpy blocks in xvmcvideo |
1385 if(s->avctx->xvmc_acceleration > 1){ | 1385 if(s->avctx->xvmc_acceleration > 1){ |
2072 Mpeg1Context *s1 = avctx->priv_data; | 2072 Mpeg1Context *s1 = avctx->priv_data; |
2073 MpegEncContext *s = &s1->mpeg_enc_ctx; | 2073 MpegEncContext *s = &s1->mpeg_enc_ctx; |
2074 uint8_t old_permutation[64]; | 2074 uint8_t old_permutation[64]; |
2075 | 2075 |
2076 if ( | 2076 if ( |
2077 (s1->mpeg_enc_ctx_allocated == 0)|| | 2077 (s1->mpeg_enc_ctx_allocated == 0)|| |
2078 avctx->coded_width != s->width || | 2078 avctx->coded_width != s->width || |
2079 avctx->coded_height != s->height|| | 2079 avctx->coded_height != s->height|| |
2080 s1->save_aspect_info != s->aspect_ratio_info|| | 2080 s1->save_aspect_info != s->aspect_ratio_info|| |
2081 0) | 2081 0) |
2082 { | 2082 { |
2086 s->parse_context.buffer=0; | 2086 s->parse_context.buffer=0; |
2087 MPV_common_end(s); | 2087 MPV_common_end(s); |
2088 s->parse_context= pc; | 2088 s->parse_context= pc; |
2089 } | 2089 } |
2090 | 2090 |
2091 if( (s->width == 0 )||(s->height == 0)) | 2091 if( (s->width == 0 )||(s->height == 0)) |
2092 return -2; | 2092 return -2; |
2093 | 2093 |
2094 avcodec_set_dimensions(avctx, s->width, s->height); | 2094 avcodec_set_dimensions(avctx, s->width, s->height); |
2095 avctx->bit_rate = s->bit_rate; | 2095 avctx->bit_rate = s->bit_rate; |
2096 s1->save_aspect_info = s->aspect_ratio_info; | 2096 s1->save_aspect_info = s->aspect_ratio_info; |
2097 | 2097 |
2127 s->avctx->sample_aspect_ratio= | 2127 s->avctx->sample_aspect_ratio= |
2128 av_div_q( | 2128 av_div_q( |
2129 mpeg2_aspect[s->aspect_ratio_info], | 2129 mpeg2_aspect[s->aspect_ratio_info], |
2130 (AVRational){s1->pan_scan.width, s1->pan_scan.height} | 2130 (AVRational){s1->pan_scan.width, s1->pan_scan.height} |
2131 ); | 2131 ); |
2132 } | 2132 } |
2133 }else{ | 2133 }else{ |
2134 s->avctx->sample_aspect_ratio= | 2134 s->avctx->sample_aspect_ratio= |
2135 mpeg2_aspect[s->aspect_ratio_info]; | 2135 mpeg2_aspect[s->aspect_ratio_info]; |
2136 } | 2136 } |
2137 }//mpeg2 | 2137 }//mpeg2 |
2310 int i,nofco; | 2310 int i,nofco; |
2311 | 2311 |
2312 nofco = 1; | 2312 nofco = 1; |
2313 if(s->progressive_sequence){ | 2313 if(s->progressive_sequence){ |
2314 if(s->repeat_first_field){ | 2314 if(s->repeat_first_field){ |
2315 nofco++; | 2315 nofco++; |
2316 if(s->top_field_first) | 2316 if(s->top_field_first) |
2317 nofco++; | 2317 nofco++; |
2318 } | 2318 } |
2319 }else{ | 2319 }else{ |
2320 if(s->picture_structure == PICT_FRAME){ | 2320 if(s->picture_structure == PICT_FRAME){ |
2321 nofco++; | 2321 nofco++; |
2322 if(s->repeat_first_field) | 2322 if(s->repeat_first_field) |
2323 nofco++; | 2323 nofco++; |
2324 } | 2324 } |
2325 } | 2325 } |
2326 for(i=0; i<nofco; i++){ | 2326 for(i=0; i<nofco; i++){ |
2327 s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16); | 2327 s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16); |
2328 skip_bits(&s->gb, 1); //marker | 2328 skip_bits(&s->gb, 1); //marker |
2329 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); | 2329 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); |
2983 are missing (open gop)*/ | 2983 are missing (open gop)*/ |
2984 broken_link = get_bits1(&s->gb); | 2984 broken_link = get_bits1(&s->gb); |
2985 | 2985 |
2986 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | 2986 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
2987 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n", | 2987 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n", |
2988 time_code_hours, time_code_minutes, time_code_seconds, | 2988 time_code_hours, time_code_minutes, time_code_seconds, |
2989 time_code_pictures, broken_link); | 2989 time_code_pictures, broken_link); |
2990 } | 2990 } |
2991 /** | 2991 /** |
2992 * finds the end of the current frame in the bitstream. | 2992 * finds the end of the current frame in the bitstream. |
2993 * @return the position of the first byte of the next frame, or -1 | 2993 * @return the position of the first byte of the next frame, or -1 |
2994 */ | 2994 */ |
3042 AVFrame *picture = data; | 3042 AVFrame *picture = data; |
3043 MpegEncContext *s2 = &s->mpeg_enc_ctx; | 3043 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
3044 dprintf("fill_buffer\n"); | 3044 dprintf("fill_buffer\n"); |
3045 | 3045 |
3046 if (buf_size == 0) { | 3046 if (buf_size == 0) { |
3047 /* special case for last picture */ | 3047 /* special case for last picture */ |
3048 if (s2->low_delay==0 && s2->next_picture_ptr) { | 3048 if (s2->low_delay==0 && s2->next_picture_ptr) { |
3049 *picture= *(AVFrame*)s2->next_picture_ptr; | 3049 *picture= *(AVFrame*)s2->next_picture_ptr; |
3050 s2->next_picture_ptr= NULL; | 3050 s2->next_picture_ptr= NULL; |
3051 | 3051 |
3052 *data_size = sizeof(AVFrame); | 3052 *data_size = sizeof(AVFrame); |
3053 } | 3053 } |
3054 return 0; | 3054 return 0; |
3055 } | 3055 } |
3056 | 3056 |
3057 if(s2->flags&CODEC_FLAG_TRUNCATED){ | 3057 if(s2->flags&CODEC_FLAG_TRUNCATED){ |
3058 int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); | 3058 int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); |
3109 | 3109 |
3110 /* prepare data for next start code */ | 3110 /* prepare data for next start code */ |
3111 switch(start_code) { | 3111 switch(start_code) { |
3112 case SEQ_START_CODE: | 3112 case SEQ_START_CODE: |
3113 mpeg1_decode_sequence(avctx, buf_ptr, | 3113 mpeg1_decode_sequence(avctx, buf_ptr, |
3114 input_size); | 3114 input_size); |
3115 break; | 3115 break; |
3116 | 3116 |
3117 case PICTURE_START_CODE: | 3117 case PICTURE_START_CODE: |
3118 /* we have a complete image : we try to decompress it */ | 3118 /* we have a complete image : we try to decompress it */ |
3119 mpeg1_decode_picture(avctx, | 3119 mpeg1_decode_picture(avctx, |
3120 buf_ptr, input_size); | 3120 buf_ptr, input_size); |
3121 break; | 3121 break; |
3122 case EXT_START_CODE: | 3122 case EXT_START_CODE: |
3123 mpeg_decode_extension(avctx, | 3123 mpeg_decode_extension(avctx, |
3124 buf_ptr, input_size); | 3124 buf_ptr, input_size); |
3125 break; | 3125 break; |