small private epg fix
[enigma2.git] / lib / dvb / epgcache.cpp
index 975d46ac0cacf94512c742237f37e6bb3e81201f..56a6a61ccbd701020a6efe86aeb8539a44313001 100644 (file)
@@ -671,9 +671,18 @@ void eEPGCache::gotMessage( const Message &msg )
                                        chid.original_network_id.get() == msg.service.onid &&
                                        data->m_PrivatePid == -1 )
                                {
+                                       data->m_PrevVersion = -1;
                                        data->m_PrivatePid = msg.pid;
                                        data->m_PrivateService = msg.service;
-                                       data->startPrivateReader(msg.pid, -1);
+                                       updateMap::iterator It = channelLastUpdated.find( channel->getChannelID() );
+                                       int update = ( It != channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (time(0)+eDVBLocalTimeHandler::getInstance()->difference()-It->second) * 1000 ) ) : ZAP_DELAY );
+                                       if (update < ZAP_DELAY)
+                                               update = ZAP_DELAY;
+                                       data->startPrivateTimer.start(update, 1);
+                                       if (update >= 60000)
+                                               eDebug("[EPGC] next private update in %i min", update/60000);
+                                       else if (update >= 1000)
+                                               eDebug("[EPGC] next private update in %i sec", update/1000);
                                        break;
                                }
                        }
@@ -899,11 +908,12 @@ void eEPGCache::save()
 
 eEPGCache::channel_data::channel_data(eEPGCache *ml)
        :cache(ml)
-       ,abortTimer(ml), zapTimer(ml)
+       ,abortTimer(ml), zapTimer(ml), startPrivateTimer(ml)
        ,state(0), isRunning(0), haveData(0), can_delete(1)
 {
        CONNECT(zapTimer.timeout, eEPGCache::channel_data::startEPG);
        CONNECT(abortTimer.timeout, eEPGCache::channel_data::abortNonAvail);
+       CONNECT(startPrivateTimer.timeout, eEPGCache::channel_data::startPrivateReader);
 }
 
 bool eEPGCache::channel_data::finishEPG()
@@ -1532,6 +1542,7 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
                PyObject *item=PyList_GET_ITEM(list, listIt++); // borrowed reference!
                if (PyTuple_Check(item))
                {
+                       bool service_changed=false;
                        int type=0;
                        long event_id=-1;
                        time_t stime=-1;
@@ -1579,6 +1590,24 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
                                eDebug("service reference for epg query is not valid");
                                continue;
                        }
+
+                       // redirect subservice querys to parent service
+                       eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&)ref;
+                       if (dvb_ref.getParentTransportStreamID().get()) // linkage subservice
+                       {
+                               eServiceCenterPtr service_center;
+                               if (!eServiceCenter::getPrivInstance(service_center))
+                               {
+                                       dvb_ref.setTransportStreamID( dvb_ref.getParentTransportStreamID() );
+                                       dvb_ref.setServiceID( dvb_ref.getParentServiceID() );
+                                       dvb_ref.setParentTransportStreamID(eTransportStreamID(0));
+                                       dvb_ref.setParentServiceID(eServiceID(0));
+                                       dvb_ref.name="";
+                                       service = PyString_FromString(dvb_ref.toString().c_str());
+                                       service_changed = true;
+                               }
+                       }
+
                        PyObject *service_name=NULL;
                        if (must_get_service_name)
                        {
@@ -1628,6 +1657,8 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
                                if (ret)
                                        return ret;
                        }
+                       if (service_changed)
+                               Py_DECREF(service);
                        if (service_name)
                                Py_DECREF(service_name);
                }
@@ -2097,7 +2128,7 @@ void eEPGCache::PMTready(eDVBServicePMTHandler *pmthandler)
                                if (tmp==3)
                                {
                                        eServiceReferenceDVB ref;
-                                       if (!pmthandler->getService(ref))
+                                       if (!pmthandler->getServiceReference(ref))
                                        {
                                                int pid = (*es)->getPid();
                                                messages.send(Message(Message::got_private_pid, ref, pid));
@@ -2195,6 +2226,14 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey &current_service, const __
                        onid |= data[ptr++];
                        int sid = data[ptr++] << 8;
                        sid |= data[ptr++];
+
+// WORKAROUND for wrong transmitted epg data
+                       if ( onid == 0x85 && tsid == 0x11 && sid == 0xd3 )  // premiere sends wrong tsid here
+                               tsid = 0x1;
+                       else if ( onid == 0x85 && tsid == 0x3 && sid == 0xf5 ) // premiere sends wrong sid here
+                               sid = 0xdc;
+////////////////////////////////////////////
+                               
                        uniqueEPGKey service( sid, onid, tsid );
                        descr_len -= 6;
                        while( descr_len > 0 )
@@ -2276,27 +2315,24 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey &current_service, const __
        }
 }
 
-void eEPGCache::channel_data::startPrivateReader(int pid, int version)
+void eEPGCache::channel_data::startPrivateReader()
 {
        eDVBSectionFilterMask mask;
        memset(&mask, 0, sizeof(mask));
-       mask.pid = pid;
+       mask.pid = m_PrivatePid;
        mask.flags = eDVBSectionFilterMask::rfCRC;
        mask.data[0] = 0xA0;
        mask.mask[0] = 0xFF;
-       eDebug("start privatefilter for pid %04x and version %d", pid, version);
-       if (version != -1)
+       eDebug("start privatefilter for pid %04x and version %d", m_PrivatePid, m_PrevVersion);
+       if (m_PrevVersion != -1)
        {
-               mask.data[3] = version << 1;
+               mask.data[3] = m_PrevVersion << 1;
                mask.mask[3] = 0x3E;
                mask.mode[3] = 0x3E;
        }
        seenPrivateSections.clear();
        m_PrivateReader->connectRead(slot(*this, &eEPGCache::channel_data::readPrivateData), m_PrivateConn);
        m_PrivateReader->start(mask);
-#ifdef NEED_DEMUX_WORKAROUND
-       m_PrevVersion=version;
-#endif
 }
 
 void eEPGCache::channel_data::readPrivateData( const __u8 *data)
@@ -2329,9 +2365,9 @@ void eEPGCache::channel_data::readPrivateData( const __u8 *data)
                        eDebug("[EPGC] private finished");
                        if (!isRunning)
                                can_delete = 1;
-                       int version = data[5];
-                       version = ((version & 0x3E) >> 1);
-                       startPrivateReader(m_PrivatePid, version);
+                       m_PrevVersion = (data[5] & 0x3E) >> 1;
+                       m_PrivateReader->stop();
+                       startPrivateTimer.start(UPDATE_INTERVAL, 1);
                }
        }
 }