diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-05-09 16:09:53 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-05-20 12:06:31 +0200 |
commit | 12ded9cd85be60d9622c438d9a8cfc099028c960 (patch) | |
tree | 9dc75e5e8e25c30c41504531556aa2cbca865b91 | |
parent | ae937c49027fab3b5f34397e04ee7aa22d9ae40f (diff) | |
download | ffmpeg-12ded9cd85be60d9622c438d9a8cfc099028c960.tar.gz |
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>
-rw-r--r-- | libavcodec/aac_parser.c | 16 | ||||
-rw-r--r-- | libavcodec/adts_header.c | 10 | ||||
-rw-r--r-- | libavcodec/adts_header.h | 14 | ||||
-rw-r--r-- | libavcodec/adts_parser.c | 18 | ||||
-rw-r--r-- | libavcodec/bsf/aac_adtstoasc.c | 6 | ||||
-rw-r--r-- | libavcodec/ftr_parser.c | 7 |
6 files changed, 35 insertions, 36 deletions
diff --git a/libavcodec/aac_parser.c b/libavcodec/aac_parser.c index f295dfccdd..186fcd887a 100644 --- a/libavcodec/aac_parser.c +++ b/libavcodec/aac_parser.c @@ -24,24 +24,18 @@ #include "aac_ac3_parser.h" #include "adts_header.h" #include "adts_parser.h" -#include "get_bits.h" -#include "mpeg4audio.h" +#include "libavutil/intreadwrite.h" static int aac_sync(uint64_t state, int *need_next_header, int *new_frame_start) { - GetBitContext bits; + uint8_t tmp[8 + AV_INPUT_BUFFER_PADDING_SIZE]; AACADTSHeaderInfo hdr; int size; - union { - uint64_t u64; - uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE]; - } tmp; - tmp.u64 = av_be2ne64(state); - init_get_bits(&bits, tmp.u8 + 8 - AV_AAC_ADTS_HEADER_SIZE, - AV_AAC_ADTS_HEADER_SIZE * 8); + AV_WB64(tmp, state); - if ((size = ff_adts_header_parse(&bits, &hdr)) < 0) + size = ff_adts_header_parse_buf(tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, &hdr); + if (size < 0) return 0; *need_next_header = 0; *new_frame_start = 1; diff --git a/libavcodec/adts_header.c b/libavcodec/adts_header.c index 8663d00f4c..0d6be1aa0e 100644 --- a/libavcodec/adts_header.c +++ b/libavcodec/adts_header.c @@ -25,6 +25,7 @@ #include "adts_parser.h" #include "get_bits.h" #include "mpeg4audio.h" +#include "libavutil/avassert.h" int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr) { @@ -71,3 +72,12 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr) return size; } + +int ff_adts_header_parse_buf(const uint8_t buf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE], + AACADTSHeaderInfo *hdr) +{ + GetBitContext gb; + av_unused int ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE); + av_assert1(ret >= 0); + return ff_adts_header_parse(&gb, hdr); +} diff --git a/libavcodec/adts_header.h b/libavcodec/adts_header.h index 929c0cb367..49bb74ee22 100644 --- a/libavcodec/adts_header.h +++ b/libavcodec/adts_header.h @@ -23,7 +23,8 @@ #ifndef AVCODEC_ADTS_HEADER_H #define AVCODEC_ADTS_HEADER_H -#include "get_bits.h" +#include "adts_parser.h" +#include "defs.h" typedef enum { AAC_PARSE_ERROR_SYNC = -0x1030c0a, @@ -43,6 +44,8 @@ typedef struct AACADTSHeaderInfo { uint32_t frame_length; } AACADTSHeaderInfo; +struct GetBitContext; + /** * Parse the ADTS frame header to the end of the variable header, which is * the first 54 bits. @@ -51,7 +54,14 @@ typedef struct AACADTSHeaderInfo { * @return the size in bytes of the header parsed on success and * AAC_PARSE_ERROR_* values otherwise. */ -int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr); +int ff_adts_header_parse(struct GetBitContext *gbc, AACADTSHeaderInfo *hdr); + +/** + * Wrapper around ff_adts_header_parse() for users that don't already have + * a suitable GetBitContext. + */ +int ff_adts_header_parse_buf(const uint8_t buf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE], + AACADTSHeaderInfo *hdr); /** * Parse the ADTS frame header contained in the buffer, which is diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c index 81e2669149..66b988d6f6 100644 --- a/libavcodec/adts_parser.c +++ b/libavcodec/adts_parser.c @@ -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); diff --git a/libavcodec/bsf/aac_adtstoasc.c b/libavcodec/bsf/aac_adtstoasc.c index dd5e8b2a31..b821414f2a 100644 --- a/libavcodec/bsf/aac_adtstoasc.c +++ b/libavcodec/bsf/aac_adtstoasc.c @@ -40,7 +40,6 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) { AACBSFContext *ctx = bsfc->priv_data; - GetBitContext gb; PutBitContext pb; AACADTSHeaderInfo hdr; int ret; @@ -55,9 +54,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) if (pkt->size < AV_AAC_ADTS_HEADER_SIZE) goto packet_too_small; - init_get_bits(&gb, pkt->data, AV_AAC_ADTS_HEADER_SIZE * 8); - - if (ff_adts_header_parse(&gb, &hdr) < 0) { + if (ff_adts_header_parse_buf(pkt->data, &hdr) < 0) { av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); ret = AVERROR_INVALIDDATA; goto fail; @@ -81,6 +78,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) uint8_t *extradata; if (!hdr.chan_config) { + GetBitContext gb; init_get_bits(&gb, pkt->data, pkt->size * 8); if (get_bits(&gb, 3) != 5) { avpriv_report_missing_feature(bsfc, diff --git a/libavcodec/ftr_parser.c b/libavcodec/ftr_parser.c index 05e6cfed98..656fd289f6 100644 --- a/libavcodec/ftr_parser.c +++ b/libavcodec/ftr_parser.c @@ -25,7 +25,6 @@ */ #include "parser.h" -#include "get_bits.h" #include "adts_header.h" #include "adts_parser.h" #include "mpeg4audio.h" @@ -45,7 +44,6 @@ static int ftr_parse(AVCodecParserContext *s, AVCodecContext *avctx, FTRParseContext *ftr = s->priv_data; uint64_t state = ftr->pc.state64; int next = END_NOT_FOUND; - GetBitContext bits; AACADTSHeaderInfo hdr; int size; @@ -71,10 +69,9 @@ static int ftr_parse(AVCodecParserContext *s, AVCodecContext *avctx, state = (state << 8) | buf[i]; AV_WB64(tmp, state); - init_get_bits(&bits, tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, - AV_AAC_ADTS_HEADER_SIZE * 8); + size = ff_adts_header_parse_buf(tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, &hdr); - if ((size = ff_adts_header_parse(&bits, &hdr)) > 0) { + if (size > 0) { ftr->skip = size - 6; ftr->frame_index += ff_mpeg4audio_channels[hdr.chan_config]; if (ftr->frame_index >= avctx->ch_layout.nb_channels) { |