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:
parent
72db6a4f5f
commit
676e7d7f9b
@ -32,6 +32,8 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
|
|||||||
int size, rdb, ch, sr;
|
int size, rdb, ch, sr;
|
||||||
int aot, crc_abs;
|
int aot, crc_abs;
|
||||||
|
|
||||||
|
memset(hdr, 0, sizeof(*hdr));
|
||||||
|
|
||||||
if (get_bits(gbc, 12) != 0xfff)
|
if (get_bits(gbc, 12) != 0xfff)
|
||||||
return AAC_AC3_PARSE_ERROR_SYNC;
|
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
|
#if CONFIG_ADTS_HEADER
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int allocated = 0;
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
|
|
||||||
if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE)
|
if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
*phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
|
if (!*phdr) {
|
||||||
|
allocated = 1;
|
||||||
|
*phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
|
||||||
|
}
|
||||||
if (!*phdr)
|
if (!*phdr)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
|
ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_freep(phdr);
|
if (allocated)
|
||||||
|
av_freep(phdr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ff_adts_header_parse(&gb, *phdr);
|
ret = ff_adts_header_parse(&gb, *phdr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_freep(phdr);
|
if (allocated)
|
||||||
|
av_freep(phdr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user