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.
Unified · Split
| @@ -24,24 +24,18 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "aac_ac3_parser.h" |
| 25 | 25 | #include "adts_header.h" |
| 26 | 26 | #include "adts_parser.h" |
| 27 | −#include "get_bits.h" | |
| 28 | −#include "mpeg4audio.h" | |
| 27 | +#include "libavutil/intreadwrite.h" | |
| 29 | 28 | |
| 30 | 29 | static int aac_sync(uint64_t state, int *need_next_header, int *new_frame_start) |
| 31 | 30 | { |
| 32 | − GetBitContext bits; | |
| 31 | + uint8_t tmp[8 + AV_INPUT_BUFFER_PADDING_SIZE]; | |
| 33 | 32 | AACADTSHeaderInfo hdr; |
| 34 | 33 | int size; |
| 35 | − union { | |
| 36 | − uint64_t u64; | |
| 37 | − uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE]; | |
| 38 | − } tmp; | |
| 39 | 34 | |
| 40 | − tmp.u64 = av_be2ne64(state); | |
| 41 | − init_get_bits(&bits, tmp.u8 + 8 - AV_AAC_ADTS_HEADER_SIZE, | |
| 42 | − AV_AAC_ADTS_HEADER_SIZE * 8); | |
| 35 | + AV_WB64(tmp, state); | |
| 43 | 36 | |
| 44 | − if ((size = ff_adts_header_parse(&bits, &hdr)) < 0) | |
| 37 | + size = ff_adts_header_parse_buf(tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, &hdr); | |
| 38 | + if (size < 0) | |
| 45 | 39 | return 0; |
| 46 | 40 | *need_next_header = 0; |
| 47 | 41 | *new_frame_start = 1; |
| @@ -25,6 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "adts_parser.h" |
| 26 | 26 | #include "get_bits.h" |
| 27 | 27 | #include "mpeg4audio.h" |
| 28 | +#include "libavutil/avassert.h" | |
| 28 | 29 | |
| 29 | 30 | int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr) |
| 30 | 31 | { |
| @@ -71,3 +72,12 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr) · 40 unmodified lines | ||
| 71 | 72 | |
| 72 | 73 | return size; |
| 73 | 74 | } |
| 75 | + | |
| 76 | +int ff_adts_header_parse_buf(const uint8_t buf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE], | |
| 77 | + AACADTSHeaderInfo *hdr) | |
| 78 | +{ | |
| 79 | + GetBitContext gb; | |
| 80 | + av_unused int ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE); | |
| 81 | + av_assert1(ret >= 0); | |
| 82 | + return ff_adts_header_parse(&gb, hdr); | |
| 83 | +} | |
| @@ -23,7 +23,8 @@ · 22 unmodified lines | ||
| 23 | 23 | #ifndef AVCODEC_ADTS_HEADER_H |
| 24 | 24 | #define AVCODEC_ADTS_HEADER_H |
| 25 | 25 | |
| 26 | −#include "get_bits.h" | |
| 26 | +#include "adts_parser.h" | |
| 27 | +#include "defs.h" | |
| 27 | 28 | |
| 28 | 29 | typedef enum { |
| 29 | 30 | AAC_PARSE_ERROR_SYNC = -0x1030c0a, |
| @@ -43,6 +44,8 @@ typedef struct AACADTSHeaderInfo { · 13 unmodified lines | ||
| 43 | 44 | uint32_t frame_length; |
| 44 | 45 | } AACADTSHeaderInfo; |
| 45 | 46 | |
| 47 | +struct GetBitContext; | |
| 48 | + | |
| 46 | 49 | /** |
| 47 | 50 | * Parse the ADTS frame header to the end of the variable header, which is |
| 48 | 51 | * the first 54 bits. |
| @@ -51,7 +54,14 @@ typedef struct AACADTSHeaderInfo { · 2 unmodified lines | ||
| 51 | 54 | * @return the size in bytes of the header parsed on success and |
| 52 | 55 | * AAC_PARSE_ERROR_* values otherwise. |
| 53 | 56 | */ |
| 54 | −int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr); | |
| 57 | +int ff_adts_header_parse(struct GetBitContext *gbc, AACADTSHeaderInfo *hdr); | |
| 58 | + | |
| 59 | +/** | |
| 60 | + * Wrapper around ff_adts_header_parse() for users that don't already have | |
| 61 | + * a suitable GetBitContext. | |
| 62 | + */ | |
| 63 | +int ff_adts_header_parse_buf(const uint8_t buf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE], | |
| 64 | + AACADTSHeaderInfo *hdr); | |
| 55 | 65 | |
| 56 | 66 | /** |
| 57 | 67 | * Parse the ADTS frame header contained in the buffer, which is |
| @@ -20,7 +20,9 @@ · 19 unmodified lines | ||
| 20 | 20 | |
| 21 | 21 | #include <stddef.h> |
| 22 | 22 | #include <stdint.h> |
| 23 | +#include <string.h> | |
| 23 | 24 | |
| 25 | +#include "libavutil/error.h" | |
| 24 | 26 | #include "libavutil/mem.h" |
| 25 | 27 | #include "adts_header.h" |
| 26 | 28 | #include "adts_parser.h" |
| @@ -29,16 +31,12 @@ int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames) · 2 unmodified lines | ||
| 29 | 31 | { |
| 30 | 32 | #if CONFIG_ADTS_HEADER |
| 31 | 33 | uint8_t tmpbuf[AV_AAC_ADTS_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; |
| 32 | − GetBitContext gb; | |
| 33 | 34 | AACADTSHeaderInfo hdr; |
| 34 | 35 | int err; |
| 35 | 36 | if (!buf) |
| 36 | 37 | return AVERROR(EINVAL); |
| 37 | 38 | memcpy(tmpbuf, buf, AV_AAC_ADTS_HEADER_SIZE); |
| 38 | − err = init_get_bits8(&gb, tmpbuf, AV_AAC_ADTS_HEADER_SIZE); | |
| 39 | − if (err < 0) | |
| 40 | − return err; | |
| 41 | − err = ff_adts_header_parse(&gb, &hdr); | |
| 39 | + err = ff_adts_header_parse_buf(tmpbuf, &hdr); | |
| 42 | 40 | if (err < 0) |
| 43 | 41 | return err; |
| 44 | 42 | *samples = hdr.samples; |
| @@ -54,7 +52,6 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_ · 9 unmodified lines | ||
| 54 | 52 | #if CONFIG_ADTS_HEADER |
| 55 | 53 | int ret = 0; |
| 56 | 54 | int allocated = 0; |
| 57 | − GetBitContext gb; | |
| 58 | 55 | |
| 59 | 56 | if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE) |
| 60 | 57 | return AVERROR_INVALIDDATA; |
| @@ -66,14 +63,7 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_ · 5 unmodified lines | ||
| 66 | 63 | if (!*phdr) |
| 67 | 64 | return AVERROR(ENOMEM); |
| 68 | 65 | |
| 69 | − ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE); | |
| 70 | − if (ret < 0) { | |
| 71 | − if (allocated) | |
| 72 | − av_freep(phdr); | |
| 73 | − return ret; | |
| 74 | − } | |
| 75 | − | |
| 76 | − ret = ff_adts_header_parse(&gb, *phdr); | |
| 66 | + ret = ff_adts_header_parse_buf(buf, *phdr); | |
| 77 | 67 | if (ret < 0) { |
| 78 | 68 | if (allocated) |
| 79 | 69 | av_freep(phdr); |
| @@ -40,7 +40,6 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) · 39 unmodified lines | ||
| 40 | 40 | { |
| 41 | 41 | AACBSFContext *ctx = bsfc->priv_data; |
| 42 | 42 | |
| 43 | − GetBitContext gb; | |
| 44 | 43 | PutBitContext pb; |
| 45 | 44 | AACADTSHeaderInfo hdr; |
| 46 | 45 | int ret; |
| @@ -55,9 +54,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) · 8 unmodified lines | ||
| 55 | 54 | if (pkt->size < AV_AAC_ADTS_HEADER_SIZE) |
| 56 | 55 | goto packet_too_small; |
| 57 | 56 | |
| 58 | − init_get_bits(&gb, pkt->data, AV_AAC_ADTS_HEADER_SIZE * 8); | |
| 59 | − | |
| 60 | − if (ff_adts_header_parse(&gb, &hdr) < 0) { | |
| 57 | + if (ff_adts_header_parse_buf(pkt->data, &hdr) < 0) { | |
| 61 | 58 | av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); |
| 62 | 59 | ret = AVERROR_INVALIDDATA; |
| 63 | 60 | goto fail; |
| @@ -81,6 +78,7 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt) · 17 unmodified lines | ||
| 81 | 78 | uint8_t *extradata; |
| 82 | 79 | |
| 83 | 80 | if (!hdr.chan_config) { |
| 81 | + GetBitContext gb; | |
| 84 | 82 | init_get_bits(&gb, pkt->data, pkt->size * 8); |
| 85 | 83 | if (get_bits(&gb, 3) != 5) { |
| 86 | 84 | avpriv_report_missing_feature(bsfc, |
| @@ -25,7 +25,6 @@ · 24 unmodified lines | ||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | #include "parser.h" |
| 28 | −#include "get_bits.h" | |
| 29 | 28 | #include "adts_header.h" |
| 30 | 29 | #include "adts_parser.h" |
| 31 | 30 | #include "mpeg4audio.h" |
| @@ -45,7 +44,6 @@ static int ftr_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 13 unmodified lines | ||
| 45 | 44 | FTRParseContext *ftr = s->priv_data; |
| 46 | 45 | uint64_t state = ftr->pc.state64; |
| 47 | 46 | int next = END_NOT_FOUND; |
| 48 | − GetBitContext bits; | |
| 49 | 47 | AACADTSHeaderInfo hdr; |
| 50 | 48 | int size; |
| 51 | 49 | |
| @@ -71,10 +69,9 @@ static int ftr_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 19 unmodified lines | ||
| 71 | 69 | |
| 72 | 70 | state = (state << 8) | buf[i]; |
| 73 | 71 | AV_WB64(tmp, state); |
| 74 | − init_get_bits(&bits, tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, | |
| 75 | − AV_AAC_ADTS_HEADER_SIZE * 8); | |
| 72 | + size = ff_adts_header_parse_buf(tmp + 8 - AV_AAC_ADTS_HEADER_SIZE, &hdr); | |
| 76 | 73 | |
| 77 | − if ((size = ff_adts_header_parse(&bits, &hdr)) > 0) { | |
| 74 | + if (size > 0) { | |
| 78 | 75 | ftr->skip = size - 6; |
| 79 | 76 | ftr->frame_index += ff_mpeg4audio_channels[hdr.chan_config]; |
| 80 | 77 | if (ftr->frame_index >= avctx->ch_layout.nb_channels) { |