comparison mpegaudiodec.c @ 9595:f9a7147cc9e6 libavcodec

Do not scan for MP3 header after the given buffer and return skipped bytes along with consumed bytes on successful decoding. patch by Zdenek Kabelac, zdenek.kabelac gmail com
author diego
date Mon, 04 May 2009 14:23:48 +0000
parents 72d9eee542c8
children 21225d993671
comparison
equal deleted inserted replaced
9594:a0517e3590fd 9595:f9a7147cc9e6
2261 const uint8_t *buf = avpkt->data; 2261 const uint8_t *buf = avpkt->data;
2262 int buf_size = avpkt->size; 2262 int buf_size = avpkt->size;
2263 MPADecodeContext *s = avctx->priv_data; 2263 MPADecodeContext *s = avctx->priv_data;
2264 uint32_t header; 2264 uint32_t header;
2265 int out_size; 2265 int out_size;
2266 int skipped = 0;
2266 OUT_INT *out_samples = data; 2267 OUT_INT *out_samples = data;
2267 2268
2268 retry: 2269 retry:
2269 if(buf_size < HEADER_SIZE) 2270 if(buf_size < HEADER_SIZE)
2270 return -1; 2271 return -1;
2271 2272
2272 header = AV_RB32(buf); 2273 header = AV_RB32(buf);
2273 if(ff_mpa_check_header(header) < 0){ 2274 if(ff_mpa_check_header(header) < 0){
2274 buf++; 2275 buf++;
2275 // buf_size--; 2276 buf_size--;
2277 skipped++;
2276 av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n"); 2278 av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
2277 goto retry; 2279 goto retry;
2278 } 2280 }
2279 2281
2280 if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { 2282 if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
2301 avctx->sample_rate = s->sample_rate; 2303 avctx->sample_rate = s->sample_rate;
2302 //FIXME maybe move the other codec info stuff from above here too 2304 //FIXME maybe move the other codec info stuff from above here too
2303 }else 2305 }else
2304 av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed 2306 av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed
2305 s->frame_size = 0; 2307 s->frame_size = 0;
2306 return buf_size; 2308 return buf_size + skipped;
2307 } 2309 }
2308 2310
2309 static void flush(AVCodecContext *avctx){ 2311 static void flush(AVCodecContext *avctx){
2310 MPADecodeContext *s = avctx->priv_data; 2312 MPADecodeContext *s = avctx->priv_data;
2311 memset(s->synth_buf, 0, sizeof(s->synth_buf)); 2313 memset(s->synth_buf, 0, sizeof(s->synth_buf));