Pass AACAC3ParseContext to sync() instead of individual arguments. Patch by

Bartlomiej Wolowiec (bartek wolowiec gmail com)

Originally committed as revision 12564 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Justin Ruggles 2008-03-23 15:43:29 +00:00
parent 721392606b
commit c599e297e7
4 changed files with 25 additions and 24 deletions

View File

@ -30,7 +30,7 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
{
AACAC3ParseContext *s = s1->priv_data;
const uint8_t *buf_ptr;
int len, sample_rate, bit_rate, channels, samples;
int len;
*poutbuf = NULL;
*poutbuf_size = 0;
@ -50,8 +50,7 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
if (s->frame_size == 0) {
if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
&samples);
len = s->sync(s);
if (len == 0) {
/* no sync found : move by one byte (inefficient, but simple!) */
memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
@ -59,19 +58,19 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
} else {
s->frame_size = len;
/* update codec info */
avctx->sample_rate = sample_rate;
avctx->sample_rate = s->sample_rate;
/* allow downmixing to stereo (or mono for AC3) */
if(avctx->request_channels > 0 &&
avctx->request_channels < channels &&
avctx->request_channels < s->channels &&
(avctx->request_channels <= 2 ||
(avctx->request_channels == 1 &&
avctx->codec_id == CODEC_ID_AC3))) {
avctx->channels = avctx->request_channels;
} else {
avctx->channels = channels;
avctx->channels = s->channels;
}
avctx->bit_rate = bit_rate;
avctx->frame_size = samples;
avctx->bit_rate = s->bit_rate;
avctx->frame_size = s->samples;
}
}
} else {

View File

@ -30,9 +30,13 @@ typedef struct AACAC3ParseContext {
uint8_t *inbuf_ptr;
int frame_size;
int header_size;
int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
int *bit_rate, int *samples);
int (*sync)(struct AACAC3ParseContext *hdr_info);
uint8_t inbuf[8192]; /* input buffer */
int channels;
int sample_rate;
int bit_rate;
int samples;
} AACAC3ParseContext;
int ff_aac_ac3_parse(AVCodecParserContext *s1,

View File

@ -38,13 +38,12 @@ static const int aac_channels[8] = {
};
static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
int *bit_rate, int *samples)
static int aac_sync(AACAC3ParseContext *hdr_info)
{
GetBitContext bits;
int size, rdb, ch, sr;
init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8);
init_get_bits(&bits, hdr_info->inbuf, AAC_HEADER_SIZE * 8);
if(get_bits(&bits, 12) != 0xfff)
return 0;
@ -73,10 +72,10 @@ static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
skip_bits(&bits, 11); /* adts_buffer_fullness */
rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
*channels = aac_channels[ch];
*sample_rate = aac_sample_rates[sr];
*samples = (rdb + 1) * 1024;
*bit_rate = size * 8 * *sample_rate / *samples;
hdr_info->channels = aac_channels[ch];
hdr_info->sample_rate = aac_sample_rates[sr];
hdr_info->samples = (rdb + 1) * 1024;
hdr_info->bit_rate = size * 8 * hdr_info->sample_rate / hdr_info->samples;
return size;
}

View File

@ -119,21 +119,20 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
return 0;
}
static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
int *bit_rate, int *samples)
static int ac3_sync(AACAC3ParseContext *hdr_info)
{
int err;
AC3HeaderInfo hdr;
err = ff_ac3_parse_header(buf, &hdr);
err = ff_ac3_parse_header(hdr_info->inbuf, &hdr);
if(err < 0)
return 0;
*sample_rate = hdr.sample_rate;
*bit_rate = hdr.bit_rate;
*channels = hdr.channels;
*samples = AC3_FRAME_SIZE;
hdr_info->sample_rate = hdr.sample_rate;
hdr_info->bit_rate = hdr.bit_rate;
hdr_info->channels = hdr.channels;
hdr_info->samples = AC3_FRAME_SIZE;
return hdr.frame_size;
}