avcodec/aac_ac3_parser: Untangle AAC and AC3 parsing error codes
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(). Reviewed-by: Andrew Sayers <ffmpeg-devel@pileofstuff.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
6c812a80dd
commit
ae937c4902
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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 0 on success and AC3_PARSE_ERROR_* values otherwise.
|
||||
*/
|
||||
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
|
||||
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "libavutil/opt.h"
|
||||
#include "libavutil/thread.h"
|
||||
#include "bswapdsp.h"
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "ac3_parser_internal.h"
|
||||
#include "ac3dec.h"
|
||||
#include "ac3dec_data.h"
|
||||
@ -1538,19 +1537,19 @@ dependent_frame:
|
||||
|
||||
if (err) {
|
||||
switch (err) {
|
||||
case AAC_AC3_PARSE_ERROR_SYNC:
|
||||
case AC3_PARSE_ERROR_SYNC:
|
||||
av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
case AAC_AC3_PARSE_ERROR_BSID:
|
||||
case AC3_PARSE_ERROR_BSID:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
|
||||
break;
|
||||
case AAC_AC3_PARSE_ERROR_SAMPLE_RATE:
|
||||
case AC3_PARSE_ERROR_SAMPLE_RATE:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
|
||||
break;
|
||||
case AAC_AC3_PARSE_ERROR_FRAME_SIZE:
|
||||
case AC3_PARSE_ERROR_FRAME_SIZE:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid frame size\n");
|
||||
break;
|
||||
case AAC_AC3_PARSE_ERROR_FRAME_TYPE:
|
||||
case AC3_PARSE_ERROR_FRAME_TYPE:
|
||||
/* skip frame if CRC is ok. otherwise use error concealment. */
|
||||
/* TODO: add support for substreams */
|
||||
if (s->substreamid) {
|
||||
@ -1563,8 +1562,7 @@ dependent_frame:
|
||||
av_log(avctx, AV_LOG_ERROR, "invalid frame type\n");
|
||||
}
|
||||
break;
|
||||
case AAC_AC3_PARSE_ERROR_CRC:
|
||||
case AAC_AC3_PARSE_ERROR_CHANNEL_CFG:
|
||||
case AC3_PARSE_ERROR_CRC:
|
||||
break;
|
||||
default: // Normal AVERROR do not try to recover.
|
||||
*got_frame_ptr = 0;
|
||||
@ -1574,7 +1572,7 @@ dependent_frame:
|
||||
/* check that reported frame size fits in input buffer */
|
||||
if (s->frame_size > buf_size) {
|
||||
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
|
||||
err = AAC_AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
err = AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
} else if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) {
|
||||
/* check for crc mismatch */
|
||||
if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2],
|
||||
@ -1582,7 +1580,7 @@ dependent_frame:
|
||||
av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n");
|
||||
if (avctx->err_recognition & AV_EF_EXPLODE)
|
||||
return AVERROR_INVALIDDATA;
|
||||
err = AAC_AC3_PARSE_ERROR_CRC;
|
||||
err = AC3_PARSE_ERROR_CRC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "adts_header.h"
|
||||
#include "adts_parser.h"
|
||||
#include "get_bits.h"
|
||||
@ -35,7 +34,7 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
|
||||
if (get_bits(gbc, 12) != 0xfff)
|
||||
return AAC_AC3_PARSE_ERROR_SYNC;
|
||||
return AAC_PARSE_ERROR_SYNC;
|
||||
|
||||
skip_bits1(gbc); /* id */
|
||||
skip_bits(gbc, 2); /* layer */
|
||||
@ -43,7 +42,7 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
|
||||
aot = get_bits(gbc, 2); /* profile_objecttype */
|
||||
sr = get_bits(gbc, 4); /* sample_frequency_index */
|
||||
if (!ff_mpeg4audio_sample_rates[sr])
|
||||
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
|
||||
return AAC_PARSE_ERROR_SAMPLE_RATE;
|
||||
skip_bits1(gbc); /* private_bit */
|
||||
ch = get_bits(gbc, 3); /* channel_configuration */
|
||||
|
||||
@ -55,7 +54,7 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
|
||||
skip_bits1(gbc); /* copyright_identification_start */
|
||||
size = get_bits(gbc, 13); /* aac_frame_length */
|
||||
if (size < AV_AAC_ADTS_HEADER_SIZE)
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
|
||||
return AAC_PARSE_ERROR_FRAME_SIZE;
|
||||
|
||||
skip_bits(gbc, 11); /* adts_buffer_fullness */
|
||||
rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */
|
||||
|
@ -25,6 +25,12 @@
|
||||
|
||||
#include "get_bits.h"
|
||||
|
||||
typedef enum {
|
||||
AAC_PARSE_ERROR_SYNC = -0x1030c0a,
|
||||
AAC_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a,
|
||||
AAC_PARSE_ERROR_FRAME_SIZE = -0x4030c0a,
|
||||
} AACParseError;
|
||||
|
||||
typedef struct AACADTSHeaderInfo {
|
||||
uint32_t sample_rate;
|
||||
uint32_t samples;
|
||||
@ -42,9 +48,8 @@ typedef struct AACADTSHeaderInfo {
|
||||
* the first 54 bits.
|
||||
* @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 version element is invalid, -3 if the sample rate
|
||||
* element is invalid, or -4 if the bit rate element is invalid.
|
||||
* @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);
|
||||
|
||||
@ -56,9 +61,8 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
|
||||
* @param[out] phdr Pointer to pointer to struct AACADTSHeaderInfo for which
|
||||
* memory is allocated and header info is written into it. After using the header
|
||||
* information, the allocated memory must be freed by using av_free.
|
||||
* @return Returns 0 on success, -1 if there is a sync word mismatch,
|
||||
* -2 if the version element is invalid, -3 if the sample rate
|
||||
* element is invalid, or -4 if the bit rate element is invalid.
|
||||
* @return 0 on success, AAC_PARSE_ERROR_* values on invalid input and
|
||||
* ordinary AVERROR codes otherwise.
|
||||
*/
|
||||
int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size);
|
||||
|
||||
|
@ -39,8 +39,8 @@
|
||||
|
||||
|
||||
#include "avcodec.h"
|
||||
#include "aac_ac3_parser.h"
|
||||
#include "ac3.h"
|
||||
#include "ac3_parser_internal.h"
|
||||
#include "ac3dec.h"
|
||||
#include "ac3dec_data.h"
|
||||
#include "eac3_data.h"
|
||||
@ -300,7 +300,7 @@ static int ff_eac3_parse_header(AC3DecodeContext *s)
|
||||
dependent streams which are used to add or replace channels. */
|
||||
if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
|
||||
return AC3_PARSE_ERROR_FRAME_TYPE;
|
||||
}
|
||||
|
||||
/* The substream id indicates which substream this frame belongs to. each
|
||||
@ -312,7 +312,7 @@ static int ff_eac3_parse_header(AC3DecodeContext *s)
|
||||
s->eac3_subsbtreamid_found = 1;
|
||||
avpriv_request_sample(s->avctx, "Additional substreams");
|
||||
}
|
||||
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
|
||||
return AC3_PARSE_ERROR_FRAME_TYPE;
|
||||
}
|
||||
|
||||
if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
|
||||
|
Loading…
Reference in New Issue
Block a user