You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
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:
@@ -30,7 +30,7 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
|||||||
{
|
{
|
||||||
AACAC3ParseContext *s = s1->priv_data;
|
AACAC3ParseContext *s = s1->priv_data;
|
||||||
const uint8_t *buf_ptr;
|
const uint8_t *buf_ptr;
|
||||||
int len, sample_rate, bit_rate, channels, samples;
|
int len;
|
||||||
|
|
||||||
*poutbuf = NULL;
|
*poutbuf = NULL;
|
||||||
*poutbuf_size = 0;
|
*poutbuf_size = 0;
|
||||||
@@ -50,8 +50,7 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
|||||||
|
|
||||||
if (s->frame_size == 0) {
|
if (s->frame_size == 0) {
|
||||||
if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
|
if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
|
||||||
len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
|
len = s->sync(s);
|
||||||
&samples);
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
/* no sync found : move by one byte (inefficient, but simple!) */
|
/* no sync found : move by one byte (inefficient, but simple!) */
|
||||||
memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
|
memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
|
||||||
@@ -59,19 +58,19 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
|||||||
} else {
|
} else {
|
||||||
s->frame_size = len;
|
s->frame_size = len;
|
||||||
/* update codec info */
|
/* update codec info */
|
||||||
avctx->sample_rate = sample_rate;
|
avctx->sample_rate = s->sample_rate;
|
||||||
/* allow downmixing to stereo (or mono for AC3) */
|
/* allow downmixing to stereo (or mono for AC3) */
|
||||||
if(avctx->request_channels > 0 &&
|
if(avctx->request_channels > 0 &&
|
||||||
avctx->request_channels < channels &&
|
avctx->request_channels < s->channels &&
|
||||||
(avctx->request_channels <= 2 ||
|
(avctx->request_channels <= 2 ||
|
||||||
(avctx->request_channels == 1 &&
|
(avctx->request_channels == 1 &&
|
||||||
avctx->codec_id == CODEC_ID_AC3))) {
|
avctx->codec_id == CODEC_ID_AC3))) {
|
||||||
avctx->channels = avctx->request_channels;
|
avctx->channels = avctx->request_channels;
|
||||||
} else {
|
} else {
|
||||||
avctx->channels = channels;
|
avctx->channels = s->channels;
|
||||||
}
|
}
|
||||||
avctx->bit_rate = bit_rate;
|
avctx->bit_rate = s->bit_rate;
|
||||||
avctx->frame_size = samples;
|
avctx->frame_size = s->samples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -30,9 +30,13 @@ typedef struct AACAC3ParseContext {
|
|||||||
uint8_t *inbuf_ptr;
|
uint8_t *inbuf_ptr;
|
||||||
int frame_size;
|
int frame_size;
|
||||||
int header_size;
|
int header_size;
|
||||||
int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
|
int (*sync)(struct AACAC3ParseContext *hdr_info);
|
||||||
int *bit_rate, int *samples);
|
|
||||||
uint8_t inbuf[8192]; /* input buffer */
|
uint8_t inbuf[8192]; /* input buffer */
|
||||||
|
|
||||||
|
int channels;
|
||||||
|
int sample_rate;
|
||||||
|
int bit_rate;
|
||||||
|
int samples;
|
||||||
} AACAC3ParseContext;
|
} AACAC3ParseContext;
|
||||||
|
|
||||||
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
||||||
|
@@ -38,13 +38,12 @@ static const int aac_channels[8] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
|
static int aac_sync(AACAC3ParseContext *hdr_info)
|
||||||
int *bit_rate, int *samples)
|
|
||||||
{
|
{
|
||||||
GetBitContext bits;
|
GetBitContext bits;
|
||||||
int size, rdb, ch, sr;
|
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)
|
if(get_bits(&bits, 12) != 0xfff)
|
||||||
return 0;
|
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 */
|
skip_bits(&bits, 11); /* adts_buffer_fullness */
|
||||||
rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
|
rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
|
||||||
|
|
||||||
*channels = aac_channels[ch];
|
hdr_info->channels = aac_channels[ch];
|
||||||
*sample_rate = aac_sample_rates[sr];
|
hdr_info->sample_rate = aac_sample_rates[sr];
|
||||||
*samples = (rdb + 1) * 1024;
|
hdr_info->samples = (rdb + 1) * 1024;
|
||||||
*bit_rate = size * 8 * *sample_rate / *samples;
|
hdr_info->bit_rate = size * 8 * hdr_info->sample_rate / hdr_info->samples;
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@@ -119,21 +119,20 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
|
static int ac3_sync(AACAC3ParseContext *hdr_info)
|
||||||
int *bit_rate, int *samples)
|
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
AC3HeaderInfo hdr;
|
AC3HeaderInfo hdr;
|
||||||
|
|
||||||
err = ff_ac3_parse_header(buf, &hdr);
|
err = ff_ac3_parse_header(hdr_info->inbuf, &hdr);
|
||||||
|
|
||||||
if(err < 0)
|
if(err < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*sample_rate = hdr.sample_rate;
|
hdr_info->sample_rate = hdr.sample_rate;
|
||||||
*bit_rate = hdr.bit_rate;
|
hdr_info->bit_rate = hdr.bit_rate;
|
||||||
*channels = hdr.channels;
|
hdr_info->channels = hdr.channels;
|
||||||
*samples = AC3_FRAME_SIZE;
|
hdr_info->samples = AC3_FRAME_SIZE;
|
||||||
return hdr.frame_size;
|
return hdr.frame_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user