make compiler happy
[enigma2.git] / lib / dvb / scan.cpp
index 89c4735ad1cd914de8158aa417551767ce71cdd5..f9114c2beb02a445ae0ec8ab9d47199d03357f0e 100644 (file)
@@ -1,7 +1,4 @@
 #include <lib/dvb/idvb.h>
-#include <dvbsi++/service_description_section.h>
-#include <dvbsi++/network_information_section.h>
-#include <dvbsi++/bouquet_association_section.h>
 #include <dvbsi++/descriptor_tag.h>
 #include <dvbsi++/service_descriptor.h>
 #include <dvbsi++/satellite_delivery_system_descriptor.h>
@@ -22,9 +19,10 @@ static bool scan_debug;
 
 DEFINE_REF(eDVBScan);
 
-eDVBScan::eDVBScan(iDVBChannel *channel, bool debug)
+eDVBScan::eDVBScan(iDVBChannel *channel, bool usePAT, bool debug)
        :m_channel(channel), m_channel_state(iDVBChannel::state_idle)
-       ,m_ready(0), m_ready_all(readySDT), m_flags(0)
+       ,m_ready(0), m_ready_all(usePAT ? (readySDT|readyPAT) : readySDT)
+       ,m_flags(0), m_usePAT(usePAT)
 {
        scan_debug=debug;
        if (m_channel->getDemux(m_demux))
@@ -89,7 +87,7 @@ RESULT eDVBScan::nextChannel()
        m_SDT = 0; m_BAT = 0; m_NIT = 0;
 
        m_ready = 0;
-       
+
                /* check what we need */
        m_ready_all = readySDT;
        
@@ -98,7 +96,10 @@ RESULT eDVBScan::nextChannel()
        
        if (m_flags & scanSearchBAT)
                m_ready_all |= readyBAT;
-       
+
+       if (m_usePAT)
+               m_ready_all |= readyPAT;
+
        if (m_ch_toScan.empty())
        {
                SCAN_eDebug("no channels left to scan.");
@@ -144,38 +145,62 @@ RESULT eDVBScan::nextChannel()
 
 RESULT eDVBScan::startFilter()
 {
+       bool startSDT=true;
        assert(m_demux);
-       
+
                        /* only start required filters filter */
-       
-       m_SDT = 0;
 
-       if (m_ready_all & readySDT)
+       if (m_ready_all & readyPAT)
+               startSDT = m_ready & readyPAT;
+
+       m_SDT = 0;
+       if (startSDT && (m_ready_all & readySDT))
        {
                m_SDT = new eTable<ServiceDescriptionSection>();
-               if (m_SDT->start(m_demux, eDVBSDTSpec()))
+               if (m_ready & readyPAT && m_ready & validPAT)
+               {
+                       std::vector<ProgramAssociationSection*>::const_iterator i =
+                               m_PAT->getSections().begin();
+                       assert(i != m_PAT->getSections().end());
+                       int tsid = (*i)->getTableIdExtension(); // in PAT this is the transport stream id
+                       if (m_SDT->start(m_demux, eDVBSDTSpec(tsid, true)))
+                               return -1;
+               }
+               else if (m_SDT->start(m_demux, eDVBSDTSpec()))
                        return -1;
                CONNECT(m_SDT->tableReady, eDVBScan::SDTready);
        }
 
-       m_NIT = 0;
-       if (m_ready_all & readyNIT)
+       if (!(m_ready & readyPAT))
        {
-               m_NIT = new eTable<NetworkInformationSection>();
-               if (m_NIT->start(m_demux, eDVBNITSpec()))
-                       return -1;
-               CONNECT(m_NIT->tableReady, eDVBScan::NITready);
-       }
+               m_PAT = 0;
+               if (m_ready_all & readyPAT)
+               {
+                       m_PAT = new eTable<ProgramAssociationSection>();
+                       if (m_PAT->start(m_demux, eDVBPATSpec()))
+                               return -1;
+                       CONNECT(m_PAT->tableReady, eDVBScan::PATready);
+               }
 
-       m_BAT = 0;
-       if (m_ready_all & readyBAT)
-       {
-               m_BAT = new eTable<BouquetAssociationSection>();
-               if (m_BAT->start(m_demux, eDVBBATSpec()))
-                       return -1;
-               CONNECT(m_BAT->tableReady, eDVBScan::BATready);
+               m_NIT = 0;
+               if (m_ready_all & readyNIT)
+               {
+                       m_NIT = new eTable<NetworkInformationSection>();
+                       if (m_NIT->start(m_demux, eDVBNITSpec()))
+                               return -1;
+                       CONNECT(m_NIT->tableReady, eDVBScan::NITready);
+               }
+
+               m_BAT = 0;
+               if (m_ready_all & readyBAT)
+               {
+                       m_BAT = new eTable<BouquetAssociationSection>();
+                       if (m_BAT->start(m_demux, eDVBBATSpec()))
+                               return -1;
+                       CONNECT(m_BAT->tableReady, eDVBScan::BATready);
+               }
        }
-       
+
        return 0;
 }
 
@@ -206,6 +231,15 @@ void eDVBScan::BATready(int err)
        channelDone();
 }
 
+void eDVBScan::PATready(int err)
+{
+       SCAN_eDebug("got pat");
+       m_ready |= readyPAT;
+       if (!err)
+               m_ready |= validPAT;
+       startFilter(); // for starting the SDT filter
+}
+
 void eDVBScan::addKnownGoodChannel(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
 {
                /* add it to the list of known channels. */
@@ -216,20 +250,23 @@ void eDVBScan::addKnownGoodChannel(const eDVBChannelID &chid, iDVBFrontendParame
 void eDVBScan::addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
 {
                /* check if we don't already have that channel ... */
-               
+
                /* ... in the list of channels to scan */
-       for (std::list<ePtr<iDVBFrontendParameters> >::const_iterator i(m_ch_toScan.begin()); i != m_ch_toScan.end(); ++i)
+       for (std::list<ePtr<iDVBFrontendParameters> >::iterator i(m_ch_toScan.begin()); i != m_ch_toScan.end(); ++i)
                if (sameChannel(*i, feparm))
+               {
+                       *i = feparm;  // update
                        return;
+               }
 
                /* ... in the list of successfully scanned channels */
        for (std::list<ePtr<iDVBFrontendParameters> >::const_iterator i(m_ch_scanned.begin()); i != m_ch_scanned.end(); ++i)
                if (sameChannel(*i, feparm))
                        return;
-               
+
                /* ... in the list of unavailable channels */
        for (std::list<ePtr<iDVBFrontendParameters> >::const_iterator i(m_ch_unavailable.begin()); i != m_ch_unavailable.end(); ++i)
-               if (sameChannel(*i, feparm))
+               if (sameChannel(*i, feparm, true))
                        return;
 
                /* ... on the current channel */
@@ -240,10 +277,10 @@ void eDVBScan::addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameter
        m_ch_toScan.push_front(feparm); // better.. then the rotor not turning wild from east to west :)
 }
 
-int eDVBScan::sameChannel(iDVBFrontendParameters *ch1, iDVBFrontendParameters *ch2) const
+int eDVBScan::sameChannel(iDVBFrontendParameters *ch1, iDVBFrontendParameters *ch2, bool exact) const
 {
        int diff;
-       if (ch1->calculateDifference(ch2, diff))
+       if (ch1->calculateDifference(ch2, diff, exact))
                return 0;
        if (diff < 4000) // more than 4mhz difference?
                return 1;
@@ -548,10 +585,9 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription
        SCAN_eDebug("ONID: %04x", sdt.getOriginalNetworkId());
        eDVBChannelID chid(dvbnamespace, sdt.getTransportStreamId(), sdt.getOriginalNetworkId());
        
-               /* save correct CHID for this channel if this is an ACTUAL_SDT */
-       if (sdt.getTableId() == TID_SDT_ACTUAL)
-               m_chid_current = chid;
-       
+       /* save correct CHID for this channel */
+       m_chid_current = chid;
+
        for (ServiceDescriptionConstIterator s(services.begin()); s != services.end(); ++s)
        {
                SCAN_eDebugNoNewLine("SID %04x: ", (*s)->getServiceId());