ask user before a recordtimer set the box to standby or deepstandby
[enigma2.git] / lib / dvb / pmt.cpp
index 74042ed09ceb951fb0986459e52ab14e90d3c9de..33ec55c1c83eec47c19a5094a0baed1ef2d0fe96 100644 (file)
@@ -12,6 +12,8 @@
 #include <dvbsi++/descriptor_tag.h>
 #include <dvbsi++/iso639_language_descriptor.h>
 #include <dvbsi++/stream_identifier_descriptor.h>
+#include <dvbsi++/subtitling_descriptor.h>
+#include <dvbsi++/teletext_descriptor.h>
 
 eDVBServicePMTHandler::eDVBServicePMTHandler()
        :m_ca_servicePtr(0), m_dvb_scan(0), m_decode_demux_num(0xFF)
@@ -83,11 +85,12 @@ void eDVBServicePMTHandler::PMTready(int error)
                serviceEvent(eventNoPMT);
        else
        {
+               m_have_cached_program = false;
                serviceEvent(eventNewProgramInfo);
                eEPGCache::getInstance()->PMTready(this);
-               if (!m_pvr_channel)
+               if (!m_pvr_channel) // don't send campmt to camd.socket for playbacked services
                {
-                       if(!m_ca_servicePtr)   // don't send campmt to camd.socket for playbacked services
+                       if(!m_ca_servicePtr)
                        {
                                int demuxes[2] = {0,0};
                                uint8_t tmp;
@@ -98,7 +101,7 @@ void eDVBServicePMTHandler::PMTready(int error)
                                else
                                        demuxes[1]=demuxes[0];
                                eDVBCAService::register_service(m_reference, demuxes, m_ca_servicePtr);
-                               eDVBCIInterfaces::getInstance()->addPMTHandler(this);
+                               eDVBCIInterfaces::getInstance()->recheckPMTHandlers();
                        }
                        eDVBCIInterfaces::getInstance()->gotPMT(this);
                }
@@ -138,260 +141,266 @@ void eDVBServicePMTHandler::PATready(int)
 
 PyObject *eDVBServicePMTHandler::getCaIds()
 {
-       PyObject *ret=0;
+       ePyObject ret;
 
-       ePtr<eTable<ProgramMapSection> > ptr;
+       program prog;
 
-       if ( ((m_service && m_service->usePMT()) || !m_service) && !m_PMT.getCurrent(ptr))
+       if ( !getProgramInfo(prog) )
        {
-               uint16_t caids[255];
-               memset(caids, 0, sizeof(caids));
-               std::vector<ProgramMapSection*>::const_iterator i = ptr->getSections().begin();
-               for (; i != ptr->getSections().end(); ++i)
-               {
-                       const ProgramMapSection &pmt = **i;
-                       ElementaryStreamInfoConstIterator es = pmt.getEsInfo()->begin();
-                       for (; es != pmt.getEsInfo()->end(); ++es)
-                       {
-                               for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
-                                               desc != (*es)->getDescriptors()->end(); ++desc)
-                               {
-                                       switch ((*desc)->getTag())
-                                       {
-                                               case CA_DESCRIPTOR:
-                                               {
-                                                       const CaDescriptor *cadescr = (const CaDescriptor*)*desc;
-                                                       uint16_t caid = cadescr->getCaSystemId();
-                                                       int idx=0;
-                                                       while (caids[idx] && caids[idx] != caid)
-                                                               ++idx;
-                                                       caids[idx]=caid;
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-                       for (DescriptorConstIterator desc = pmt.getDescriptors()->begin();
-                               desc != pmt.getDescriptors()->end(); ++desc)
-                       {
-                               switch ((*desc)->getTag())
-                               {
-                                       case CA_DESCRIPTOR:
-                                       {
-                                               const CaDescriptor *cadescr = (const CaDescriptor*)*desc;
-                                               uint16_t caid = cadescr->getCaSystemId();
-                                               int idx=0;
-                                               while (caids[idx] && caids[idx] != caid)
-                                                       ++idx;
-                                               caids[idx]=caid;
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               int cnt=0;
-               while (caids[cnt])
-                       ++cnt;
+               int cnt=prog.caids.size();
                if (cnt)
                {
                        ret=PyList_New(cnt);
+                       std::set<uint16_t>::iterator it(prog.caids.begin());
                        while(cnt--)
-                               PyList_SET_ITEM(ret, cnt, PyInt_FromLong(caids[cnt]));
+                               PyList_SET_ITEM(ret, cnt, PyInt_FromLong(*it++));
                }
        }
 
-       if (!ret)
-               ret=PyList_New(0);
-
-       return ret;
+       return ret ? (PyObject*)ret : (PyObject*)PyList_New(0);
 }
 
 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
 {
        ePtr<eTable<ProgramMapSection> > ptr;
+       int cached_apid_ac3 = -1;
+       int cached_apid_mpeg = -1;
+       int cached_vpid = -1;
+       int cached_tpid = -1;
+       int ret = -1;
 
        program.videoStreams.clear();
        program.audioStreams.clear();
        program.pcrPid = -1;
-       program.isCrypted = false;
        program.pmtPid = -1;
        program.textPid = -1;
 
+       if ( m_service && !m_service->cacheEmpty() )
+       {
+               cached_vpid = m_service->getCacheEntry(eDVBService::cVPID);
+               cached_apid_mpeg = m_service->getCacheEntry(eDVBService::cAC3PID);
+               cached_apid_ac3 = m_service->getCacheEntry(eDVBService::cAPID);
+               cached_tpid = m_service->getCacheEntry(eDVBService::cTPID);
+       }
+
        if ( ((m_service && m_service->usePMT()) || !m_service) && !m_PMT.getCurrent(ptr))
        {
-               int cached_apid_ac3 = -1;
-               int cached_apid_mpeg = -1;
-               int cached_vpid = -1;
-               int cached_tpid = -1;
-               if ( m_service && !m_service->cacheEmpty() )
+               if (m_have_cached_program)
                {
-                       cached_vpid = m_service->getCachePID(eDVBService::cVPID);
-                       cached_apid_mpeg = m_service->getCachePID(eDVBService::cAC3PID);
-                       cached_apid_ac3 = m_service->getCachePID(eDVBService::cAPID);
-                       cached_tpid = m_service->getCachePID(eDVBService::cTPID);
+                       program = m_cached_program;
+                       ret = 0;
                }
-               eDVBTableSpec table_spec;
-               ptr->getSpec(table_spec);
-               program.pmtPid = table_spec.pid < 0x1fff ? table_spec.pid : -1;
-               std::vector<ProgramMapSection*>::const_iterator i;
-               for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
+               else
                {
-                       const ProgramMapSection &pmt = **i;
-                       program.pcrPid = pmt.getPcrPid();
-                       
-                       ElementaryStreamInfoConstIterator es;
-                       for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
+                       eDVBTableSpec table_spec;
+                       ptr->getSpec(table_spec);
+                       program.pmtPid = table_spec.pid < 0x1fff ? table_spec.pid : -1;
+                       std::vector<ProgramMapSection*>::const_iterator i;
+                       for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
                        {
-                               int isaudio = 0, isvideo = 0, cadescriptors = 0;
-                               videoStream video;
-                               audioStream audio;
-                               audio.component_tag=-1;
-                               video.component_tag=-1;
-
-                               video.pid = (*es)->getPid();
-                               audio.pid = (*es)->getPid();
-
-                               switch ((*es)->getType())
+                               const ProgramMapSection &pmt = **i;
+                               program.pcrPid = pmt.getPcrPid();
+                       
+                               ElementaryStreamInfoConstIterator es;
+                               for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
                                {
-                               case 0x01: // MPEG 1 video
-                               case 0x02: // MPEG 2 video
-                                       isvideo = 1;
-                                       //break; fall through !!!
-                               case 0x03: // MPEG 1 audio
-                               case 0x04: // MPEG 2 audio:
-                                       if (!isvideo)
-                                       {
-                                               isaudio = 1;
-                                               audio.type = audioStream::atMPEG;
-                                       }
-                                       //break; fall through !!!
-                               case 0x06: // PES Private
-                                               /* PES private can contain AC-3, DTS or lots of other stuff.
-                                                  check descriptors to get the exact type. */
-                                       for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
-                                                       desc != (*es)->getDescriptors()->end(); ++desc)
+                                       int isaudio = 0, isvideo = 0;
+                                       videoStream video;
+                                       audioStream audio;
+                                       audio.component_tag=video.component_tag=-1;
+                                       video.type = videoStream::vtMPEG2;
+
+                                       switch ((*es)->getType())
                                        {
-                                               switch ((*desc)->getTag())
+                                       case 0x1b: // AVC Video Stream (MPEG4 H264)
+                                               video.type = videoStream::vtMPEG4_H264;
+                                       case 0x01: // MPEG 1 video
+                                       case 0x02: // MPEG 2 video
+                                               isvideo = 1;
+                                               //break; fall through !!!
+                                       case 0x03: // MPEG 1 audio
+                                       case 0x04: // MPEG 2 audio:
+                                               if (!isvideo)
+                                               {
+                                                       isaudio = 1;
+                                                       audio.type = audioStream::atMPEG;
+                                               }
+                                               //break; fall through !!!
+                                       case 0x06: // PES Private
+                                                       /* PES private can contain AC-3, DTS or lots of other stuff.
+                                                          check descriptors to get the exact type. */
+                                               for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
+                                                               desc != (*es)->getDescriptors()->end(); ++desc)
                                                {
-                                               case TELETEXT_DESCRIPTOR:
-                                                       if ( program.textPid == -1 || (*es)->getPid() == cached_tpid )
-                                                               program.textPid = (*es)->getPid();
-                                                       break;
-                                               case AC3_DESCRIPTOR:
-                                                       if (!isvideo)
+                                                       switch ((*desc)->getTag())
                                                        {
+                                                       case SUBTITLING_DESCRIPTOR:
+                                                       {
+                                                               SubtitlingDescriptor *d = (SubtitlingDescriptor*)(*desc);
+                                                               const SubtitlingList *list = d->getSubtitlings();
+                                                               subtitleStream s;
+                                                               s.pid = (*es)->getPid();
+                                                               for (SubtitlingConstIterator it(list->begin()); it != list->end(); ++it)
+                                                               {
+                                                                       s.subtitling_type = (*it)->getSubtitlingType();
+                                                                       s.composition_page_id = (*it)->getCompositionPageId();
+                                                                       s.ancillary_page_id = (*it)->getAncillaryPageId();
+                                                                       s.language_code = (*it)->getIso639LanguageCode();
+//                                                                     eDebug("add dvb subtitle %s PID %04x, type %d, composition page %d, ancillary_page %d",
+//                                                                             s.language_code.c_str(), s.pid, s.subtitling_type, s.composition_page_id, s.ancillary_page_id);
+                                                                       program.subtitleStreams.push_back(s);
+                                                               }
+                                                               break;
+                                                       }
+                                                       case TELETEXT_DESCRIPTOR:
+                                                               if ( program.textPid == -1 || (*es)->getPid() == cached_tpid )
+                                                               {
+                                                                       subtitleStream s;
+                                                                       s.subtitling_type = 0x01; // EBU TELETEXT SUBTITLES
+                                                                       s.pid = program.textPid = (*es)->getPid();
+                                                                       TeletextDescriptor *d = (TeletextDescriptor*)(*desc);
+                                                                       const VbiTeletextList *list = d->getVbiTeletexts();
+                                                                       for (VbiTeletextConstIterator it(list->begin()); it != list->end(); ++it)
+                                                                       {
+                                                                               switch((*it)->getTeletextType())
+                                                                               {
+                                                                                       case 0x02: // Teletext subtitle page
+                                                                                       case 0x05: // Teletext subtitle page for hearing impaired pepople
+                                                                                               s.language_code = (*it)->getIso639LanguageCode();
+                                                                                               s.teletext_page_number = (*it)->getTeletextPageNumber();
+                                                                                               s.teletext_magazine_number = (*it)->getTeletextMagazineNumber();
+//                                                                                             eDebug("add teletext subtitle %s PID %04x, page number %d, magazine number %d",
+//                                                                                                     s.language_code.c_str(), s.pid, s.teletext_page_number, s.teletext_magazine_number);
+                                                                                               program.subtitleStreams.push_back(s);
+                                                                                               break;
+                                                                               }
+                                                                       }
+                                                               }
+                                                               break;
+                                                       case DTS_DESCRIPTOR:
+                                                               isaudio = 1;
+                                                               audio.type = audioStream::atDTS;
+                                                               break;
+                                                       case AAC_DESCRIPTOR:
+                                                               isaudio = 1;
+                                                               audio.type = audioStream::atAAC;
+                                                               break;
+                                                       case AC3_DESCRIPTOR:
                                                                isaudio = 1;
                                                                audio.type = audioStream::atAC3;
-                                                       }
-                                                       break;
-                                               case ISO_639_LANGUAGE_DESCRIPTOR:
-                                                       if (!isvideo)
+                                                               break;
+                                                       case ISO_639_LANGUAGE_DESCRIPTOR:
+                                                               if (!isvideo)
+                                                               {
+                                                                       const Iso639LanguageList *languages = ((Iso639LanguageDescriptor*)*desc)->getIso639Languages();
+                                                                               /* use last language code */
+                                                                       for (Iso639LanguageConstIterator i(languages->begin()); i != languages->end(); ++i)
+                                                                               audio.language_code = (*i)->getIso639LanguageCode();
+                                                               }
+                                                               break;
+                                                       case STREAM_IDENTIFIER_DESCRIPTOR:
+                                                               audio.component_tag =
+                                                                       video.component_tag =
+                                                                               ((StreamIdentifierDescriptor*)*desc)->getComponentTag();
+                                                               break;
+                                                       case CA_DESCRIPTOR:
                                                        {
-                                                               const Iso639LanguageList *languages = ((Iso639LanguageDescriptor*)*desc)->getIso639Languages();
-                                                                       /* use last language code */
-                                                               for (Iso639LanguageConstIterator i(languages->begin()); i != languages->end(); ++i)
-                                                                       audio.language_code = (*i)->getIso639LanguageCode();
+                                                               CaDescriptor *descr = (CaDescriptor*)(*desc);
+                                                               program.caids.insert(descr->getCaSystemId());
+                                                               break;
+                                                       }
                                                        }
-                                                       break;
-                                               case STREAM_IDENTIFIER_DESCRIPTOR:
-                                                       audio.component_tag =
-                                                               video.component_tag =
-                                                                       ((StreamIdentifierDescriptor*)*desc)->getComponentTag();
-                                                       break;
-                                               case CA_DESCRIPTOR:
-                                                       ++cadescriptors;
-                                                       break;
                                                }
+                                               break;
                                        }
-                                       break;
-                               }
-                               if (isaudio)
-                               {
-                                       if ( !program.audioStreams.empty() &&
-                                               ( audio.pid == cached_apid_ac3 || audio.pid == cached_apid_mpeg) )
+                                       if (isaudio)
                                        {
-                                               program.audioStreams.push_back(program.audioStreams[0]);
-                                               program.audioStreams[0] = audio;
+                                               audio.pid = (*es)->getPid();
+                                               if ( !program.audioStreams.empty() &&
+                                                       ( audio.pid == cached_apid_ac3 || audio.pid == cached_apid_mpeg) )
+                                               {
+                                                       program.audioStreams.push_back(program.audioStreams[0]);
+                                                       program.audioStreams[0] = audio;
+                                               }
+                                               else
+                                                       program.audioStreams.push_back(audio);
                                        }
-                                       else
-                                               program.audioStreams.push_back(audio);
-                               }
-                               else if (isvideo)
-                               {
-                                       if ( !program.videoStreams.empty() && video.pid == cached_vpid )
+                                       else if (isvideo)
                                        {
-                                               program.videoStreams.push_back(program.videoStreams[0]);
-                                               program.videoStreams[0] = video;
+                                               video.pid = (*es)->getPid();
+                                               if ( !program.videoStreams.empty() && video.pid == cached_vpid )
+                                               {
+                                                       program.videoStreams.push_back(program.videoStreams[0]);
+                                                       program.videoStreams[0] = video;
+                                               }
+                                               else
+                                                       program.videoStreams.push_back(video);
                                        }
                                        else
-                                               program.videoStreams.push_back(video);
+                                               continue;
                                }
-                               else
-                                       continue;
-                               if ( cadescriptors > 0 )
-                                       program.isCrypted=true;
-                       }
-                       if ( !program.isCrypted )
-                       {
                                for (DescriptorConstIterator desc = pmt.getDescriptors()->begin();
                                        desc != pmt.getDescriptors()->end(); ++desc)
                                {
-                                       switch ((*desc)->getTag())
+                                       if ((*desc)->getTag() == CA_DESCRIPTOR)
                                        {
-                                       case CA_DESCRIPTOR:
-                                               program.isCrypted=true;
-                                               break;
+                                               CaDescriptor *descr = (CaDescriptor*)(*desc);
+                                               program.caids.insert(descr->getCaSystemId());
                                        }
                                }
-                               break;
                        }
+                       ret = 0;
+                       m_cached_program = program;
+                       m_have_cached_program = true;
                }
-               return 0;
        } else if ( m_service && !m_service->cacheEmpty() )
        {
-               int vpid = m_service->getCachePID(eDVBService::cVPID),
-                       apid_ac3 = m_service->getCachePID(eDVBService::cAC3PID),
-                       apid_mpeg = m_service->getCachePID(eDVBService::cAPID),
-                       pcrpid = m_service->getCachePID(eDVBService::cPCRPID),
-                       tpid = m_service->getCachePID(eDVBService::cTPID),
+               int cached_pcrpid = m_service->getCacheEntry(eDVBService::cPCRPID),
+                       vpidtype = m_service->getCacheEntry(eDVBService::cVTYPE),
                        cnt=0;
-               if ( vpid != -1 )
+               if ( vpidtype == -1 )
+                       vpidtype = videoStream::vtMPEG2;
+               if ( cached_vpid != -1 )
                {
                        videoStream s;
-                       s.pid = vpid;
+                       s.pid = cached_vpid;
+                       s.type = vpidtype;
                        program.videoStreams.push_back(s);
                        ++cnt;
                }
-               if ( apid_ac3 != -1 )
+               if ( cached_apid_ac3 != -1 )
                {
                        audioStream s;
                        s.type = audioStream::atAC3;
-                       s.pid = apid_ac3;
+                       s.pid = cached_apid_ac3;
                        program.audioStreams.push_back(s);
                        ++cnt;
                }
-               if ( apid_mpeg != -1 )
+               if ( cached_apid_mpeg != -1 )
                {
                        audioStream s;
                        s.type = audioStream::atMPEG;
-                       s.pid = apid_mpeg;
+                       s.pid = cached_apid_mpeg;
                        program.audioStreams.push_back(s);
                        ++cnt;
                }
-               if ( pcrpid != -1 )
+               if ( cached_pcrpid != -1 )
                {
                        ++cnt;
-                       program.pcrPid = pcrpid;
+                       program.pcrPid = cached_pcrpid;
                }
-               if ( tpid != -1 )
+               if ( cached_tpid != -1 )
                {
                        ++cnt;
-                       program.textPid = tpid;
+                       program.textPid = cached_tpid;
                }
+               CAID_LIST &caids = m_service->m_ca;
+               for (CAID_LIST::iterator it(caids.begin()); it != caids.end(); ++it)
+                       program.caids.insert(*it);
                if ( cnt )
-                       return 0;
+                       ret = 0;
        }
-       return -1;
+       return ret;
 }
 
 int eDVBServicePMTHandler::getChannel(eUsePtr<iDVBChannel> &channel)
@@ -443,32 +452,21 @@ int eDVBServicePMTHandler::getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel)
 
 void eDVBServicePMTHandler::SDTScanEvent(int event)
 {
-       eDebug("scan event %d!", event);
-
        switch (event)
        {
                case eDVBScan::evtFinish:
                {
                        ePtr<iDVBChannelList> db;
-                       int err;
-                       if ((err = m_resourceManager->getChannelList(db)) != 0)
+                       if (m_resourceManager->getChannelList(db) != 0)
                                eDebug("no channel list");
                        else
                        {
-                               m_dvb_scan->insertInto(db);
-                               eDebug("scan done!");
+                               m_dvb_scan->insertInto(db, true);
+                               eDebug("sdt update done!");
                        }
                        break;
                }
 
-               case eDVBScan::evtNewService:
-                       eDebug("scan new service");
-                       break;
-
-               case eDVBScan::evtFail:
-                       eDebug("scan failed.");
-                       break;
-
                default:
                        break;
        }
@@ -488,6 +486,13 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux,
                ref.getChannelID(chid);
                res = m_resourceManager->allocateChannel(chid, m_channel);
                eDebug("allocate Channel: res %d", res);
+
+               ePtr<iDVBChannelList> db;
+               if (!m_resourceManager->getChannelList(db))
+                               db->getService((eServiceReferenceDVB&)m_reference, m_service);
+
+               if (!res)
+                       eDVBCIInterfaces::getInstance()->addPMTHandler(this);
        } else
        {
                eDVBMetaParser parser;
@@ -519,10 +524,6 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux,
                m_channel = m_pvr_channel;
        }
 
-       ePtr<iDVBChannelList> db;
-       if (!m_resourceManager->getChannelList(db))
-               db->getService((eServiceReferenceDVB&)m_reference, m_service);
-
        if (m_channel)
        {
                m_channel->connectStateChange(
@@ -538,12 +539,12 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux,
                if (ref.path.empty())
                {
                        delete m_dvb_scan;
-                       m_dvb_scan = new eDVBScan(m_channel);
+                       m_dvb_scan = new eDVBScan(m_channel, false, false);
                        m_dvb_scan->connectEvent(slot(*this, &eDVBServicePMTHandler::SDTScanEvent), m_scan_event_connection);
                }
        } else
        {
-               serviceEvent(eventTuneFailed);
+               serviceEvent(eventNoResources);
                return res;
        }
 
@@ -558,7 +559,6 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux,
 
 void eDVBServicePMTHandler::free()
 {
-       eDVBScan *tmp = m_dvb_scan;
        m_dvb_scan = 0;
        delete m_dvb_scan;
 
@@ -575,10 +575,12 @@ void eDVBServicePMTHandler::free()
                ePtr<eTable<ProgramMapSection> > ptr;
                m_PMT.getCurrent(ptr);
                eDVBCAService::unregister_service(m_reference, demuxes, ptr);
-               eDVBCIInterfaces::getInstance()->removePMTHandler(this);
                m_ca_servicePtr = 0;
        }
 
+       if (m_channel)
+               eDVBCIInterfaces::getInstance()->removePMTHandler(this);
+
        if (m_pvr_channel)
        {
                m_pvr_channel->stopFile();
@@ -854,3 +856,52 @@ void eDVBCAService::sendCAPMT()
                ++m_sendstate;
        }
 }
+
+static PyObject *createTuple(int pid, const char *type)
+{
+       PyObject *r = PyTuple_New(2);
+       PyTuple_SetItem(r, 0, PyInt_FromLong(pid));
+       PyTuple_SetItem(r, 1, PyString_FromString(type));
+       return r;
+}
+
+static inline void PyList_AppendSteal(PyObject *list, PyObject *item)
+{
+       PyList_Append(list, item);
+       Py_DECREF(item);
+}
+
+PyObject *eDVBServicePMTHandler::program::createPythonObject()
+{
+       PyObject *r = PyDict_New();
+
+       PyObject *l = PyList_New(0);
+       
+       PyList_AppendSteal(l, createTuple(0, "pat"));
+
+       if (pmtPid != -1)
+               PyList_AppendSteal(l, createTuple(pmtPid, "pmt"));
+       
+       for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
+                       i(videoStreams.begin()); 
+                       i != videoStreams.end(); ++i)
+               PyList_AppendSteal(l, createTuple(i->pid, "video"));
+
+       for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
+                       i(audioStreams.begin()); 
+                       i != audioStreams.end(); ++i)
+               PyList_AppendSteal(l, createTuple(i->pid, "audio"));
+
+       for (std::vector<eDVBServicePMTHandler::subtitleStream>::const_iterator
+                       i(subtitleStreams.begin());
+                       i != subtitleStreams.end(); ++i)
+               PyList_AppendSteal(l, createTuple(i->pid, "subtitle"));
+
+       PyList_AppendSteal(l, createTuple(pcrPid, "pcr"));
+
+       if (textPid != -1)
+               PyList_AppendSteal(l, createTuple(textPid, "text"));
+               
+       PyDict_SetItemString(r, "pids", l);
+       return r;
+}