servicedvb.cpp: more exact resume after seek and slowmotion
[enigma2.git] / lib / service / servicedvb.cpp
index ddc675e66bbf150ad58af62d0fee750f2208c109..6b258ac1e487d7dbe76ed4ae65c37eb784d4b8c4 100644 (file)
@@ -917,7 +917,7 @@ eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *serv
        m_is_pvr = !m_reference.path.empty();
        
        m_timeshift_enabled = m_timeshift_active = 0, m_timeshift_changed = 0;
-       m_skipmode = 0;
+       m_skipmode = m_fastforward = m_slowmotion = 0;
        
        CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
        CONNECT(m_service_handler_timeshift.serviceEvent, eDVBServicePlay::serviceEventTimeshift);
@@ -1185,7 +1185,10 @@ RESULT eDVBServicePlay::setSlowMotion(int ratio)
        eDebug("eDVBServicePlay::setSlowMotion(%d)", ratio);
        setFastForward_internal(0);
        if (m_decoder)
+       {
+               m_slowmotion = ratio;
                return m_decoder->setSlowMotion(ratio);
+       }
        else
                return -1;
 }
@@ -1197,10 +1200,11 @@ RESULT eDVBServicePlay::setFastForward(int ratio)
        return setFastForward_internal(ratio);
 }
 
-RESULT eDVBServicePlay::setFastForward_internal(int ratio)
+RESULT eDVBServicePlay::setFastForward_internal(int ratio, bool final_seek)
 {
-       int skipmode, ffratio;
-       
+       int skipmode, ffratio, ret = 0;
+       pts_t pos=0;
+
        if (ratio > 8)
        {
                skipmode = ratio;
@@ -1225,19 +1229,28 @@ RESULT eDVBServicePlay::setFastForward_internal(int ratio)
                if (m_cue)
                        m_cue->setSkipmode(skipmode * 90000); /* convert to 90000 per second */
        }
-       
+
        m_skipmode = skipmode;
-       
+
+       if (final_seek)
+               eDebug("trickplay stopped .. ret %d, pos %lld", getPlayPosition(pos), pos);
+
+       m_fastforward = ffratio;
+
        if (!m_decoder)
                return -1;
-               
+
        if (ffratio == 0)
                ; /* return m_decoder->play(); is done in caller*/
        else if (ffratio != 1)
-               return m_decoder->setFastForward(ffratio);
+               ret = m_decoder->setFastForward(ffratio);
        else
-               return m_decoder->setTrickmode();
-       return 0;
+               ret = m_decoder->setTrickmode();
+
+       if (pos)
+               eDebug("final seek after trickplay ret %d", seekTo(pos));
+
+       return ret;
 }
 
 RESULT eDVBServicePlay::seek(ePtr<iSeekableService> &ptr)
@@ -1278,9 +1291,10 @@ RESULT eDVBServicePlay::pause()
 RESULT eDVBServicePlay::unpause()
 {
        eDebug("eDVBServicePlay::unpause");
-       setFastForward_internal(0);
+       setFastForward_internal(0, m_slowmotion || m_fastforward > 1);
        if (m_decoder)
        {
+               m_slowmotion = 0;
                m_is_paused = 0;
                return m_decoder->play();
        } else
@@ -1370,7 +1384,7 @@ RESULT eDVBServicePlay::setTrickmode(int trick)
 
 RESULT eDVBServicePlay::isCurrentlySeekable()
 {
-       return m_is_pvr || m_timeshift_active ? 3 : 0; // fast forward/backward possible and seeking possible
+       return m_is_pvr || m_timeshift_active;
 }
 
 RESULT eDVBServicePlay::frontendInfo(ePtr<iFrontendInformation> &ptr)
@@ -2229,7 +2243,7 @@ void eDVBServicePlay::switchToLive()
        m_new_subtitle_page_connection = 0;
        m_rds_decoder_event_connection = 0;
        m_video_event_connection = 0;
-       m_is_paused = m_skipmode = 0; /* not supported in live mode */
+       m_is_paused = m_skipmode = m_fastforward = m_slowmotion = 0; /* not supported in live mode */
 
                /* free the timeshift service handler, we need the resources */
        m_service_handler_timeshift.free();
@@ -2398,17 +2412,8 @@ void eDVBServicePlay::updateDecoder()
                        }
                }
 
-               std::string config_delay;
-               int config_delay_int = 0;
-               if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
-                       config_delay_int = atoi(config_delay.c_str());
-               m_decoder->setAC3Delay(ac3_delay == -1 ? config_delay_int : ac3_delay + config_delay_int);
-
-               if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
-                       config_delay_int = atoi(config_delay.c_str());
-               else
-                       config_delay_int = 0;
-               m_decoder->setPCMDelay(pcm_delay == -1 ? config_delay_int : pcm_delay + config_delay_int);
+               setAC3Delay(ac3_delay == -1 ? 0 : ac3_delay);
+               setPCMDelay(pcm_delay == -1 ? 0 : pcm_delay);
 
                m_decoder->setVideoPID(vpid, vpidtype);
                selectAudioStream();
@@ -2932,16 +2937,28 @@ void eDVBServicePlay::setAC3Delay(int delay)
 {
        if (m_dvb_service)
                m_dvb_service->setCacheEntry(eDVBService::cAC3DELAY, delay ? delay : -1);
-       if (m_decoder)
-               m_decoder->setAC3Delay(delay);
+       if (m_decoder) {
+               std::string config_delay;
+               int config_delay_int = 0;
+               if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
+                       config_delay_int = atoi(config_delay.c_str());
+               m_decoder->setAC3Delay(delay + config_delay_int);
+       }
 }
 
 void eDVBServicePlay::setPCMDelay(int delay)
 {
        if (m_dvb_service)
                m_dvb_service->setCacheEntry(eDVBService::cPCMDELAY, delay ? delay : -1);
-       if (m_decoder)
-               m_decoder->setPCMDelay(delay);
+       if (m_decoder) {
+               std::string config_delay;
+               int config_delay_int = 0;
+               if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
+                       config_delay_int = atoi(config_delay.c_str());
+               else
+                       config_delay_int = 0;
+               m_decoder->setPCMDelay(delay + config_delay_int);
+       }
 }
 
 void eDVBServicePlay::video_event(struct iTSMPEGDecoder::videoEvent event)