MythTV  master
iptvstreamhandler.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef IPTVSTREAMHANDLER_H
4 #define IPTVSTREAMHANDLER_H
5 
6 #include <vector>
7 
8 #include <QHostAddress>
9 #include <QUdpSocket>
10 #include <QString>
11 #include <QMutex>
12 #include <QMap>
13 
14 #include <QNetworkAccessManager>
15 
16 #include "channelutil.h"
17 #include "streamhandler.h"
18 
19 static constexpr size_t IPTV_SOCKET_COUNT { 3 };
20 static constexpr std::chrono::milliseconds RTCP_TIMER { 10s };
21 
22 class IPTVStreamHandler;
23 class DTVSignalMonitor;
24 class MPEGStreamData;
25 class PacketBuffer;
26 class IPTVChannel;
27 
28 class IPTVStreamHandlerReadHelper : public QObject
29 {
30  Q_OBJECT
31 
32  public:
33  IPTVStreamHandlerReadHelper(IPTVStreamHandler *p, QUdpSocket *s, uint stream);
34 
35  public slots:
36  void ReadPending(void);
37 
38  private:
40  QUdpSocket *m_socket {nullptr};
41  QHostAddress m_sender;
43 };
44 
46 {
47  Q_OBJECT
48 
49 public:
51  : m_parent(p) {}
53 
54  void Start(void)
55  {
56  m_timer = startTimer(200ms);
57  }
58  void StartRTCPRR(void)
59  {
60  m_timerRtcp = startTimer(RTCP_TIMER);
61  }
62 
63  void SendRTCPReport(void);
64 
65 private:
66  void timerEvent(QTimerEvent *event) override; // QObject
67 
68 private:
70  int m_timer {0};
71  int m_timerRtcp {0};
75  int m_lost {0};
76  int m_lostInterval {0};
77 };
78 
80 {
83  public:
84  static IPTVStreamHandler *Get(const IPTVTuningData &tuning, int inputid);
85  static void Return(IPTVStreamHandler * & ref, int inputid);
86 
88  bool /*allow_section_reader*/ = false,
89  bool /*needs_drb*/ = false,
90  const QString& output_file = QString()) override // StreamHandler
91  {
92  // Force allow_section_reader and needs_buffering to false;
93  StreamHandler::AddListener(data, false, false, output_file);
94  }
95 
96  protected:
97  explicit IPTVStreamHandler(const IPTVTuningData &tuning, int inputid);
98 
99  void run(void) override; // MThread
100 
101  protected:
103  std::array<QUdpSocket*,IPTV_SOCKET_COUNT> m_sockets {};
104  std::array<IPTVStreamHandlerReadHelper*,IPTV_SOCKET_COUNT> m_readHelpers {};
105  std::array<QHostAddress,IPTV_SOCKET_COUNT> m_sender;
107  PacketBuffer *m_buffer {nullptr};
108 
110  ushort m_rtspRtpPort {0};
111  ushort m_rtspRtcpPort {0};
112  uint32_t m_rtspSsrc {0};
113  QHostAddress m_rtcpDest;
114 
115  // for implementing Get & Return
116  static QMutex s_iptvhandlers_lock;
117  static QMap<QString, IPTVStreamHandler*> s_iptvhandlers;
118  static QMap<QString, uint> s_iptvhandlers_refcnt;
119 
120 private:
121  void timerEvent(QTimerEvent*);
122 
123 };
124 
125 #endif // IPTVSTREAMHANDLER_H
IPTVStreamHandler::Return
static void Return(IPTVStreamHandler *&ref, int inputid)
Definition: iptvstreamhandler.cpp:69
IPTVStreamHandler::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: iptvstreamhandler.cpp:116
IPTVStreamHandler::m_tuning
IPTVTuningData m_tuning
Definition: iptvstreamhandler.h:102
IPTVStreamHandlerReadHelper::m_parent
IPTVStreamHandler * m_parent
Definition: iptvstreamhandler.h:39
IPTVStreamHandlerReadHelper::m_sender
QHostAddress m_sender
Definition: iptvstreamhandler.h:41
IPTVStreamHandlerReadHelper
Definition: iptvstreamhandler.h:28
streamhandler.h
IPTVStreamHandler::IPTVStreamHandler
IPTVStreamHandler(const IPTVTuningData &tuning, int inputid)
Definition: iptvstreamhandler.cpp:109
IPTVStreamHandler::m_rtspSsrc
uint32_t m_rtspSsrc
Definition: iptvstreamhandler.h:112
IPTVStreamHandler::m_readHelpers
std::array< IPTVStreamHandlerReadHelper *, IPTV_SOCKET_COUNT > m_readHelpers
Definition: iptvstreamhandler.h:104
IPTVStreamHandlerWriteHelper::Start
void Start(void)
Definition: iptvstreamhandler.h:54
IPTVStreamHandlerWriteHelper::~IPTVStreamHandlerWriteHelper
~IPTVStreamHandlerWriteHelper() override
Definition: iptvstreamhandler.cpp:402
IPTVStreamHandlerWriteHelper::IPTVStreamHandlerWriteHelper
IPTVStreamHandlerWriteHelper(IPTVStreamHandler *p)
Definition: iptvstreamhandler.h:50
IPTVStreamHandler::m_sockets
std::array< QUdpSocket *, IPTV_SOCKET_COUNT > m_sockets
Definition: iptvstreamhandler.h:103
StreamHandler
Definition: streamhandler.h:56
IPTVStreamHandlerWriteHelper::StartRTCPRR
void StartRTCPRR(void)
Definition: iptvstreamhandler.h:58
PacketBuffer
Definition: packetbuffer.h:15
IPTVStreamHandlerReadHelper::ReadPending
void ReadPending(void)
Definition: iptvstreamhandler.cpp:348
IPTVStreamHandlerWriteHelper::m_lastSequenceNumber
uint m_lastSequenceNumber
Definition: iptvstreamhandler.h:72
IPTVStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: iptvstreamhandler.h:87
IPTVStreamHandlerWriteHelper::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: iptvstreamhandler.cpp:417
IPTVStreamHandlerReadHelper::m_stream
uint m_stream
Definition: iptvstreamhandler.h:42
IPTVStreamHandlerWriteHelper
Definition: iptvstreamhandler.h:45
IPTVStreamHandler::s_iptvhandlers
static QMap< QString, IPTVStreamHandler * > s_iptvhandlers
Definition: iptvstreamhandler.h:117
IPTVStreamHandlerWriteHelper::m_timerRtcp
int m_timerRtcp
Definition: iptvstreamhandler.h:71
IPTVStreamHandlerWriteHelper::m_lostInterval
int m_lostInterval
Definition: iptvstreamhandler.h:76
IPTVStreamHandlerWriteHelper::m_parent
IPTVStreamHandler * m_parent
Definition: iptvstreamhandler.h:69
IPTVStreamHandlerWriteHelper::m_previousLastSequenceNumber
uint m_previousLastSequenceNumber
Definition: iptvstreamhandler.h:74
RTCP_TIMER
static constexpr std::chrono::milliseconds RTCP_TIMER
Definition: iptvstreamhandler.h:20
hardwareprofile.config.p
p
Definition: config.py:33
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:85
IPTVStreamHandler::s_iptvhandlers_refcnt
static QMap< QString, uint > s_iptvhandlers_refcnt
Definition: iptvstreamhandler.h:118
IPTVStreamHandler::m_useRtpStreaming
bool m_useRtpStreaming
Definition: iptvstreamhandler.h:109
IPTVStreamHandlerWriteHelper::m_lost
int m_lost
Definition: iptvstreamhandler.h:75
IPTVTuningData
Definition: iptvtuningdata.h:21
IPTVChannel
Definition: iptvchannel.h:24
IPTVStreamHandler::Get
static IPTVStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: iptvstreamhandler.cpp:36
IPTVStreamHandler::m_sender
std::array< QHostAddress, IPTV_SOCKET_COUNT > m_sender
Definition: iptvstreamhandler.h:105
uint
unsigned int uint
Definition: compat.h:81
IPTVStreamHandler::timerEvent
void timerEvent(QTimerEvent *)
channelutil.h
IPTVStreamHandler::m_buffer
PacketBuffer * m_buffer
Definition: iptvstreamhandler.h:107
IPTV_SOCKET_COUNT
static constexpr size_t IPTV_SOCKET_COUNT
Definition: iptvstreamhandler.h:19
IPTVStreamHandler::m_rtcpDest
QHostAddress m_rtcpDest
Definition: iptvstreamhandler.h:113
DTVSignalMonitor
This class is intended to detect the presence of needed tables.
Definition: dtvsignalmonitor.h:14
IPTVStreamHandler::m_rtspRtpPort
ushort m_rtspRtpPort
Definition: iptvstreamhandler.h:110
IPTVStreamHandlerWriteHelper::SendRTCPReport
void SendRTCPReport(void)
Definition: iptvstreamhandler.cpp:518
IPTVStreamHandler
Definition: iptvstreamhandler.h:79
IPTVStreamHandler::m_rtspRtcpPort
ushort m_rtspRtcpPort
Definition: iptvstreamhandler.h:111
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
IPTVStreamHandler::s_iptvhandlers_lock
static QMutex s_iptvhandlers_lock
Definition: iptvstreamhandler.h:116
IPTVStreamHandlerReadHelper::m_socket
QUdpSocket * m_socket
Definition: iptvstreamhandler.h:40
IPTVStreamHandlerReadHelper::IPTVStreamHandlerReadHelper
IPTVStreamHandlerReadHelper(IPTVStreamHandler *p, QUdpSocket *s, uint stream)
Definition: iptvstreamhandler.cpp:337
IPTVStreamHandler::m_writeHelper
IPTVStreamHandlerWriteHelper * m_writeHelper
Definition: iptvstreamhandler.h:106
IPTVStreamHandlerWriteHelper::m_timer
int m_timer
Definition: iptvstreamhandler.h:70
IPTVStreamHandlerWriteHelper::m_lastTimestamp
uint m_lastTimestamp
Definition: iptvstreamhandler.h:73