MythTV  master
mythsingledownload.h
Go to the documentation of this file.
1 #ifndef MYTH_SINGLE_DOWNLOAD_H
2 #define MYTH_SINGLE_DOWNLOAD_H
3 
4 //#include <QObject>
5 #include <QString>
6 #include <QByteArray>
7 #include <QNetworkAccessManager>
8 #include <QNetworkRequest>
9 #include <QNetworkReply>
10 #include <QMutex>
11 #include <QTimer>
12 #include <QEventLoop>
13 
14 #include "mythbaseexp.h"
15 
16 using namespace std::chrono_literals;
17 
18 /*
19  * MythDownloadManager leaks memory. For things like the HLS
20  * recorder, this leads to aborts in mythbackend when all the memory
21  * is exhausted. Until the leak can be found in MythDownloadManager,
22  * avoid the issue by using MythSingleDownload instead.
23  */
24 
25 class MBASE_PUBLIC MythSingleDownload : public QObject
26 {
27  Q_OBJECT
28 
29  public:
30  MythSingleDownload(void) = default;
31  ~MythSingleDownload(void) override = default;
32 
33  bool DownloadURL(const QUrl &url, QByteArray *buffer, std::chrono::seconds timeout = 30s,
34  uint redirs = 0, qint64 maxsize = 0, QString *final_url = nullptr);
35  void Cancel(void);
36  QString ErrorString(void) const { return m_errorstring; }
37  QNetworkReply::NetworkError ErrorCode(void) const { return m_errorcode; }
38 
39  private slots:
40  void Progress(qint64 bytesRead, qint64 totalBytes);
41 
42  private:
43  QNetworkAccessManager m_mgr;
44  QTimer m_timer;
45  QNetworkReply *m_reply {nullptr};
46  QMutex m_lock;
47  QMutex m_replylock;
48 
49  QString m_errorstring;
50  QNetworkReply::NetworkError m_errorcode {QNetworkReply::NoError};
51  QByteArray *m_buffer {nullptr};
52  qint64 m_maxsize {0};
53 };
54 
55 #endif // MYTH_SINGLE_DOWNLOAD_H
MythSingleDownload::m_lock
QMutex m_lock
Definition: mythsingledownload.h:46
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
mythbaseexp.h
MythSingleDownload::m_mgr
QNetworkAccessManager m_mgr
Definition: mythsingledownload.h:43
MythSingleDownload::m_timer
QTimer m_timer
Definition: mythsingledownload.h:44
MythSingleDownload::m_errorstring
QString m_errorstring
Definition: mythsingledownload.h:49
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythSingleDownload::ErrorCode
QNetworkReply::NetworkError ErrorCode(void) const
Definition: mythsingledownload.h:37
uint
unsigned int uint
Definition: compat.h:140
MythSingleDownload
Definition: mythsingledownload.h:25
MythSingleDownload::ErrorString
QString ErrorString(void) const
Definition: mythsingledownload.h:36
MythSingleDownload::m_replylock
QMutex m_replylock
Definition: mythsingledownload.h:47