2002-05-20 11:18:09 +02:00
|
|
|
/*
|
|
|
|
* eitscan.c: EIT scanner
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2011-08-12 14:37:25 +02:00
|
|
|
* $Id: eitscan.c 2.2 2011/08/12 14:18:04 kls Exp $
|
2002-05-20 11:18:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "eitscan.h"
|
2002-08-04 14:57:29 +02:00
|
|
|
#include <stdlib.h>
|
2002-10-06 10:25:42 +02:00
|
|
|
#include "channels.h"
|
2002-09-04 17:26:02 +02:00
|
|
|
#include "dvbdevice.h"
|
2004-05-16 10:35:36 +02:00
|
|
|
#include "skins.h"
|
2005-06-12 14:09:45 +02:00
|
|
|
#include "transfer.h"
|
2002-05-20 11:18:09 +02:00
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
// --- cScanData -------------------------------------------------------------
|
|
|
|
|
|
|
|
class cScanData : public cListObject {
|
|
|
|
private:
|
2004-01-17 13:13:47 +01:00
|
|
|
cChannel channel;
|
2004-01-04 12:30:00 +01:00
|
|
|
public:
|
2004-01-17 13:13:47 +01:00
|
|
|
cScanData(const cChannel *Channel);
|
2004-11-01 10:40:38 +01:00
|
|
|
virtual int Compare(const cListObject &ListObject) const;
|
|
|
|
int Source(void) const { return channel.Source(); }
|
|
|
|
int Transponder(void) const { return channel.Transponder(); }
|
|
|
|
const cChannel *GetChannel(void) const { return &channel; }
|
2004-01-04 12:30:00 +01:00
|
|
|
};
|
|
|
|
|
2004-01-17 13:13:47 +01:00
|
|
|
cScanData::cScanData(const cChannel *Channel)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2004-01-17 13:13:47 +01:00
|
|
|
channel = *Channel;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2004-11-01 10:40:38 +01:00
|
|
|
int cScanData::Compare(const cListObject &ListObject) const
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2004-11-01 10:40:38 +01:00
|
|
|
const cScanData *sd = (const cScanData *)&ListObject;
|
|
|
|
int r = Source() - sd->Source();
|
|
|
|
if (r == 0)
|
|
|
|
r = Transponder() - sd->Transponder();
|
|
|
|
return r;
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cScanList -------------------------------------------------------------
|
|
|
|
|
|
|
|
class cScanList : public cList<cScanData> {
|
|
|
|
public:
|
2004-01-17 13:13:47 +01:00
|
|
|
void AddTransponders(cList<cChannel> *Channels);
|
2004-01-04 12:30:00 +01:00
|
|
|
void AddTransponder(const cChannel *Channel);
|
|
|
|
};
|
|
|
|
|
2004-01-17 13:13:47 +01:00
|
|
|
void cScanList::AddTransponders(cList<cChannel> *Channels)
|
2004-01-04 12:30:00 +01:00
|
|
|
{
|
2004-01-11 15:54:37 +01:00
|
|
|
for (cChannel *ch = Channels->First(); ch; ch = Channels->Next(ch))
|
2004-01-04 12:30:00 +01:00
|
|
|
AddTransponder(ch);
|
|
|
|
Sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cScanList::AddTransponder(const cChannel *Channel)
|
|
|
|
{
|
2004-01-17 13:13:47 +01:00
|
|
|
if (Channel->Source() && Channel->Transponder()) {
|
|
|
|
for (cScanData *sd = First(); sd; sd = Next(sd)) {
|
|
|
|
if (sd->Source() == Channel->Source() && ISTRANSPONDER(sd->Transponder(), Channel->Transponder()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Add(new cScanData(Channel));
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:54:37 +01:00
|
|
|
// --- cTransponderList ------------------------------------------------------
|
|
|
|
|
|
|
|
class cTransponderList : public cList<cChannel> {
|
|
|
|
public:
|
|
|
|
void AddTransponder(cChannel *Channel);
|
|
|
|
};
|
|
|
|
|
|
|
|
void cTransponderList::AddTransponder(cChannel *Channel)
|
|
|
|
{
|
|
|
|
for (cChannel *ch = First(); ch; ch = Next(ch)) {
|
|
|
|
if (ch->Source() == Channel->Source() && ch->Transponder() == Channel->Transponder()) {
|
|
|
|
delete Channel;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Add(Channel);
|
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
// --- cEITScanner -----------------------------------------------------------
|
|
|
|
|
2003-05-24 13:38:28 +02:00
|
|
|
cEITScanner EITScanner;
|
|
|
|
|
2002-05-20 11:18:09 +02:00
|
|
|
cEITScanner::cEITScanner(void)
|
|
|
|
{
|
|
|
|
lastScan = lastActivity = time(NULL);
|
2003-09-06 13:22:24 +02:00
|
|
|
currentDevice = NULL;
|
2002-05-20 11:18:09 +02:00
|
|
|
currentChannel = 0;
|
2004-01-04 12:30:00 +01:00
|
|
|
scanList = NULL;
|
2004-01-11 15:54:37 +01:00
|
|
|
transponderList = NULL;
|
2002-05-20 11:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cEITScanner::~cEITScanner()
|
|
|
|
{
|
2004-01-04 12:30:00 +01:00
|
|
|
delete scanList;
|
2004-01-11 15:54:37 +01:00
|
|
|
delete transponderList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEITScanner::AddTransponder(cChannel *Channel)
|
|
|
|
{
|
|
|
|
if (!transponderList)
|
|
|
|
transponderList = new cTransponderList;
|
|
|
|
transponderList->AddTransponder(Channel);
|
2002-05-20 11:18:09 +02:00
|
|
|
}
|
|
|
|
|
2004-01-17 15:38:11 +01:00
|
|
|
void cEITScanner::ForceScan(void)
|
|
|
|
{
|
|
|
|
lastActivity = 0;
|
|
|
|
}
|
|
|
|
|
2002-05-20 11:18:09 +02:00
|
|
|
void cEITScanner::Activity(void)
|
|
|
|
{
|
|
|
|
if (currentChannel) {
|
|
|
|
Channels.SwitchTo(currentChannel);
|
|
|
|
currentChannel = 0;
|
|
|
|
}
|
|
|
|
lastActivity = time(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEITScanner::Process(void)
|
|
|
|
{
|
2010-02-07 12:14:02 +01:00
|
|
|
if (Setup.EPGScanTimeout || !lastActivity) { // !lastActivity means a scan was forced
|
2002-05-20 11:18:09 +02:00
|
|
|
time_t now = time(NULL);
|
|
|
|
if (now - lastScan > ScanTimeout && now - lastActivity > ActivityTimeout) {
|
2004-01-04 12:30:00 +01:00
|
|
|
if (Channels.Lock(false, 10)) {
|
2004-01-17 13:13:47 +01:00
|
|
|
if (!scanList) {
|
|
|
|
scanList = new cScanList;
|
|
|
|
if (transponderList) {
|
|
|
|
scanList->AddTransponders(transponderList);
|
|
|
|
delete transponderList;
|
|
|
|
transponderList = NULL;
|
|
|
|
}
|
2011-08-12 14:37:25 +02:00
|
|
|
scanList->AddTransponders(&Channels);
|
2004-01-17 13:13:47 +01:00
|
|
|
}
|
2005-06-12 14:09:45 +02:00
|
|
|
bool AnyDeviceSwitched = false;
|
|
|
|
for (int i = 0; i < cDevice::NumDevices(); i++) {
|
|
|
|
cDevice *Device = cDevice::GetDevice(i);
|
|
|
|
if (Device) {
|
|
|
|
for (cScanData *ScanData = scanList->First(); ScanData; ScanData = scanList->Next(ScanData)) {
|
|
|
|
const cChannel *Channel = ScanData->GetChannel();
|
|
|
|
if (Channel) {
|
2006-01-07 14:10:17 +01:00
|
|
|
if (!Channel->Ca() || Channel->Ca() == Device->DeviceNumber() + 1 || Channel->Ca() >= CA_ENCRYPTED_MIN) {
|
2005-06-12 14:09:45 +02:00
|
|
|
if (Device->ProvidesTransponder(Channel)) {
|
|
|
|
if (!Device->Receiving()) {
|
2005-11-05 15:48:05 +01:00
|
|
|
bool MaySwitchTransponder = Device->MaySwitchTransponder();
|
|
|
|
if (MaySwitchTransponder || Device->ProvidesTransponderExclusively(Channel) && now - lastActivity > Setup.EPGScanTimeout * 3600) {
|
|
|
|
if (!MaySwitchTransponder) {
|
|
|
|
if (Device == cDevice::ActualDevice() && !currentChannel) {
|
2005-06-12 14:09:45 +02:00
|
|
|
cDevice::PrimaryDevice()->StopReplay(); // stop transfer mode
|
2005-11-05 15:48:05 +01:00
|
|
|
currentChannel = Device->CurrentChannel();
|
|
|
|
Skins.Message(mtInfo, tr("Starting EPG scan"));
|
|
|
|
}
|
2004-01-17 15:38:11 +01:00
|
|
|
}
|
2004-01-10 16:52:01 +01:00
|
|
|
currentDevice = Device;//XXX see also dvbdevice.c!!!
|
2005-06-12 14:09:45 +02:00
|
|
|
//dsyslog("EIT scan: device %d source %-8s tp %5d", Device->DeviceNumber() + 1, *cSource::ToString(Channel->Source()), Channel->Transponder());
|
2004-01-10 16:52:01 +01:00
|
|
|
Device->SwitchChannel(Channel, false);
|
|
|
|
currentDevice = NULL;
|
|
|
|
scanList->Del(ScanData);
|
|
|
|
AnyDeviceSwitched = true;
|
2005-06-12 14:09:45 +02:00
|
|
|
break;
|
2004-01-10 16:52:01 +01:00
|
|
|
}
|
2003-05-24 13:38:28 +02:00
|
|
|
}
|
2003-03-16 13:29:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2002-05-20 11:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
2005-06-12 14:09:45 +02:00
|
|
|
if (!scanList->Count() || !AnyDeviceSwitched) {
|
|
|
|
delete scanList;
|
|
|
|
scanList = NULL;
|
|
|
|
if (lastActivity == 0) // this was a triggered scan
|
|
|
|
Activity();
|
|
|
|
}
|
2005-06-05 14:44:27 +02:00
|
|
|
Channels.Unlock();
|
2004-01-04 12:30:00 +01:00
|
|
|
}
|
2004-01-05 09:56:54 +01:00
|
|
|
lastScan = time(NULL);
|
2002-05-20 11:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|