Skip to content

Commit

Permalink
add dvb-t lcn support
Browse files Browse the repository at this point in the history
  • Loading branch information
atvcaptain committed Jun 10, 2014
1 parent 88a156c commit b13920f
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
103 changes: 102 additions & 1 deletion lib/dvb/scan.cpp
Expand Up @@ -4,6 +4,7 @@
#include <dvbsi++/service_descriptor.h>
#include <dvbsi++/satellite_delivery_system_descriptor.h>
#include <dvbsi++/terrestrial_delivery_system_descriptor.h>
#include <dvbsi++/logical_channel_descriptor.h>
#include <dvbsi++/cable_delivery_system_descriptor.h>
#include <dvbsi++/ca_identifier_descriptor.h>
#include <dvbsi++/registration_descriptor.h>
Expand All @@ -18,6 +19,7 @@
#include <lib/base/estring.h>
#include <lib/dvb/dvb.h>
#include <lib/dvb/db.h>
#include <lib/python/python.h>
#include <errno.h>

#define SCAN_eDebug(x...) do { if (m_scan_debug) eDebug(x); } while(0)
Expand All @@ -39,10 +41,13 @@ eDVBScan::eDVBScan(iDVBChannel *channel, bool usePAT, bool debug)
if (m_channel->getDemux(m_demux))
SCAN_eDebug("scan: failed to allocate demux!");
m_channel->connectStateChange(slot(*this, &eDVBScan::stateChange), m_stateChanged_connection);
m_lcn_file = NULL;
}

eDVBScan::~eDVBScan()
{
if (m_lcn_file)
fclose(m_lcn_file);
}

int eDVBScan::isValidONIDTSID(int orbital_position, eOriginalNetworkID onid, eTransportStreamID tsid)
Expand Down Expand Up @@ -469,6 +474,39 @@ void eDVBScan::addKnownGoodChannel(const eDVBChannelID &chid, iDVBFrontendParame
m_new_channels.insert(std::pair<eDVBChannelID,ePtr<iDVBFrontendParameters> >(chid, feparm));
}

void eDVBScan::addLcnToDB(eDVBNamespace ns, eOriginalNetworkID onid, eTransportStreamID tsid, eServiceID sid, uint16_t lcn, uint32_t signal)
{
if (m_lcn_file)
{
int size = 0;
char row[40];
bool added = false;
sprintf(row, "%08x:%04x:%04x:%04x:%05d:%08d\n", ns.get(), onid.get(), tsid.get(), sid.get(), lcn, signal);
fseek(m_lcn_file, 0, SEEK_END);
size = ftell(m_lcn_file);

for (int i = 0; i < size / 39; i++)
{
char tmp[40];
fseek(m_lcn_file, i*39, SEEK_SET);
fread (tmp, 1, 39, m_lcn_file);
if (memcmp(tmp, row, 23) == 0)
{
fseek(m_lcn_file, i*39, SEEK_SET);
fwrite(row, 1, 39, m_lcn_file);
added = true;
break;
}
}

if (!added)
{
fseek(m_lcn_file, 0, SEEK_END);
fwrite(row, 1, 39, m_lcn_file);
}
}
}

void eDVBScan::addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameters *feparm)
{
/* check if we don't already have that channel ... */
Expand Down Expand Up @@ -615,6 +653,7 @@ void eDVBScan::channelDone()

eOriginalNetworkID onid = (*tsinfo)->getOriginalNetworkId();
eTransportStreamID tsid = (*tsinfo)->getTransportStreamId();
eDVBNamespace ns(0);

for (DescriptorConstIterator desc = (*tsinfo)->getDescriptors()->begin();
desc != (*tsinfo)->getDescriptors()->end(); ++desc)
Expand Down Expand Up @@ -652,13 +691,18 @@ void eDVBScan::channelDone()

unsigned long hash=0;
feparm->getHash(hash);
eDVBNamespace ns = buildNamespace(onid, tsid, hash);
ns = buildNamespace(onid, tsid, hash);

addChannelToScan(
eDVBChannelID(ns, tsid, onid),
feparm);
break;
}
case LOGICAL_CHANNEL_DESCRIPTOR:
{
// we handle it later
break;
}
case SATELLITE_DELIVERY_SYSTEM_DESCRIPTOR:
{
if (system != iDVBFrontend::feSatellite)
Expand Down Expand Up @@ -703,6 +747,43 @@ void eDVBScan::channelDone()
break;
}
}
// we do this after the main loop because we absolutely need the namespace
for (DescriptorConstIterator desc = (*tsinfo)->getDescriptors()->begin();
desc != (*tsinfo)->getDescriptors()->end(); ++desc)
{
switch ((*desc)->getTag())
{
case LOGICAL_CHANNEL_DESCRIPTOR:
{
if (system != iDVBFrontend::feTerrestrial)
break; // when current locked transponder is no terrestrial transponder ignore this descriptor

if (ns.get() == 0)
break; // invalid namespace

int signal = 0;
ePtr<iDVBFrontend> fe;

if (!m_channel->getFrontend(fe))
signal = fe->readFrontendData(iFrontendInformation_ENUMS::signalQuality);

LogicalChannelDescriptor &d = (LogicalChannelDescriptor&)**desc;
for (LogicalChannelListConstIterator it = d.getChannelList()->begin(); it != d.getChannelList()->end(); it++)
{
LogicalChannel *ch = *it;
if (ch->getVisibleServiceFlag())
{
addLcnToDB(ns, onid, tsid, eServiceID(ch->getServiceId()), ch->getLogicalChannelNumber(), signal);
SCAN_eDebug("NAMESPACE: %08x TSID: %04x ONID: %04x SID: %04x LCN: %05d SIGNAL: %08d", ns.get(), onid.get(), tsid.get(), ch->getServiceId(), ch->getLogicalChannelNumber(), signal);
}
}
break;
}
default:
break;
}
}

}

}
Expand Down Expand Up @@ -912,6 +993,26 @@ void eDVBScan::start(const eSmartPtrList<iDVBFrontendParameters> &known_transpon
m_new_services.clear();
m_last_service = m_new_services.end();

if (m_lcn_file)
fclose(m_lcn_file);

if (m_flags & scanRemoveServices)
{
m_lcn_file = fopen(eEnv::resolve("${sysconfdir}/enigma2/lcndb").c_str(), "w");
if (!m_lcn_file)
eDebug("couldn't open file lcndb");
}
else
{
m_lcn_file = fopen(eEnv::resolve("${sysconfdir}/enigma2/lcndb").c_str(), "r+");
if (!m_lcn_file)
{
m_lcn_file = fopen(eEnv::resolve("${sysconfdir}/enigma2/lcndb").c_str(), "w");
if (!m_lcn_file)
eDebug("couldn't open file lcndb");
}
}

for (eSmartPtrList<iDVBFrontendParameters>::const_iterator i(known_transponders.begin()); i != known_transponders.end(); ++i)
{
bool exist=false;
Expand Down
3 changes: 3 additions & 0 deletions lib/dvb/scan.h
Expand Up @@ -93,6 +93,9 @@ class eDVBScan: public Object, public iObject
int m_networkid;
bool m_usePAT;
bool m_scan_debug;

FILE *m_lcn_file;
void addLcnToDB(eDVBNamespace ns, eOriginalNetworkID onid, eTransportStreamID tsid, eServiceID sid, uint16_t lcn, uint32_t signal);
public:
eDVBScan(iDVBChannel *channel, bool usePAT=true, bool debug=true );
~eDVBScan();
Expand Down

0 comments on commit b13920f

Please sign in to comment.