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