use explicit default track instead of first one (as the default one isn't always...
authorFelix Domke <tmbinc@elitedvb.net>
Sat, 25 Aug 2007 00:01:27 +0000 (00:01 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sat, 25 Aug 2007 00:01:27 +0000 (00:01 +0000)
lib/service/servicedvb.cpp
lib/service/servicedvb.h

index 5a6999d385e74ad5a92c407e8e70ec99f7e9478f..790ca2f7bd736a92a2c175ab63aba7b7eb9a4f3a 100644 (file)
@@ -1656,6 +1656,23 @@ int eDVBServicePlay::getNumberOfTracks()
        return program.audioStreams.size();
 }
 
+int eDVBServicePlay::getCurrentTrack()
+{
+       eDVBServicePMTHandler::program program;
+       eDVBServicePMTHandler &h = m_timeshift_active ? m_service_handler_timeshift : m_service_handler;
+       if (h.getProgramInfo(program))
+               return 0;
+
+       int max = program.audioStreams.size();
+       int i;
+
+       for (i = 0; i < max; ++i)
+               if (program.audioStreams[i].pid == m_current_audio_pid)
+                       return i;
+
+       return 0;
+}
+
 RESULT eDVBServicePlay::selectTrack(unsigned int i)
 {
        int ret = selectAudioStream(i);
@@ -1712,30 +1729,46 @@ int eDVBServicePlay::selectAudioStream(int i)
 
        if (h.getProgramInfo(program))
                return -1;
-       
+
        if ((unsigned int)i >= program.audioStreams.size())
                return -2;
-       
+
        if (!m_decoder)
                return -3;
-       
-       if (m_decoder->setAudioPID(program.audioStreams[i].pid, program.audioStreams[i].type))
-               return -4;
 
-       if (m_rds_decoder)
-               m_rds_decoder->start(program.audioStreams[i].pid);
+       int stream = i;
+       if (stream == -1)
+               stream = program.defaultAudioStream;
 
-       if (m_dvb_service && !m_is_pvr)
+       m_current_audio_pid = program.audioStreams[stream].pid;
+
+       if (m_decoder->setAudioPID(program.audioStreams[stream].pid, program.audioStreams[stream].type))
        {
-               if (program.audioStreams[i].type == eDVBAudio::aMPEG)
+               eDebug("set audio pid failed");
+               return -4;
+       }
+
+       if (m_rds_decoder)
+               m_rds_decoder->start(program.audioStreams[stream].pid);
+
+                       /* store new pid as default only when:
+                               a.) we have an entry in the service db for the current service,
+                               b.) we are not playing back something,
+                               c.) we are not selecting the default entry. (we wouldn't change 
+                                   anything in the best case, or destroy the default setting in
+                                   case the real default is not yet available.)
+                       */
+       if (m_dvb_service && !m_is_pvr && (i != -1))
+       {
+               if (program.audioStreams[stream].type == eDVBAudio::aMPEG)
                {
-                       m_dvb_service->setCacheEntry(eDVBService::cAPID, program.audioStreams[i].pid);
+                       m_dvb_service->setCacheEntry(eDVBService::cAPID, program.audioStreams[stream].pid);
                        m_dvb_service->setCacheEntry(eDVBService::cAC3PID, -1);
                }
                else
                {
                        m_dvb_service->setCacheEntry(eDVBService::cAPID, -1);
-                       m_dvb_service->setCacheEntry(eDVBService::cAC3PID, program.audioStreams[i].pid);
+                       m_dvb_service->setCacheEntry(eDVBService::cAC3PID, program.audioStreams[stream].pid);
                }
        }
 
@@ -2336,7 +2369,8 @@ void eDVBServicePlay::updateDecoder()
                m_decoder->setPCMDelay(pcm_delay == -1 ? 0 : pcm_delay);
 
                m_decoder->setVideoPID(vpid, vpidtype);
-               m_decoder->setAudioPID(apid, apidtype);
+               selectAudioStream();
+
                if (!(m_is_pvr || m_timeshift_active || !m_is_primary))
                {
                        m_decoder->setSyncPCR(pcrpid);
index 4a40df1204a9c6609e2d58e43bd745d45716f0fe..789edbea701b396e088a12450a8e238747f49ef3 100644 (file)
@@ -139,6 +139,7 @@ public:
        int getNumberOfTracks();
        RESULT selectTrack(unsigned int i);
        RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
+       int getCurrentTrack();
 
                // iAudioChannelSelection       
        int getCurrentChannel();
@@ -194,6 +195,7 @@ private:
                /* in timeshift mode, we essentially have two channels, and thus pmt handlers. */
        eDVBServicePMTHandler m_service_handler_timeshift;
        eDVBServiceEITHandler m_event_handler;
+       int m_current_audio_pid;
        
        eDVBServicePlay(const eServiceReference &ref, eDVBService *service);
        
@@ -214,7 +216,7 @@ private:
        ePtr<iDVBDemux> m_decode_demux;
 
        int m_current_audio_stream;
-       int selectAudioStream(int n);
+       int selectAudioStream(int n = -1);
        
                /* timeshift */
        ePtr<iDVBTSRecorder> m_record;