forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTMedia.h
176 lines (150 loc) · 7.26 KB
/
TMedia.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef MUDLET_TMEDIA_H
#define MUDLET_TMEDIA_H
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014-2017 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2014-2019 by Stephen Lyons - slysven@virginmedia.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Host.h"
#include "TEvent.h"
#include "mudlet.h"
class TMediaData
{
public:
enum MediaProtocol { MediaProtocolMSP = 90, MediaProtocolGMCP = 201, MediaProtocolNotSet = 0 };
enum MediaType { MediaTypeSound = 1, MediaTypeMusic = 2, MediaTypeNotSet = 0 };
enum MediaVolume { MediaVolumeMax = 100, MediaVolumeHigh = 75, MediaVolumeDefault = 50, MediaVolumeLow = 25, MediaVolumeMin = 1, MediaVolumePreload = 0 };
enum MediaLoops { MediaLoopsDefault = 1, MediaLoopsRepeat = -1 };
enum MediaPriority { MediaPriorityMax = 100, MediaPriorityHigh = 75, MediaPriorityDefault = 50, MediaPriorityLow = 25, MediaPriorityMin = 1, MediaPriorityNotSet = 0 };
enum MediaContinue { MediaContinueDefault = true, MediaContinueRestart = false };
TMediaData()
{
mMediaProtocol = MediaProtocolNotSet;
mMediaType = MediaTypeNotSet;
mMediaVolume = MediaVolumeDefault;
mMediaLoops = MediaLoopsDefault;
mMediaPriority = MediaPriorityNotSet;
mMediaContinue = MediaContinueDefault;
}
int getMediaProtocol() { return mMediaProtocol; }
void setMediaProtocol(int mediaProtocol) { mMediaProtocol = mediaProtocol; }
int getMediaType() { return mMediaType; }
void setMediaType(int mediaType) { mMediaType = mediaType; }
QString getMediaFileName() { return mMediaFileName; }
void setMediaFileName(QString mediaFileName) { mMediaFileName = mediaFileName; }
int getMediaVolume() { return mMediaVolume; }
void setMediaVolume(int mediaVolume) { mMediaVolume = mediaVolume; }
int getMediaLoops() { return mMediaLoops; }
void setMediaLoops(int mediaLoops) { mMediaLoops = mediaLoops; }
int getMediaPriority() { return mMediaPriority; }
void setMediaPriority(int mediaPriority) { mMediaPriority = mediaPriority; }
bool getMediaContinue() { return mMediaContinue; }
void setMediaContinue(bool mediaContinue) { mMediaContinue = mediaContinue; }
QString getMediaTag() { return mMediaTag; }
void setMediaTag(QString mediaTag) { mMediaTag = mediaTag; }
QString getMediaUrl() { return mMediaUrl; }
void setMediaUrl(QString mediaUrl) { mMediaUrl = mediaUrl; }
QString getMediaKey() { return mMediaKey; }
void setMediaKey(QString mediaKey) { mMediaKey = mediaKey; }
QString getMediaAbsolutePathFileName() { return mMediaAbsolutePathFileName; }
void setMediaAbsolutePathFileName(QString mediaAbsolutePathFileName) { mMediaAbsolutePathFileName = mediaAbsolutePathFileName; }
private:
int mMediaProtocol;
int mMediaType;
QString mMediaFileName;
int mMediaVolume;
int mMediaLoops;
int mMediaPriority;
bool mMediaContinue;
QString mMediaTag;
QString mMediaUrl;
QString mMediaKey;
QString mMediaAbsolutePathFileName;
};
class TMediaPlayer
{
public:
TMediaPlayer() {}
~TMediaPlayer() {}
TMediaPlayer(Host* pHost, TMediaData& mediaData)
{
mpHost = pHost;
mMediaPlayer = new QMediaPlayer(pHost);
mMediaData = mediaData;
initialized = true;
}
TMediaData getMediaData() { return mMediaData; }
void setMediaData(TMediaData& mediaData) { mMediaData = mediaData; }
QMediaPlayer* getMediaPlayer() const { return mMediaPlayer; }
bool isInitialized() { return initialized; }
private:
QPointer<Host> mpHost;
TMediaData mMediaData;
QMediaPlayer* mMediaPlayer;
bool initialized = false;
};
class TMedia : public QObject
{
Q_OBJECT
public:
Q_DISABLE_COPY(TMedia)
TMedia(Host* pHost, const QString& profileName);
~TMedia();
void playMedia(TMediaData& mediaData);
void stopMedia(TMediaData& mediaData);
void parseGMCP(QString& packageMessage, QString& gmcp);
private:
QUrl parseUrl(TMediaData& mediaData);
static bool isValidUrl(QUrl& url);
static bool isFileRelative(TMediaData& mediaData);
QStringList parseFileNameList(TMediaData& mediaData, QDir& dir);
QStringList getFileNameList(TMediaData& mediaData);
QUrl getFileUrl(TMediaData& mediaData);
bool processUrl(TMediaData& mediaData);
void writeFile(QNetworkReply* reply);
void downloadFile(TMediaData& mediaData);
QString setupMediaAbsolutePathFileName(TMediaData& mediaData);
QList<TMediaPlayer> getMediaPlayerList(TMediaData& mediaData);
TMediaPlayer getMediaPlayer(TMediaData& mediaData);
TMediaPlayer matchMediaPlayer(TMediaData& mediaData, const QString& absolutePathFileName);
bool doesMediaHavePriorityToPlay(TMediaData& mediaData, const QString& absolutePathFileName);
void matchMediaKeyAndStopMediaVariants(TMediaData& mediaData, const QString& absolutePathFileName);
void play(TMediaData& mediaData);
static TMediaData::MediaType parseJSONByMediaType(QJsonObject& json);
static QString parseJSONByMediaFileName(QJsonObject& json);
static int parseJSONByMediaVolume(QJsonObject& json);
static int parseJSONByMediaPriority(QJsonObject& json);
static int parseJSONByMediaLoops(QJsonObject& json);
static TMediaData::MediaContinue parseJSONByMediaContinue(QJsonObject& json);
static QString parseJSONByMediaTag(QJsonObject& json);
static QString parseJSONByMediaUrl(QJsonObject& json);
static QString parseJSONByMediaKey(QJsonObject& json);
void parseJSONForMediaDefault(QJsonObject& json);
void parseJSONForMediaLoad(QJsonObject& json);
void parseJSONForMediaPlay(QJsonObject& json);
void parseJSONForMediaStop(QJsonObject& json);
QPointer<Host> mpHost;
QString mProfileName;
QList<TMediaPlayer> mMSPSoundList;
QList<TMediaPlayer> mMSPMusicList;
QList<TMediaPlayer> mGMCPSoundList;
QList<TMediaPlayer> mGMCPMusicList;
QNetworkAccessManager* mpNetworkAccessManager;
QMap<QNetworkReply*, TMediaData> mMediaDownloads;
};
#endif // MUDLET_TMEDIA_H