summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
Diffstat (limited to 'libhb')
-rw-r--r--libhb/audio_remap.c22
-rw-r--r--libhb/audio_remap.h3
-rw-r--r--libhb/audio_resample.c4
-rw-r--r--libhb/audio_resample.h5
-rw-r--r--libhb/deca52.c11
-rw-r--r--libhb/decavcodec.c43
-rw-r--r--libhb/declpcm.c3
-rw-r--r--libhb/hb.c17
-rw-r--r--libhb/hbffmpeg.h1
-rw-r--r--libhb/platform/macosx/encca_aac.c2
10 files changed, 31 insertions, 80 deletions
diff --git a/libhb/audio_remap.c b/libhb/audio_remap.c
index 44f0d73d3..d8c7f3de7 100644
--- a/libhb/audio_remap.c
+++ b/libhb/audio_remap.c
@@ -246,19 +246,25 @@ fail:
}
void hb_audio_remap_set_channel_layout(hb_audio_remap_t *remap,
- uint64_t channel_layout,
- int channels)
+ uint64_t channel_layout)
{
if (remap != NULL)
{
int ii;
remap->remap_needed = 0;
+ // sanitize the layout
+ if (channel_layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
+ {
+ channel_layout = AV_CH_LAYOUT_STEREO;
+ }
+ remap->nchannels = av_get_channel_layout_nb_channels(channel_layout);
+
// in some cases, remapping is not necessary and/or supported
- if (channels > HB_AUDIO_REMAP_MAX_CHANNELS)
+ if (remap->nchannels > HB_AUDIO_REMAP_MAX_CHANNELS)
{
hb_log("hb_audio_remap_set_channel_layout: too many channels (%d)",
- channels);
+ remap->nchannels);
return;
}
if (remap->channel_map_in == remap->channel_map_out)
@@ -266,14 +272,6 @@ void hb_audio_remap_set_channel_layout(hb_audio_remap_t *remap,
return;
}
- // sanitize the layout
- channel_layout = hb_ff_layout_xlat(channel_layout, channels);
- if (channel_layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
- {
- channel_layout = AV_CH_LAYOUT_STEREO;
- }
- remap->nchannels = av_get_channel_layout_nb_channels(channel_layout);
-
// build the table and check whether remapping is necessary
hb_audio_remap_build_table(remap->channel_map_out,
remap->channel_map_in, channel_layout,
diff --git a/libhb/audio_remap.h b/libhb/audio_remap.h
index 3092fb854..6f44ad6b9 100644
--- a/libhb/audio_remap.h
+++ b/libhb/audio_remap.h
@@ -73,8 +73,7 @@ hb_audio_remap_t* hb_audio_remap_init(enum AVSampleFormat sample_fmt,
* Must be called at least once before remapping.
*/
void hb_audio_remap_set_channel_layout(hb_audio_remap_t *remap,
- uint64_t channel_layout,
- int channels);
+ uint64_t channel_layout);
/*
* Free an hb_audio_remap_t.
diff --git a/libhb/audio_resample.c b/libhb/audio_resample.c
index b48cc7271..913186cc0 100644
--- a/libhb/audio_resample.c
+++ b/libhb/audio_resample.c
@@ -75,12 +75,10 @@ fail:
}
void hb_audio_resample_set_channel_layout(hb_audio_resample_t *resample,
- uint64_t channel_layout,
- int channels)
+ uint64_t channel_layout)
{
if (resample != NULL)
{
- channel_layout = hb_ff_layout_xlat(channel_layout, channels);
if (channel_layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
{
// Dolby Surround is Stereo when it comes to remixing
diff --git a/libhb/audio_resample.h b/libhb/audio_resample.h
index bac3b3292..9242d78a5 100644
--- a/libhb/audio_resample.h
+++ b/libhb/audio_resample.h
@@ -74,13 +74,10 @@ hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
*
* They should be called whenever the relevant characteristic(s) differ from the
* requested output characteristics, or if they may have changed in the source.
- *
- * Note: channel_layout is automatically sanitized.
*/
void hb_audio_resample_set_channel_layout(hb_audio_resample_t *resample,
- uint64_t channel_layout,
- int channels);
+ uint64_t channel_layout);
void hb_audio_resample_set_mix_levels(hb_audio_resample_t *resample,
double surround_mix_level,
diff --git a/libhb/deca52.c b/libhb/deca52.c
index f5dac1f96..5dde0378a 100644
--- a/libhb/deca52.c
+++ b/libhb/deca52.c
@@ -38,7 +38,6 @@ struct hb_work_private_s
uint8_t buf[6][6][256 * sizeof(float)]; // decoded frame (up to 6 channels, 6 blocks * 256 samples)
uint8_t *samples[6]; // pointers to the start of each plane (1 per channel)
- int nchannels;
int use_mix_levels;
uint64_t channel_layout;
hb_audio_remap_t *remap;
@@ -383,13 +382,10 @@ static hb_buffer_t* Decode(hb_work_object_t *w)
if (new_layout != pv->channel_layout)
{
pv->channel_layout = new_layout;
- pv->nchannels = av_get_channel_layout_nb_channels(new_layout);
hb_audio_remap_set_channel_layout(pv->remap,
- pv->channel_layout,
- pv->nchannels);
+ pv->channel_layout);
hb_audio_resample_set_channel_layout(pv->resample,
- pv->channel_layout,
- pv->nchannels);
+ pv->channel_layout);
}
if (pv->use_mix_levels)
{
@@ -416,7 +412,8 @@ static hb_buffer_t* Decode(hb_work_object_t *w)
*
* copy samples to our internal buffer
*/
- for (j = 0; j < pv->nchannels; j++)
+ for (j = 0;
+ j < av_get_channel_layout_nb_channels(pv->channel_layout); j++)
{
pv->samples[j] = (uint8_t*)pv->buf[j];
memcpy(pv->buf[j][i], block_samples, 256 * sizeof(float));
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index a0f5a59c4..5a4b0513c 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -655,18 +655,17 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
avp.size = pbuffer_size;
len = avcodec_decode_audio4(context, frame, &got_frame, &avp);
- if (len > 0 && context->sample_rate > 0)
+ if (len > 0 && got_frame)
{
info->rate_base = 1;
- info->rate = context->sample_rate;
+ info->rate = frame->sample_rate;
info->samples_per_frame = frame->nb_samples;
int bps = av_get_bits_per_sample(context->codec_id);
- if (bps > 0 && context->channels > 0)
+ int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
+ if (bps > 0)
{
- info->bitrate = (bps *
- context->channels *
- context->sample_rate);
+ info->bitrate = (bps * channels * info->rate);
}
else if (context->bit_rate > 0)
{
@@ -683,9 +682,7 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
}
else
{
- info->channel_layout =
- hb_ff_layout_xlat(context->channel_layout,
- context->channels);
+ info->channel_layout = frame->channel_layout;
}
ret = 1;
@@ -2081,26 +2078,11 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
pos += len;
- // set the duration on every frame since the stream format can
- // change (it shouldn't but there's no way to guarantee it).
- // duration is a scaling factor to go from #bytes in the decoded
- // frame to frame time (in 90KHz mpeg ticks). 'channels' converts
- // total samples to per-channel samples. 'sample_rate' converts
- // per-channel samples to seconds per sample and the 90000
- // is mpeg ticks per second.
- //
- // Also, sample rate is not available until we have decoded some
- // audio.
- if ( pv->context->sample_rate )
- {
- pv->duration = 90000. / (double)( pv->context->sample_rate );
- }
-
if (got_frame)
{
hb_buffer_t *out;
- double duration = pv->frame->nb_samples * pv->duration;
- double pts_next = pv->pts_next + duration;
+ double duration = (90000. * pv->frame->nb_samples /
+ (double)pv->frame->sample_rate);
if (audio->config.out.codec & HB_ACODEC_PASS_FLAG)
{
@@ -2113,10 +2095,9 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
else
{
hb_audio_resample_set_channel_layout(pv->resample,
- context->channel_layout,
- context->channels);
+ pv->frame->channel_layout);
hb_audio_resample_set_sample_fmt(pv->resample,
- context->sample_fmt);
+ pv->frame->format);
if (hb_audio_resample_update(pv->resample))
{
hb_log("decavcodec: hb_audio_resample_update() failed");
@@ -2132,8 +2113,8 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
{
out->s.start = pv->pts_next;
out->s.duration = duration;
- out->s.stop = pts_next;
- pv->pts_next = pts_next;
+ out->s.stop = duration + pv->pts_next;
+ pv->pts_next = duration + pv->pts_next;
hb_list_add(pv->list, out);
}
}
diff --git a/libhb/declpcm.c b/libhb/declpcm.c
index 7a17f2a14..a8f2e32d4 100644
--- a/libhb/declpcm.c
+++ b/libhb/declpcm.c
@@ -330,8 +330,7 @@ static hb_buffer_t *Decode( hb_work_object_t *w )
}
hb_audio_resample_set_channel_layout(pv->resample,
- hdr2layout[pv->nchannels - 1],
- pv->nchannels);
+ hdr2layout[pv->nchannels - 1]);
if (hb_audio_resample_update(pv->resample))
{
hb_log("declpcm: hb_audio_resample_update() failed");
diff --git a/libhb/hb.c b/libhb/hb.c
index 2b9609aa6..156d1241d 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -288,23 +288,6 @@ uint64_t hb_ff_mixdown_xlat(int hb_mixdown, int *downmix_mode)
return ff_layout;
}
-uint64_t hb_ff_layout_xlat(uint64_t ff_channel_layout, int nchannels)
-{
- uint64_t hb_layout = ff_channel_layout;
- if (!hb_layout || av_get_channel_layout_nb_channels(hb_layout) != nchannels)
- {
- hb_layout = av_get_default_channel_layout(nchannels);
- if (!hb_layout)
- {
- // This will likely not sound very good ;)
- hb_layout = AV_CH_LAYOUT_STEREO;
- hb_error("hb_ff_layout_xlat: unsupported layout 0x%"PRIx64" with %d channels",
- ff_channel_layout, nchannels);
- }
- }
- return hb_layout;
-}
-
/*
* Set sample format to the request format if supported by the codec.
* The planar/packed variant of the requested format is the next best thing.
diff --git a/libhb/hbffmpeg.h b/libhb/hbffmpeg.h
index 776eec61a..94b1a903e 100644
--- a/libhb/hbffmpeg.h
+++ b/libhb/hbffmpeg.h
@@ -23,7 +23,6 @@ void hb_avcodec_init(void);
int hb_avcodec_open(AVCodecContext *, AVCodec *, AVDictionary **, int);
int hb_avcodec_close(AVCodecContext *);
-uint64_t hb_ff_layout_xlat(uint64_t ff_channel_layout, int nchannels);
uint64_t hb_ff_mixdown_xlat(int hb_mixdown, int *downmix_mode);
void hb_ff_set_sample_fmt(AVCodecContext *, AVCodec *, enum AVSampleFormat);
diff --git a/libhb/platform/macosx/encca_aac.c b/libhb/platform/macosx/encca_aac.c
index 19e182a22..882b97a5a 100644
--- a/libhb/platform/macosx/encca_aac.c
+++ b/libhb/platform/macosx/encca_aac.c
@@ -297,7 +297,7 @@ int encCoreAudioInit(hb_work_object_t *w, hb_job_t *job, enum AAC_MODE mode)
hb_error("encCoreAudioInit: hb_audio_remap_init() failed");
}
uint64_t layout = hb_ff_mixdown_xlat(audio->config.out.mixdown, NULL);
- hb_audio_remap_set_channel_layout(pv->remap, layout, pv->nchannels);
+ hb_audio_remap_set_channel_layout(pv->remap, layout);
// get maximum output size
AudioConverterGetProperty(pv->converter,