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