avformat/aacdec: factorize the adts frame resync code

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2019-07-20 10:13:08 -03:00
parent 5941b7f615
commit a38eab8b75
1 changed files with 25 additions and 12 deletions

View File

@ -80,10 +80,31 @@ static int adts_aac_probe(const AVProbeData *p)
return 0; return 0;
} }
static int adts_aac_resync(AVFormatContext *s)
{
uint16_t state;
// skip data until an ADTS frame is found
state = avio_r8(s->pb);
while (!avio_feof(s->pb) && avio_tell(s->pb) < s->probesize) {
state = (state << 8) | avio_r8(s->pb);
if ((state >> 4) != 0xFFF)
continue;
avio_seek(s->pb, -2, SEEK_CUR);
break;
}
if (s->pb->eof_reached)
return AVERROR_EOF;
if ((state >> 4) != 0xFFF)
return AVERROR_INVALIDDATA;
return 0;
}
static int adts_aac_read_header(AVFormatContext *s) static int adts_aac_read_header(AVFormatContext *s)
{ {
AVStream *st; AVStream *st;
uint16_t state; int ret;
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) if (!st)
@ -101,17 +122,9 @@ static int adts_aac_read_header(AVFormatContext *s)
avio_seek(s->pb, cur, SEEK_SET); avio_seek(s->pb, cur, SEEK_SET);
} }
// skip data until the first ADTS frame is found ret = adts_aac_resync(s);
state = avio_r8(s->pb); if (ret < 0)
while (!avio_feof(s->pb) && avio_tell(s->pb) < s->probesize) { return ret;
state = (state << 8) | avio_r8(s->pb);
if ((state >> 4) != 0xFFF)
continue;
avio_seek(s->pb, -2, SEEK_CUR);
break;
}
if ((state >> 4) != 0xFFF)
return AVERROR_INVALIDDATA;
// LCM of all possible ADTS sample rates // LCM of all possible ADTS sample rates
avpriv_set_pts_info(st, 64, 1, 28224000); avpriv_set_pts_info(st, 64, 1, 28224000);