vdr  2.4.0
eitscan.c
Go to the documentation of this file.
1 /*
2  * eitscan.c: EIT scanner
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: eitscan.c 4.2 2015/09/10 11:05:03 kls Exp $
8  */
9 
10 #include "eitscan.h"
11 #include <stdlib.h>
12 #include "channels.h"
13 #include "dvbdevice.h"
14 #include "skins.h"
15 #include "transfer.h"
16 
17 // --- cScanData -------------------------------------------------------------
18 
19 class cScanData : public cListObject {
20 private:
22 public:
23  cScanData(const cChannel *Channel);
24  virtual int Compare(const cListObject &ListObject) const;
25  int Source(void) const { return channel.Source(); }
26  int Transponder(void) const { return channel.Transponder(); }
27  const cChannel *GetChannel(void) const { return &channel; }
28  };
29 
31 {
32  channel = *Channel;
33 }
34 
35 int cScanData::Compare(const cListObject &ListObject) const
36 {
37  const cScanData *sd = (const cScanData *)&ListObject;
38  int r = Source() - sd->Source();
39  if (r == 0)
40  r = Transponder() - sd->Transponder();
41  return r;
42 }
43 
44 // --- cScanList -------------------------------------------------------------
45 
46 class cScanList : public cList<cScanData> {
47 public:
48  void AddTransponders(const cList<cChannel> *Channels);
49  void AddTransponder(const cChannel *Channel);
50  };
51 
53 {
54  for (const cChannel *ch = Channels->First(); ch; ch = Channels->Next(ch))
55  AddTransponder(ch);
56  Sort();
57 }
58 
59 void cScanList::AddTransponder(const cChannel *Channel)
60 {
61  if (Channel->Source() && Channel->Transponder()) {
62  for (cScanData *sd = First(); sd; sd = Next(sd)) {
63  if (sd->Source() == Channel->Source() && ISTRANSPONDER(sd->Transponder(), Channel->Transponder()))
64  return;
65  }
66  Add(new cScanData(Channel));
67  }
68 }
69 
70 // --- cTransponderList ------------------------------------------------------
71 
72 class cTransponderList : public cList<cChannel> {
73 public:
74  void AddTransponder(cChannel *Channel);
75  };
76 
78 {
79  for (cChannel *ch = First(); ch; ch = Next(ch)) {
80  if (ch->Source() == Channel->Source() && ch->Transponder() == Channel->Transponder()) {
81  delete Channel;
82  return;
83  }
84  }
85  Add(Channel);
86 }
87 
88 // --- cEITScanner -----------------------------------------------------------
89 
91 
93 {
94  lastScan = lastActivity = time(NULL);
95  currentChannel = 0;
96  scanList = NULL;
97  transponderList = NULL;
98 }
99 
101 {
102  delete scanList;
103  delete transponderList;
104 }
105 
107 {
108  if (!transponderList)
111 }
112 
114 {
115  lastActivity = 0;
116 }
117 
119 {
120  if (currentChannel) {
122  Channels->SwitchTo(currentChannel);
123  currentChannel = 0;
124  }
125  lastActivity = time(NULL);
126 }
127 
129 {
130  if (Setup.EPGScanTimeout || !lastActivity) { // !lastActivity means a scan was forced
131  time_t now = time(NULL);
132  if (now - lastScan > ScanTimeout && now - lastActivity > ActivityTimeout) {
133  cStateKey StateKey;
134  if (const cChannels *Channels = cChannels::GetChannelsRead(StateKey, 10)) {
135  if (!scanList) {
136  scanList = new cScanList;
137  if (transponderList) {
139  delete transponderList;
140  transponderList = NULL;
141  }
142  scanList->AddTransponders(Channels);
143  }
144  bool AnyDeviceSwitched = false;
145  for (int i = 0; i < cDevice::NumDevices(); i++) {
146  cDevice *Device = cDevice::GetDevice(i);
147  if (Device && Device->ProvidesEIT()) {
148  for (cScanData *ScanData = scanList->First(); ScanData; ScanData = scanList->Next(ScanData)) {
149  const cChannel *Channel = ScanData->GetChannel();
150  if (Channel) {
151  if (!Channel->Ca() || Channel->Ca() == Device->DeviceNumber() + 1 || Channel->Ca() >= CA_ENCRYPTED_MIN) {
152  if (Device->ProvidesTransponder(Channel)) {
153  if (Device->Priority() < 0) {
154  if (const cPositioner *Positioner = Device->Positioner()) {
155  if (Positioner->LastLongitude() != cSource::Position(Channel->Source()))
156  continue;
157  }
158  bool MaySwitchTransponder = Device->MaySwitchTransponder(Channel);
159  if (MaySwitchTransponder || Device->ProvidesTransponderExclusively(Channel) && now - lastActivity > Setup.EPGScanTimeout * 3600) {
160  if (!MaySwitchTransponder) {
161  if (Device == cDevice::ActualDevice() && !currentChannel) {
162  cDevice::PrimaryDevice()->StopReplay(); // stop transfer mode
163  currentChannel = Device->CurrentChannel();
164  Skins.Message(mtInfo, tr("Starting EPG scan"));
165  }
166  }
167  //dsyslog("EIT scan: device %d source %-8s tp %5d", Device->DeviceNumber() + 1, *cSource::ToString(Channel->Source()), Channel->Transponder());
168  Device->SwitchChannel(Channel, false);
169  scanList->Del(ScanData);
170  AnyDeviceSwitched = true;
171  break;
172  }
173  }
174  }
175  }
176  }
177  }
178  }
179  }
180  if (!scanList->Count() || !AnyDeviceSwitched) {
181  delete scanList;
182  scanList = NULL;
183  if (lastActivity == 0) // this was a triggered scan
184  Activity();
185  }
186  StateKey.Remove();
187  }
188  lastScan = time(NULL);
189  }
190  }
191 }
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
Definition: channels.c:849
virtual bool MaySwitchTransponder(const cChannel *Channel) const
Returns true if it is ok to switch to the Channel's transponder on this device, without disturbing an...
Definition: device.c:780
#define CA_ENCRYPTED_MIN
Definition: channels.h:44
cEITScanner EITScanner
Definition: eitscan.c:90
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:2152
int currentChannel
Definition: eitscan.h:27
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
Definition: eitscan.c:35
int Source(void) const
Definition: channels.h:150
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
Definition: thread.c:859
~cEITScanner()
Definition: eitscan.c:100
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
Definition: device.c:223
Definition: tools.h:594
static int NumDevices(void)
Returns the total number of devices.
Definition: device.h:127
void ForceScan(void)
Definition: eitscan.c:113
int Ca(int Index=0) const
Definition: channels.h:171
virtual bool ProvidesEIT(void) const
Returns true if this device provides EIT data and thus wants to be tuned to the channels it can recei...
Definition: device.c:740
cScanData(const cChannel *Channel)
Definition: eitscan.c:30
A steerable satellite dish generally points to the south on the northern hemisphere,...
Definition: positioner.h:31
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
Definition: channels.c:146
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition: device.h:350
void AddTransponder(const cChannel *Channel)
Definition: eitscan.c:59
void Activity(void)
Definition: eitscan.c:118
#define ISTRANSPONDER(f1, f2)
Definition: channels.h:18
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
Definition: device.c:785
#define LOCK_CHANNELS_READ
Definition: channels.h:265
void AddTransponders(const cList< cChannel > *Channels)
Definition: eitscan.c:52
int Transponder(void) const
Definition: eitscan.c:26
void Process(void)
Definition: eitscan.c:128
void Sort(void)
Definition: tools.c:2276
cScanList * scanList
Definition: eitscan.h:28
Definition: skins.h:37
int EPGScanTimeout
Definition: config.h:292
cSetup Setup
Definition: config.c:372
virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const
Returns true if this is the only device that is able to provide the given channel's transponder.
Definition: device.c:726
int Source(void) const
Definition: eitscan.c:25
cChannel channel
Definition: eitscan.c:21
eKeys Message(eMessageType Type, const char *s, int Seconds=0)
Displays the given message, either through a currently visible display object that is capable of doin...
Definition: skins.c:250
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition: tools.h:606
cEITScanner(void)
Definition: eitscan.c:92
void Del(cListObject *Object, bool DeleteObject=true)
Definition: tools.c:2184
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
Definition: device.c:160
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition: device.h:146
virtual const cPositioner * Positioner(void) const
Returns a pointer to the positioner (if any) this device has used to move the satellite dish to the r...
Definition: device.c:750
void StopReplay(void)
Stops the current replay session (if any).
Definition: device.c:1357
#define tr(s)
Definition: i18n.h:85
static cDevice * ActualDevice(void)
Returns the actual receiving device in case of Transfer Mode, or the primary device otherwise.
Definition: device.c:215
int Position(void)
Returns the orbital position of the satellite in case this is a DVB-S source (zero otherwise).
Definition: sources.h:35
void AddTransponder(cChannel *Channel)
Definition: eitscan.c:106
cTransponderList * transponderList
Definition: eitscan.h:29
void AddTransponder(cChannel *Channel)
Definition: eitscan.c:77
int Count(void) const
Definition: tools.h:590
time_t lastScan
Definition: eitscan.h:26
time_t lastActivity
Definition: eitscan.h:26
virtual bool ProvidesTransponder(const cChannel *Channel) const
Returns true if this device can provide the transponder of the given Channel (which implies that it c...
Definition: device.c:721
int Priority(void) const
Returns the priority of the current receiving session (-MAXPRIORITY..MAXPRIORITY),...
Definition: device.c:1632
const cChannel * GetChannel(void) const
Definition: eitscan.c:27
cSkins Skins
Definition: skins.c:219
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition: tools.h:613