use green to add a timer directly from the epgSelection
[enigma2.git] / lib / dvb / scan.cpp
index 0fc3e0a8ed34c04accff85149505ea3f677f4872..2be8a66db0cc23b6ca559d9522b9c663ab052799 100644 (file)
@@ -1,16 +1,17 @@
 #include <lib/dvb/idvb.h>
-#include <lib/dvb_si/sdt.h>
-#include <lib/dvb_si/nit.h>
-#include <lib/dvb_si/bat.h>
-#include <lib/dvb_si/descriptor_tag.h>
-#include <lib/dvb_si/service_descriptor.h>
-#include <lib/dvb_si/satellite_delivery_system_descriptor.h>
-#include <lib/dvb_si/ca_identifier_descriptor.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>
+#include <dvbsi++/ca_identifier_descriptor.h>
 #include <lib/dvb/specs.h>
 #include <lib/dvb/esection.h>
 #include <lib/dvb/scan.h>
 #include <lib/dvb/frontend.h>
 #include <lib/base/eerror.h>
+#include <lib/base/estring.h>
 #include <errno.h>
 
 #define SCAN_eDebug(x...) eDebug(x)
@@ -68,11 +69,12 @@ void eDVBScan::stateChange(iDVBChannel *ch)
        {
                startFilter();
                m_channel_state = state;
-       } else if (state == iDVBChannel::state_unavailable)
+       } else if (state == iDVBChannel::state_failed)
        {
                m_ch_unavailable.push_back(m_ch_current);
                nextChannel();
        }
+                       /* unavailable will timeout, anyway. */
 }
 
 RESULT eDVBScan::nextChannel()
@@ -93,6 +95,8 @@ RESULT eDVBScan::nextChannel()
        }
        
        m_ch_current = m_ch_toScan.front();
+       m_chid_current = eDVBChannelID();
+       
        m_ch_toScan.pop_front();
        
        if (m_channel->getFrontend(fe))
@@ -104,6 +108,7 @@ RESULT eDVBScan::nextChannel()
        m_channel_state = iDVBChannel::state_idle;
        if (fe->tune(*m_ch_current))
        {
+               return nextChannel();
                m_event(evtFail);
                return -EINVAL;
        }
@@ -116,18 +121,18 @@ RESULT eDVBScan::startFilter()
 {
        assert(m_demux);
        
-       m_SDT = new eTable<ServiceDescriptionTable>();
+       m_SDT = new eTable<ServiceDescriptionSection>();
        if (m_SDT->start(m_demux, eDVBSDTSpec()))
                return -1;
        CONNECT(m_SDT->tableReady, eDVBScan::SDTready);
 
        m_NIT = 0;
-       m_NIT = new eTable<NetworkInformationTable>();
+       m_NIT = new eTable<NetworkInformationSection>();
        if (m_NIT->start(m_demux, eDVBNITSpec()))
                return -1;
        CONNECT(m_NIT->tableReady, eDVBScan::NITready);
        
-       m_BAT = new eTable<BouquetAssociationTable>();
+       m_BAT = new eTable<BouquetAssociationSection>();
        if (m_BAT->start(m_demux, eDVBBATSpec()))
                return -1;
        CONNECT(m_BAT->tableReady, eDVBScan::BATready);
@@ -162,12 +167,15 @@ void eDVBScan::BATready(int err)
        channelDone();
 }
 
