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>
pull/388/head
James Almer 2 years ago
parent 72db6a4f5f
commit 676e7d7f9b
  1. 2
      libavcodec/adts_header.c
  2. 12
      libavcodec/adts_parser.c

@ -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;

@ -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;
}

Loading…
Cancel
Save