-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuter.cpp
More file actions
93 lines (80 loc) · 2.27 KB
/
executer.cpp
File metadata and controls
93 lines (80 loc) · 2.27 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
#include <assert.h>
#include "resource.h"
#include "executer.h"
#include "player.h"
#include "./common/mcommon.h"
#include <VLCQtCore/MediaPlayer.h>
#include <VLCQtCore/Audio.h>
Executer::Executer(Player *player, QObject *parent) :
AbstractExecuter(parent),
mPlayer(player),
mStreamProcess(nullptr)
{
assert(player != nullptr);
}
Executer::~Executer()
{
stopStream();
delete mStreamProcess;
}
MStatusWrapper Executer::status() const
{
return MStatusWrapper(
mPlayer->mediaName(),
mPlayer->state(),
mPlayer->duration(),
mPlayer->time(),
mPlayer->volume());
}
// if buffer empty -> execute at once - checkBuffer
QString Executer::setStatus(const MStatusWrapper &status)
{
QString out;
const StatusContainer *cont = status.container();
if (status.isValid()) {
if (mPlayer->setMediaName(cont->act)) {
if (!startStream(mPlayer->mediaId(), mPlayer->location())) {
out = "Unable to start stream";
}
}
else if (!mPlayer->isMediaName(cont->act)) {
out = "Media not set";
}
}
else {
out = "Status is invalid";
}
// if error, reset player
if (!out.isEmpty()) {
mPlayer->reset();
}
// success -> set status
else {
mPlayer->setTime (cont->pos );
mPlayer->setVolume(cont->vol );
mPlayer->setState (cont->state);
}
return out;
}
void Executer::stopStream()
{
if (mStreamProcess != nullptr) {
if (mStreamProcess->state() != QProcess::NotRunning) {
mStreamProcess->close();
mStreamProcess->waitForFinished();
}
else {
mStreamProcess->deleteLater();
}
}
}
bool Executer::startStream(const QString &mediaId, const QString &file)
{
stopStream();
mStreamProcess = new QProcess;
mStreamProcess->start("./tools/stream-mp4", QStringList() << "-s" << mediaId << file);
mStreamProcess->waitForStarted();
connect(mStreamProcess, SIGNAL(finished(int)),
mStreamProcess, SLOT (deleteLater()));
return mStreamProcess->state() != QProcess::NotRunning;
}