-
Notifications
You must be signed in to change notification settings - Fork 341
/
channelscanner.cpp
439 lines (376 loc) · 12.9 KB
/
channelscanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/* -*- Mode: c++ -*-
* vim: set expandtab tabstop=4 shiftwidth=4:
*
* Original Project
* MythTV http://www.mythtv.org
*
* Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
* Copyright (c) 2005 - 2007 Daniel Kristjansson
*
* Description:
* Collection of classes to provide channel scanning functionallity
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*
*/
#include <algorithm>
using namespace std;
#include "analogsignalmonitor.h"
#include "iptvchannelfetcher.h"
#include "dvbsignalmonitor.h"
#include "scanwizardconfig.h"
#include "channelscan_sm.h"
#include "channelscanner.h"
#include "hdhrchannel.h"
#include "scanmonitor.h"
#include "asichannel.h"
#include "dvbchannel.h"
#include "v4lchannel.h"
#include "cardutil.h"
#define LOC QString("ChScan: ")
ChannelScanner::ChannelScanner() :
scanMonitor(NULL), channel(NULL), sigmonScanner(NULL), iptvScanner(NULL),
freeToAirOnly(false), serviceRequirements(kRequireAV)
{
}
ChannelScanner::~ChannelScanner()
{
Teardown();
if (scanMonitor)
{
scanMonitor->deleteLater();
scanMonitor = NULL;
}
}
void ChannelScanner::Teardown(void)
{
if (sigmonScanner)
{
delete sigmonScanner;
sigmonScanner = NULL;
}
if (channel)
{
delete channel;
channel = NULL;
}
if (iptvScanner)
{
iptvScanner->Stop();
delete iptvScanner;
iptvScanner = NULL;
}
if (scanMonitor)
{
scanMonitor->deleteLater();
scanMonitor = NULL;
}
}
// full scan of existing transports broken
// existing transport scan broken
void ChannelScanner::Scan(
int scantype,
uint cardid,
const QString &inputname,
uint sourceid,
bool do_ignore_signal_timeout,
bool do_follow_nit,
bool do_test_decryption,
bool do_fta_only,
ServiceRequirements service_requirements,
// stuff needed for particular scans
uint mplexid /* TransportScan */,
const QMap<QString,QString> &startChan /* NITAddScan */,
const QString &freq_std /* FullScan */,
const QString &mod /* FullScan */,
const QString &tbl /* FullScan */,
const QString &tbl_start /* FullScan optional */,
const QString &tbl_end /* FullScan optional */)
{
freeToAirOnly = do_fta_only;
serviceRequirements = service_requirements;
PreScanCommon(scantype, cardid, inputname,
sourceid, do_ignore_signal_timeout, do_test_decryption);
LOG(VB_CHANSCAN, LOG_INFO, LOC + "Scan()");
if (!sigmonScanner)
{
LOG(VB_CHANSCAN, LOG_ERR, LOC + "Scan(): scanner does not exist...");
return;
}
sigmonScanner->StartScanner();
scanMonitor->ScanUpdateStatusText("");
bool ok = false;
if ((ScanTypeSetting::FullScan_ATSC == scantype) ||
(ScanTypeSetting::FullScan_DVBC == scantype) ||
(ScanTypeSetting::FullScan_DVBT == scantype) ||
(ScanTypeSetting::FullScan_Analog == scantype))
{
LOG(VB_CHANSCAN, LOG_INFO, LOC + QString("ScanTransports(%1, %2, %3)")
.arg(freq_std).arg(mod).arg(tbl));
// HACK HACK HACK -- begin
// if using QAM we may need additional time... (at least with HD-3000)
if ((mod.startsWith("qam", Qt::CaseInsensitive)) &&
(sigmonScanner->GetSignalTimeout() < 1000))
{
sigmonScanner->SetSignalTimeout(1000);
}
// HACK HACK HACK -- end
sigmonScanner->SetAnalog(ScanTypeSetting::FullScan_Analog == scantype);
ok = sigmonScanner->ScanTransports(
sourceid, freq_std, mod, tbl, tbl_start, tbl_end);
}
else if ((ScanTypeSetting::NITAddScan_DVBT == scantype) ||
(ScanTypeSetting::NITAddScan_DVBS == scantype) ||
(ScanTypeSetting::NITAddScan_DVBS2 == scantype) ||
(ScanTypeSetting::NITAddScan_DVBC == scantype))
{
LOG(VB_CHANSCAN, LOG_INFO, LOC + "ScanTransports()");
ok = sigmonScanner->ScanTransportsStartingOn(sourceid, startChan);
}
else if (ScanTypeSetting::FullTransportScan == scantype)
{
LOG(VB_CHANSCAN, LOG_INFO, LOC + QString("ScanExistingTransports(%1)")
.arg(sourceid));
ok = sigmonScanner->ScanExistingTransports(sourceid, do_follow_nit);
if (ok)
{
scanMonitor->ScanPercentComplete(0);
}
else
{
InformUser(tr("Error tuning to transport"));
Teardown();
}
}
else if ((ScanTypeSetting::DVBUtilsImport == scantype) && channels.size())
{
ok = true;
LOG(VB_CHANSCAN, LOG_INFO, LOC +
QString("ScanForChannels(%1)").arg(sourceid));
QString card_type = CardUtil::GetRawCardType(cardid);
QString sub_type = card_type;
if (card_type == "DVB")
{
QString device = CardUtil::GetVideoDevice(cardid);
ok = !device.isEmpty();
if (ok)
sub_type = CardUtil::ProbeDVBType(device).toUpper();
}
if (ok)
{
ok = sigmonScanner->ScanForChannels(sourceid, freq_std,
sub_type, channels);
}
if (ok)
{
scanMonitor->ScanPercentComplete(0);
}
else
{
InformUser(tr("Error tuning to transport"));
Teardown();
}
}
else if (ScanTypeSetting::TransportScan == scantype)
{
LOG(VB_CHANSCAN, LOG_INFO, LOC +
QString("ScanTransport(%1)").arg(mplexid));
ok = sigmonScanner->ScanTransport(mplexid, do_follow_nit);
}
else if (ScanTypeSetting::CurrentTransportScan == scantype)
{
QString sistandard = "mpeg";
LOG(VB_CHANSCAN, LOG_INFO, LOC +
"ScanCurrentTransport(" + sistandard + ")");
ok = sigmonScanner->ScanCurrentTransport(sistandard);
}
if (!ok)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to handle tune complete.");
InformUser(tr("Programmer Error: "
"Failed to handle tune complete."));
}
}
DTVConfParser::return_t ChannelScanner::ImportDVBUtils(
uint sourceid, int cardtype, const QString &file)
{
channels.clear();
DTVConfParser::cardtype_t type = DTVConfParser::UNKNOWN;
type = (CardUtil::DVBT == cardtype) ? DTVConfParser::OFDM : type;
type = (CardUtil::QPSK == cardtype) ? DTVConfParser::QPSK : type;
type = (CardUtil::DVBC == cardtype) ? DTVConfParser::QAM : type;
type = (CardUtil::DVBS2 == cardtype) ? DTVConfParser::DVBS2 : type;
type = ((CardUtil::ATSC == cardtype) ||
(CardUtil::HDHOMERUN == cardtype)) ? DTVConfParser::ATSC : type;
DTVConfParser::return_t ret = DTVConfParser::OK;
if (type == DTVConfParser::UNKNOWN)
ret = DTVConfParser::ERROR_CARDTYPE;
else
{
DTVConfParser parser(type, sourceid, file);
ret = parser.Parse();
if (DTVConfParser::OK == ret)
channels = parser.GetChannels();
}
if (DTVConfParser::OK != ret)
{
QString msg = (DTVConfParser::ERROR_PARSE == ret) ?
tr("Failed to parse '%1'").arg(file) :
((DTVConfParser::ERROR_CARDTYPE == ret) ?
tr("Programmer Error : incorrect card type") :
tr("Failed to open '%1'").arg(file));
InformUser(msg);
}
return ret;
}
bool ChannelScanner::ImportM3U(
uint cardid, const QString &inputname, uint sourceid)
{
(void) cardid;
(void) inputname;
(void) sourceid;
if (!scanMonitor)
scanMonitor = new ScanMonitor(this);
// Create an IPTV scan object
iptvScanner = new IPTVChannelFetcher(
cardid, inputname, sourceid, scanMonitor);
MonitorProgress(false, false, false, false);
iptvScanner->Scan();
return true;
}
void ChannelScanner::PreScanCommon(
int scantype,
uint cardid,
const QString &inputname,
uint sourceid,
bool do_ignore_signal_timeout,
bool do_test_decryption)
{
uint signal_timeout = 1000;
uint channel_timeout = 40000;
CardUtil::GetTimeouts(cardid, signal_timeout, channel_timeout);
QString device = CardUtil::GetVideoDevice(cardid);
if (device.isEmpty())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "No Device");
InformUser(tr("Programmer Error: No Device"));
return;
}
if (!scanMonitor)
scanMonitor = new ScanMonitor(this);
QString card_type = CardUtil::GetRawCardType(cardid);
if ("DVB" == card_type)
{
QString sub_type = CardUtil::ProbeDVBType(device).toUpper();
bool need_nit = (("QAM" == sub_type) ||
("QPSK" == sub_type) ||
("OFDM" == sub_type));
// Ugh, Some DVB drivers don't fully support signal monitoring...
if ((ScanTypeSetting::TransportScan == scantype) ||
(ScanTypeSetting::FullTransportScan == scantype))
{
signal_timeout = (do_ignore_signal_timeout) ?
channel_timeout * 10 : signal_timeout;
}
// ensure a minimal signal timeout of 1 second
signal_timeout = max(signal_timeout, 1000U);
// Make sure that channel_timeout is at least 7 seconds to catch
// at least one SDT section. kDVBTableTimeout in ChannelScanSM
// ensures that we catch the NIT then.
channel_timeout = max(channel_timeout, need_nit * 7 * 1000U);
}
#ifdef USING_DVB
if ("DVB" == card_type)
channel = new DVBChannel(device);
#endif
#ifdef USING_V4L2
if (("V4L" == card_type) || ("MPEG" == card_type))
channel = new V4LChannel(NULL, device);
#endif
#ifdef USING_HDHOMERUN
if ("HDHOMERUN" == card_type)
{
channel = new HDHRChannel(NULL, device);
}
#endif // USING_HDHOMERUN
#ifdef USING_ASI
if ("ASI" == card_type)
{
channel = new ASIChannel(NULL, device);
}
#endif // USING_ASI
if (!channel)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Channel not created");
InformUser(tr("Programmer Error: Channel not created"));
return;
}
// explicitly set the cardid
channel->SetCardID(cardid);
// If the backend is running this may fail...
if (!channel->Open())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Channel could not be opened");
InformUser(tr("Channel could not be opened."));
return;
}
ScanMonitor *lis = scanMonitor;
sigmonScanner = new ChannelScanSM(
lis, card_type, channel, sourceid,
signal_timeout, channel_timeout, inputname,
do_test_decryption);
// If we know the channel types we can give the signal montior a hint.
// Since we unfortunately do not record this info in the DB, we cannot
// do this for the other scan types and have to guess later on...
switch (scantype)
{
case ScanTypeSetting::FullScan_ATSC:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeATSC);
break;
case ScanTypeSetting::FullScan_DVBC:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBC);
break;
case ScanTypeSetting::FullScan_DVBT:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBT);
break;
case ScanTypeSetting::NITAddScan_DVBT:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBT);
break;
case ScanTypeSetting::NITAddScan_DVBS:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBS1);
break;
case ScanTypeSetting::NITAddScan_DVBS2:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBS2);
break;
case ScanTypeSetting::NITAddScan_DVBC:
sigmonScanner->SetScanDTVTunerType(DTVTunerType::kTunerTypeDVBC);
break;
default:
break;
}
// Signal Meters are connected here
SignalMonitor *mon = sigmonScanner->GetSignalMonitor();
if (mon)
mon->AddListener(lis);
DVBSignalMonitor *dvbm = NULL;
bool using_rotor = false;
#ifdef USING_DVB
dvbm = sigmonScanner->GetDVBSignalMonitor();
if (dvbm && mon)
using_rotor = mon->HasFlags(SignalMonitor::kDVBSigMon_WaitForPos);
#endif // USING_DVB
MonitorProgress(mon, mon, dvbm, using_rotor);
}