MythTV  master
hdhrstreamhandler.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef HDHRSTREAMHANDLER_H
4 #define HDHRSTREAMHANDLER_H
5 
6 #include <vector>
7 
8 #include <QString>
9 #include <QMutex>
10 #include <QMap>
11 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
12 #include <QRecursiveMutex>
13 #endif
14 
15 #include "mythdate.h"
16 #include "DeviceReadBuffer.h"
17 #include "mpegstreamdata.h"
18 #include "streamhandler.h"
19 #include "dtvconfparserhelpers.h"
20 
21 class HDHRStreamHandler;
22 class DTVSignalMonitor;
23 class HDHRChannel;
24 class DeviceReadBuffer;
25 
26 // HDHomeRun headers
27 #ifdef USING_HDHOMERUN
28 #include HDHOMERUN_HEADERFILE
29 #else
30 struct hdhomerun_device_t { int dummy; };
31 struct hdhomerun_device_selector_t { int dummy; };
32 #endif
33 
40 };
41 
42 // Note : This class never uses a DRB && always uses a TS reader.
43 
44 // locking order
45 // _pid_lock -> _listener_lock -> _start_stop_lock
46 // -> _hdhr_lock
47 
49 {
50  public:
51  static HDHRStreamHandler *Get(const QString &devname, int inputid,
52  int majorid);
53  static void Return(HDHRStreamHandler * & ref, int inputid);
54 
56  bool /*allow_section_reader*/ = false,
57  bool /*needs_drb*/ = false,
58  const QString& output_file = QString()) override // StreamHandler
59  {
60  StreamHandler::AddListener(data, false, false, output_file);
61  }
62 
63  void GetTunerStatus(struct hdhomerun_tuner_status_t *status);
64  bool IsConnected(void) const;
65  std::vector<DTVTunerType> GetTunerTypes(void) const { return m_tunerTypes; }
66 
67  // Commands
68  bool TuneChannel(const QString &chanid);
69  bool TuneProgram(uint mpeg_prog_num);
70  bool TuneVChannel(const QString &vchn);
71 
72  private:
73  explicit HDHRStreamHandler(const QString &device, int inputid, int majorid);
74 
75  bool Connect(void);
76 
77  QString TunerGet(const QString &name,
78  bool report_error_return = true,
79  bool print_error = true) const;
80  QString TunerSet(const QString &name, const QString &value,
81  bool report_error_return = true,
82  bool print_error = true);
83 
84  bool Open(void);
85  void Close(void);
86 
87  void run(void) override; // MThread
88 
89  bool UpdateFilters(void) override; // StreamHandler
90 
91  private:
92  hdhomerun_device_t *m_hdhomerunDevice {nullptr};
93  hdhomerun_device_selector_t *m_deviceSelector {nullptr};
94  int m_tuner {-1};
95  std::vector<DTVTunerType> m_tunerTypes;
96  HDHRTuneMode m_tuneMode {hdhrTuneModeNone}; // debug self check
97  int m_majorId;
98 
99 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
100  mutable QMutex m_hdhrLock {QMutex::Recursive};
101 #else
102  mutable QRecursiveMutex m_hdhrLock;
103 #endif
104 
105  // for implementing Get & Return
106  static QMutex s_handlersLock;
107  static QMap<int, HDHRStreamHandler*> s_handlers;
108  static QMap<int, uint> s_handlersRefCnt;
109 };
110 
111 #endif // HDHRSTREAMHANDLER_H
HDHRStreamHandler::Close
void Close(void)
Definition: hdhrstreamhandler.cpp:356
streamhandler.h
HDHRStreamHandler::run
void run(void) override
Reads HDHomeRun socket for tables & data.
Definition: hdhrstreamhandler.cpp:111
HDHRStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: hdhrstreamhandler.h:55
StreamHandler
Definition: streamhandler.h:57
hdhrTuneModeNone
@ hdhrTuneModeNone
Definition: hdhrstreamhandler.h:35
hdhrTuneModeFrequency
@ hdhrTuneModeFrequency
Definition: hdhrstreamhandler.h:36
HDHRStreamHandler::m_tunerTypes
std::vector< DTVTunerType > m_tunerTypes
Definition: hdhrstreamhandler.h:95
HDHRStreamHandler::s_handlersRefCnt
static QMap< int, uint > s_handlersRefCnt
Definition: hdhrstreamhandler.h:108
HDHRStreamHandler::m_deviceSelector
hdhomerun_device_selector_t * m_deviceSelector
Definition: hdhrstreamhandler.h:93
HDHRStreamHandler::Connect
bool Connect(void)
Definition: hdhrstreamhandler.cpp:371
DeviceReadBuffer
Buffers reads from device files.
Definition: DeviceReadBuffer.h:34
HDHRStreamHandler::TuneVChannel
bool TuneVChannel(const QString &vchn)
Definition: hdhrstreamhandler.cpp:542
HDHRChannel
Definition: hdhrchannel.h:20
HDHRStreamHandler::GetTunerTypes
std::vector< DTVTunerType > GetTunerTypes(void) const
Definition: hdhrstreamhandler.h:65
hdhrTuneModeFrequencyPid
@ hdhrTuneModeFrequencyPid
Definition: hdhrstreamhandler.h:37
hdhrTuneModeVChannel
@ hdhrTuneModeVChannel
Definition: hdhrstreamhandler.h:39
mythdate.h
HDHRStreamHandler::TunerGet
QString TunerGet(const QString &name, bool report_error_return=true, bool print_error=true) const
Definition: hdhrstreamhandler.cpp:410
HDHRStreamHandler::Return
static void Return(HDHRStreamHandler *&ref, int inputid)
Definition: hdhrstreamhandler.cpp:63
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:84
HDHRStreamHandler::m_hdhomerunDevice
hdhomerun_device_t * m_hdhomerunDevice
Definition: hdhrstreamhandler.h:92
HDHRStreamHandler::IsConnected
bool IsConnected(void) const
Definition: hdhrstreamhandler.cpp:503
uint
unsigned int uint
Definition: compat.h:140
HDHRStreamHandler::m_tuneMode
HDHRTuneMode m_tuneMode
Definition: hdhrstreamhandler.h:96
mpegstreamdata.h
HDHRStreamHandler::HDHRStreamHandler
HDHRStreamHandler(const QString &device, int inputid, int majorid)
Definition: hdhrstreamhandler.cpp:100
hdhrTuneModeFrequencyProgram
@ hdhrTuneModeFrequencyProgram
Definition: hdhrstreamhandler.h:38
HDHRStreamHandler
Definition: hdhrstreamhandler.h:48
HDHRStreamHandler::m_tuner
int m_tuner
Definition: hdhrstreamhandler.h:94
HDHRStreamHandler::Open
bool Open(void)
Definition: hdhrstreamhandler.cpp:297
HDHRStreamHandler::TuneChannel
bool TuneChannel(const QString &chanid)
Definition: hdhrstreamhandler.cpp:508
HDHRStreamHandler::m_hdhrLock
QRecursiveMutex m_hdhrLock
Definition: hdhrstreamhandler.h:102
HDHRStreamHandler::m_majorId
int m_majorId
Definition: hdhrstreamhandler.h:97
HDHRStreamHandler::GetTunerStatus
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
Definition: hdhrstreamhandler.cpp:496
HDHRStreamHandler::UpdateFilters
bool UpdateFilters(void) override
Definition: hdhrstreamhandler.cpp:235
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:14
StreamHandler::AddListener
virtual void AddListener(MPEGStreamData *data, bool allow_section_reader=false, bool needs_buffering=false, const QString &output_file=QString())
Definition: streamhandler.cpp:33
HDHRStreamHandler::TuneProgram
bool TuneProgram(uint mpeg_prog_num)
Definition: hdhrstreamhandler.cpp:525
HDHRStreamHandler::TunerSet
QString TunerSet(const QString &name, const QString &value, bool report_error_return=true, bool print_error=true)
Definition: hdhrstreamhandler.cpp:447
HDHRStreamHandler::Get
static HDHRStreamHandler * Get(const QString &devname, int inputid, int majorid)
Definition: hdhrstreamhandler.cpp:32
HDHRStreamHandler::s_handlersLock
static QMutex s_handlersLock
Definition: hdhrstreamhandler.h:106
DeviceReadBuffer.h
HDHRTuneMode
HDHRTuneMode
Definition: hdhrstreamhandler.h:34
dtvconfparserhelpers.h
HDHRStreamHandler::s_handlers
static QMap< int, HDHRStreamHandler * > s_handlers
Definition: hdhrstreamhandler.h:107