[FFmpeg-devel] [PATCH 1/3] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header

James Almer jamrial at gmail.com
Tue Jan 19 20:57:19 EET 2021


On 1/18/2021 2:39 PM, Nachiket Tarate wrote:
> These will be used by HLS demuxer in case of SAMPLE-AES encryption/decryption.
> 
> Signed-off-by: Nachiket Tarate <nachiket.programmer at gmail.com>
> ---
>   libavcodec/adts_header.c |  1 +
>   libavcodec/adts_header.h |  1 +
>   libavcodec/adts_parser.c | 29 ++++++++++++++++++++++++++++-
>   libavcodec/adts_parser.h |  4 ++++
>   4 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/adts_header.c b/libavcodec/adts_header.c
> index 0889820f8a..c6680b0fc8 100644
> --- a/libavcodec/adts_header.c
> +++ b/libavcodec/adts_header.c
> @@ -66,6 +66,7 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
>       hdr->sample_rate    = avpriv_mpeg4audio_sample_rates[sr];
>       hdr->samples        = (rdb + 1) * 1024;
>       hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
> +    hdr->frame_length	= size;
>   
>       return size;
>   }
> diff --git a/libavcodec/adts_header.h b/libavcodec/adts_header.h
> index f615f6a9f9..c362ce46a5 100644
> --- a/libavcodec/adts_header.h
> +++ b/libavcodec/adts_header.h
> @@ -34,6 +34,7 @@ typedef struct AACADTSHeaderInfo {
>       uint8_t  sampling_index;
>       uint8_t  chan_config;
>       uint8_t  num_aac_frames;
> +    uint32_t frame_length;
>   } AACADTSHeaderInfo;
>   
>   /**
> diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
> index 5c9f8ff6f2..3421d9fee8 100644
> --- a/libavcodec/adts_parser.c
> +++ b/libavcodec/adts_parser.c
> @@ -21,7 +21,6 @@
>   #include <stddef.h>
>   #include <stdint.h>
>   
> -#include "adts_header.h"
>   #include "adts_parser.h"
>   
>   int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
> @@ -42,3 +41,31 @@ int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
>       return AVERROR(ENOSYS);
>   #endif
>   }
> +
> +int avpriv_adts_header_parse (AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size)
> +{
> +#if CONFIG_ADTS_HEADER
> +    int ret = 0;
> +    GetBitContext gb;
> +
> +    if (size < AV_AAC_ADTS_HEADER_SIZE)
> +        return AVERROR_INVALIDDATA;
> +
> +    if (!*phdr)
> +        *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
> +    if (!*phdr)
> +        return AVERROR(ENOMEM);
> +
> +    ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
> +    if (ret < 0)
> +        return ret;
> +
> +    ret = ff_adts_header_parse(&gb, *phdr);
> +    if (ret < 0)
> +        return ret;
> +
> +    return 0;
> +#else
> +    return AVERROR(ENOSYS);
> +#endif
> +}
> diff --git a/libavcodec/adts_parser.h b/libavcodec/adts_parser.h
> index f85becd131..faa6e47426 100644
> --- a/libavcodec/adts_parser.h
> +++ b/libavcodec/adts_parser.h
> @@ -22,6 +22,8 @@
>   #include <stddef.h>
>   #include <stdint.h>
>   
> +#include "adts_header.h"
> +
>   #define AV_AAC_ADTS_HEADER_SIZE 7
>   
>   /**
> @@ -34,4 +36,6 @@
>   int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
>                            uint8_t *frames);
>   
> +int avpriv_adts_header_parse (AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size);

This is a private function, so it must not be in an installed header. It 
should be in adts_header.h, alongside ff_adts_header_parse().

> +
>   #endif /* AVCODEC_ADTS_PARSER_H */
> 



More information about the ffmpeg-devel mailing list