Commit c3202fc9 authored by michael's avatar michael

require a few valid and equal mp3 headers for resync


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@3900 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 93a72f1d
...@@ -494,6 +494,8 @@ typedef struct MpegAudioParseContext { ...@@ -494,6 +494,8 @@ typedef struct MpegAudioParseContext {
int frame_size; int frame_size;
int free_format_frame_size; int free_format_frame_size;
int free_format_next_header; int free_format_next_header;
uint32_t header;
int header_count;
} MpegAudioParseContext; } MpegAudioParseContext;
#define MPA_HEADER_SIZE 4 #define MPA_HEADER_SIZE 4
...@@ -515,7 +517,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -515,7 +517,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
const uint8_t *buf, int buf_size) const uint8_t *buf, int buf_size)
{ {
MpegAudioParseContext *s = s1->priv_data; MpegAudioParseContext *s = s1->priv_data;
int len, ret; int len, ret, sr;
uint32_t header; uint32_t header;
const uint8_t *buf_ptr; const uint8_t *buf_ptr;
...@@ -549,11 +551,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -549,11 +551,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
} }
if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
got_header: got_header:
sr= avctx->sample_rate;
header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
(s->inbuf[2] << 8) | s->inbuf[3]; (s->inbuf[2] << 8) | s->inbuf[3];
ret = mpa_decode_header(avctx, header); ret = mpa_decode_header(avctx, header);
if (ret < 0) { if (ret < 0) {
s->header_count= -2;
/* no sync found : move by one byte (inefficient, but simple!) */ /* no sync found : move by one byte (inefficient, but simple!) */
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
s->inbuf_ptr--; s->inbuf_ptr--;
...@@ -562,7 +566,12 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -562,7 +566,12 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
to get a new bitrate */ to get a new bitrate */
s->free_format_frame_size = 0; s->free_format_frame_size = 0;
} else { } 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; s->frame_size = ret;
#if 0 #if 0
/* free format: prepare to compute frame size */ /* free format: prepare to compute frame size */
if (decode_header(s, header) == 1) { if (decode_header(s, header) == 1) {
...@@ -570,6 +579,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -570,6 +579,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
} }
#endif #endif
} }
if(s->header_count <= 0)
avctx->sample_rate= sr; //FIXME ugly
} }
} else } else
#if 0 #if 0
...@@ -642,8 +653,10 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -642,8 +653,10 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
// next_data: // next_data:
if (s->frame_size > 0 && if (s->frame_size > 0 &&
(s->inbuf_ptr - s->inbuf) >= s->frame_size) { (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
*poutbuf = s->inbuf; if(s->header_count > 0){
*poutbuf_size = s->inbuf_ptr - s->inbuf; *poutbuf = s->inbuf;
*poutbuf_size = s->inbuf_ptr - s->inbuf;
}
s->inbuf_ptr = s->inbuf; s->inbuf_ptr = s->inbuf;
s->frame_size = 0; s->frame_size = 0;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment