MythTV master
channelscan_sm.h
Go to the documentation of this file.
1/* -*- Mode: c++ -*-
2 * vim: set expandtab tabstop=4 shiftwidth=4:
3 *
4 * Original Project
5 * MythTV http://www.mythtv.org
6 *
7 * Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
8 * Copyright (c) 2005 - 2007 Daniel Kristjansson
9 *
10 * Description:
11 * Collection of classes to provide channel scanning functionallity
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 *
28 */
29
30#ifndef SISCAN_H
31#define SISCAN_H
32
33// Qt includes
34#include <QElapsedTimer>
35#include <QList>
36#include <QMap>
37#include <QMutex>
38#include <QPair>
39#include <QRunnable>
40#include <QSet>
41#include <QString>
42
43// MythTV includes
44#ifndef __cpp_size_t_suffix
46#endif
47#include "dtvconfparserhelpers.h" // for DTVTunerType
48#include "frequencytables.h"
49#include "iptvchannelfetcher.h"
51#include "scanmonitor.h"
53
54class MThread;
55class MSqlQuery;
56
57class ChannelBase;
58class DTVChannel;
59class V4LChannel;
60class DVBChannel;
61class HDHRChannel;
62
63class SignalMonitor;
66
67using pmt_vec_t = std::vector<const ProgramMapTable*>;
68using pmt_map_t = QMap<uint, pmt_vec_t>;
70using ChannelListItem = QPair<transport_scan_items_it_t, ScannedChannelInfo*>;
71using ChannelList = QList<ChannelListItem>;
72
73class ChannelScanSM;
75{
76 public:
77 explicit AnalogSignalHandler(ChannelScanSM *_siscan) : m_siScan(_siscan) { }
78
79 public:
80 inline void AllGood(void) override; // SignalMonitorListener
81 void StatusSignalLock(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
82 void StatusChannelTuned(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
83 void StatusSignalStrength(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
84
85 private:
87};
88
93 public QRunnable
94{
95 friend class AnalogSignalHandler;
96
97 public:
98 ChannelScanSM(ScanMonitor *scan_monitor,
99 const QString &cardtype, ChannelBase* channel, int sourceID,
100 std::chrono::milliseconds signal_timeout, std::chrono::milliseconds channel_timeout,
101 QString inputname, bool test_decryption);
102 ~ChannelScanSM() override;
103
104 void run(void) override; // QRunnable
105
106 void StartScanner(void);
107 void StopScanner(void);
108
109 bool ScanTransports(
110 int SourceID, const QString &std, const QString &mod, const QString &country,
111 const QString &table_start = QString(),
112 const QString &table_end = QString());
114 int sourceid, const QMap<QString,QString> &startChan);
115 bool ScanTransport(uint mplexid, bool follow_nit);
116 bool ScanCurrentTransport(const QString &sistandard);
117 bool ScanForChannels(
118 uint sourceid, const QString &std, const QString &cardtype,
119 const DTVChannelList &channels);
120 bool ScanIPTVChannels(uint sourceid, const fbox_chan_map_t &iptv_channels);
121
122 bool ScanExistingTransports(uint sourceid, bool follow_nit);
123
124 void SetAnalog(bool is_analog);
126 void SetSignalTimeout(std::chrono::milliseconds val) { m_signalTimeout = val; }
127 void SetChannelTimeout(std::chrono::milliseconds val) { m_channelTimeout = val; }
130
131 std::chrono::milliseconds GetSignalTimeout(void) const { return m_signalTimeout; }
132 std::chrono::milliseconds GetChannelTimeout(void) const { return m_channelTimeout; }
133
137
138 using chan_info_map_t = QMap<uint,ChannelInsertInfo>;
140 ScannedChannelInfo *scan_info) const;
141 uint GetCurrentTransportInfo(QString &chan, QString &chan_tr) const;
142 ScanDTVTransportList GetChannelList(bool addFullTS) const;
143
144 // MPEG
145 void HandlePAT(const ProgramAssociationTable *pat) override; // MPEGStreamListener
146 void HandleCAT(const ConditionalAccessTable *cat) override; // MPEGStreamListener
147 void HandlePMT(uint program_num, const ProgramMapTable *pmt) override; // MPEGStreamListener
148 void HandleEncryptionStatus(uint pnum, bool encrypted) override; // MPEGStreamListener
149
150 // ATSC Main
151 void HandleSTT(const SystemTimeTable */*stt*/) override {} // ATSCMainStreamListener
152 void HandleMGT(const MasterGuideTable *mgt) override; // ATSCMainStreamListener
153 void HandleVCT(uint tsid, const VirtualChannelTable *vct) override; // ATSCMainStreamListener
154
155 // DVB Main
156 void HandleNIT(const NetworkInformationTable *nit) override; // DVBMainStreamListener
157 void HandleSDT(uint tsid, const ServiceDescriptionTable *sdt) override; // DVBMainStreamListener
158 void HandleTDT(const TimeDateTable */*tdt*/) override {} // DVBMainStreamListener
159
160 // DVB Other
161 void HandleNITo(const NetworkInformationTable */*nit*/) override {} // DVBOtherStreamListener
162 void HandleSDTo(uint tsid, const ServiceDescriptionTable *sdt) override; // DVBOtherStreamListener
163 void HandleBAT(const BouquetAssociationTable *bat) override; // DVBOtherStreamListener
164
165 private:
166 // Gets
168 const DTVChannel *GetDTVChannel(void) const;
172 const DVBChannel *GetDVBChannel(void) const;
173
174 bool HasTimedOut(void);
175 void HandleActiveScan(void);
176 bool Tune(transport_scan_items_it_t transport);
179 static void LogLines(const QString& string);
180
181 // Updates Transport Scan progress bar
182 inline void UpdateScanPercentCompleted(void);
183
184 bool CheckImportedList(const DTVChannelInfoList &channels,
185 uint mpeg_program_num,
186 QString &service_name,
187 QString &callsign,
188 QString &common_status_info);
189
190 void IgnoreDataOnlyMsg( const QString &name, int aux_num);
191 void IgnoreEmptyChanMsg(const QString &name, int aux_num);
192 void IgnoreAudioOnlyMsg(const QString &name, int aux_num);
193 void IgnoreEncryptedMsg(const QString &name, int aux_num);
194
195 bool TestNextProgramEncryption(void);
196 void UpdateScanTransports(uint frequency, const NetworkInformationTable *nit);
197 bool UpdateChannelInfo(bool wait_until_complete);
198
199 void HandleAllGood(void); // used for analog scanner
200
201 bool AddToList(uint mplexid);
202
203 static QString loc(const ChannelScanSM *siscan);
204
205 static const std::chrono::milliseconds kDVBTableTimeout;
206 static const std::chrono::milliseconds kATSCTableTimeout;
207 static const std::chrono::milliseconds kMPEGTableTimeout;
208
209 private:
210 // Set in constructor
215 std::chrono::milliseconds m_signalTimeout;
216 std::chrono::milliseconds m_channelTimeout;
217 std::chrono::milliseconds m_otherTableTimeout {0ms};
218 std::chrono::milliseconds m_otherTableTime {0ms};
219 bool m_setOtherTables {false};
220 QString m_inputName;
222 bool m_extendScanList {false};
223
224 // Scanning parameters
230
231 // Optional info
233
235 mutable QMutex m_lock;
236
237 // State
238 bool m_scanning {false};
239 volatile bool m_threadExit {false};
240 bool m_waitingForTables {false};
241 QElapsedTimer m_timer;
242
243 // Transports List
245 QSet<uint32_t> m_tsScanned;
246 QMap<uint32_t,DTVMultiplex> m_extendTransports;
253 QMap<uint64_t, QString> m_defAuthorities;
254 bool m_dvbt2Tried {false};
255
260
261 // Analog Info
263
264 // Scanner thread, runs ChannelScanSM::run()
266
267 // Protect UpdateChannelInfo
268 QMutex m_mutex;
269};
270
272{
273#ifdef __cpp_size_t_suffix
274 int tmp = (m_transportsScanned * 100Z) /
275 (m_scanTransports.size() + m_extendTransports.size());
276#else
277 int tmp = (m_transportsScanned * 100_Z) /
278 (m_scanTransports.size() + m_extendTransports.size());
279#endif
281}
282
284{
286}
287
288#endif // SISCAN_H
QList< ChannelListItem > ChannelList
QMap< uint, pmt_vec_t > pmt_map_t
std::vector< const ProgramMapTable * > pmt_vec_t
QPair< transport_scan_items_it_t, ScannedChannelInfo * > ChannelListItem
ChannelScanSM * m_siScan
void StatusChannelTuned(const SignalMonitorValue &) override
Signal to be sent with change change status.
void AllGood(void) override
Signal to be sent when you have a lock on all values.
void StatusSignalStrength(const SignalMonitorValue &) override
Signal to be sent with an actual signal value.
AnalogSignalHandler(ChannelScanSM *_siscan)
void StatusSignalLock(const SignalMonitorValue &) override
Signal to be sent as true when it is safe to begin or continue recording, and false if it may not be ...
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
Definition: dvbtables.h:193
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:32
Scanning class for cards that support a SignalMonitor class.
bool ScanTransportsStartingOn(int sourceid, const QMap< QString, QString > &startChan)
Generates a list of frequencies to scan and adds it to the scanTransport list, and then sets the scan...
QMutex m_lock
The big lock.
QElapsedTimer m_timer
DTVTunerType GuessDTVTunerType(DTVTunerType type) const
void UpdateScanPercentCompleted(void)
void run(void) override
This runs the event loop for ChannelScanSM until 'm_threadExit' is true.
void HandleTDT(const TimeDateTable *) override
void UpdateScanTransports(uint frequency, const NetworkInformationTable *nit)
void IgnoreAudioOnlyMsg(const QString &name, int aux_num)
QSet< uint32_t > m_tsScanned
std::chrono::milliseconds m_otherTableTimeout
void HandleMGT(const MasterGuideTable *mgt) override
QMap< uint32_t, DTVMultiplex > m_extendTransports
std::chrono::milliseconds m_otherTableTime
void SetSourceID(int SourceID)
DTVTunerType m_scanDTVTunerType
ChannelList m_channelList
Found Channel Info.
DTVChannel * GetDTVChannel(void)
void HandleActiveScan(void)
Handles the TRANSPORT_LIST ChannelScanSM mode.
bool ScanForChannels(uint sourceid, const QString &std, const QString &cardtype, const DTVChannelList &channels)
void HandleEncryptionStatus(uint pnum, bool encrypted) override
void IgnoreDataOnlyMsg(const QString &name, int aux_num)
transport_scan_items_t m_scanTransports
static const std::chrono::milliseconds kMPEGTableTimeout
No logic here, lets just wait at least 15 seconds.
bool ScanTransport(uint mplexid, bool follow_nit)
void HandleSDTo(uint tsid, const ServiceDescriptionTable *sdt) override
void IgnoreEmptyChanMsg(const QString &name, int aux_num)
static const std::chrono::milliseconds kATSCTableTimeout
No logic here, lets just wait at least 10 seconds.
void SetAnalog(bool is_analog)
void HandleVCT(uint tsid, const VirtualChannelTable *vct) override
void HandleNIT(const NetworkInformationTable *nit) override
std::chrono::milliseconds m_signalTimeout
static QString loc(const ChannelScanSM *siscan)
void HandleSDT(uint tsid, const ServiceDescriptionTable *sdt) override
uint GetCurrentTransportInfo(QString &chan, QString &chan_tr) const
DVBSignalMonitor * GetDVBSignalMonitor(void)
void SetSignalTimeout(std::chrono::milliseconds val)
QMap< uint64_t, QString > m_defAuthorities
DTVSignalMonitor * GetDTVSignalMonitor(void)
MThread * m_scannerThread
static const std::chrono::milliseconds kDVBTableTimeout
SDT's should be sent every 2 seconds and NIT's every 10 seconds, so lets wait at least 30 seconds,...
QMap< uint, bool > m_currentEncryptionStatusChecked
SignalMonitor * GetSignalMonitor(void)
bool UpdateChannelInfo(bool wait_until_complete)
bool ScanTransports(int SourceID, const QString &std, const QString &mod, const QString &country, const QString &table_start=QString(), const QString &table_end=QString())
Generates a list of frequencies to scan and adds it to the scanTransport list, and then sets the scan...
bool Tune(transport_scan_items_it_t transport)
AnalogSignalHandler * m_analogSignalHandler
V4LChannel * GetV4LChannel(void)
chan_info_map_t GetChannelList(transport_scan_items_it_t trans_info, ScannedChannelInfo *scan_info) const
void HandlePMT(uint program_num, const ProgramMapTable *pmt) override
void HandleSTT(const SystemTimeTable *) override
void HandlePAT(const ProgramAssociationTable *pat) override
HDHRChannel * GetHDHRChannel(void)
~ChannelScanSM() override
bool m_currentTestingDecryption
ChannelScanSM(ScanMonitor *scan_monitor, const QString &cardtype, ChannelBase *channel, int sourceID, std::chrono::milliseconds signal_timeout, std::chrono::milliseconds channel_timeout, QString inputname, bool test_decryption)
static void LogLines(const QString &string)
void HandleAllGood(void)
std::chrono::milliseconds GetSignalTimeout(void) const
void HandleCAT(const ConditionalAccessTable *cat) override
void SetScanDTVTunerType(int t)
QMap< uint, uint > m_currentEncryptionStatus
bool ScanExistingTransports(uint sourceid, bool follow_nit)
If we are not already scanning a frequency table, this creates a new frequency table from database an...
void IgnoreEncryptedMsg(const QString &name, int aux_num)
bool HasTimedOut(void)
ScannedChannelInfo * m_currentInfo
transport_scan_items_it_t m_current
std::chrono::milliseconds m_channelTimeout
SignalMonitor * m_signalMonitor
QString m_inputName
void SetChannelTimeout(std::chrono::milliseconds val)
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
bool ScanCurrentTransport(const QString &sistandard)
void HandleBAT(const BouquetAssociationTable *bat) override
void StartScanner(void)
Starts the ChannelScanSM event loop.
transport_scan_items_it_t m_nextIt
std::chrono::milliseconds GetChannelTimeout(void) const
void HandleNITo(const NetworkInformationTable *) override
DVBChannel * GetDVBChannel(void)
ChannelBase * m_channel
ScanMonitor * m_scanMonitor
QMap< uint, ChannelInsertInfo > chan_info_map_t
bool CheckImportedList(const DTVChannelInfoList &channels, uint mpeg_program_num, QString &service_name, QString &callsign, QString &common_status_info)
If we are scanning a dvb-utils import verify channel is in list.
bool TestNextProgramEncryption(void)
bool AddToList(uint mplexid)
bool ScanIPTVChannels(uint sourceid, const fbox_chan_map_t &iptv_channels)
void SetScanDTVTunerType(DTVTunerType t)
volatile bool m_threadExit
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
Definition: mpegtables.h:839
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
This class is intended to detect the presence of needed tables.
static const int kTunerTypeUnknown
Provides interface to the tuning hardware when using DVB drivers.
Definition: dvbchannel.h:31
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
This table tells the decoder on which PIDs to find other tables, and their sizes and each table's cur...
Definition: atsctables.h:81
This table tells the decoder on which PIDs to find other tables.
Definition: dvbtables.h:34
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
Definition: mpegtables.h:599
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
Definition: mpegtables.h:676
void ScanPercentComplete(int pct)
This table tells the decoder on which PIDs to find A/V data.
Definition: dvbtables.h:114
Signal monitoring base class.
Definition: signalmonitor.h:31
This table contains the GPS time at the time of transmission.
Definition: atsctables.h:686
This table gives the current DVB stream time.
Definition: dvbtables.h:387
Implements tuning for TV cards using the V4L driver API, both versions 1 and 2.
Definition: v4lchannel.h:33
This table contains information about the channels transmitted on this multiplex.
Definition: atsctables.h:195
unsigned int uint
Definition: compat.h:60
std::vector< DTVChannelInfo > DTVChannelInfoList
Definition: dtvconfparser.h:58
std::vector< DTVTransport > DTVChannelList
Definition: dtvconfparser.h:68
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
std::list< TransportScanItem > transport_scan_items_t
QMap< QString, IPTVChannelInfo > fbox_chan_map_t