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 <QRunnable>
35 #include <QString>
36 #include <QList>
37 #include <QPair>
38 #include <QMap>
39 #include <QSet>
40 #include <QMutex>
41 
42 // MythTV includes
43 #include "frequencytables.h"
44 #include "iptvchannelfetcher.h"
45 #include "streamlisteners.h"
46 #include "scanmonitor.h"
47 #include "signalmonitorlistener.h"
48 #include "dtvconfparserhelpers.h" // for DTVTunerType
49 
50 class MThread;
51 class MSqlQuery;
52 
53 class ChannelBase;
54 class DTVChannel;
55 class V4LChannel;
56 class DVBChannel;
57 class HDHRChannel;
58 
59 class SignalMonitor;
60 class DTVSignalMonitor;
62 
63 typedef vector<const ProgramMapTable*> pmt_vec_t;
64 typedef QMap<uint, pmt_vec_t> pmt_map_t;
66 typedef QPair<transport_scan_items_it_t, ScannedChannelInfo*> ChannelListItem;
67 typedef QList<ChannelListItem> ChannelList;
68 
69 class ChannelScanSM;
71 {
72  public:
73  explicit AnalogSignalHandler(ChannelScanSM *_siscan) : siscan(_siscan) { }
74 
75  public:
76  inline void AllGood(void) override; // SignalMonitorListener
77  void StatusSignalLock(const SignalMonitorValue&) override { } // SignalMonitorListener
78  void StatusChannelTuned(const SignalMonitorValue&) override { } // SignalMonitorListener
79  void StatusSignalStrength(const SignalMonitorValue&) override { } // SignalMonitorListener
80 
81  private:
83 };
84 
87  public DVBMainStreamListener,
89  public QRunnable
90 {
91  friend class AnalogSignalHandler;
92 
93  public:
94  ChannelScanSM(ScanMonitor *_scan_monitor,
95  const QString &_cardtype, ChannelBase* _channel, int _sourceID,
96  uint signal_timeout, uint channel_timeout,
97  const QString &_inputname, bool test_decryption);
99 
100  void StartScanner(void);
101  void StopScanner(void);
102 
103  bool ScanTransports(
104  int SourceID, const QString &std, const QString &mod, const QString &country,
105  const QString &table_start = QString(),
106  const QString &table_end = QString());
108  int sourceid, const QMap<QString,QString> &startChan);
109  bool ScanTransport(uint mplexid, bool follow_nit);
110  bool ScanCurrentTransport(const QString &sistandard);
111  bool ScanForChannels(
112  uint sourceid, const QString &std, const QString &cardtype,
113  const DTVChannelList&);
114  bool ScanIPTVChannels(uint sourceid, const fbox_chan_map_t &iptv_channels);
115 
116  bool ScanExistingTransports(uint sourceid, bool follow_nit);
117 
118  void SetAnalog(bool is_analog);
119  void SetSourceID(int _SourceID) { m_sourceID = _SourceID; }
120  void SetSignalTimeout(uint val) { m_signalTimeout = val; }
124 
125  uint GetSignalTimeout(void) const { return m_signalTimeout; }
126  uint GetChannelTimeout(void) const { return m_channelTimeout; }
127 
131 
132  typedef QMap<uint,ChannelInsertInfo> chan_info_map_t;
134  ScannedChannelInfo *scan_info) const;
135  uint GetCurrentTransportInfo(QString &chan, QString &chan_tr) const;
136  ScanDTVTransportList GetChannelList(bool addFullTS) const;
137 
138  // MPEG
139  void HandlePAT(const ProgramAssociationTable*) override; // MPEGStreamListener
140  void HandleCAT(const ConditionalAccessTable*) override { } // MPEGStreamListener
141  void HandlePMT(uint, const ProgramMapTable*) override; // MPEGStreamListener
142  void HandleEncryptionStatus(uint pnum, bool encrypted) override; // MPEGStreamListener
143 
144  // ATSC Main
145  void HandleSTT(const SystemTimeTable*) override {} // ATSCMainStreamListener
146  void HandleMGT(const MasterGuideTable*) override; // ATSCMainStreamListener
147  void HandleVCT(uint tsid, const VirtualChannelTable*) override; // ATSCMainStreamListener
148 
149  // DVB Main
150  void HandleNIT(const NetworkInformationTable*) override; // DVBMainStreamListener
151  void HandleSDT(uint tsid, const ServiceDescriptionTable*) override; // DVBMainStreamListener
152  void HandleTDT(const TimeDateTable*) override {} // DVBMainStreamListener
153 
154  // DVB Other
155  void HandleNITo(const NetworkInformationTable*) override {} // DVBOtherStreamListener
156  void HandleSDTo(uint tsid, const ServiceDescriptionTable*) override; // DVBOtherStreamListener
157  void HandleBAT(const BouquetAssociationTable*) override; // DVBOtherStreamListener
158 
159  private:
160  // some useful gets
161  DTVChannel *GetDTVChannel(void);
162  const DTVChannel *GetDTVChannel(void) const;
163  V4LChannel *GetV4LChannel(void);
165  DVBChannel *GetDVBChannel(void);
166  const DVBChannel *GetDVBChannel(void) const;
167 
168  void run(void) override; // QRunnable
169 
170  bool HasTimedOut(void);
171  void HandleActiveScan(void);
172  bool Tune(const transport_scan_items_it_t &transport);
173  void ScanTransport(const transport_scan_items_it_t &transport);
175  void LogLines(const QString& string) const;
176 
178  inline void UpdateScanPercentCompleted(void);
179 
181  uint mpeg_program_num,
182  QString &service_name,
183  QString &callsign,
184  QString &common_status_info);
185 
186  void IgnoreDataOnlyMsg( const QString &name, int aux_num);
187  void IgnoreEmptyChanMsg(const QString &name, int aux_num);
188  void IgnoreAudioOnlyMsg(const QString &name, int aux_num);
189  void IgnoreEncryptedMsg(const QString &name, int aux_num);
190 
191  bool TestNextProgramEncryption(void);
193  bool UpdateChannelInfo(bool wait_until_complete);
194 
195  void HandleAllGood(void); // used for analog scanner
196 
197  bool AddToList(uint mplexid);
198 
199  static QString loc(const ChannelScanSM*);
200 
201  static const uint kDVBTableTimeout;
202  static const uint kATSCTableTimeout;
203  static const uint kMPEGTableTimeout;
204 
205  private:
206  // Set in constructor
215  bool m_setOtherTables {false};
216  QString m_inputName;
218  bool m_extendScanList {false};
219 
220  // Freesat
223 
224  // Optional info
226 
228  mutable QMutex m_lock;
229 
230  // State
231  bool m_scanning {false};
232  volatile bool m_threadExit {false};
233  bool m_waitingForTables {false};
234  QTime m_timer;
235 
236  // Transports List
238  QSet<uint32_t> m_tsScanned;
239  QMap<uint32_t,DTVMultiplex> m_extendTransports;
244  QMap<uint, uint> m_currentEncryptionStatus;
246  QMap<uint64_t, QString> m_defAuthorities;
248 
253 
254  // Analog Info
256 
259  QMutex m_mutex;
260 };
261 
263 {
264  int tmp = (m_transportsScanned * 100) /
265  (m_scanTransports.size() + m_extendTransports.size());
267 }
268 
270 {
272 }
273 
274 #endif // SISCAN_H
V4LChannel * GetV4LChannel(void)
void AllGood(void) override
Signal to be sent when you have a lock on all values.
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
bool UpdateChannelInfo(bool wait_until_complete)
bool ScanCurrentTransport(const QString &sistandard)
void HandleActiveScan(void)
Handles the TRANSPORT_LIST ChannelScanSM mode.
void UpdateScanTransports(const NetworkInformationTable *nit)
transport_scan_items_t m_scanTransports
bool HasTimedOut(void)
uint m_otherTableTimeout
This table tells the decoder on which PIDs to find A/V data.
Definition: dvbtables.h:101
void run(void) override
This runs the event loop for ChannelScanSM until 'threadExit' is true.
QMap< uint32_t, DTVMultiplex > m_extendTransports
bool CheckImportedList(const DTVChannelInfoList &, 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.
void HandlePMT(uint, const ProgramMapTable *) override
DTVTunerType GuessDTVTunerType(DTVTunerType) const
volatile bool m_threadExit
static const int kTunerTypeUnknown
ScannedChannelInfo * m_currentInfo
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
DVBChannel * GetDVBChannel(void)
void HandleEncryptionStatus(uint pnum, bool encrypted) override
bool Tune(const transport_scan_items_it_t &transport)
vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:141
QMap< uint, ChannelInsertInfo > chan_info_map_t
vector< DTVTransport > DTVChannelList
Definition: dtvconfparser.h:70
bool ScanTransport(uint mplexid, bool follow_nit)
This table gives the current DVB stream time.
Definition: dvbtables.h:373
void SetSignalTimeout(uint val)
ChannelList m_channelList
Found Channel Info.
uint GetSignalTimeout(void) const
void ScanPercentComplete(int pct)
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...
unsigned int uint
Definition: compat.h:140
Provides interface to the tuning hardware when using DVB drivers.
Definition: dvbchannel.h:29
QMap< uint, pmt_vec_t > pmt_map_t
DVBSignalMonitor * GetDVBSignalMonitor(void)
static const uint kATSCTableTimeout
No logic here, lets just wait at least 10 seconds.
bool m_currentTestingDecryption
QMap< QString, IPTVChannelInfo > fbox_chan_map_t
void IgnoreEncryptedMsg(const QString &name, int aux_num)
static guint32 * tmp
Definition: goom_core.c:35
bool ScanIPTVChannels(uint sourceid, const fbox_chan_map_t &iptv_channels)
void HandleAllGood(void)
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...
void IgnoreEmptyChanMsg(const QString &name, int aux_num)
static const uint kDVBTableTimeout
SDT's should be sent every 2 seconds and NIT's every 10 seconds, so lets wait at least 30 seconds,...
MThread * m_scannerThread
Scanner thread, runs ChannelScanSM::run()
chan_info_map_t GetChannelList(transport_scan_items_it_t trans_info, ScannedChannelInfo *scan_info) const
void SetScanDTVTunerType(DTVTunerType t)
void StatusChannelTuned(const SignalMonitorValue &) override
Signal to be sent with change change status.
void IgnoreDataOnlyMsg(const QString &name, int aux_num)
ChannelScanSM * siscan
void IgnoreAudioOnlyMsg(const QString &name, int aux_num)
void SetChannelTimeout(uint val)
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:34
uint GetCurrentTransportInfo(QString &chan, QString &chan_tr) const
The CAT is used to transmit additional ConditionalAccessDescriptor instances, in addition to the ones...
Definition: mpegtables.h:818
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...
ChannelBase * m_channel
bool ScanForChannels(uint sourceid, const QString &std, const QString &cardtype, const DTVChannelList &)
void SetScanDTVTunerType(int t)
bool TestNextProgramEncryption(void)
unsigned char t
Definition: ParseText.cpp:329
HDHRChannel * GetHDHRChannel(void)
void SetAnalog(bool is_analog)
void HandleCAT(const ConditionalAccessTable *) override
AnalogSignalHandler(ChannelScanSM *_siscan)
uint GetChannelTimeout(void) const
void HandleNIT(const NetworkInformationTable *) override
void HandleTDT(const TimeDateTable *) override
void HandleSDTo(uint tsid, const ServiceDescriptionTable *) override
void SetSourceID(int _SourceID)
const char * name
Definition: ParseText.cpp:328
Implements tuning for TV cards using the V4L driver API, both versions 1 and 2.
Definition: v4lchannel.h:32
The Program Association Table lists all the programs in a stream, and is always found on PID 0.
Definition: mpegtables.h:579
QMap< uint64_t, QString > m_defAuthorities
QString m_inputName
void HandleBAT(const BouquetAssociationTable *) override
void HandleSDT(uint tsid, const ServiceDescriptionTable *) override
DTVTunerType m_scanDTVTunerType
transport_scan_items_it_t m_current
This class is intended to detect the presence of needed tables.
SignalMonitor * m_signalMonitor
list< TransportScanItem > transport_scan_items_t
Signal monitoring base class.
Definition: signalmonitor.h:32
vector< DTVChannelInfo > DTVChannelInfoList
Definition: dtvconfparser.h:60
Scanning class for cards that support a SignalMonitor class.
static QString loc(const ChannelScanSM *)
void HandlePAT(const ProgramAssociationTable *) override
vector< const ProgramMapTable * > pmt_vec_t
Abstract class providing a generic interface to tuning hardware.
Definition: channelbase.h:31
This table tells the decoder on which PIDs to find other tables, and their sizes and each table's cur...
Definition: atsctables.h:74
DTVChannel * GetDTVChannel(void)
ChannelScanSM(ScanMonitor *_scan_monitor, const QString &_cardtype, ChannelBase *_channel, int _sourceID, uint signal_timeout, uint channel_timeout, const QString &_inputname, bool test_decryption)
QSet< uint32_t > m_tsScanned
void StopScanner(void)
Stops the ChannelScanSM event loop and the signal monitor, blocking until both exit.
void HandleSTT(const SystemTimeTable *) override
bool AddToList(uint mplexid)
This table contains information about the channels transmitted on this multiplex.
Definition: atsctables.h:189
Tells what channels can be found on each transponder for one bouquet (a bunch of channels from one pr...
Definition: dvbtables.h:179
void UpdateScanPercentCompleted(void)
Updates Transport Scan progress bar.
transport_scan_items_it_t m_nextIt
SignalMonitor * GetSignalMonitor(void)
QMap< uint, uint > m_currentEncryptionStatus
void StartScanner(void)
Starts the ChannelScanSM event loop.
void HandleMGT(const MasterGuideTable *) override
void HandleNITo(const NetworkInformationTable *) override
QMap< uint, bool > m_currentEncryptionStatusChecked
This table tells the decoder on which PIDs to find other tables.
Definition: dvbtables.h:21
This table contains the GPS time at the time of transmission.
Definition: atsctables.h:683
void StatusSignalStrength(const SignalMonitorValue &) override
Signal to be sent with an actual signal value.
void LogLines(const QString &string) const
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
Definition: mpegtables.h:656
AnalogSignalHandler * m_analogSignalHandler
static const uint kMPEGTableTimeout
No logic here, lets just wait at least 15 seconds.
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 ...
QList< ChannelListItem > ChannelList
DTVSignalMonitor * GetDTVSignalMonitor(void)
void HandleVCT(uint tsid, const VirtualChannelTable *) override
QPair< transport_scan_items_it_t, ScannedChannelInfo * > ChannelListItem
ScanMonitor * m_scanMonitor
QMutex m_lock
The big lock.