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#include "dtvconfparserhelpers.h" // for DTVTunerType
45#include "frequencytables.h"
46#include "iptvchannelfetcher.h"
48#include "scanmonitor.h"
50
51class MThread;
52class MSqlQuery;
53
54class ChannelBase;
55class DTVChannel;
56class V4LChannel;
57class DVBChannel;
58class HDHRChannel;
59
60class SignalMonitor;
63
64using pmt_vec_t = std::vector<const ProgramMapTable*>;
65using pmt_map_t = QMap<uint, pmt_vec_t>;
67using ChannelListItem = QPair<transport_scan_items_it_t, ScannedChannelInfo*>;
68using ChannelList = QList<ChannelListItem>;
69
70class ChannelScanSM;
72{
73 public:
74 explicit AnalogSignalHandler(ChannelScanSM *_siscan) : m_siScan(_siscan) { }
75
76 public:
77 inline void AllGood(void) override; // SignalMonitorListener
78 void StatusSignalLock(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
79 void StatusChannelTuned(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
80 void StatusSignalStrength(const SignalMonitorValue &/*val*/) override { } // SignalMonitorListener
81
82 private:
84};
85
90 public QRunnable
91{
92 friend class AnalogSignalHandler;
93
94 public:
95 ChannelScanSM(ScanMonitor *scan_monitor,
96 const QString &cardtype, ChannelBase* channel, int sourceID,
97 std::chrono::milliseconds signal_timeout, std::chrono::milliseconds channel_timeout,
98 QString inputname, bool test_decryption);
99 ~ChannelScanSM() override;
100
101 void StartScanner(void);
102 void StopScanner(void);
103
104 bool ScanTransports(
105 int SourceID, const QString &std, const QString &mod, const QString &country,
106 const QString &table_start = QString(),
107 const QString &table_end = QString());
109 int sourceid, const QMap<QString,QString> &startChan);
110 bool ScanTransport(uint mplexid, bool follow_nit);
111 bool ScanCurrentTransport(const QString &sistandard);
112 bool ScanForChannels(
113 uint sourceid, const QString &std, const QString &cardtype,
114 const DTVChannelList &channels);
115 bool ScanIPTVChannels(uint sourceid, const fbox_chan_map_t &iptv_channels);
116
117 bool ScanExistingTransports(uint sourceid, bool follow_nit);
118
119 void SetAnalog(bool is_analog);
121 void SetSignalTimeout(std::chrono::milliseconds val) { m_signalTimeout = val; }
122 void SetChannelTimeout(std::chrono::milliseconds val) { m_channelTimeout = val; }
125
126 std::chrono::milliseconds GetSignalTimeout(void) const { return m_signalTimeout; }
127 std::chrono::milliseconds GetChannelTimeout(void) const { return m_channelTimeout; }
128
132
133 using chan_info_map_t = QMap<uint,ChannelInsertInfo>;
135 ScannedChannelInfo *scan_info) const;
136 uint GetCurrentTransportInfo(QString &chan, QString &chan_tr) const;
137 ScanDTVTransportList GetChannelList(bool addFullTS) const;
138
139 // MPEG
140 void HandlePAT(const ProgramAssociationTable *pat) override; // MPEGStreamListener
141 void HandleCAT(const ConditionalAccessTable *cat) override; // MPEGStreamListener
142 void HandlePMT(uint program_num, const ProgramMapTable *pmt) override; // MPEGStreamListener
143 void HandleEncryptionStatus(uint pnum, bool encrypted) override; // MPEGStreamListener
144
145 // ATSC Main
146 void HandleSTT(const SystemTimeTable */*stt*/) override {} // ATSCMainStreamListener
147 void HandleMGT(const MasterGuideTable *mgt) override; // ATSCMainStreamListener
148 void HandleVCT(uint tsid, const VirtualChannelTable *vct) override; // ATSCMainStreamListener
149
150 // DVB Main
151 void HandleNIT(const NetworkInformationTable *nit) override; // DVBMainStreamListener
152 void HandleSDT(uint tsid, const ServiceDescriptionTable *sdt) override; // DVBMainStreamListener
153 void HandleTDT(const TimeDateTable */*tdt*/) override {} // DVBMainStreamListener
154
155 // DVB Other
156 void HandleNITo(const NetworkInformationTable */*nit*/) override {} // DVBOtherStreamListener
157 void HandleSDTo(uint tsid, const ServiceDescriptionTable *sdt) override; // DVBOtherStreamListener
158 void HandleBAT(const BouquetAssociationTable *bat) override; // DVBOtherStreamListener
159
160 private:
161 // Gets
163 const DTVChannel *GetDTVChannel(void) const;
167 const DVBChannel *GetDVBChannel(void) const;
168
169 void run(void) override; // QRunnable
170
171 bool HasTimedOut(void);
172 void HandleActiveScan(void);
173 bool Tune(transport_scan_items_it_t transport);
176 static void LogLines(const QString& string);
177
178 // Updates Transport Scan progress bar
179 inline void UpdateScanPercentCompleted(void);
180
181 bool CheckImportedList(const DTVChannelInfoList &channels,
182 uint mpeg_program_num,
183 QString &service_name,
184 QString &callsign,
185 QString &common_status_info);
186
187 void IgnoreDataOnlyMsg( const QString &name, int aux_num);
188 void IgnoreEmptyChanMsg(const QString &name, int aux_num);
189 void IgnoreAudioOnlyMsg(const QString &name, int aux_num);
190 void IgnoreEncryptedMsg(const QString &name, int aux_num);
191
192 bool TestNextProgramEncryption(void);
193 void UpdateScanTransports(uint frequency, const NetworkInformationTable *nit);
194 bool UpdateChannelInfo(bool wait_until_complete);
195
196 void HandleAllGood(void); // used for analog scanner
197
198 bool AddToList(uint mplexid);
199
200 static QString loc(const ChannelScanSM *siscan);
201
202 static const std::chrono::milliseconds kDVBTableTimeout;
203 static const std::chrono::milliseconds kATSCTableTimeout;
204 static const std::chrono::milliseconds kMPEGTableTimeout;
205
206 private:
207 // Set in constructor
212 std::chrono::milliseconds m_signalTimeout;
213 std::chrono::milliseconds m_channelTimeout;
214 std::chrono::milliseconds m_otherTableTimeout {0ms};
215 std::chrono::milliseconds m_otherTableTime {0ms};
216 bool m_setOtherTables {false};
217 QString m_inputName;
219 bool m_extendScanList {false};
220
221 // Scanning parameters
227
228 // Optional info
230
232 mutable QMutex m_lock;
233
234 // State
235 bool m_scanning {false};
236 volatile bool m_threadExit {false};
237 bool m_waitingForTables {false};
238 QElapsedTimer m_timer;
239
240 // Transports List
242 QSet<uint32_t> m_tsScanned;
243 QMap<uint32_t,DTVMultiplex> m_extendTransports;
250 QMap<uint64_t, QString> m_defAuthorities;
251 bool m_dvbt2Tried {false};
252
257
258 // Analog Info
260
261 // Scanner thread, runs ChannelScanSM::run()
263
264 // Protect UpdateChannelInfo
265 QMutex m_mutex;
266};
267
269{
270 int tmp = (m_transportsScanned * 100) /
271 (m_scanTransports.size() + m_extendTransports.size());
273}
274
276{
278}
279
280#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:83
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:688
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:32
This table contains information about the channels transmitted on this multiplex.
Definition: atsctables.h:197
std::vector< DTVChannelInfo > DTVChannelInfoList
Definition: dtvconfparser.h:58
std::vector< DTVTransport > DTVChannelList
Definition: dtvconfparser.h:68
std::vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:143
unsigned int uint
Definition: freesurround.h:24
std::list< TransportScanItem > transport_scan_items_t
static guint32 * tmp
Definition: goom_core.cpp:26
QMap< QString, IPTVChannelInfo > fbox_chan_map_t
STL namespace.