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