mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-15 11:30:08 +01:00
avcodec/adts_header: Add ff_adts_header_parse_buf()
Most users of ff_adts_header_parse() don't already have an opened GetBitContext for the header, so add a convenience function for them. Also use a forward declaration of GetBitContext in adts_header.h as this avoids (implicit) inclusion of get_bits.h in some of the users that now no longer use a GetBitContext of their own. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -20,7 +20,9 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/error.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "adts_header.h"
|
||||
#include "adts_parser.h"
|
||||
@@ -29,16 +31,12 @@ int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
|
||||
{
|
||||
#if CONFIG_ADTS_HEADER
|
||||
uint8_t tmpbuf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
|
||||
GetBitContext gb;
|
||||
AACADTSHeaderInfo hdr;
|
||||
int err;
|
||||
if (!buf)
|
||||
return AVERROR(EINVAL);
|
||||
memcpy(tmpbuf, buf, AV_AAC_ADTS_HEADER_SIZE);
|
||||
err = init_get_bits8(&gb, tmpbuf, AV_AAC_ADTS_HEADER_SIZE);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = ff_adts_header_parse(&gb, &hdr);
|
||||
err = ff_adts_header_parse_buf(tmpbuf, &hdr);
|
||||
if (err < 0)
|
||||
return err;
|
||||
*samples = hdr.samples;
|
||||
@@ -54,7 +52,6 @@ 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;
|
||||
@@ -66,14 +63,7 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_
|
||||
if (!*phdr)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
|
||||
if (ret < 0) {
|
||||
if (allocated)
|
||||
av_freep(phdr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ff_adts_header_parse(&gb, *phdr);
|
||||
ret = ff_adts_header_parse_buf(buf, *phdr);
|
||||
if (ret < 0) {
|
||||
if (allocated)
|
||||
av_freep(phdr);
|
||||
|
||||
Reference in New Issue
Block a user