add audioselection, removed democode
[enigma2.git] / lib / dvb / pmt.cpp
index f948e95..e743d26 100644 (file)
@@ -5,9 +5,10 @@
 #include <lib/dvb/metaparser.h>
 #include <dvbsi++/ca_program_map_section.h>
 
-eDVBServicePMTHandler::eDVBServicePMTHandler()
+eDVBServicePMTHandler::eDVBServicePMTHandler(int record)
        :m_pmt_pid(0xFFFF), m_ca_servicePtr(0)
 {
+       m_record = record;
        eDVBResourceManager::getInstance(m_resourceManager);
        CONNECT(m_PMT.tableReady, eDVBServicePMTHandler::PMTready);
        CONNECT(m_PAT.tableReady, eDVBServicePMTHandler::PATready);
@@ -27,8 +28,8 @@ void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
                && (state == iDVBChannel::state_ok) && (!m_demux))
        {
                if (m_channel)
-                       if (m_channel->getDemux(m_demux))
-                               eDebug("shit it failed.. again.");
+                       if (m_channel->getDemux(m_demux, m_record ? 0 : iDVBChannel::capDecode))
+                               eDebug("Allocating a demux for now tuned-in channel failed.");
                
                serviceEvent(eventTuned);
                
@@ -43,6 +44,11 @@ void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
                        if ( m_service && !m_service->cacheEmpty() )
                                serviceEvent(eventNewProgramInfo);
                }
+       } else if ((m_last_channel_state != iDVBChannel::state_failed) && 
+                       (state == iDVBChannel::state_failed))
+       {
+               eDebug("tune failed.");
+               serviceEvent(eventTuneFailed);
        }
 }
 
@@ -89,12 +95,12 @@ void eDVBServicePMTHandler::PATready(int)
 
 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
 {
-       eDebug("got PMT");
        ePtr<eTable<ProgramMapSection> > ptr;
 
        program.videoStreams.clear();
        program.audioStreams.clear();
        program.pcrPid = -1;
+       program.pmtPid = m_pmt_pid < 0x1fff ? m_pmt_pid : -1;
 
        if (!m_PMT.getCurrent(ptr))
        {
@@ -198,14 +204,13 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
        RESULT res;
        m_reference = ref;
        
-//     ref.path = "/viva.ts"; // hrhr.
-       
                /* is this a normal (non PVR) channel? */
        if (ref.path.empty())
        {
                eDVBChannelID chid;
                ref.getChannelID(chid);
                res = m_resourceManager->allocateChannel(chid, m_channel);
+               eDebug("allocate Channel: res %d", res);
        } else
        {
                eDVBMetaParser parser;
@@ -230,6 +235,10 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
                        m_channelStateChanged_connection);
                m_last_channel_state = -1;
                channelStateChanged(m_channel);
+       } else
+       {
+               serviceEvent(eventTuneFailed);
+               return res;
        }
 
        if (m_pvr_channel)
@@ -269,7 +278,7 @@ void eDVBCAService::buildCAPMT()
 
                while( i != ptr->getSections().end() )
                {
-                       eDebug("append");
+//                     eDebug("append");
                        capmt.append(*i++);
                }
 
@@ -284,8 +293,8 @@ void eDVBCAService::buildCAPMT()
 
                tmp[0] = 0x82; // demux
                tmp[1] = 0x02;
-               m_parent.m_demux->getCADemuxID(tmp[2]);  // descramble on demux
-               m_parent.m_demux->getCADemuxID(tmp[3]);  // get section data from demux1
+               m_parent.m_demux->getCADemuxID(tmp[3]); // read section data from demux number
+               tmp[2] = 1 << tmp[3];                   // descramble bitmask
                capmt.injectDescriptor(tmp, false);
 
                tmp[0] = 0x81; // dvbnamespace
@@ -352,11 +361,11 @@ void eDVBCAService::sendCAPMT()
                        case 0xFFFFFFFF:
                                ++m_sendstate;
                                m_retryTimer.start(0,true);
-                               eDebug("[eDVBCAHandler] send failed .. immediate retry");
+//                             eDebug("[eDVBCAHandler] send failed .. immediate retry");
                                break;
                        default:
                                m_retryTimer.start(5000,true);
-                               eDebug("[eDVBCAHandler] send failed .. retry in 5 sec");
+//                             eDebug("[eDVBCAHandler] send failed .. retry in 5 sec");
                                break;
                }
                ++m_sendstate;