Mercurial > libavcodec.hg
comparison h261.c @ 2356:def33a002b94 libavcodec
fix parser
author | michael |
---|---|
date | Fri, 19 Nov 2004 11:37:03 +0000 |
parents | ada3891b859d |
children | 26560d4fdb1f |
comparison
equal
deleted
inserted
replaced
2355:69fcdad5f7d5 | 2356:def33a002b94 |
---|---|
849 uint32_t state; | 849 uint32_t state; |
850 | 850 |
851 vop_found= pc->frame_start_found; | 851 vop_found= pc->frame_start_found; |
852 state= pc->state; | 852 state= pc->state; |
853 | 853 |
854 i=0; | 854 for(i=0; i<buf_size && !vop_found; i++){ |
855 if(!vop_found){ | 855 state= (state<<8) | buf[i]; |
856 for(i=0; i<buf_size; i++){ | 856 for(j=0; j<8; j++){ |
857 if(((state>>j)&0xFFFFF) == 0x00010){ | |
858 i++; | |
859 vop_found=1; | |
860 break; | |
861 } | |
862 } | |
863 } | |
864 if(vop_found){ | |
865 for(; i<buf_size; i++){ | |
857 state= (state<<8) | buf[i]; | 866 state= (state<<8) | buf[i]; |
858 for(j=0; j<8; j++){ | 867 for(j=0; j<8; j++){ |
859 if(( ( (state<<j) | (buf[i]>>(8-j)) )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){ | 868 if(((state>>j)&0xFFFFF) == 0x00010){ |
860 i++; | |
861 vop_found=1; | |
862 break; | |
863 } | |
864 } | |
865 if(vop_found) | |
866 break; | |
867 } | |
868 } | |
869 if(vop_found){ | |
870 for(; i<buf_size; i++){ | |
871 if(avctx->flags & CODEC_FLAG_TRUNCATED)//XXX ffplay workaround, someone a better solution? | |
872 state= (state<<8) | buf[i]; | |
873 for(j=0; j<8; j++){ | |
874 if(( ( (state<<j) | (buf[i]>>(8-j)) )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){ | |
875 pc->frame_start_found=0; | 869 pc->frame_start_found=0; |
876 pc->state=-1; | 870 pc->state= state>>(2*8); |
877 return i-3; | 871 return i-1; |
878 } | 872 } |
879 } | 873 } |
880 } | 874 } |
881 } | 875 } |
882 | 876 |
906 | 900 |
907 /** | 901 /** |
908 * returns the number of bytes consumed for building the current frame | 902 * returns the number of bytes consumed for building the current frame |
909 */ | 903 */ |
910 static int get_consumed_bytes(MpegEncContext *s, int buf_size){ | 904 static int get_consumed_bytes(MpegEncContext *s, int buf_size){ |
911 if(s->flags&CODEC_FLAG_TRUNCATED){ | 905 int pos= get_bits_count(&s->gb)>>3; |
912 int pos= (get_bits_count(&s->gb)+7)>>3; | 906 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) |
913 pos -= s->parse_context.last_index; | 907 if(pos+10>buf_size) pos=buf_size; // oops ;) |
914 if(pos<0) pos=0;// padding is not really read so this might be -1 | 908 |
915 return pos; | 909 return pos; |
916 }else{ | |
917 int pos= get_bits_count(&s->gb)>>3; | |
918 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | |
919 if(pos+10>buf_size) pos=buf_size; // oops ;) | |
920 | |
921 return pos; | |
922 } | |
923 } | 910 } |
924 | 911 |
925 static int h261_decode_frame(AVCodecContext *avctx, | 912 static int h261_decode_frame(AVCodecContext *avctx, |
926 void *data, int *data_size, | 913 void *data, int *data_size, |
927 uint8_t *buf, int buf_size) | 914 uint8_t *buf, int buf_size) |
940 | 927 |
941 /* no supplementary picture */ | 928 /* no supplementary picture */ |
942 if (buf_size == 0) { | 929 if (buf_size == 0) { |
943 return 0; | 930 return 0; |
944 } | 931 } |
945 | 932 |
946 if(s->flags&CODEC_FLAG_TRUNCATED){ | 933 h->gob_start_code_skipped=0; |
947 int next; | |
948 | |
949 next= h261_find_frame_end(&s->parse_context,avctx, buf, buf_size); | |
950 | |
951 if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) | |
952 return buf_size; | |
953 } | |
954 | |
955 | 934 |
956 retry: | 935 retry: |
957 | 936 |
958 init_get_bits(&s->gb, buf, buf_size*8); | 937 init_get_bits(&s->gb, buf, buf_size*8); |
959 | 938 |
1011 } | 990 } |
1012 MPV_frame_end(s); | 991 MPV_frame_end(s); |
1013 | 992 |
1014 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); | 993 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); |
1015 assert(s->current_picture.pict_type == s->pict_type); | 994 assert(s->current_picture.pict_type == s->pict_type); |
1016 *pict= *(AVFrame*)&s->current_picture; | 995 *pict= *(AVFrame*)s->current_picture_ptr; |
1017 ff_print_debug_info(s, pict); | 996 ff_print_debug_info(s, pict); |
1018 | 997 |
1019 /* Return the Picture timestamp as the frame number */ | 998 /* Return the Picture timestamp as the frame number */ |
1020 /* we substract 1 because it is added on utils.c */ | 999 /* we substract 1 because it is added on utils.c */ |
1021 avctx->frame_number = s->picture_number - 1; | 1000 avctx->frame_number = s->picture_number - 1; |
1051 sizeof(H261Context), | 1030 sizeof(H261Context), |
1052 h261_decode_init, | 1031 h261_decode_init, |
1053 NULL, | 1032 NULL, |
1054 h261_decode_end, | 1033 h261_decode_end, |
1055 h261_decode_frame, | 1034 h261_decode_frame, |
1056 CODEC_CAP_TRUNCATED, | 1035 CODEC_CAP_DR1, |
1057 }; | 1036 }; |
1058 | 1037 |
1059 AVCodecParser h261_parser = { | 1038 AVCodecParser h261_parser = { |
1060 { CODEC_ID_H261 }, | 1039 { CODEC_ID_H261 }, |
1061 sizeof(ParseContext), | 1040 sizeof(ParseContext), |