Mercurial > libavcodec.hg
changeset 2470:06aafb585f69 libavcodec
require a few valid and equal mp3 headers for resync
author | michael |
---|---|
date | Sat, 29 Jan 2005 23:59:32 +0000 |
parents | df02930c138b |
children | 805431763e84 |
files | parser.c |
diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/parser.c Sat Jan 29 20:09:33 2005 +0000 +++ b/parser.c Sat Jan 29 23:59:32 2005 +0000 @@ -494,6 +494,8 @@ int frame_size; int free_format_frame_size; int free_format_next_header; + uint32_t header; + int header_count; } MpegAudioParseContext; #define MPA_HEADER_SIZE 4 @@ -515,7 +517,7 @@ const uint8_t *buf, int buf_size) { MpegAudioParseContext *s = s1->priv_data; - int len, ret; + int len, ret, sr; uint32_t header; const uint8_t *buf_ptr; @@ -549,11 +551,13 @@ } if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { got_header: + sr= avctx->sample_rate; header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; ret = mpa_decode_header(avctx, header); if (ret < 0) { + s->header_count= -2; /* no sync found : move by one byte (inefficient, but simple!) */ memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; @@ -562,7 +566,12 @@ to get a new bitrate */ s->free_format_frame_size = 0; } else { + if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) + s->header_count= -3; + s->header= header; + s->header_count++; s->frame_size = ret; + #if 0 /* free format: prepare to compute frame size */ if (decode_header(s, header) == 1) { @@ -570,6 +579,8 @@ } #endif } + if(s->header_count <= 0) + avctx->sample_rate= sr; //FIXME ugly } } else #if 0 @@ -642,8 +653,10 @@ // next_data: if (s->frame_size > 0 && (s->inbuf_ptr - s->inbuf) >= s->frame_size) { - *poutbuf = s->inbuf; - *poutbuf_size = s->inbuf_ptr - s->inbuf; + if(s->header_count > 0){ + *poutbuf = s->inbuf; + *poutbuf_size = s->inbuf_ptr - s->inbuf; + } s->inbuf_ptr = s->inbuf; s->frame_size = 0; break;