comparison h264.c @ 11777:82a880c86afd libavcodec

Factorize ff_h264_decode_extradata(). Patch by Howard Chu, hyc highlandsun com
author cehoyos
date Wed, 26 May 2010 19:00:59 +0000
parents 7dd2a45249a9
children cb40fa41b796
comparison
equal deleted inserted replaced
11776:906fdc96cdf4 11777:82a880c86afd
842 842
843 memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t)); 843 memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t));
844 memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t)); 844 memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t));
845 } 845 }
846 846
847 av_cold int ff_h264_decode_init(AVCodecContext *avctx){ 847 int ff_h264_decode_extradata(H264Context *h)
848 H264Context *h= avctx->priv_data; 848 {
849 MpegEncContext * const s = &h->s; 849 AVCodecContext *avctx = h->s.avctx;
850 850
851 MPV_decode_defaults(s); 851 if(*(char *)avctx->extradata == 1){
852
853 s->avctx = avctx;
854 common_init(h);
855
856 s->out_format = FMT_H264;
857 s->workaround_bugs= avctx->workaround_bugs;
858
859 // set defaults
860 // s->decode_mb= ff_h263_decode_mb;
861 s->quarter_sample = 1;
862 if(!avctx->has_b_frames)
863 s->low_delay= 1;
864
865 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
866
867 ff_h264_decode_init_vlc();
868
869 h->thread_context[0] = h;
870 h->outputed_poc = INT_MIN;
871 h->prev_poc_msb= 1<<16;
872 h->x264_build = -1;
873 ff_h264_reset_sei(h);
874 if(avctx->codec_id == CODEC_ID_H264){
875 if(avctx->ticks_per_frame == 1){
876 s->avctx->time_base.den *=2;
877 }
878 avctx->ticks_per_frame = 2;
879 }
880
881 if(avctx->extradata_size > 0 && avctx->extradata && *(char *)avctx->extradata == 1){
882 int i, cnt, nalsize; 852 int i, cnt, nalsize;
883 unsigned char *p = avctx->extradata; 853 unsigned char *p = avctx->extradata;
884 854
885 h->is_avc = 1; 855 h->is_avc = 1;
886 856
914 } 884 }
915 // Now store right nal length size, that will be use to parse all other nals 885 // Now store right nal length size, that will be use to parse all other nals
916 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; 886 h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1;
917 } else { 887 } else {
918 h->is_avc = 0; 888 h->is_avc = 0;
919 if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0) 889 if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0)
920 return -1; 890 return -1;
921 } 891 }
892 return 0;
893 }
894
895 av_cold int ff_h264_decode_init(AVCodecContext *avctx){
896 H264Context *h= avctx->priv_data;
897 MpegEncContext * const s = &h->s;
898
899 MPV_decode_defaults(s);
900
901 s->avctx = avctx;
902 common_init(h);
903
904 s->out_format = FMT_H264;
905 s->workaround_bugs= avctx->workaround_bugs;
906
907 // set defaults
908 // s->decode_mb= ff_h263_decode_mb;
909 s->quarter_sample = 1;
910 if(!avctx->has_b_frames)
911 s->low_delay= 1;
912
913 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
914
915 ff_h264_decode_init_vlc();
916
917 h->thread_context[0] = h;
918 h->outputed_poc = INT_MIN;
919 h->prev_poc_msb= 1<<16;
920 h->x264_build = -1;
921 ff_h264_reset_sei(h);
922 if(avctx->codec_id == CODEC_ID_H264){
923 if(avctx->ticks_per_frame == 1){
924 s->avctx->time_base.den *=2;
925 }
926 avctx->ticks_per_frame = 2;
927 }
928
929 if(avctx->extradata_size > 0 && avctx->extradata &&
930 ff_h264_decode_extradata(h))
931 return -1;
932
922 if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){ 933 if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){
923 s->avctx->has_b_frames = h->sps.num_reorder_frames; 934 s->avctx->has_b_frames = h->sps.num_reorder_frames;
924 s->low_delay = 0; 935 s->low_delay = 0;
925 } 936 }
926 937