Mercurial > libavcodec.hg
comparison mpeg12.c @ 3086:befacb1cb573 libavcodec
faster find_startcode()
author | michael |
---|---|
date | Sat, 04 Feb 2006 20:32:02 +0000 |
parents | c5e521489fdf |
children | 00b2754a9bb2 |
comparison
equal
deleted
inserted
replaced
3085:95bee8ba8870 | 3086:befacb1cb573 |
---|---|
2169 s1->mpeg_enc_ctx_allocated = 1; | 2169 s1->mpeg_enc_ctx_allocated = 1; |
2170 } | 2170 } |
2171 return 0; | 2171 return 0; |
2172 } | 2172 } |
2173 | 2173 |
2174 /* return the 8 bit start code value and update the search | |
2175 state. Return -1 if no start code found */ | |
2176 static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end) | |
2177 { | |
2178 const uint8_t *buf_ptr= *pbuf_ptr; | |
2179 | |
2180 buf_ptr++; //gurantees that -1 is within the array | |
2181 buf_end -= 3; // gurantees that +3 is within the array | |
2182 | |
2183 while (buf_ptr < buf_end) { | |
2184 if(*buf_ptr==0){ | |
2185 while(buf_ptr < buf_end && buf_ptr[1]==0) | |
2186 buf_ptr++; | |
2187 | |
2188 if(buf_ptr[-1] == 0 && buf_ptr[1] == 1){ | |
2189 *pbuf_ptr = buf_ptr+3; | |
2190 return buf_ptr[2] + 0x100; | |
2191 } | |
2192 } | |
2193 buf_ptr += 2; | |
2194 } | |
2195 buf_end += 3; //undo the hack above | |
2196 | |
2197 *pbuf_ptr = buf_end; | |
2198 return -1; | |
2199 } | |
2200 | |
2201 static int mpeg1_decode_picture(AVCodecContext *avctx, | 2174 static int mpeg1_decode_picture(AVCodecContext *avctx, |
2202 const uint8_t *buf, int buf_size) | 2175 const uint8_t *buf, int buf_size) |
2203 { | 2176 { |
2204 Mpeg1Context *s1 = avctx->priv_data; | 2177 Mpeg1Context *s1 = avctx->priv_data; |
2205 MpegEncContext *s = &s1->mpeg_enc_ctx; | 2178 MpegEncContext *s = &s1->mpeg_enc_ctx; |
2713 } | 2686 } |
2714 | 2687 |
2715 if(s->mb_y == s->end_mb_y) | 2688 if(s->mb_y == s->end_mb_y) |
2716 return 0; | 2689 return 0; |
2717 | 2690 |
2718 start_code = find_start_code(&buf, s->gb.buffer_end); | 2691 start_code= -1; |
2692 buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code); | |
2719 mb_y= start_code - SLICE_MIN_START_CODE; | 2693 mb_y= start_code - SLICE_MIN_START_CODE; |
2720 if(mb_y < 0 || mb_y >= s->end_mb_y) | 2694 if(mb_y < 0 || mb_y >= s->end_mb_y) |
2721 return -1; | 2695 return -1; |
2722 } | 2696 } |
2723 | 2697 |
2993 * @return the position of the first byte of the next frame, or -1 | 2967 * @return the position of the first byte of the next frame, or -1 |
2994 */ | 2968 */ |
2995 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) | 2969 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) |
2996 { | 2970 { |
2997 int i; | 2971 int i; |
2998 uint32_t state; | 2972 uint32_t state= pc->state; |
2999 | |
3000 state= pc->state; | |
3001 | 2973 |
3002 i=0; | 2974 i=0; |
3003 if(!pc->frame_start_found){ | 2975 if(!pc->frame_start_found){ |
3004 for(i=0; i<buf_size; i++){ | 2976 for(i=0; i<buf_size; i++){ |
3005 state= (state<<8) | buf[i]; | 2977 i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; |
3006 if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ | 2978 if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ |
3007 i++; | 2979 i++; |
3008 pc->frame_start_found=1; | 2980 pc->frame_start_found=1; |
3009 break; | 2981 break; |
3010 } | 2982 } |
3014 if(pc->frame_start_found){ | 2986 if(pc->frame_start_found){ |
3015 /* EOF considered as end of frame */ | 2987 /* EOF considered as end of frame */ |
3016 if (buf_size == 0) | 2988 if (buf_size == 0) |
3017 return 0; | 2989 return 0; |
3018 for(; i<buf_size; i++){ | 2990 for(; i<buf_size; i++){ |
3019 state= (state<<8) | buf[i]; | 2991 i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; |
3020 if((state&0xFFFFFF00) == 0x100){ | 2992 if((state&0xFFFFFF00) == 0x100){ |
3021 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ | 2993 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ |
3022 pc->frame_start_found=0; | 2994 pc->frame_start_found=0; |
3023 pc->state=-1; | 2995 pc->state=-1; |
3024 return i-3; | 2996 return i-3; |
3081 | 3053 |
3082 s->slice_count= 0; | 3054 s->slice_count= 0; |
3083 | 3055 |
3084 for(;;) { | 3056 for(;;) { |
3085 /* find start next code */ | 3057 /* find start next code */ |
3086 start_code = find_start_code(&buf_ptr, buf_end); | 3058 start_code = -1; |
3059 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); | |
3087 if (start_code < 0){ | 3060 if (start_code < 0){ |
3088 if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ | 3061 if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ |
3089 if(avctx->thread_count > 1){ | 3062 if(avctx->thread_count > 1){ |
3090 int i; | 3063 int i; |
3091 | 3064 |