-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknotsplayerproperties.cpp
More file actions
executable file
·163 lines (129 loc) · 4.57 KB
/
knotsplayerproperties.cpp
File metadata and controls
executable file
·163 lines (129 loc) · 4.57 KB
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
#include "knots.h"
#include "knotsplayerproperties.h"
#include <QDebug>
#include <QMutexLocker>
KnotsPlayerProperties::KnotsPlayerProperties(QObject *parent )
: QObject( parent )
, _position(0.0)
, _duration(0)
, _currentDownload(0)
, _waitingForRequest(QMutex::Recursive)
{
_processingThread.start(QThread::LowPriority);
moveToThread(&_processingThread);
_xmlReader = new QXmlSimpleReader();
_xmlReader->setContentHandler(this);
connect(&Knots::instance().serverConnection(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(fetchFinished(QNetworkReply*)));
}
KnotsPlayerProperties::~KnotsPlayerProperties()
{
delete _xmlSource; _xmlSource = 0;
delete _xmlReader; _xmlReader = 0;
disconnect(this);
}
void KnotsPlayerProperties::updateStatus(QString &playerId, QString &password)
{
QUrl statusUrl = Knots::instance().serverAddress();
statusUrl.setPath("/external/player_properties");
statusUrl.addQueryItem("player_id",playerId);
_playerId = playerId;
_password = password;
// If not waiting for properties then request new set
if( _currentDownload == 0 )
{
QMutexLocker locker(&_waitingForRequest);
QNetworkRequest request( statusUrl );
_currentDownload = Knots::instance().serverConnection().get(request);
_xmlSource = new QXmlInputSource( _currentDownload );
}
// else wait for the existing request to finish.
}
void KnotsPlayerProperties::fetchFinished( QNetworkReply* reply )
{
// qWarning() << "Fetched from " << reply->url() ;
// qWarning() << "Read " << reply->bytesAvailable() << " Bytes";
// qWarning() << reply->peek( 256 );
if( reply == _currentDownload )
{
QMutexLocker locker(&_waitingForRequest);
_xmlReader->parse(_xmlSource );
reply->deleteLater();
QUrl streamUrl;
streamUrl.setScheme("http");
streamUrl.setUserName(_playerId);
streamUrl.setPassword(_password);
streamUrl.setPort(_port.toInt());
streamUrl.setHost( Knots::instance().serverAddress().host());
streamUrl.setPath("/" + _stream);
_streamUrl = streamUrl.toString();
delete _xmlSource;
_xmlSource=0;
_currentDownload = 0;
qDebug() << "Duration: " << this->_duration;
qDebug() << "Position: " << this->_position;
emit propertiesUpdated();
}
}
bool KnotsPlayerProperties::startDocument()
{
return true;
}
bool KnotsPlayerProperties::startElement(const QString & /* namespaceURI */,
const QString &/*localName*/,
const QString &/*qName*/,
const QXmlAttributes &/*attributes*/)
{
_currentText.clear();
return true;
}
bool KnotsPlayerProperties::endElement(const QString & /* namespaceURI */,
const QString &localName ,
const QString &/*qName*/)
{
if( localName == "seekable" ) {
_seekable = _currentText;
} else if ( localName == "mediatype" ) {
_mediatype = _currentText;
} else if ( localName == "title" ) {
_title = _currentText;
} else if ( localName == "position" ) {
_position = _currentText.toFloat();
} else if ( localName == "media_id" ) {
_media_id = _currentText;
} else if ( localName == "playlistindex" ) {
_playlistindex = _currentText;
} else if ( localName == "playlist_length" ) {
_playlist_length = _currentText;
} else if ( localName == "currently_playing_filename" ) {
_currently_playing_filename = _currentText;
} else if ( localName == "video_width" ) {
_video_width = _currentText;
} else if ( localName == "video_height" ) {
_video_height = _currentText;
} else if ( localName == "mux" ) {
_mux = _currentText;
} else if ( localName == "stream" ) {
_stream = _currentText;
} else if ( localName == "port" ) {
_port = _currentText;
} else if ( localName == "buffer" ) {
_buffer = _currentText;
} else if ( localName == "address" ) {
_address = _currentText;
} else if ( localName == "looped" ) {
_looped = _currentText;
} else if ( localName == "duration") {
_duration = _currentText.toInt();
}
return true;
}
bool KnotsPlayerProperties::characters(const QString &str)
{
_currentText += str;
return true;
}
bool KnotsPlayerProperties::fatalError(const QXmlParseException &/*exception*/)
{
return false;
}