-void eDVBScan::addChannel(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
+void eDVBScan::addKnownGoodChannel(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
 {
                /* add it to the list of known channels. */
        if (chid)
                m_new_channels.insert(std::pair<eDVBChannelID,ePtr<iDVBFrontendParameters> >(chid, feparm));
-       
+}
+
+void eDVBScan::addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
+{
                /* check if we don't already have that channel ... */
                
                /* ... in the list of channels to scan */
@@ -216,7 +224,7 @@ void eDVBScan::channelDone()
                        hash);
                
                SCAN_eDebug("SDT: ");
-               ServiceDescriptionTableConstIterator i;
+               std::vector<ServiceDescriptionSection*>::const_iterator i;
                for (i = m_SDT->getSections().begin(); i != m_SDT->getSections().end(); ++i)
                        processSDT(dvbnamespace, **i);
                m_ready &= ~validSDT;
@@ -225,10 +233,10 @@ void eDVBScan::channelDone()
        if (m_ready & validNIT)
        {
                SCAN_eDebug("dumping NIT");
-               NetworkInformationTableConstIterator i;
+               std::vector<NetworkInformationSection*>::const_iterator i;
                for (i = m_NIT->getSections().begin(); i != m_NIT->getSections().end(); ++i)
                {
-                       const TransportStreamInfoVector &tsinfovec = *(*i)->getTsInfo();
+                       const TransportStreamInfoList &tsinfovec = *(*i)->getTsInfo();
                        
                        for (TransportStreamInfoConstIterator tsinfo(tsinfovec.begin()); 
                                tsinfo != tsinfovec.end(); ++tsinfo)
@@ -270,7 +278,7 @@ void eDVBScan::channelDone()
                                                
                                                eDVBNamespace ns = buildNamespace(onid, tsid, hash);
 
-                                               addChannel(
+                                               addChannelToScan(
                                                                eDVBChannelID(ns, tsid, onid),
                                                                feparm);
                                                break;
@@ -289,6 +297,33 @@ void eDVBScan::channelDone()
        if ((m_ready  & readyAll) != readyAll)
                return;
        SCAN_eDebug("channel done!");
+       
+               /* if we had services on this channel, we declare
+                  this channels as "known good". add it.
+                  
+                  (TODO: not yet implemented)
+                  a NIT entry could have possible overridden
+                  our frontend data with more exact data.
+                  
+                  (TODO: not yet implemented)
+                  the tuning process could have lead to more
+                  exact data than the user entered.
+                  
+                  The channel id was probably corrected
+                  by the data written in the SDT. this is
+                  important, as "initial transponder lists"
+                  usually don't have valid CHIDs (and that's
+                  good).
+                  
+                  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);
        nextChannel();
 }
@@ -320,12 +355,16 @@ void eDVBScan::insertInto(iDVBChannelList *db)
        }
 }
 
-RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescriptionTable &sdt)
+RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescriptionSection &sdt)
 {
-       const ServiceDescriptionVector &services = *sdt.getDescriptions();
+       const ServiceDescriptionList &services = *sdt.getDescriptions();
        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;
+       
        for (ServiceDescriptionConstIterator s(services.begin()); s != services.end(); ++s)
        {
                SCAN_eDebugNoNewLine("SID %04x: ", (*s)->getServiceId());
@@ -349,17 +388,17 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription
                        case SERVICE_DESCRIPTOR:
                        {
                                ServiceDescriptor &d = (ServiceDescriptor&)**desc;
-                               SCAN_eDebug("name '%s', provider_name '%s'", d.getServiceName().c_str(), d.getServiceProviderName().c_str());
-                               service->m_service_name = d.getServiceName();
-                               service->m_provider_name = d.getServiceProviderName();
+                               service->m_service_name = convertDVBUTF8(d.getServiceName());
+                               service->m_provider_name = convertDVBUTF8(d.getServiceProviderName());
+                               SCAN_eDebug("name '%s', provider_name '%s'", service->m_service_name.c_str(), service->m_provider_name.c_str());
                                break;
                        }
                        case CA_IDENTIFIER_DESCRIPTOR:
                        {
                                CaIdentifierDescriptor &d = (CaIdentifierDescriptor&)**desc;
-                               const CaSystemIdVector &caids = *d.getCaSystemIds();
+                               const CaSystemIdList &caids = *d.getCaSystemIds();
                                SCAN_eDebugNoNewLine("CA ");
-                               for (CaSystemIdVector::const_iterator i(caids.begin()); i != caids.end(); ++i)
+                               for (CaSystemIdList::const_iterator i(caids.begin()); i != caids.end(); ++i)
                                {
                                        SCAN_eDebugNoNewLine("%04x ", *i);
                                        service->m_ca.insert(*i);