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  QString TunerSet(const QString &name, const QString &value);
80 
81  bool Open(void);
82  void Close(void);
83 
84  void run(void) override; // MThread
85 
86  bool UpdateFilters(void) override; // StreamHandler
87 
88  private:
89  hdhomerun_device_t *m_hdhomerunDevice {nullptr};
90  hdhomerun_device_selector_t *m_deviceSelector {nullptr};
91  int m_tuner {-1};
92  std::vector<DTVTunerType> m_tunerTypes;
93  HDHRTuneMode m_tuneMode {hdhrTuneModeNone}; // debug self check
94  int m_majorId;
95 
96 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
97  mutable QMutex m_hdhrLock {QMutex::Recursive};
98 #else
99  mutable QRecursiveMutex m_hdhrLock;
100 #endif
101 
102  // for implementing Get & Return
103  static QMutex s_handlersLock;
104  static QMap<int, HDHRStreamHandler*> s_handlers;
105  static QMap<int, uint> s_handlersRefCnt;
106 };
107 
108 #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::TunerSet
QString TunerSet(const QString &name, const QString &value)
Definition: hdhrstreamhandler.cpp:446
HDHRStreamHandler::TunerGet
QString TunerGet(const QString &name)
Definition: hdhrstreamhandler.cpp:414
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:92
HDHRStreamHandler::s_handlersRefCnt
static QMap< int, uint > s_handlersRefCnt
Definition: hdhrstreamhandler.h:105
HDHRStreamHandler::m_deviceSelector
hdhomerun_device_selector_t * m_deviceSelector
Definition: hdhrstreamhandler.h:90
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:542
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::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:89
HDHRStreamHandler::IsConnected
bool IsConnected(void) const
Definition: hdhrstreamhandler.cpp:503
uint
unsigned int uint
Definition: compat.h:81
HDHRStreamHandler::m_tuneMode
HDHRTuneMode m_tuneMode
Definition: hdhrstreamhandler.h:93
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:91
HDHRStreamHandler::Open
bool Open(void)
Definition: hdhrstreamhandler.cpp:301
HDHRStreamHandler::TuneChannel
bool TuneChannel(const QString &chanid)
Definition: hdhrstreamhandler.cpp:508
HDHRStreamHandler::m_hdhrLock
QRecursiveMutex m_hdhrLock
Definition: hdhrstreamhandler.h:99
HDHRStreamHandler::m_majorId
int m_majorId
Definition: hdhrstreamhandler.h:94
HDHRStreamHandler::GetTunerStatus
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
Definition: hdhrstreamhandler.cpp:496
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:525
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:103
DeviceReadBuffer.h
HDHRTuneMode
HDHRTuneMode
Definition: hdhrstreamhandler.h:35
dtvconfparserhelpers.h
HDHRStreamHandler::s_handlers
static QMap< int, HDHRStreamHandler * > s_handlers
Definition: hdhrstreamhandler.h:104