compile fixes for old dvb api (7020....)
[enigma2.git] / lib / dvb / scan.cpp
index 00564cdbb05f61be32594bb969467fbcc9f4a0d1..d53281636e49941fb9b9d998afbf972ea939605f 100644 (file)
@@ -120,16 +120,7 @@ RESULT eDVBScan::nextChannel()
                return -ENOTSUP;
        }
 
-       int fetype;
-       fe->getFrontendType(fetype);
-       if ( fetype == iDVBFrontend::feSatellite)
-       {
-               eDVBFrontendParametersSatellite p;
-               m_ch_current->getDVBS(p);
-               m_chid_current = eDVBChannelID(p.orbital_position << 16, -1, -1);
-       }
-       else
-               m_chid_current = eDVBChannelID();
+       m_chid_current = eDVBChannelID();
 
        m_channel_state = iDVBChannel::state_idle;
        if (fe->tune(*m_ch_current))
@@ -283,14 +274,33 @@ void eDVBScan::addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameter
        }
        }
 
+       int found_count=0;
                /* ... in the list of channels to scan */
-       for (std::list<ePtr<iDVBFrontendParameters> >::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();)
+       {
                if (sameChannel(*i, feparm))
                {
-                       *i = feparm;  // update
-                       eDebug("update");
-                       return;
+                       if (!found_count)
+                       {
+                               *i = feparm;  // update
+                               eDebug("update");
+                       }
+                       else
+                       {
+                               eDebug("remove dupe");
+                               m_ch_toScan.erase(i++);
+                               continue;
+                       }
+                       ++found_count;
                }
+               ++i;
+       }
+
+       if (found_count > 0)
+       {
+               eDebug("already in todo list");
+               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)
@@ -356,11 +366,14 @@ void eDVBScan::channelDone()
        
        if (m_ready & validNIT)
        {
+               int system;
+               std::list<ePtr<iDVBFrontendParameters> > m_ch_toScan_backup;
+               m_ch_current->getSystem(system);
                SCAN_eDebug("dumping NIT");
                if (m_flags & clearToScanOnFirstNIT)
                {
+                       m_ch_toScan_backup = m_ch_toScan;
                        m_ch_toScan.clear();
-                       m_flags &= ~clearToScanOnFirstNIT;
                }
                std::vector<NetworkInformationSection*>::const_iterator i;
                for (i = m_NIT->getSections().begin(); i != m_NIT->getSections().end(); ++i)
@@ -383,6 +396,8 @@ void eDVBScan::channelDone()
                                        {
                                        case CABLE_DELIVERY_SYSTEM_DESCRIPTOR:
                                        {
+                                               if (system != iDVBFrontend::feCable)
+                                                       break; // when current locked transponder is no cable transponder ignore this descriptor
                                                CableDeliverySystemDescriptor &d = (CableDeliverySystemDescriptor&)**desc;
                                                ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
                                                eDVBFrontendParametersCable cable;
@@ -400,6 +415,8 @@ void eDVBScan::channelDone()
                                        }
                                        case TERRESTRIAL_DELIVERY_SYSTEM_DESCRIPTOR:
                                        {
+                                               if (system != iDVBFrontend::feTerrestrial)
+                                                       break; // when current locked transponder is no terrestrial transponder ignore this descriptor
                                                TerrestrialDeliverySystemDescriptor &d = (TerrestrialDeliverySystemDescriptor&)**desc;
                                                ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
                                                eDVBFrontendParametersTerrestrial terr;
@@ -417,6 +434,9 @@ void eDVBScan::channelDone()
                                        }
                                        case SATELLITE_DELIVERY_SYSTEM_DESCRIPTOR:
                                        {
+                                               if (system != iDVBFrontend::feSatellite)
+                                                       break; // when current locked transponder is no satellite transponder ignore this descriptor
+
                                                SatelliteDeliverySystemDescriptor &d = (SatelliteDeliverySystemDescriptor&)**desc;
                                                if (d.getFrequency() < 10000)
                                                        break;
@@ -424,19 +444,29 @@ void eDVBScan::channelDone()
                                                ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
                                                eDVBFrontendParametersSatellite sat;
                                                sat.set(d);
+
+                                               eDVBFrontendParametersSatellite p;
+                                               m_ch_current->getDVBS(p);
+
+                                               if ( abs(p.orbital_position - sat.orbital_position) < 5 )
+                                                       sat.orbital_position = p.orbital_position;
+
+                                               if ( abs(abs(3600 - p.orbital_position) - sat.orbital_position) < 5 )
+                                               {
+                                                       eDebug("found transponder with incorrect west/east flag ... correct this");
+                                                       sat.orbital_position = p.orbital_position;
+                                               }
+
                                                feparm->setDVBS(sat);
-                                               unsigned long hash=0;
-                                               feparm->getHash(hash);
-                                               
-                                               eDVBNamespace ns = buildNamespace(onid, tsid, hash);
-                                               
-                                               if ( m_chid_current.dvbnamespace.get() != -1 &&
-                                                       ((ns.get() ^ m_chid_current.dvbnamespace.get()) & 0xFFFF0000))
+
+                                               if ( p.orbital_position != sat.orbital_position)
                                                        SCAN_eDebug("dropping this transponder, it's on another satellite.");
                                                else
                                                {
+                                                       unsigned long hash=0;
+                                                       feparm->getHash(hash);
                                                        addChannelToScan(
-                                                                       eDVBChannelID(ns, tsid, onid),
+                                                                       eDVBChannelID(buildNamespace(onid, tsid, hash), tsid, onid),
                                                                        feparm);
                                                }
                                                break;
@@ -446,9 +476,25 @@ void eDVBScan::channelDone()
                                                break;
                                        }
                                }
-                               
                        }
