dvdplayer: Fix m_streaminfo updates from passthrough codec
authorAnssi Hannula <anssi@xbmc.org>
Sat, 31 Aug 2013 12:49:12 +0000 (15:49 +0300)
committerAnssi Hannula <anssi@xbmc.org>
Sat, 31 Aug 2013 13:05:30 +0000 (16:05 +0300)
Use the GetEncodedSampleRate() method instead of GetSampleRate() to
populate m_streaminfo, since the latter returns the passthrough frame
rate which is not relevant in the context of m_streaminfo.

Also, do not overwrite channel count and sample rate with zero after
opening a passthrough codec, instead keep the demuxer values. These are
only used internally for codec selection.

This fixes some unnecessary back-and-forth checking between regular
and passthrough codec when opening a stream due to wrongly detected
sample rate changes in certain situations.

xbmc/cores/dvdplayer/DVDPlayerAudio.cpp

index 583a7f8..38a53e7 100644 (file)
@@ -175,9 +175,14 @@ void CDVDPlayerAudio::OpenStream( CDVDStreamInfo &hints, CDVDAudioCodec* codec )
   /* store our stream hints */
   m_streaminfo = hints;
 
-  /* update codec information from what codec gave ut */
-  m_streaminfo.channels = m_pAudioCodec->GetChannels();
-  m_streaminfo.samplerate = m_pAudioCodec->GetSampleRate();
+  /* update codec information from what codec gave out, if any */
+  int channelsFromCodec = m_pAudioCodec->GetChannels();
+  int samplerateFromCodec = m_pAudioCodec->GetEncodedSampleRate();
+
+  if (channelsFromCodec > 0)
+    m_streaminfo.channels = channelsFromCodec;
+  if (samplerateFromCodec > 0)
+    m_streaminfo.samplerate = samplerateFromCodec;
 
   /* check if we only just got sample rate, in which case the previous call
    * to CreateAudioCodec() couldn't have started passthrough */
@@ -312,12 +317,12 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
       audioframe.encoded_sample_rate   = m_pAudioCodec->GetEncodedSampleRate();
       audioframe.passthrough           = m_pAudioCodec->NeedPassthrough();
 
-      if (m_streaminfo.samplerate != audioframe.sample_rate)
+      if (m_streaminfo.samplerate != audioframe.encoded_sample_rate)
       {
         // The sample rate has changed or we just got it for the first time
         // for this stream. See if we should enable/disable passthrough due
         // to it.
-        m_streaminfo.samplerate = audioframe.sample_rate;
+        m_streaminfo.samplerate = audioframe.encoded_sample_rate;
         if (!switched && SwitchCodecIfNeeded()) {
           // passthrough has been enabled/disabled, reprocess the packet
           m_decode.data -= len;