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