bouquets and lamedb now stored in /etc/enigma2 (CONFIGDIR/enigma2)
[enigma2.git] / lib / dvb / pmt.cpp
index 5a1b7c5c4fc7a14f590e930cc004a7ae1584632c..6b2c835c51e427643fef831a03c110d2daebe19c 100644 (file)
@@ -7,7 +7,7 @@
 #include <dvbsi++/ca_program_map_section.h>
 #include <dvbsi++/descriptor_tag.h>
 #include <dvbsi++/iso639_language_descriptor.h>
-#include <dvbsi++/component_descriptor.h>
+#include <dvbsi++/stream_identifier_descriptor.h>
 
 eDVBServicePMTHandler::eDVBServicePMTHandler(int record)
        :m_ca_servicePtr(0)
@@ -52,8 +52,6 @@ void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
                {
                        eDebug("ok ... now we start!!");
 
-                       /* emit */ m_resourceManager->m_channelRunning(channel);
-
                        m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
 
                        if ( m_service && !m_service->cacheEmpty() )
@@ -127,6 +125,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
        program.videoStreams.clear();
        program.audioStreams.clear();
        program.pcrPid = -1;
+       program.isCrypted = false;
 
        if (!m_PMT.getCurrent(ptr))
        {
@@ -142,24 +141,29 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                        ElementaryStreamInfoConstIterator es;
                        for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
                        {
-                               int isaudio = 0, isvideo = 0;
+                               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())
                                {
                                case 0x01: // MPEG 1 video
                                case 0x02: // MPEG 2 video
                                        isvideo = 1;
-                                       break;
+                                       //break; fall through !!!
                                case 0x03: // MPEG 1 audio
                                case 0x04: // MPEG 2 audio:
-                                       isaudio = 1;
-                                       audio.type = audioStream::atMPEG;
-                                       break;
+                                       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. */
@@ -169,40 +173,55 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                switch ((*desc)->getTag())
                                                {
                                                case AC3_DESCRIPTOR:
-                                                       isaudio = 1;
-                                                       audio.type = audioStream::atAC3;
+                                                       if (!isvideo)
+                                                       {
+                                                               isaudio = 1;
+                                                               audio.type = audioStream::atAC3;
+                                                       }
+                                                       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:
+                                                       ++cadescriptors;
                                                        break;
                                                }
                                        }
                                        break;
                                }
                                if (isaudio)
+                                       program.audioStreams.push_back(audio);
+                               else if (isvideo)
+                                       program.videoStreams.push_back(video);
+                               else
+                                       continue;
+                               if ( cadescriptors > 0 )
+                                       program.isCrypted=true;
+                       }
+                       if ( !program.isCrypted )
+                       {
+                               for (DescriptorConstIterator desc = pmt.getDescriptors()->begin();
+                                       desc != pmt.getDescriptors()->end(); ++desc)
                                {
-                                       for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
-                                                       desc != (*es)->getDescriptors()->end(); ++desc)
+                                       switch ((*desc)->getTag())
                                        {
-                                               switch ((*desc)->getTag())
-                                               {
-                                               case ISO_639_LANGUAGE_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();
-
-                                                       break;
-                                               }
-                                               case COMPONENT_DESCRIPTOR:
-                                                       audio.component_tag = ((ComponentDescriptor*)*desc)->getComponentTag();
-                                                       break;
-                                               }
+                                       case CA_DESCRIPTOR:
+                                               program.isCrypted=true;
+                                               break;
                                        }
-
-                                       program.audioStreams.push_back(audio);
                                }
-                               if (isvideo)
-                                       program.videoStreams.push_back(video);
+                               break;
                        }
                }
                return 0;
@@ -210,8 +229,8 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
        else if ( m_service && !m_service->cacheEmpty() )
        {
                int vpid = m_service->getCachePID(eDVBService::cVPID),
-                       apid_ac3 = m_service->getCachePID(eDVBService::cAPID),
-                       apid_mpeg = m_service->getCachePID(eDVBService::cAC3PID),
+                       apid_ac3 = m_service->getCachePID(eDVBService::cAC3PID),
+                       apid_mpeg = m_service->getCachePID(eDVBService::cAPID),
                        pcrpid = m_service->getCachePID(eDVBService::cPCRPID),
                        cnt=0;
                if ( vpid != -1 )
@@ -352,7 +371,7 @@ RESULT eDVBCAService::register_service( const eServiceReferenceDVB &ref, int dem
        {
                caservice = (exist[ref]=new eDVBCAService());
                caservice->m_service = ref;
-               eDebug("[eDVBCAHandler] new service %s", ref.toString().c_str() );
+               eDebug("[eDVBCAService] new service %s", ref.toString().c_str() );
        }
 // search free demux entry
        int iter=0, max_demux_slots = sizeof(caservice->m_used_demux);
@@ -363,11 +382,11 @@ RESULT eDVBCAService::register_service( const eServiceReferenceDVB &ref, int dem
        if ( iter < max_demux_slots )
        {
                caservice->m_used_demux[iter] = demux_num & 0xFF;
-               eDebug("[eDVBCAHandler] add demux %d to slot %d service %s", demux_num, iter, ref.toString().c_str());
+               eDebug("[eDVBCAService] add demux %d to slot %d service %s", demux_num, iter, ref.toString().c_str());
        }
        else
        {
-               eDebug("[eDVBCAHandler] no more demux slots free for service %s!!", ref.toString().c_str());
+               eDebug("[eDVBCAService] no more demux slots free for service %s!!", ref.toString().c_str());
                return -1;
        }
        return 0;
@@ -378,7 +397,7 @@ RESULT eDVBCAService::unregister_service( const eServiceReferenceDVB &ref, int d
        CAServiceMap::iterator it = exist.find(ref);
        if ( it == exist.end() )
        {
-               eDebug("[eDVBCAHandler] try to unregister non registered %s", ref.toString().c_str());
+               eDebug("[eDVBCAService] try to unregister non registered %s", ref.toString().c_str());
                return -1;
        }
        else
@@ -418,7 +437,7 @@ RESULT eDVBCAService::unregister_service( const eServiceReferenceDVB &ref, int d
                        if (ptr)
                                it->second->buildCAPMT(ptr);
                        else
-                               eDebug("[eDVBCAHandler] can not send updated demux info");
+                               eDebug("[eDVBCAService] can not send updated demux info");
                }
        }
        return 0;
@@ -561,7 +580,7 @@ void eDVBCAService::sendCAPMT()
        if ( write(m_sock, m_capmt, wp) == wp )
        {
                m_sendstate=0xFFFFFFFF;
-               eDebug("[eDVBCAHandler] send %d bytes",wp);
+               eDebug("[eDVBCAService] send %d bytes",wp);
 #if 1
                for(int i=0;i<wp;i++)
                        eDebugNoNewLine("%02x ", m_capmt[i]);
@@ -575,11 +594,11 @@ void eDVBCAService::sendCAPMT()
                        case 0xFFFFFFFF:
                                ++m_sendstate;
                                m_retryTimer.start(0,true);
-//                             eDebug("[eDVBCAHandler] send failed .. immediate retry");
+//                             eDebug("[eDVBCAService] send failed .. immediate retry");
                                break;
                        default:
                                m_retryTimer.start(5000,true);
-//                             eDebug("[eDVBCAHandler] send failed .. retry in 5 sec");
+//                             eDebug("[eDVBCAService] send failed .. retry in 5 sec");
                                break;
                }
                ++m_sendstate;