MythTV  master
httptsstreamhandler.h
Go to the documentation of this file.
1 #ifndef HTTPTSSTREAMHANDLER_H
2 #define HTTPTSSTREAMHANDLER_H
3 
4 #include <vector>
5 using namespace std;
6 
7 #include <QString>
8 #include <QMutex>
9 #include <QMap>
10 #include <QNetworkAccessManager>
11 #include <QNetworkRequest>
12 #include <QNetworkReply>
13 
14 #include "channelutil.h"
15 #include "iptvstreamhandler.h"
16 
17 class HTTPReader;
18 
20 {
21  friend class HTTPReader;
22  public:
23  static HTTPTSStreamHandler* Get(const IPTVTuningData& tuning, int inputid);
24  static void Return(HTTPTSStreamHandler * & ref, int inputid);
25 
26 protected:
27  explicit HTTPTSStreamHandler(const IPTVTuningData &tuning, int inputid);
28  ~HTTPTSStreamHandler(void) override;
29  void run(void) override; // MThread
30 
31  protected:
32  HTTPReader* m_reader {nullptr};
33  // for implementing Get & Return
34  static QMutex s_httphandlers_lock;
35  static QMap<QString, HTTPTSStreamHandler*> s_httphandlers;
36  static QMap<QString, uint> s_httphandlers_refcnt;
37 };
38 
39 
40 class MTV_PUBLIC HTTPReader : public QObject
41 {
42  Q_OBJECT
43 
44  public:
45  explicit HTTPReader(HTTPTSStreamHandler* parent) :
46  m_parent(parent) {}
47  void Cancel(void);
48  bool DownloadStream(const QUrl& url);
49 
50  protected:
51  void ReadBytes();
52  void WriteBytes();
53 
54  private slots:
55  void HttpRead();
56 
57  private:
58  QString m_url;
59  HTTPTSStreamHandler *m_parent {nullptr};
60  QTimer m_timer;
61  QNetworkAccessManager m_mgr;
62  QNetworkReply *m_reply {nullptr};
63  QMutex m_lock;
64  QMutex m_replylock;
65  QMutex m_bufferlock;
66  uint8_t *m_buffer {nullptr};
67  bool m_ok {true};
68  int m_size {0};
69 };
70 
71 #endif // HTTPTSSTREAMHANDLER_H
HTTPReader::m_url
QString m_url
Definition: httptsstreamhandler.h:58
slots
std::array< unsigned int, 4 > slots
Definition: element.cpp:38
HTTPTSStreamHandler::s_httphandlers
static QMap< QString, HTTPTSStreamHandler * > s_httphandlers
Definition: httptsstreamhandler.h:35
HTTPTSStreamHandler::s_httphandlers_refcnt
static QMap< QString, uint > s_httphandlers_refcnt
Definition: httptsstreamhandler.h:36
HTTPReader::HTTPReader
HTTPReader(HTTPTSStreamHandler *parent)
Definition: httptsstreamhandler.h:45
HTTPReader::m_lock
QMutex m_lock
Definition: httptsstreamhandler.h:63
HTTPTSStreamHandler
Definition: httptsstreamhandler.h:20
IPTVTuningData
Definition: iptvtuningdata.h:17
HTTPReader::m_bufferlock
QMutex m_bufferlock
Definition: httptsstreamhandler.h:65
HTTPReader
Definition: httptsstreamhandler.h:41
HTTPReader::m_mgr
QNetworkAccessManager m_mgr
Definition: httptsstreamhandler.h:61
channelutil.h
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
HTTPReader::m_timer
QTimer m_timer
Definition: httptsstreamhandler.h:60
IPTVStreamHandler
Definition: iptvstreamhandler.h:82
HTTPReader::m_replylock
QMutex m_replylock
Definition: httptsstreamhandler.h:64
iptvstreamhandler.h
HTTPTSStreamHandler::s_httphandlers_lock
static QMutex s_httphandlers_lock
Definition: httptsstreamhandler.h:34