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