vdr 2.6.7
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 5.3 2024/03/10 11:16:29 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
19class cScanData : public cListObject {
20private:
22public:
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
35int 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
46class cScanList : public cList<cScanData> {
47public:
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))
56 Sort();
57}
58
60{
61 if (Channel->Source() && Channel->Transponder() && (Setup.EPGScanMaxChannel <= 0 || Channel->Number() < Setup.EPGScanMaxChannel)) {
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
72class cTransponderList : public cList<cChannel> {
73public:
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 = 0;
95 lastActivity = time(NULL);
97 scanList = new cScanList;
98 transponderList = NULL;
99}
100
102{
103 delete scanList;
104 delete transponderList;
105}
106
113
115{
116 lastActivity = 0;
117}
118
120{
121 if (currentChannel) {
123 Channels->SwitchTo(currentChannel);
124 currentChannel = 0;
125 }
126 lastActivity = time(NULL);
127}
128
130{
131 if (Setup.EPGScanTimeout || !lastActivity) { // !lastActivity means a scan was forced
132 time_t now = time(NULL);
133 if (now - lastScan > ScanTimeout && now - lastActivity > ActivityTimeout) {
135 return; // pause for Setup.EPGScanTimeout hours
136 cStateKey StateKey;
137 if (const cChannels *Channels = cChannels::GetChannelsRead(StateKey, 10)) {
138 if (scanList->Count() == 0) {
139 if (transponderList) {
141 delete transponderList;
142 transponderList = NULL;
143 }
144 scanList->AddTransponders(Channels);
145 //dsyslog("EIT scan: %d scanList entries", scanList->Count());
146 }
147 for (int i = 0; i < cDevice::NumDevices(); i++) {
148 cDevice *Device = cDevice::GetDevice(i);
149 if (Device && Device->ProvidesEIT()) {
150 for (cScanData *ScanData = scanList->First(); ScanData; ScanData = scanList->Next(ScanData)) {
151 const cChannel *Channel = ScanData->GetChannel();
152 if (Channel) {
153 if (Device->IsTunedToTransponder(Channel))
154 scanList->Del(ScanData);
155 else if (!Channel->Ca() || Channel->Ca() == Device->DeviceNumber() + 1 || Channel->Ca() >= CA_ENCRYPTED_MIN) {
156 if (Device->ProvidesTransponder(Channel)) {
157 if (Device->Priority() < 0) {
158 if (const cPositioner *Positioner = Device->Positioner()) {
159 if (Positioner->LastLongitude() != cSource::Position(Channel->Source()))
160 continue;
161 }
162 bool MaySwitchTransponder = Device->MaySwitchTransponder(Channel);
163 if (MaySwitchTransponder || Device->ProvidesTransponderExclusively(Channel) && now - lastActivity > Setup.EPGScanTimeout * 3600) {
164 if (!MaySwitchTransponder) {
165 if (Device == cDevice::ActualDevice() && !currentChannel) {
166 cDevice::PrimaryDevice()->StopReplay(); // stop transfer mode
167 currentChannel = Device->CurrentChannel();
168 Skins.Message(mtInfo, tr("Starting EPG scan"));
169 }
170 }
171 //dsyslog("EIT scan: %d device %d source %-8s tp %5d", scanList->Count(), Device->DeviceNumber() + 1, *cSource::ToString(Channel->Source()), Channel->Transponder());
172 Device->SwitchChannel(Channel, false);
173 scanList->Del(ScanData);
174 break;
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 if (scanList->Count() == 0) {
184 if (lastActivity == 0) // this was a triggered scan
185 Activity();
186 }
187 StateKey.Remove();
188 }
189 lastScan = time(NULL);
190 }
191 }
192}
#define CA_ENCRYPTED_MIN
Definition channels.h:44
#define LOCK_CHANNELS_READ
Definition channels.h:270
#define ISTRANSPONDER(f1, f2)
Definition channels.h:18
int Source(void) const
Definition channels.h:152
int Number(void) const
Definition channels.h:179
int Ca(int Index=0) const
Definition channels.h:173
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
Definition channels.c:154
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
Definition channels.c:856
int Priority(bool IgnoreOccupied=false) const
Returns the priority of the current receiving session (-MAXPRIORITY..MAXPRIORITY),...
Definition device.c:1682
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:780
static cDevice * ActualDevice(void)
Returns the actual receiving device in case of Transfer Mode, or the primary device otherwise.
Definition device.c:222
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition device.h:148
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:810
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
Definition device.c:230
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
Definition device.c:815
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
Definition device.c:167
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:770
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition device.h:363
void StopReplay(void)
Stops the current replay session (if any).
Definition device.c:1408
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:756
static int NumDevices(void)
Returns the total number of devices.
Definition device.h:129
virtual bool IsTunedToTransponder(const cChannel *Channel) const
Returns true if this device is currently tuned to the given Channel's transponder.
Definition device.c:805
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:751
int currentChannel
Definition eitscan.h:27
cEITScanner(void)
Definition eitscan.c:92
void AddTransponder(cChannel *Channel)
Definition eitscan.c:107
@ ScanTimeout
Definition eitscan.h:24
@ ActivityTimeout
Definition eitscan.h:23
void ForceScan(void)
Definition eitscan.c:114
void Process(void)
Definition eitscan.c:129
cScanList * scanList
Definition eitscan.h:28
time_t lastActivity
Definition eitscan.h:26
cTransponderList * transponderList
Definition eitscan.h:29
void Activity(void)
Definition eitscan.c:119
time_t lastScan
Definition eitscan.h:26
void Del(cListObject *Object, bool DeleteObject=true)
Definition tools.c:2246
int Count(void) const
Definition tools.h:640
void Add(cListObject *Object, cListObject *After=NULL)
Definition tools.c:2214
void Sort(void)
Definition tools.c:2338
Definition tools.h:644
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition tools.h:656
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:663
A steerable satellite dish generally points to the south on the northern hemisphere,...
Definition positioner.h:31
int Transponder(void) const
Definition eitscan.c:26
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 eitscan.c:25
const cChannel * GetChannel(void) const
Definition eitscan.c:27
cChannel channel
Definition eitscan.c:21
cScanData(const cChannel *Channel)
Definition eitscan.c:30
void AddTransponder(const cChannel *Channel)
Definition eitscan.c:59
void AddTransponders(const cList< cChannel > *Channels)
Definition eitscan.c:52
int EPGPauseAfterScan
Definition config.h:299
int EPGScanMaxChannel
Definition config.h:298
int EPGScanTimeout
Definition config.h:300
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
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 Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
Definition thread.c:867
void AddTransponder(cChannel *Channel)
Definition eitscan.c:77
cSetup Setup
Definition config.c:372
cEITScanner EITScanner
Definition eitscan.c:90
#define tr(s)
Definition i18n.h:85
cSkins Skins
Definition skins.c:219
@ mtInfo
Definition skins.h:37