[FFmpeg-devel] [PATCH 2/4] avcodec/aac_ac3_parser: Untangle AAC and AC3 parsing error codes

Andrew Sayers ffmpeg-devel at pileofstuff.org
Sat May 11 16:44:11 EEST 2024


On Fri, May 10, 2024 at 06:56:25PM +0200, Andreas Rheinhardt wrote:
> Also remove the (unused) AAC_AC3_PARSE_ERROR_CHANNEL_CFG while at it;
> furthermore, fix the documentation of ff_ac3_parse_header()
> and (ff|avpriv)_adts_header_parse().
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>  libavcodec/aac_ac3_parser.h      | 10 ----------
>  libavcodec/ac3_parser.c          | 14 +++++++-------
>  libavcodec/ac3_parser_internal.h | 13 ++++++++++---
>  libavcodec/ac3dec.c              | 18 ++++++++----------
>  libavcodec/adts_header.c         |  7 +++----
>  libavcodec/adts_header.h         | 16 ++++++++++------
>  libavcodec/eac3dec.c             |  6 +++---
>  7 files changed, 41 insertions(+), 43 deletions(-)
> 
> diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h
> index bc16181a19..e3259d1841 100644
> --- a/libavcodec/aac_ac3_parser.h
> +++ b/libavcodec/aac_ac3_parser.h
> @@ -28,16 +28,6 @@
>  #include "avcodec.h"
>  #include "parser.h"
>  
> -typedef enum {
> -    AAC_AC3_PARSE_ERROR_SYNC        = -0x1030c0a,
> -    AAC_AC3_PARSE_ERROR_BSID        = -0x2030c0a,
> -    AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a,
> -    AAC_AC3_PARSE_ERROR_FRAME_SIZE  = -0x4030c0a,
> -    AAC_AC3_PARSE_ERROR_FRAME_TYPE  = -0x5030c0a,
> -    AAC_AC3_PARSE_ERROR_CRC         = -0x6030c0a,
> -    AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -0x7030c0a,
> -} AACAC3ParseError;
> -
>  typedef struct AACAC3ParseContext {
>      ParseContext pc;
>      int header_size;
> diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
> index 4e0ba73481..69989690dd 100644
> --- a/libavcodec/ac3_parser.c
> +++ b/libavcodec/ac3_parser.c
> @@ -81,12 +81,12 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
>  
>      hdr->sync_word = get_bits(gbc, 16);
>      if(hdr->sync_word != 0x0B77)
> -        return AAC_AC3_PARSE_ERROR_SYNC;
> +        return AC3_PARSE_ERROR_SYNC;
>  
>      /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */
>      hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F;
>      if(hdr->bitstream_id > 16)
> -        return AAC_AC3_PARSE_ERROR_BSID;
> +        return AC3_PARSE_ERROR_BSID;
>  
>      hdr->num_blocks = 6;
>      hdr->ac3_bit_rate_code = -1;
> @@ -103,11 +103,11 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
>          hdr->crc1 = get_bits(gbc, 16);
>          hdr->sr_code = get_bits(gbc, 2);
>          if(hdr->sr_code == 3)
> -            return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
> +            return AC3_PARSE_ERROR_SAMPLE_RATE;
>  
>          frame_size_code = get_bits(gbc, 6);
>          if(frame_size_code > 37)
> -            return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
> +            return AC3_PARSE_ERROR_FRAME_SIZE;
>  
>          hdr->ac3_bit_rate_code = (frame_size_code >> 1);
>  
> @@ -138,19 +138,19 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
>          hdr->crc1 = 0;
>          hdr->frame_type = get_bits(gbc, 2);
>          if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)
> -            return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
> +            return AC3_PARSE_ERROR_FRAME_TYPE;
>  
>          hdr->substreamid = get_bits(gbc, 3);
>  
>          hdr->frame_size = (get_bits(gbc, 11) + 1) << 1;
>          if(hdr->frame_size < AC3_HEADER_SIZE)
> -            return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
> +            return AC3_PARSE_ERROR_FRAME_SIZE;
>  
>          hdr->sr_code = get_bits(gbc, 2);
>          if (hdr->sr_code == 3) {
>              int sr_code2 = get_bits(gbc, 2);
>              if(sr_code2 == 3)
> -                return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
> +                return AC3_PARSE_ERROR_SAMPLE_RATE;
>              hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
>              hdr->sr_shift = 1;
>          } else {
> diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
> index 2ac0e67ec2..2c4eb546e5 100644
> --- a/libavcodec/ac3_parser_internal.h
> +++ b/libavcodec/ac3_parser_internal.h
> @@ -64,15 +64,22 @@ typedef struct AC3HeaderInfo {
>      /** @} */
>  } AC3HeaderInfo;
>  
> +typedef enum {
> +    AC3_PARSE_ERROR_SYNC        = -0x1030c0a,
> +    AC3_PARSE_ERROR_BSID        = -0x2030c0a,
> +    AC3_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a,
> +    AC3_PARSE_ERROR_FRAME_SIZE  = -0x4030c0a,
> +    AC3_PARSE_ERROR_FRAME_TYPE  = -0x5030c0a,
> +    AC3_PARSE_ERROR_CRC         = -0x6030c0a,
> +} AC3ParseError;
> +
>  /**
>   * Parse AC-3 frame header.
>   * Parse the header up to the lfeon element, which is the first 52 or 54 bits
>   * depending on the audio coding mode.
>   * @param[in]  gbc BitContext containing the first 54 bits of the frame.
>   * @param[out] hdr Pointer to struct where header info is written.
> - * @return Returns 0 on success, -1 if there is a sync word mismatch,
> - * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
> - * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
> + * @return Returns 0 on success and AC3_PARSE_ERROR_* values otherwise.

"@return Returns" is redundant - can this (and similar below) just be
"@return 0 on success ..."?


More information about the ffmpeg-devel mailing list