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  virtual ~HTTPTSStreamHandler(void);
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_
unsigned int slots[4]
Definition: element.c:38
static QMap< QString, HTTPTSStreamHandler * > s_httphandlers
static QMutex s_httphandlers_lock
static QMap< QString, uint > s_httphandlers_refcnt
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QNetworkAccessManager m_mgr
HTTPReader(HTTPTSStreamHandler *parent)