Skip to content

Commit

Permalink
Avoid unnecessary downmixing when only determining audio duration.
Browse files Browse the repository at this point in the history
For the purposes of estimating the duration, we don't need to incur
the overhead of downmixing 5.1 audios.

git-svn-id: svn://svn.daper.net/moc/trunk@3004 910807d9-36e0-0310-a014-e9ea483e2ba4
  • Loading branch information
jcf committed Sep 14, 2019
1 parent 1be01a2 commit e9bff2a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions decoder_plugins/aac/aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ static int aac_count_time (struct aac_data *data)
return -1;

samples /= frames;
samples /= MIN(2, data->channels);
samples /= data->channels;
bytes /= frames;

return ((file_size / bytes) * samples) / data->sample_rate;
}

static void *aac_open_internal (struct io_stream *stream, const char *fname)
static struct aac_data *aac_open_internal (struct io_stream *stream,
const char *fname, bool timing_only)
{
struct aac_data *data;
NeAACDecConfigurationPtr neaac_cfg;
Expand All @@ -270,7 +271,7 @@ static void *aac_open_internal (struct io_stream *stream, const char *fname)
/* set decoder config */
neaac_cfg = NeAACDecGetCurrentConfiguration(data->decoder);
neaac_cfg->outputFormat = FAAD_FMT_16BIT; /* force 16 bit audio */
neaac_cfg->downMatrix = 1; /* 5.1 -> stereo */
neaac_cfg->downMatrix = !timing_only; /* 5.1 -> stereo */
neaac_cfg->dontUpSampleImplicitSBR = 0; /* upsample, please! */
NeAACDecSetConfiguration(data->decoder, neaac_cfg);

Expand Down Expand Up @@ -314,14 +315,16 @@ static void *aac_open_internal (struct io_stream *stream, const char *fname)
return data;
}

if (data->channels == 6) {
logit ("sample rate %dHz, channels %d (downmixed to stereo)",
data->sample_rate, data->channels);
data->channels = 2;
if (!timing_only) {
if (data->channels == 6) {
logit ("sample rate %dHz, channels %d (downmixed to stereo)",
data->sample_rate, data->channels);
data->channels = 2;
}
else
logit ("sample rate %dHz, channels %d",
data->sample_rate, data->channels);
}
else
logit ("sample rate %dHz, channels %d", data->sample_rate,
data->channels);

if (!data->sample_rate || !data->channels) {
decoder_error (&data->error, ERROR_FATAL, 0,
Expand Down Expand Up @@ -349,12 +352,11 @@ static void aac_close (void *prv_data)
free (data);
}


static void *aac_open (const char *file)
{
struct aac_data *data;

data = aac_open_internal (NULL, file);
data = aac_open_internal (NULL, file, true);

if (data->ok) {
int duration = -1;
Expand All @@ -366,7 +368,8 @@ static void *aac_open (const char *file)
if (duration > 0 && file_size != -1)
avg_bitrate = file_size / duration * 8;
aac_close (data);
data = aac_open_internal (NULL, file);

data = aac_open_internal (NULL, file, false);
data->duration = duration;
data->avg_bitrate = avg_bitrate;
}
Expand All @@ -378,7 +381,7 @@ static void *aac_open_stream (struct io_stream *stream)
{
assert (stream != NULL);

return aac_open_internal (stream, NULL);
return aac_open_internal (stream, NULL, false);
}

static char *get_tag (struct id3_tag *tag, const char *what)
Expand Down Expand Up @@ -433,7 +436,7 @@ static void aac_info (const char *file_name,
if (tags_sel & TAGS_TIME) {
struct aac_data *data;

data = aac_open_internal (NULL, file_name);
data = aac_open_internal (NULL, file_name, true);

if (data->ok)
info->time = aac_count_time (data);
Expand Down

0 comments on commit e9bff2a

Please sign in to comment.