Permalink
Browse files

Fix DTS playback under some circumstances.

When playing a DTS-HD track on a system only supporting DTS core (like when using SPDIF) we would try to decode the DTS-HD track which wouldn't work as FFmpeg doesn't support it. Instead on those system we bitstream the DTS core found in those DTS-HD stream.
When selecting which audio track to play, we don't even try to search for DTS-HD unless the hardware supports it.
Audio framework when being fed DTS (HD or not) will only use DTS core if it finds that the hardware doesn't support it. For the audio framework to attempt bitstreaming DTS-HD requires the hardware to support it
  • Loading branch information...
1 parent 06e19da commit e05e5036e0183a177f5c89455bda293195671a7a @jyavenard jyavenard committed Oct 1, 2011
@@ -268,6 +268,7 @@ bool AudioOutputBase::CanPassthrough(int samplerate, int channels,
case FF_PROFILE_DTS_HD_HRA:
case FF_PROFILE_DTS_HD_MA:
arg = FEATURE_DTSHD;
+ break;
default:
break;
}
@@ -516,6 +517,13 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
int samplerate_tmp, channels_tmp;
if (settings.use_passthru)
{
+ if (settings.codec == CODEC_ID_DTS &&
+ !output_settingsdigital->canFeature(FEATURE_DTSHD))
+ {
+ // We do not support DTS-HD bitstream so force extraction of the
+ // DTS core track instead
+ settings.codec_profile = FF_PROFILE_DTS;
+ }
samplerate_tmp = settings.samplerate;
SetupPassthrough(settings.codec, settings.codec_profile,
samplerate_tmp, channels_tmp);
@@ -3646,7 +3646,7 @@ int AvFormatDecoder::filter_max_ch(const AVFormatContext *ic,
if (codecId == CODEC_ID_DTS && profile > 0)
{
// we cannot decode dts-hd, so only select it if passthrough
- if (!DoPassThrough(ctx) || ctx->profile != profile)
+ if (!DoPassThrough(ctx, true) || ctx->profile != profile)
continue;
}
selectedTrack = *it;
@@ -3722,7 +3722,7 @@ int AvFormatDecoder::AutoSelectAudioTrack(void)
AVCodecContext *codec_ctx = ic->streams[idx]->codec;
AudioInfo item(codec_ctx->codec_id, codec_ctx->bps,
codec_ctx->sample_rate, codec_ctx->channels,
- DoPassThrough(codec_ctx));
+ DoPassThrough(codec_ctx, true));
LOG(VB_AUDIO, LOG_DEBUG, LOC + " * " + item.toString());
}
#endif
@@ -3981,7 +3981,7 @@ bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt,
QMutexLocker locker(avcodeclock);
- if (DoPassThrough(ctx) || !DecoderWillDownmix(ctx))
+ if (DoPassThrough(ctx, false) || !DecoderWillDownmix(ctx))
{
// for passthru or codecs for which the decoder won't downmix
// let the decoder set the number of channels. For other codecs
@@ -4557,12 +4557,19 @@ inline bool AvFormatDecoder::DecoderWillDownmix(const AVCodecContext *ctx)
}
}
-bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx)
+bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx, bool withProfile)
{
bool passthru;
- passthru = m_audio->CanPassthrough(ctx->sample_rate, ctx->channels,
- ctx->codec_id, ctx->profile);
+ // if withProfile == false, we will accept any DTS stream regardless
+ // of its profile. We do so, so we can bitstream DTS-HD as DTS core
+ if (!withProfile && ctx->codec_id == CODEC_ID_DTS && !m_audio->CanDTSHD())
+ passthru = m_audio->CanPassthrough(ctx->sample_rate, ctx->channels,
+ ctx->codec_id, FF_PROFILE_DTS);
+ else
+ passthru = m_audio->CanPassthrough(ctx->sample_rate, ctx->channels,
+ ctx->codec_id, ctx->profile);
+
passthru &= !disable_passthru;
return passthru;
@@ -4624,7 +4631,7 @@ bool AvFormatDecoder::SetupAudioStream(void)
return false;
}
- using_passthru = DoPassThrough(ctx);
+ using_passthru = DoPassThrough(ctx, false);
ctx->request_channels = ctx->channels;
@@ -231,7 +231,7 @@ class AvFormatDecoder : public DecoderBase
void SeekReset(long long, uint skipFrames, bool doFlush, bool discardFrames);
inline bool DecoderWillDownmix(const AVCodecContext *ctx);
- bool DoPassThrough(const AVCodecContext *ctx);
+ bool DoPassThrough(const AVCodecContext *ctx, bool withProfile=true);
bool SetupAudioStream(void);
void SetupAudioStreamSubIndexes(int streamIndex);
void RemoveAudioStreams();

0 comments on commit e05e503

Please sign in to comment.