1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avcodec/adts_parser: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse()

Code freeing the struct on failure is kept for backwards compatibility, but
should be removed in the next major bump, and the existing lavf user adapted.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2022-10-22 22:07:34 -03:00
parent 72db6a4f5f
commit 676e7d7f9b
2 changed files with 11 additions and 3 deletions

View File

@ -32,6 +32,8 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
int size, rdb, ch, sr;
int aot, crc_abs;
memset(hdr, 0, sizeof(*hdr));
if (get_bits(gbc, 12) != 0xfff)
return AAC_AC3_PARSE_ERROR_SYNC;

View File

@ -47,24 +47,30 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_
{
#if CONFIG_ADTS_HEADER
int ret = 0;
int allocated = 0;
GetBitContext gb;
if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE)
return AVERROR_INVALIDDATA;
*phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
if (!*phdr) {
allocated = 1;
*phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
}
if (!*phdr)
return AVERROR(ENOMEM);
ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
if (ret < 0) {
av_freep(phdr);
if (allocated)
av_freep(phdr);
return ret;
}
ret = ff_adts_header_parse(&gb, *phdr);
if (ret < 0) {
av_freep(phdr);
if (allocated)
av_freep(phdr);
return ret;
}