+                       
                }
+
+                       /* a pitfall is to have the clearToScanOnFirstNIT-flag set, and having channels which have
+                          no or invalid NIT. this code will not erase the toScan list unless at least one valid entry
+                          has been found.
+
+                          This is not a perfect solution, as the channel could contain a partial NIT. Life's bad.
+                       */
+               if (m_flags & clearToScanOnFirstNIT)
+               {
+                       if (m_ch_toScan.empty())
+                       {
+                               eWarning("clearToScanOnFirstNIT was set, but NIT is invalid. Refusing to stop scan.");
+                               m_ch_toScan = m_ch_toScan_backup;
+                       } else
+                               m_flags &= ~clearToScanOnFirstNIT;
+               }
                m_ready &= ~validNIT;
        }
        
@@ -476,13 +522,25 @@ void eDVBScan::channelDone()
                   These are the reasons for adding the transponder
                   here, and not before.
                */
-
+       
        if (!m_chid_current)
                eWarning("SCAN: the current channel's ID was not corrected - not adding channel.");
        else
                addKnownGoodChannel(m_chid_current, m_ch_current);
        
        m_ch_scanned.push_back(m_ch_current);
+       
+       for (std::list<ePtr<iDVBFrontendParameters> >::iterator i(m_ch_toScan.begin()); i != m_ch_toScan.end();)
+       {
+               if (sameChannel(*i, m_ch_current))
+               {
+                       eDebug("remove dupe 2");
+                       m_ch_toScan.erase(i++);
+                       continue;
+               }
+               ++i;
+       }
+       
        nextChannel();
 }
 
@@ -501,7 +559,7 @@ void eDVBScan::start(const eSmartPtrList<iDVBFrontendParameters> &known_transpon
                bool exist=false;
                for (std::list<ePtr<iDVBFrontendParameters> >::const_iterator ii(m_ch_toScan.begin()); ii != m_ch_toScan.end(); ++ii)
                {
-                       if (sameChannel(*i, *ii))
+                       if (sameChannel(*i, *ii, true))
                        {
                                exist=true;
                                break;