1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that

will follow

Patch by Alex Converse ( alex converse gmail com )

Originally committed as revision 16479 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Alex Converse 2009-01-07 18:10:10 +00:00 committed by Robert Swain
parent 4b82e3cedc
commit 11d6f38cc9
5 changed files with 31 additions and 28 deletions

View File

@ -27,6 +27,16 @@
#include "avcodec.h" #include "avcodec.h"
#include "parser.h" #include "parser.h"
typedef enum {
AAC_AC3_PARSE_ERROR_SYNC = -1,
AAC_AC3_PARSE_ERROR_BSID = -2,
AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -3,
AAC_AC3_PARSE_ERROR_FRAME_SIZE = -4,
AAC_AC3_PARSE_ERROR_FRAME_TYPE = -5,
AAC_AC3_PARSE_ERROR_CRC = -6,
AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -7,
} AACAC3ParseError;
typedef struct AACAC3ParseContext { typedef struct AACAC3ParseContext {
ParseContext pc; ParseContext pc;
int frame_size; int frame_size;

View File

@ -42,12 +42,12 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
hdr->sync_word = get_bits(gbc, 16); hdr->sync_word = get_bits(gbc, 16);
if(hdr->sync_word != 0x0B77) if(hdr->sync_word != 0x0B77)
return AC3_PARSE_ERROR_SYNC; return AAC_AC3_PARSE_ERROR_SYNC;
/* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */
hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F; hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F;
if(hdr->bitstream_id > 16) if(hdr->bitstream_id > 16)
return AC3_PARSE_ERROR_BSID; return AAC_AC3_PARSE_ERROR_BSID;
hdr->num_blocks = 6; hdr->num_blocks = 6;
@ -60,11 +60,11 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
hdr->crc1 = get_bits(gbc, 16); hdr->crc1 = get_bits(gbc, 16);
hdr->sr_code = get_bits(gbc, 2); hdr->sr_code = get_bits(gbc, 2);
if(hdr->sr_code == 3) if(hdr->sr_code == 3)
return AC3_PARSE_ERROR_SAMPLE_RATE; return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
frame_size_code = get_bits(gbc, 6); frame_size_code = get_bits(gbc, 6);
if(frame_size_code > 37) if(frame_size_code > 37)
return AC3_PARSE_ERROR_FRAME_SIZE; return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
skip_bits(gbc, 5); // skip bsid, already got it skip_bits(gbc, 5); // skip bsid, already got it
@ -93,19 +93,19 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
hdr->crc1 = 0; hdr->crc1 = 0;
hdr->frame_type = get_bits(gbc, 2); hdr->frame_type = get_bits(gbc, 2);
if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED) if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)
return AC3_PARSE_ERROR_FRAME_TYPE; return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
hdr->substreamid = get_bits(gbc, 3); hdr->substreamid = get_bits(gbc, 3);
hdr->frame_size = (get_bits(gbc, 11) + 1) << 1; hdr->frame_size = (get_bits(gbc, 11) + 1) << 1;
if(hdr->frame_size < AC3_HEADER_SIZE) if(hdr->frame_size < AC3_HEADER_SIZE)
return AC3_PARSE_ERROR_FRAME_SIZE; return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
hdr->sr_code = get_bits(gbc, 2); hdr->sr_code = get_bits(gbc, 2);
if (hdr->sr_code == 3) { if (hdr->sr_code == 3) {
int sr_code2 = get_bits(gbc, 2); int sr_code2 = get_bits(gbc, 2);
if(sr_code2 == 3) if(sr_code2 == 3)
return AC3_PARSE_ERROR_SAMPLE_RATE; return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
hdr->sr_shift = 1; hdr->sr_shift = 1;
} else { } else {

View File

@ -26,15 +26,6 @@
#include "ac3.h" #include "ac3.h"
#include "bitstream.h" #include "bitstream.h"
typedef enum {
AC3_PARSE_ERROR_SYNC = -1,
AC3_PARSE_ERROR_BSID = -2,
AC3_PARSE_ERROR_SAMPLE_RATE = -3,
AC3_PARSE_ERROR_FRAME_SIZE = -4,
AC3_PARSE_ERROR_FRAME_TYPE = -5,
AC3_PARSE_ERROR_CRC = -6,
} AC3ParseError;
/** /**
* Parses AC-3 frame header. * Parses AC-3 frame header.
* Parses the header up to the lfeon element, which is the first 52 or 54 bits * Parses the header up to the lfeon element, which is the first 52 or 54 bits

View File

@ -36,6 +36,7 @@
#include "libavutil/crc.h" #include "libavutil/crc.h"
#include "internal.h" #include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3_parser.h" #include "ac3_parser.h"
#include "ac3dec.h" #include "ac3dec.h"
#include "ac3dec_data.h" #include "ac3dec_data.h"
@ -1248,32 +1249,32 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
/* check that reported frame size fits in input buffer */ /* check that reported frame size fits in input buffer */
if(s->frame_size > buf_size) { if(s->frame_size > buf_size) {
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
err = AC3_PARSE_ERROR_FRAME_SIZE; err = AAC_AC3_PARSE_ERROR_FRAME_SIZE;
} }
/* check for crc mismatch */ /* check for crc mismatch */
if(err != AC3_PARSE_ERROR_FRAME_SIZE && avctx->error_recognition >= FF_ER_CAREFUL) { if(err != AAC_AC3_PARSE_ERROR_FRAME_SIZE && avctx->error_recognition >= FF_ER_CAREFUL) {
if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) {
av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n");
err = AC3_PARSE_ERROR_CRC; err = AAC_AC3_PARSE_ERROR_CRC;
} }
} }
if(err && err != AC3_PARSE_ERROR_CRC) { if(err && err != AAC_AC3_PARSE_ERROR_CRC) {
switch(err) { switch(err) {
case AC3_PARSE_ERROR_SYNC: case AAC_AC3_PARSE_ERROR_SYNC:
av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
return -1; return -1;
case AC3_PARSE_ERROR_BSID: case AAC_AC3_PARSE_ERROR_BSID:
av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
break; break;
case AC3_PARSE_ERROR_SAMPLE_RATE: case AAC_AC3_PARSE_ERROR_SAMPLE_RATE:
av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
break; break;
case AC3_PARSE_ERROR_FRAME_SIZE: case AAC_AC3_PARSE_ERROR_FRAME_SIZE:
av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); av_log(avctx, AV_LOG_ERROR, "invalid frame size\n");
break; break;
case AC3_PARSE_ERROR_FRAME_TYPE: case AAC_AC3_PARSE_ERROR_FRAME_TYPE:
/* skip frame if CRC is ok. otherwise use error concealment. */ /* skip frame if CRC is ok. otherwise use error concealment. */
/* TODO: add support for substreams and dependent frames */ /* TODO: add support for substreams and dependent frames */
if(s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { if(s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) {

View File

@ -22,6 +22,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3.h" #include "ac3.h"
#include "ac3_parser.h" #include "ac3_parser.h"
#include "ac3dec.h" #include "ac3dec.h"
@ -184,10 +185,10 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
dependent streams which are used to add or replace channels. */ dependent streams which are used to add or replace channels. */
if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
ff_log_missing_feature(s->avctx, "Dependent substream decoding", 1); ff_log_missing_feature(s->avctx, "Dependent substream decoding", 1);
return AC3_PARSE_ERROR_FRAME_TYPE; return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
} else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) { } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n"); av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
return AC3_PARSE_ERROR_FRAME_TYPE; return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
} }
/* The substream id indicates which substream this frame belongs to. each /* The substream id indicates which substream this frame belongs to. each
@ -196,7 +197,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
if (s->substreamid) { if (s->substreamid) {
/* only decode substream with id=0. skip any additional substreams. */ /* only decode substream with id=0. skip any additional substreams. */
ff_log_missing_feature(s->avctx, "Additional substreams", 1); ff_log_missing_feature(s->avctx, "Additional substreams", 1);
return AC3_PARSE_ERROR_FRAME_TYPE; return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
} }
if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) { if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {