From bcfb71b423699d8f7e1d1e7bb5dc24ad4413a4ae Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Wed, 26 Apr 2006 17:18:52 +0000 Subject: [PATCH 1/1] add function to get a list of CAIDs for a running dvb service from python --- lib/dvb/pmt.cpp | 71 ++++++++++++++++++++++++++++++++++++++ lib/dvb/pmt.h | 2 ++ lib/service/iservice.h | 6 ++-- lib/service/service.cpp | 8 +++++ lib/service/servicedvb.cpp | 21 +++++++++-- lib/service/servicedvb.h | 1 + 6 files changed, 105 insertions(+), 4 deletions(-) diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index 5ea47467..5e9c7602 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,76 @@ void eDVBServicePMTHandler::PATready(int) serviceEvent(eventNoPAT); } +PyObject *eDVBServicePMTHandler::getCaIds() +{ + PyObject *ret=0; + + ePtr > ptr; + + if ( ((m_service && m_service->usePMT()) || !m_service) && !m_PMT.getCurrent(ptr)) + { + uint16_t caids[255]; + memset(caids, 0, sizeof(caids)); + std::vector::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: + { + CaDescriptor *cadescr = *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: + { + CaDescriptor *cadescr = *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; + if (cnt) + { + ret=PyList_New(cnt); + while(cnt--) + PyList_SET_ITEM(ret, cnt, PyInt_FromLong(caids[cnt])); + } + } + + if (!ret) + ret=PyList_New(0); + + return ret; +} + int eDVBServicePMTHandler::getProgramInfo(struct program &program) { ePtr > ptr; diff --git a/lib/dvb/pmt.h b/lib/dvb/pmt.h index 79d7917c..5149167c 100644 --- a/lib/dvb/pmt.h +++ b/lib/dvb/pmt.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -120,6 +121,7 @@ public: int getProgramInfo(struct program &program); int getDataDemux(ePtr &demux); int getDecodeDemux(ePtr &demux); + PyObject *getCaIds(); int getPVRChannel(ePtr &pvr_channel); int getService(eServiceReferenceDVB &service) { service = m_reference; return 0; } diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 7ea8c17b..53abbf1a 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -225,7 +225,7 @@ public: virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0; virtual SWIG_VOID(RESULT) getEvent(ePtr &SWIG_OUTPUT, int nownext); - enum { + enum { sIsCrypted, /* is encrypted (no indication if decrypt was possible) */ sAspect, /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */ sIsMultichannel, /* multichannel *available* (probably not selected) */ @@ -260,11 +260,13 @@ public: sComment, sTracknumber, sGenre, + sCAIDs, }; - enum { resNA = -1, resIsString = -2 }; + enum { resNA = -1, resIsString = -2, resIsPyObject = -3 }; virtual int getInfo(int w); virtual std::string getInfoString(int w); + virtual PyObject *getInfoObject(int w); }; TEMPLATE_TYPEDEF(ePtr, iServiceInformationPtr); diff --git a/lib/service/service.cpp b/lib/service/service.cpp index d079965b..11f88b1f 100644 --- a/lib/service/service.cpp +++ b/lib/service/service.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include #include +#include eServiceReference::eServiceReference(const std::string &string) { @@ -190,4 +192,10 @@ std::string iServiceInformation::getInfoString(int w) return ""; } +PyObject* iServiceInformation::getInfoObject(int w) +{ + Py_INCREF(Py_None); + return Py_None; +} + eAutoInitPtr init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter"); diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index a6f4eec7..fb84aa18 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -1017,6 +1017,9 @@ int eDVBServicePlay::getInfo(int w) { eDVBServicePMTHandler::program program; + if (w == sCAIDs) + return resIsPyObject; + if (m_service_handler.getProgramInfo(program)) return -1; @@ -1078,15 +1081,29 @@ int eDVBServicePlay::getInfo(int w) } std::string eDVBServicePlay::getInfoString(int w) -{ +{ switch (w) { case sProvider: if (!m_dvb_service) return ""; return m_dvb_service->m_provider_name; default: - return ""; + break; + } + return iServiceInformation::getInfoString(w); +} + +PyObject *eDVBServicePlay::getInfoObject(int w) +{ + switch (w) + { + case sCAIDs: + if (m_dvb_service) + return m_service_handler.getCaIds(); + default: + break; } + return iServiceInformation::getInfoObject(w); } int eDVBServicePlay::getNumberOfTracks() diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index d79e6202..4b13193e 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -99,6 +99,7 @@ public: RESULT getEvent(ePtr &evt, int nownext); int getInfo(int w); std::string getInfoString(int w); + PyObject *getInfoObject(int w); // iAudioTrackSelection int getNumberOfTracks(); -- 2.30.2