require a few valid and equal mp3 headers for resync
Originally committed as revision 3900 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
f4ff1b92cc
commit
4b9ac0b5f0
@ -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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
#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,
|
|||||||
// 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) {
|
||||||
|
if(s->header_count > 0){
|
||||||
*poutbuf = s->inbuf;
|
*poutbuf = s->inbuf;
|
||||||
*poutbuf_size = s->inbuf_ptr - 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user