aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2005-01-29 23:59:32 +0000
committerMichael Niedermayer <michaelni@gmx.at>2005-01-29 23:59:32 +0000
commit4b9ac0b5f070f35eff671d83cee436db40631112 (patch)
tree3143cfcb1be29f3736ed4e6c4e8b73d9c1a398d7 /libavcodec
parentf4ff1b92cc062ea465ac280c03d93491a70507b9 (diff)
downloadffmpeg-4b9ac0b5f070f35eff671d83cee436db40631112.tar.gz
require a few valid and equal mp3 headers for resync
Originally committed as revision 3900 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/parser.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 60f55758ff..44496a5f10 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -494,6 +494,8 @@ typedef struct MpegAudioParseContext {
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 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
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 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
}
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 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
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 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
}
#endif
}
+ if(s->header_count <= 0)
+ avctx->sample_rate= sr; //FIXME ugly
}
} else
#if 0
@@ -642,8 +653,10 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
// 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;