servicedvb.cpp: re-enable subtitles on live/timeshift transition
[enigma2.git] / lib / service / servicedvb.cpp
index 45a12ce29b27911263f1f6049a3a805762d8e620..5166414f82b727eac56ef0f5e485262407a96656 100644 (file)
@@ -336,6 +336,7 @@ public:
        int isPlayable(const eServiceReference &ref, const eServiceReference &ignore) { return 1; }
        int getInfo(const eServiceReference &ref, int w);
        std::string getInfoString(const eServiceReference &ref,int w);
+       PyObject *getInfoObject(const eServiceReference &r, int what);
 };
 
 DEFINE_REF(eStaticServiceDVBPVRInformation);
@@ -400,6 +401,8 @@ int eStaticServiceDVBPVRInformation::getInfo(const eServiceReference &ref, int w
                return iServiceInformation::resIsString;
        case iServiceInformation::sServiceref:
                return iServiceInformation::resIsString;
+       case iServiceInformation::sFileSize:
+               return m_parser.m_filesize;
        case iServiceInformation::sTimeCreate:
                if (m_parser.m_time_create)
                        return m_parser.m_time_create;
@@ -425,6 +428,17 @@ std::string eStaticServiceDVBPVRInformation::getInfoString(const eServiceReferen
        }
 }
 
+PyObject *eStaticServiceDVBPVRInformation::getInfoObject(const eServiceReference &r, int what)
+{
+       switch (what)
+       {
+       case iServiceInformation::sFileSize:
+               return PyLong_FromLongLong(m_parser.m_filesize);
+       default:
+               Py_RETURN_NONE;
+       }
+}
+
 RESULT eStaticServiceDVBPVRInformation::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
 {
        if (!ref.path.empty())
@@ -906,7 +920,7 @@ eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *serv
        m_is_primary = 1;
        m_is_pvr = !m_reference.path.empty();
        
-       m_timeshift_enabled = m_timeshift_active = 0;
+       m_timeshift_enabled = m_timeshift_active = 0, m_timeshift_changed = 0;
        m_skipmode = 0;
        
        CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
@@ -1223,6 +1237,7 @@ RESULT eDVBServicePlay::setFastForward_internal(int ratio)
                return m_decoder->setFastForward(ffratio);
        else
                return m_decoder->setTrickmode();
+       return 0;
 }
 
 RESULT eDVBServicePlay::seek(ePtr<iSeekableService> &ptr)
@@ -1514,7 +1529,7 @@ int eDVBServicePlay::getInfo(int w)
                int aspect = -1;
                if (m_decoder)
                        aspect = m_decoder->getVideoAspect();
-               if (no_program_info)
+               if (aspect == -1 && no_program_info)
                        break;
                else if (aspect == -1 && !program.videoStreams.empty() && program.videoStreams[0].component_tag != -1)
                {
@@ -2209,10 +2224,12 @@ 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 */
 
                /* free the timeshift service handler, we need the resources */
        m_service_handler_timeshift.free();
        m_timeshift_active = 0;
+       m_timeshift_changed = 1;
 
        m_event((iPlayableService*)this, evSeekableStatusChanged);
 
@@ -2235,6 +2252,7 @@ void eDVBServicePlay::switchToTimeshift()
        m_video_event_connection = 0;
 
        m_timeshift_active = 1;
+       m_timeshift_changed = 1;
 
        eServiceReferenceDVB r = (eServiceReferenceDVB&)m_reference;
        r.path = m_timeshift_file;
@@ -2302,28 +2320,42 @@ void eDVBServicePlay::updateDecoder()
        if (!m_decoder)
        {
                h.getDecodeDemux(m_decode_demux);
+               if (m_timeshift_changed)
+                       m_decoder = 0;
                if (m_decode_demux)
                {
                        m_decode_demux->getMPEGDecoder(m_decoder, m_is_primary);
                        if (m_decoder)
                                m_decoder->connectVideoEvent(slot(*this, &eDVBServicePlay::video_event), m_video_event_connection);
+                       if (m_is_primary)
+                       {
+                               ePyObject subs;
+                               if (m_timeshift_changed)
+                                       subs = getCachedSubtitle();
+                               m_teletext_parser = new eDVBTeletextParser(m_decode_demux);
+                               m_teletext_parser->connectNewPage(slot(*this, &eDVBServicePlay::newSubtitlePage), m_new_subtitle_page_connection);
+                               m_subtitle_parser = new eDVBSubtitleParser(m_decode_demux);
+                               m_subtitle_parser->connectNewPage(slot(*this, &eDVBServicePlay::newDVBSubtitlePage), m_new_dvb_subtitle_page_connection);
+                               if (subs)
+                               {
+                                       int type = PyInt_AsLong(PyTuple_GET_ITEM(subs, 0)),
+                                           pid = PyInt_AsLong(PyTuple_GET_ITEM(subs, 1)),
+                                           comp_page = PyInt_AsLong(PyTuple_GET_ITEM(subs, 2)), // ttx page
+                                           anc_page = PyInt_AsLong(PyTuple_GET_ITEM(subs, 3)); // ttx magazine
+                                       if (type == 0) // dvb
+                                               m_subtitle_parser->start(pid, comp_page, anc_page);
+                                       else if (type == 1) // ttx
+                                               m_teletext_parser->setPageAndMagazine(comp_page, anc_page);
+                                       Py_DECREF(subs);
+                               }
+                       }
                }
-               if (m_decode_demux && m_is_primary)
-               {
-                       m_teletext_parser = new eDVBTeletextParser(m_decode_demux);
-                       m_teletext_parser->connectNewPage(slot(*this, &eDVBServicePlay::newSubtitlePage), m_new_subtitle_page_connection);
-                       m_subtitle_parser = new eDVBSubtitleParser(m_decode_demux);
-                       m_subtitle_parser->connectNewPage(slot(*this, &eDVBServicePlay::newDVBSubtitlePage), m_new_dvb_subtitle_page_connection);
-               } else
-               {
-                       m_teletext_parser = 0;
-                       m_subtitle_parser = 0;
-               }
-
                if (m_cue)
                        m_cue->setDecodingDemux(m_decode_demux, m_decoder);
        }
 
+       m_timeshift_changed = 0;
+
        if (m_decoder)
        {
                if (m_dvb_service)
@@ -2687,7 +2719,7 @@ PyObject *eDVBServicePlay::getCachedSubtitle()
                                        PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(1)); // type teletext
                                else
                                        PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(0)); // type dvb
-                               PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((data&0xFFFF0000)>>16)); // pid
+                               PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(pid)); // pid
                                PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong((data&0xFF00)>>8)); // composition_page / page
                                PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(data&0xFF)); // ancillary_page / magazine
                                return tuple;
@@ -2822,18 +2854,22 @@ void eDVBServicePlay::checkSubtitleTiming()
                        m_decoder->getPTS(0, pos);
 
                eDebug("%lld %lld", pos, show_time);
-               int diff =  show_time - pos;
+               int diff = show_time - pos;
+               if (type == TELETEXT && !page.m_have_pts)
+               {
+                       eDebug("ttx subtitle page without pts... immediate show");
+                       diff = 0;
+               }
                if (diff < 0)
                {
                        eDebug("[late (%d ms)]", -diff / 90);
                        diff = 0;
                }
-//             if (diff > 900000)
-//             {
-//                     eDebug("[invalid]");
-//                     diff = 0;
-//             }
-       
+               if (abs(diff) > 1800000)
+               {
+                       eDebug("[invalid]... immediate show!");
+                       diff = 0;
+               }
                if ((diff/90)<20)
                {
                        if (type == TELETEXT)