-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodergenericnetworksource.h
136 lines (98 loc) · 3.47 KB
/
decodergenericnetworksource.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
This file is part of Waver
Copyright (C) 2021 Peter Papp
Please visit https://launchpad.net/waver for details
*/
#ifndef DECODERGENERICNETWORKSOURCE_H
#define DECODERGENERICNETWORKSOURCE_H
#include <QByteArray>
#include <QDateTime>
#include <QGuiApplication>
#include <QIODevice>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QString>
#include <QStringList>
#include <QThread>
#include <QTimer>
#include <QUrl>
#include <QVector>
#include <QWaitCondition>
#include "radiotitlecallback.h"
#ifdef QT_DEBUG
#include <QDebug>
#endif
class DecoderGenericNetworkSource : public QIODevice
{
Q_OBJECT
public:
DecoderGenericNetworkSource(QUrl url, QWaitCondition *waitCondition, RadioTitleCallback::RadioTitleCallbackInfo radioTitleCallbackInfo);
~DecoderGenericNetworkSource();
qint64 readData(char *data, qint64 maxlen) override;
qint64 writeData(const char *data, qint64 len) override;
bool seek(qint64 pos) override;
bool atEnd() const override;
bool isSequential() const override;
qint64 bytesAvailable() const override;
qint64 pos() const override;
qint64 size() const override;
qint64 realBytesAvailable();
qint64 mostRealBytesAvailable();
bool isDownloadFinished();
void setErrorOnUnderrun(bool errorOnUnderrun);
qint64 downloadedSize();
private:
static const int CONNECTION_ATTEMPTS = 3;
static const int CONNECTION_TIMEOUT = 7500;
static const int PRE_CACHE_TIMEOUT = 15000;
struct RadioTitlePosition {
qint64 compressedBytes;
QString title;
};
QUrl url;
QWaitCondition *waitCondition;
QNetworkAccessManager *networkAccessManager;
QNetworkReply *networkReply;
QVector<QByteArray *> buffer;
qint64 totalDownloadedBytes;
qint64 totalExpectedBytes;
qint64 fakePosition;
qint64 firstBufferPosition;
qint64 maxRealBytesAvailable;
QVector<qint64> seekHistory;
QMutex mutex;
QTimer *connectionTimer;
QTimer *preCacheTimer;
int connectionAttempt;
bool downloadStarted;
bool downloadFinished;
bool readyEmitted;
bool errorOnUnderrun;
int rawChunkSize;
int rawCount;
int metaSize;
int metaCount;
QByteArray metaBuffer;
qint64 totalMetaBytes;
RadioTitleCallback::RadioTitleCallbackInfo radioTitleCallbackInfo;
QVector<RadioTitlePosition> radioTitlePositions;
bool bufferIndexPositionFromPosition(qint64 position, int *bufferIndex, int *bufferPosition);
QNetworkRequest buildNetworkRequest();
signals:
void error(QString errorString);
void info(QString errorString);
void sessionExpired();
void ready();
void changed();
public slots:
void run();
private slots:
void emitReady();
void networkDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void networkError(QNetworkReply::NetworkError code);
void connectionTimeout();
void preCacheTimeout();
};
#endif // DECODERGENERICNETWORKSOURCE_H