MythTV  master
satipstreamhandler.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef SATIPSTREAMHANDLER_H
4 #define SATIPSTREAMHANDLER_H
5 
6 // Qt headers
7 #include <QString>
8 #include <QStringList>
9 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
10 #include <QMutex>
11 #else
12 #include <QRecursiveMutex>
13 #endif
14 #include <QMap>
15 
16 // MythTV headers
17 #include "dtvconfparserhelpers.h"
18 #include "dtvmultiplex.h"
19 #include "mpeg/mpegstreamdata.h"
20 #include "satiprtsp.h"
21 #include "streamhandler.h"
22 
25 
27 {
28  friend class SatIPDataReadHelper;
29 
30  public:
31  static SatIPStreamHandler *Get(const QString &devname, int inputid);
32  static void Return(SatIPStreamHandler * & ref, int inputid);
33 
35  bool /*allow_section_reader*/ = false,
36  bool /*needs_drb*/ = false,
37  const QString& output_file = QString()) override // StreamHandler
38  {
39  StreamHandler::AddListener(data, false, false, output_file);
40  } // StreamHandler
41 
42  bool UpdateFilters() override; // StreamHandler
43  bool Tune(const DTVMultiplex &tuning);
44 
45  private:
46  explicit SatIPStreamHandler(const QString & device, int inputid);
47 
48  bool Open(void);
49  void Close(void);
50 
51  void run(void) override; // MThread
52 
53  // For implementing Get & Return
54  static QMap<QString, SatIPStreamHandler*> s_handlers;
55  static QMap<QString, uint> s_handlersRefCnt;
56  static QMutex s_handlersLock;
57 
58  public:
59  int m_inputId {0};
60  int m_satipsrc {1};
61 
62  private:
64  QString m_device;
65  uint m_frontend {UINT_MAX};
66  QUrl m_baseurl;
69  bool m_setupinvoked {false};
70 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
71  QMutex m_tunelock {QMutex::Recursive};
72 #else
73  QRecursiveMutex m_tunelock;
74 #endif
75  QStringList m_oldpids;
76 
77  public:
78  QUdpSocket *m_dsocket {nullptr}; // RTP data socket
79  QUdpSocket *m_csocket {nullptr}; // RTCP control socket
80  ushort m_dport {0}; // RTP data port Note: this is m_dsocket->localPort()
81  ushort m_cport {0}; // RTCP control port Note: this is m_csocket->localPort()
82 
83  public:
84  SatIPRTSP *m_rtsp {nullptr};
87 
88  public:
89  bool HasLock();
90  int GetSignalStrength();
91  void SetSigmonValues(bool lock, int level);
92 
93  private:
94  QMutex m_sigmonLock;
95  bool m_hasLock {false};
97 
98  public:
99  static uint GetUDPReceiveBufferSize(QUdpSocket *socket);
100  static uint SetUDPReceiveBufferSize(QUdpSocket *socket, uint rcvbuffersize);
101 };
102 
103 // --- SatIPDataReadHelper ---------------------------------------------------
104 
105 class SatIPDataReadHelper : public QObject
106 {
107  Q_OBJECT
108 
109  public:
110  explicit SatIPDataReadHelper(SatIPStreamHandler *handler);
111  ~SatIPDataReadHelper() override;
112 
113  public slots:
114  void ReadPending(void);
115 
116  private:
118  QUdpSocket *m_socket {nullptr};
119  int m_timer {0};
122  bool m_valid {false};
123 };
124 
125 // --- SatIPControlReadHelper ------------------------------------------------
126 
127 class SatIPControlReadHelper : public QObject
128 {
129  Q_OBJECT
130 
131  public:
132  explicit SatIPControlReadHelper(SatIPStreamHandler *handler);
133  ~SatIPControlReadHelper() override = default;
134 
135  public slots:
136  void ReadPending(void);
137 
138  private:
140  QUdpSocket *m_socket {nullptr};
141 };
142 
143 #endif // SATIPSTREAMHANDLER_H
DTVMultiplex
Definition: dtvmultiplex.h:24
SatIPControlReadHelper::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satipstreamhandler.h:139
streamhandler.h
SatIPStreamHandler::m_dport
ushort m_dport
Definition: satipstreamhandler.h:80
StreamHandler
Definition: streamhandler.h:58
SatIPStreamHandler::m_sigmonLock
QMutex m_sigmonLock
Definition: satipstreamhandler.h:94
SatIPStreamHandler::m_tuningurl
QUrl m_tuningurl
Definition: satipstreamhandler.h:67
SatIPDataReadHelper::ReadPending
void ReadPending(void)
Definition: satipstreamhandler.cpp:541
SatIPStreamHandler::m_signalStrength
int m_signalStrength
Definition: satipstreamhandler.h:96
SatIPStreamHandler::m_dsocket
QUdpSocket * m_dsocket
Definition: satipstreamhandler.h:78
SatIPControlReadHelper::~SatIPControlReadHelper
~SatIPControlReadHelper() override=default
SatIPStreamHandler::m_rtsp
SatIPRTSP * m_rtsp
Definition: satipstreamhandler.h:84
SatIPStreamHandler::m_oldtuningurl
QUrl m_oldtuningurl
Definition: satipstreamhandler.h:68
dtvmultiplex.h
SatIPStreamHandler::s_handlersRefCnt
static QMap< QString, uint > s_handlersRefCnt
Definition: satipstreamhandler.h:55
SatIPStreamHandler::HasLock
bool HasLock()
Definition: satipstreamhandler.cpp:484
DTVTunerType
Definition: dtvconfparserhelpers.h:76
SatIPStreamHandler::SetUDPReceiveBufferSize
static uint SetUDPReceiveBufferSize(QUdpSocket *socket, uint rcvbuffersize)
Set receive buffer size of UDP socket.
Definition: satipstreamhandler.cpp:725
SatIPControlReadHelper
Definition: satipstreamhandler.h:127
SatIPDataReadHelper::m_sequenceNumber
uint m_sequenceNumber
Definition: satipstreamhandler.h:120
SatIPStreamHandler::SetSigmonValues
void SetSigmonValues(bool lock, int level)
Definition: satipstreamhandler.cpp:496
SatIPStreamHandler::Return
static void Return(SatIPStreamHandler *&ref, int inputid)
Definition: satipstreamhandler.cpp:63
SatIPDataReadHelper::m_timer
int m_timer
Definition: satipstreamhandler.h:119
SatIPControlReadHelper::ReadPending
void ReadPending(void)
Definition: satipstreamhandler.cpp:645
SatIPStreamHandler::Open
bool Open(void)
Definition: satipstreamhandler.cpp:439
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:85
SatIPStreamHandler::m_tunerType
DTVTunerType m_tunerType
Definition: satipstreamhandler.h:63
SatIPStreamHandler::GetSignalStrength
int GetSignalStrength()
Definition: satipstreamhandler.cpp:490
SatIPControlReadHelper::SatIPControlReadHelper
SatIPControlReadHelper(SatIPStreamHandler *handler)
Definition: satipstreamhandler.cpp:632
SatIPStreamHandler::SatIPStreamHandler
SatIPStreamHandler(const QString &device, int inputid)
Definition: satipstreamhandler.cpp:108
SatIPStreamHandler::m_hasLock
bool m_hasLock
Definition: satipstreamhandler.h:95
uint
unsigned int uint
Definition: compat.h:79
mpegstreamdata.h
SatIPStreamHandler::Close
void Close(void)
Definition: satipstreamhandler.cpp:477
SatIPStreamHandler::m_satipsrc
int m_satipsrc
Definition: satipstreamhandler.h:60
SatIPStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: satipstreamhandler.h:34
SatIPControlReadHelper::m_socket
QUdpSocket * m_socket
Definition: satipstreamhandler.h:140
SatIPStreamHandler::m_baseurl
QUrl m_baseurl
Definition: satipstreamhandler.h:66
SatIPDataReadHelper::m_count
uint m_count
Definition: satipstreamhandler.h:121
SatIPDataReadHelper::SatIPDataReadHelper
SatIPDataReadHelper(SatIPStreamHandler *handler)
Definition: satipstreamhandler.cpp:516
SatIPDataReadHelper::m_socket
QUdpSocket * m_socket
Definition: satipstreamhandler.h:118
SatIPStreamHandler::UpdateFilters
bool UpdateFilters() override
Definition: satipstreamhandler.cpp:234
SatIPStreamHandler::m_cport
ushort m_cport
Definition: satipstreamhandler.h:81
satiprtsp.h
SatIPStreamHandler::s_handlersLock
static QMutex s_handlersLock
Definition: satipstreamhandler.h:56
SatIPDataReadHelper::~SatIPDataReadHelper
~SatIPDataReadHelper() override
Definition: satipstreamhandler.cpp:536
SatIPStreamHandler::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: satipstreamhandler.cpp:279
SatIPDataReadHelper
Definition: satipstreamhandler.h:105
SatIPRTSP
-*- Mode: c++ -*-
Definition: satiprtsp.h:25
SatIPStreamHandler::m_dataReadHelper
SatIPDataReadHelper * m_dataReadHelper
Definition: satipstreamhandler.h:85
SatIPStreamHandler::Get
static SatIPStreamHandler * Get(const QString &devname, int inputid)
Definition: satipstreamhandler.cpp:32
SatIPStreamHandler::m_setupinvoked
bool m_setupinvoked
Definition: satipstreamhandler.h:69
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
SatIPStreamHandler::GetUDPReceiveBufferSize
static uint GetUDPReceiveBufferSize(QUdpSocket *socket)
Get receive buffer size of UDP socket.
Definition: satipstreamhandler.cpp:710
SatIPStreamHandler::m_tunelock
QRecursiveMutex m_tunelock
Definition: satipstreamhandler.h:73
SatIPDataReadHelper::m_valid
bool m_valid
Definition: satipstreamhandler.h:122
SatIPStreamHandler::m_csocket
QUdpSocket * m_csocket
Definition: satipstreamhandler.h:79
SatIPStreamHandler::Tune
bool Tune(const DTVMultiplex &tuning)
Definition: satipstreamhandler.cpp:345
SatIPStreamHandler::s_handlers
static QMap< QString, SatIPStreamHandler * > s_handlers
Definition: satipstreamhandler.h:54
dtvconfparserhelpers.h
SatIPStreamHandler::m_device
QString m_device
Definition: satipstreamhandler.h:64
SatIPStreamHandler::m_inputId
int m_inputId
Definition: satipstreamhandler.h:59
SatIPStreamHandler
Definition: satipstreamhandler.h:26
SatIPDataReadHelper::m_streamHandler
SatIPStreamHandler * m_streamHandler
Definition: satipstreamhandler.h:117
SatIPStreamHandler::m_oldpids
QStringList m_oldpids
Definition: satipstreamhandler.h:75
SatIPStreamHandler::m_frontend
uint m_frontend
Definition: satipstreamhandler.h:65
SatIPStreamHandler::m_controlReadHelper
SatIPControlReadHelper * m_controlReadHelper
Definition: satipstreamhandler.h:86