MythTV  master
dvbchannel.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 /*
3  * Copyright (C) Kenneth Aafloy 2003
4  *
5  * Copyright notice is in dvbchannel.cpp of the MythTV project.
6  */
7 
8 #ifndef DVBCHANNEL_H
9 #define DVBCHANNEL_H
10 
11 #include <QMap>
12 #include <QObject>
13 #include <QString>
14 
15 #include "libmyth/mythcontext.h"
16 #include "libmythbase/mythdate.h"
17 #include "libmythbase/mythdbcon.h"
18 
19 #include "diseqc.h"
20 #include "dtvchannel.h"
21 #include "dtvconfparserhelpers.h" // for DTVTunerType
22 #include "mpeg/streamlisteners.h"
23 
24 class TVRec;
25 class DVBCam;
26 class DVBRecorder;
27 class DVBChannel;
28 
29 using IsOpenMap = QMap<const DVBChannel*,bool>;
30 
31 class DVBChannel : public DTVChannel
32 {
33  public:
34  explicit DVBChannel(QString device, TVRec *parent = nullptr);
35  ~DVBChannel() override;
36 
37  bool Open(void) override // ChannelBase
38  { return Open(this); }
39  void Close(void) override // ChannelBase
40  { Close(this); }
41 
42  bool Init(QString &startchannel, bool setchan) override; // ChannelBase
43 
44  // Sets
45  void SetPMT(const ProgramMapTable *pmt);
46  void SetTimeOffset(double offset);
47  void SetSlowTuning(std::chrono::milliseconds how_slow)
48  { m_tuningDelay = how_slow; }
49 
50  // Gets
51  bool IsOpen(void) const override; // ChannelBase
52  int GetFd(void) const override // ChannelBase
53  { return m_fdFrontend; }
54  bool IsTuningParamsProbeSupported(void) const;
55 
56  QString GetDevice(void) const override // ChannelBase
57  { return m_device; }
59  QString GetCardNum(void) const { return m_device; };
61  QString GetFrontendName(void) const { return m_frontendName; }
62  bool IsMaster(void) const override; // DTVChannel
64  bool HasCRCBug(void) const { return m_hasCrcBug; }
65  std::chrono::milliseconds GetMinSignalMonitorDelay(void) const { return m_sigMonDelay; }
67  const DiSEqCDevRotor *GetRotor(void) const;
68 
70  bool HasLock(bool *ok = nullptr) const;
72  double GetSignalStrength(bool *ok = nullptr) const;
80  double GetSNR(bool *ok = nullptr) const;
82  double GetBitErrorRate(bool *ok = nullptr) const;
84  double GetUncorrectedBlockCount(bool *ok = nullptr) const;
85  uint64_t GetCapabilities(void) const { return m_capabilities; }
86  bool CanDo(uint64_t capability) const { return (m_capabilities & capability) != 0; }
87 
88  // Commands
89  bool SwitchToInput(int newcapchannel, bool setstarting);
90  using DTVChannel::Tune;
91  bool Tune(const DTVMultiplex &tuning) override; // DTVChannel
92  bool Tune(const DTVMultiplex &tuning,
93  bool force_reset = false, bool same_input = false);
94  bool Retune(void) override; // ChannelBase
95 
96  bool ProbeTuningParams(DTVMultiplex &tuning) const;
97 
98  private:
99  bool Open(DVBChannel *who);
100  void Close(DVBChannel *who);
101 
102  int GetChanID(void) const override; // ChannelBase
103 
104  void CheckOptions(DTVMultiplex &t) const override; // DTVChannel
105  void CheckFrequency(uint64_t frequency) const;
106  bool CheckModulation(DTVModulation modulation) const;
107  bool CheckCodeRate(DTVCodeRate rate) const;
108 
109  DVBChannel *GetMasterLock(void) const;
110  static void ReturnMasterLock(DVBChannel* &dvbm);
111 
116  double GetSignalStrengthDVBv5(bool *ok) const;
121  double GetSNRDVBv5(bool *ok) const;
125  double GetBitErrorRateDVBv5(bool *ok) const;
129  double GetUncorrectedBlockCountDVBv5(bool *ok) const;
130 
131  void DrainDVBEvents(void);
132  bool WaitForBackend(std::chrono::milliseconds timeout_ms);
133 
134  private:
136 
137  // Data
140  DVBCam *m_dvbCam {nullptr}; // Used to decrypt encrypted streams
141 
142  // Device info
143  QString m_frontendName;
144  uint64_t m_capabilities {0};
145  uint64_t m_extModulations {0};
146  uint64_t m_frequencyMinimum {0};
147  uint64_t m_frequencyMaximum {0};
150 
151  uint m_version {0}; // DVB API version
152  bool m_legacyFe {false}; // Use legacy DVBv3 API
153  bool m_hasV5Stats {false}; // Use DVBv5 API for statistics
154  DTVModulationSystem m_currentSys; // Currently configured modulation system
155  QList<DTVModulationSystem> m_sysList; // List of supported modulation systems
156 
157  // Tuning State
158  mutable QMutex m_tuneLock;
159  mutable QRecursiveMutex m_hwLock;
160 
161  DTVMultiplex m_desiredTuning; // Last tuning options Tune() attempted to send to hardware
162  DTVMultiplex m_prevTuning; // Last tuning options Tune() succesfully sent to hardware
163 
165 
166  std::chrono::milliseconds m_tuningDelay { 0ms}; // Extra delay to add for broken drivers
167  std::chrono::milliseconds m_sigMonDelay {25ms}; // Minimum delay between FE_LOCK checks
168  bool m_firstTune {true}; // Used to force hardware reset
169 
170  // Other State
171  int m_fdFrontend {-1}; // File descriptor for tuning hardware
172  QString m_device; // DVB Device
173  QString m_key; // master lock key
174  bool m_hasCrcBug {false}; // true iff our driver munges PMT
175 
176  static std::chrono::milliseconds s_lastTuning; // Time of last tuning
178 };
179 
180 #endif
DVBChannel::GetFd
int GetFd(void) const override
Returns file descriptor, -1 if it does not exist.
Definition: dvbchannel.h:52
DVBChannel::CheckModulation
bool CheckModulation(DTVModulation modulation) const
Return true iff modulation is supported modulation on the frontend.
Definition: dvbchannel.cpp:702
DTVMultiplex
Definition: dtvmultiplex.h:24
dtvchannel.h
DVBChannel::GetUncorrectedBlockCount
double GetUncorrectedBlockCount(bool *ok=nullptr) const
Returns # of uncorrected blocks since last call. First call undefined.
Definition: dvbchannel.cpp:1493
DVBChannel::Init
bool Init(QString &startchannel, bool setchan) override
Definition: dvbchannel.cpp:553
DVBChannel::m_extModulations
uint64_t m_extModulations
Definition: dvbchannel.h:145
DVBChannel::ReturnMasterLock
static void ReturnMasterLock(DVBChannel *&dvbm)
Definition: dvbchannel.cpp:1524
DVBChannel::m_currentSys
DTVModulationSystem m_currentSys
Definition: dvbchannel.h:154
DVBChannel::m_tuneLock
QMutex m_tuneLock
Definition: dvbchannel.h:158
DVBChannel::IsTuningParamsProbeSupported
bool IsTuningParamsProbeSupported(void) const
Returns true iff tuning info probing is working.
Definition: dvbchannel.cpp:989
DVBChannel::m_frontendName
QString m_frontendName
Definition: dvbchannel.h:143
DVBChannel::GetRotor
const DiSEqCDevRotor * GetRotor(void) const
Returns rotor object if it exists, nullptr otherwise.
Definition: dvbchannel.cpp:1159
DiSEqCDevRotor
Rotor class.
Definition: diseqc.h:302
DVBChannel::m_frequencyMinimum
uint64_t m_frequencyMinimum
Definition: dvbchannel.h:146
DVBChannel::DVBChannel
DVBChannel(QString device, TVRec *parent=nullptr)
Definition: dvbchannel.cpp:81
DVBChannel::GetBitErrorRateDVBv5
double GetBitErrorRateDVBv5(bool *ok) const
Get Bit Error Rate from the DVBv5 interface.
Definition: dvbchannel.cpp:1375
DVBChannel::CheckCodeRate
bool CheckCodeRate(DTVCodeRate rate) const
Return true iff rate is supported rate on the frontend.
Definition: dvbchannel.cpp:683
DVBChannel::CanDo
bool CanDo(uint64_t capability) const
Definition: dvbchannel.h:86
diseqc.h
DVBChannel::GetCapabilities
uint64_t GetCapabilities(void) const
Definition: dvbchannel.h:85
ProgramMapTable
A PMT table maps a program described in the ProgramAssociationTable to various PID's which describe t...
Definition: mpegtables.h:694
DVBChannel::CheckOptions
void CheckOptions(DTVMultiplex &t) const override
Checks tuning for problems, and tries to fix them.
Definition: dvbchannel.cpp:576
mythdbcon.h
DVBChannel::m_symbolRateMaximum
uint m_symbolRateMaximum
Definition: dvbchannel.h:149
x0
static int x0
Definition: mythsocket.cpp:49
streamlisteners.h
DTVChannel::Tune
virtual bool Tune(const DTVMultiplex &tuning)=0
This performs the actual frequency tuning and in some cases input switching.
DVBChannel::m_key
QString m_key
Definition: dvbchannel.h:173
DVBChannel::GetSignalStrength
double GetSignalStrength(bool *ok=nullptr) const
Returns signal strength in the range [0.0..1.0] (non-calibrated).
Definition: dvbchannel.cpp:1257
DVBChannel::SetPMT
void SetPMT(const ProgramMapTable *pmt)
Tells the Conditional Access Module which streams we wish to decode.
Definition: dvbchannel.cpp:727
DVBChannel::m_isOpen
IsOpenMap m_isOpen
Definition: dvbchannel.h:135
DVBChannel::m_frequencyMaximum
uint64_t m_frequencyMaximum
Definition: dvbchannel.h:147
DVBChannel::SwitchToInput
bool SwitchToInput(int newcapchannel, bool setstarting)
DVBChannel::IsMaster
bool IsMaster(void) const override
Returns true if this is the first of a number of multi-rec devs.
Definition: dvbchannel.cpp:1540
DTVCodeRate
Definition: dtvconfparserhelpers.h:280
DVBChannel::m_capabilities
uint64_t m_capabilities
Definition: dvbchannel.h:144
DiSEqCDevSettings
DVB-S device settings class.
Definition: diseqc.h:36
DVBCam
Definition: dvbcam.h:22
DVBChannel::m_prevTuning
DTVMultiplex m_prevTuning
Definition: dvbchannel.h:162
mythdate.h
DVBChannel::m_dvbCam
DVBCam * m_dvbCam
Definition: dvbchannel.h:140
DVBChannel::SetSlowTuning
void SetSlowTuning(std::chrono::milliseconds how_slow)
Definition: dvbchannel.h:47
DVBChannel::GetDevice
QString GetDevice(void) const override
Returns String representing device, useful for debugging.
Definition: dvbchannel.h:56
DVBChannel::m_hasV5Stats
bool m_hasV5Stats
Definition: dvbchannel.h:153
hardwareprofile.i18n.t
t
Definition: i18n.py:36
DVBChannel::WaitForBackend
bool WaitForBackend(std::chrono::milliseconds timeout_ms)
Waits for backend to get tune message.
Definition: dvbchannel.cpp:1587
DVBChannel::Tune
bool Tune(const DTVMultiplex &tuning) override
This performs the actual frequency tuning and in some cases input switching.
Definition: dvbchannel.cpp:745
DVBChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: dvbchannel.h:39
DVBChannel::~DVBChannel
~DVBChannel() override
Definition: dvbchannel.cpp:107
DVBChannel::GetSNR
double GetSNR(bool *ok=nullptr) const
Returns signal/noise in the range [0..1.0].
Definition: dvbchannel.cpp:1342
DVBChannel::m_symbolRateMinimum
uint m_symbolRateMinimum
Definition: dvbchannel.h:148
DVBChannel::m_sysList
QList< DTVModulationSystem > m_sysList
Definition: dvbchannel.h:155
DVBChannel::m_fdFrontend
int m_fdFrontend
Definition: dvbchannel.h:171
DVBChannel::m_version
uint m_version
Definition: dvbchannel.h:151
DVBChannel::m_diseqcSettings
DiSEqCDevSettings m_diseqcSettings
Definition: dvbchannel.h:138
DVBChannel::m_sigMonDelay
std::chrono::milliseconds m_sigMonDelay
Definition: dvbchannel.h:167
uint
unsigned int uint
Definition: compat.h:81
DVBChannel::m_legacyFe
bool m_legacyFe
Definition: dvbchannel.h:152
DVBChannel::m_lastLnbDevId
uint m_lastLnbDevId
Definition: dvbchannel.h:164
DVBChannel::m_desiredTuning
DTVMultiplex m_desiredTuning
Definition: dvbchannel.h:161
DVBChannel::GetUncorrectedBlockCountDVBv5
double GetUncorrectedBlockCountDVBv5(bool *ok) const
Get Uncorrected Block Count from the DVBv5 interface.
Definition: dvbchannel.cpp:1456
DVBRecorder
This is a specialization of DTVRecorder used to handle streams from DVB drivers.
Definition: dvbrecorder.h:21
DVBChannel::Retune
bool Retune(void) override
Definition: dvbchannel.cpp:981
DVBChannel::GetMinSignalMonitorDelay
std::chrono::milliseconds GetMinSignalMonitorDelay(void) const
Definition: dvbchannel.h:65
DVBChannel::GetBitErrorRate
double GetBitErrorRate(bool *ok=nullptr) const
Returns # of corrected bits since last call. First call undefined.
Definition: dvbchannel.cpp:1425
DVBChannel
Provides interface to the tuning hardware when using DVB drivers.
Definition: dvbchannel.h:31
DVBChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: dvbchannel.h:37
DVBChannel::GetSNRDVBv5
double GetSNRDVBv5(bool *ok) const
Get SNR from the DVBv5 interface [0-1.0] It is transformed to a linear relative scale if provided in ...
Definition: dvbchannel.cpp:1290
DVBChannel::m_hwLock
QRecursiveMutex m_hwLock
Definition: dvbchannel.h:159
DVBChannel::HasCRCBug
bool HasCRCBug(void) const
Returns true iff we have a faulty DVB driver that munges PMT.
Definition: dvbchannel.h:64
DTVModulationSystem
Definition: dtvconfparserhelpers.h:644
IsOpenMap
QMap< const DVBChannel *, bool > IsOpenMap
Definition: dvbchannel.h:29
DVBChannel::GetFrontendName
QString GetFrontendName(void) const
Returns frontend name as reported by driver.
Definition: dvbchannel.h:61
DVBChannel::m_firstTune
bool m_firstTune
Definition: dvbchannel.h:168
DVBChannel::SetTimeOffset
void SetTimeOffset(double offset)
Tells the Conditional Access Module the offset from the computers utc time to dvb time.
Definition: dvbchannel.cpp:739
DVBChannel::m_tuningDelay
std::chrono::milliseconds m_tuningDelay
Definition: dvbchannel.h:166
DVBChannel::CheckFrequency
void CheckFrequency(uint64_t frequency) const
Checks tuning frequency.
Definition: dvbchannel.cpp:564
DVBChannel::m_diseqcTree
DiSEqCDevTree * m_diseqcTree
Definition: dvbchannel.h:139
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
mythcontext.h
DVBChannel::ProbeTuningParams
bool ProbeTuningParams(DTVMultiplex &tuning) const
Fetches DTVMultiplex params from driver.
Definition: dvbchannel.cpp:1035
DVBChannel::HasLock
bool HasLock(bool *ok=nullptr) const
Returns true iff we have a signal carrier lock.
Definition: dvbchannel.cpp:1167
DVBChannel::m_hasCrcBug
bool m_hasCrcBug
Definition: dvbchannel.h:174
DVBChannel::m_device
QString m_device
Definition: dvbchannel.h:172
DiSEqCDevTree
DVB-S device tree class. Represents a tree of DVB-S devices.
Definition: diseqc.h:74
DVBChannel::GetMasterLock
DVBChannel * GetMasterLock(void) const
Definition: dvbchannel.cpp:1531
DVBChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: dvbchannel.cpp:545
DVBChannel::GetChanID
int GetChanID(void) const override
Returns Channel ID.
Definition: dvbchannel.cpp:1095
DTVChannel
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:33
DVBChannel::DrainDVBEvents
void DrainDVBEvents(void)
Definition: dvbchannel.cpp:1552
DVBChannel::GetSignalStrengthDVBv5
double GetSignalStrengthDVBv5(bool *ok) const
Get Signal strength from the DVBv5 interface [0-1.0] It is transformed to a linear relative scale if ...
Definition: dvbchannel.cpp:1201
DVBChannel::m_tuneDelayLock
QMutex m_tuneDelayLock
Definition: dvbchannel.h:177
DVBChannel::s_lastTuning
static std::chrono::milliseconds s_lastTuning
Definition: dvbchannel.h:176
dtvconfparserhelpers.h
DVBChannel::GetCardNum
QString GetCardNum(void) const
Returns DVB device number, used to construct filenames for DVB devices.
Definition: dvbchannel.h:59
DTVModulation
Definition: dtvconfparserhelpers.h:347