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 
12 #include "mythdate.h"
13 #include "DeviceReadBuffer.h"
14 #include "mpegstreamdata.h"
15 #include "streamhandler.h"
16 #include "dtvconfparserhelpers.h"
17 
18 class HDHRStreamHandler;
19 class DTVSignalMonitor;
20 class HDHRChannel;
21 class DeviceReadBuffer;
22 
23 // HDHomeRun headers
24 #ifdef USING_HDHOMERUN
25 #include HDHOMERUN_HEADERFILE
26 #else
27 struct hdhomerun_device_t { int dummy; };
28 struct hdhomerun_device_selector_t { int dummy; };
29 #endif
30 
37 };
38 
39 // Note : This class never uses a DRB && always uses a TS reader.
40 
41 // locking order
42 // _pid_lock -> _listener_lock -> _start_stop_lock
43 // -> _hdhr_lock
44 
46 {
47  public:
48  static HDHRStreamHandler *Get(const QString &devname, int inputid,
49  int majorid);
50  static void Return(HDHRStreamHandler * & ref, int inputid);
51 
53  bool /*allow_section_reader*/ = false,
54  bool /*needs_drb*/ = false,
55  const QString& output_file = QString()) override // StreamHandler
56  {
57  StreamHandler::AddListener(data, false, false, output_file);
58  }
59 
60  void GetTunerStatus(struct hdhomerun_tuner_status_t *status);
61  bool IsConnected(void) const;
62  std::vector<DTVTunerType> GetTunerTypes(void) const { return m_tunerTypes; }
63 
64  // Commands
65  bool TuneChannel(const QString &chanid);
66  bool TuneProgram(uint mpeg_prog_num);
67  bool TuneVChannel(const QString &vchn);
68 
69  private:
70  explicit HDHRStreamHandler(const QString &device, int inputid, int majorid);
71 
72  bool Connect(void);
73 
74  QString TunerGet(const QString &name,
75  bool report_error_return = true,
76  bool print_error = true) const;
77  QString TunerSet(const QString &name, const QString &value,
78  bool report_error_return = true,
79  bool print_error = true);
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  mutable QMutex m_hdhrLock {QMutex::Recursive};
97 
98  // for implementing Get & Return
99  static QMutex s_handlersLock;
100  static QMap<int, HDHRStreamHandler*> s_handlers;
101  static QMap<int, uint> s_handlersRefCnt;
102 };
103 
104 #endif // HDHRSTREAMHANDLER_H
HDHRStreamHandler::Close
void Close(void)
Definition: hdhrstreamhandler.cpp:355
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:52
StreamHandler
Definition: streamhandler.h:55
hdhrTuneModeNone
@ hdhrTuneModeNone
Definition: hdhrstreamhandler.h:32
hdhrTuneModeFrequency
@ hdhrTuneModeFrequency
Definition: hdhrstreamhandler.h:33
HDHRStreamHandler::m_tunerTypes
std::vector< DTVTunerType > m_tunerTypes
Definition: hdhrstreamhandler.h:92
HDHRStreamHandler::s_handlersRefCnt
static QMap< int, uint > s_handlersRefCnt
Definition: hdhrstreamhandler.h:101
HDHRStreamHandler::m_deviceSelector
hdhomerun_device_selector_t * m_deviceSelector
Definition: hdhrstreamhandler.h:90
HDHRStreamHandler::Connect
bool Connect(void)
Definition: hdhrstreamhandler.cpp:370
DeviceReadBuffer
Buffers reads from device files.
Definition: DeviceReadBuffer.h:35
HDHRStreamHandler::TuneVChannel
bool TuneVChannel(const QString &vchn)
Definition: hdhrstreamhandler.cpp:541
HDHRChannel
Definition: hdhrchannel.h:21
HDHRStreamHandler::GetTunerTypes
std::vector< DTVTunerType > GetTunerTypes(void) const
Definition: hdhrstreamhandler.h:62
hdhrTuneModeFrequencyPid
@ hdhrTuneModeFrequencyPid
Definition: hdhrstreamhandler.h:34
hdhrTuneModeVChannel
@ hdhrTuneModeVChannel
Definition: hdhrstreamhandler.h:36
mythdate.h
HDHRStreamHandler::TunerGet
QString TunerGet(const QString &name, bool report_error_return=true, bool print_error=true) const
Definition: hdhrstreamhandler.cpp:409
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:85
HDHRStreamHandler::m_hdhomerunDevice
hdhomerun_device_t * m_hdhomerunDevice
Definition: hdhrstreamhandler.h:89
HDHRStreamHandler::IsConnected
bool IsConnected(void) const
Definition: hdhrstreamhandler.cpp:502
HDHRStreamHandler::m_hdhrLock
QMutex m_hdhrLock
Definition: hdhrstreamhandler.h:96
uint
unsigned int uint
Definition: compat.h:141
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:100
hdhrTuneModeFrequencyProgram
@ hdhrTuneModeFrequencyProgram
Definition: hdhrstreamhandler.h:35
HDHRStreamHandler
Definition: hdhrstreamhandler.h:46
HDHRStreamHandler::m_tuner
int m_tuner
Definition: hdhrstreamhandler.h:91
HDHRStreamHandler::Open
bool Open(void)
Definition: hdhrstreamhandler.cpp:296
HDHRStreamHandler::TuneChannel
bool TuneChannel(const QString &chanid)
Definition: hdhrstreamhandler.cpp:507
HDHRStreamHandler::m_majorId
int m_majorId
Definition: hdhrstreamhandler.h:94
HDHRStreamHandler::GetTunerStatus
void GetTunerStatus(struct hdhomerun_tuner_status_t *status)
Definition: hdhrstreamhandler.cpp:495
HDHRStreamHandler::UpdateFilters
bool UpdateFilters(void) override
Definition: hdhrstreamhandler.cpp:234
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:19
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:524
HDHRStreamHandler::TunerSet
QString TunerSet(const QString &name, const QString &value, bool report_error_return=true, bool print_error=true)
Definition: hdhrstreamhandler.cpp:446
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:99
DeviceReadBuffer.h
HDHRTuneMode
HDHRTuneMode
Definition: hdhrstreamhandler.h:31
dtvconfparserhelpers.h
HDHRStreamHandler::s_handlers
static QMap< int, HDHRStreamHandler * > s_handlers
Definition: hdhrstreamhandler.h:100