-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhlsvideo.cpp
More file actions
137 lines (120 loc) · 3.28 KB
/
hlsvideo.cpp
File metadata and controls
137 lines (120 loc) · 3.28 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
#include "hlsvideo.h"
#include "hlsserver.h"
#include "hlstranscode.h"
#include <QCoreApplication>
#include <QProcess>
#include <QFile>
#include <QDebug>
HlsVideo::HlsVideo(QString streamPath, QObject *parent)
: QObject(parent), hlsServer(), hlsTranscode(), streamPath(streamPath)
{
}
void HlsVideo::start(QString file, QString subs, int port)
{
httpPort = port;
videoFile = file;
srtFile = subs;
// start server & transcoder
hlsServer = new HlsServer(videoFile, getFfmpegPath(), streamPath, 8888, this);
hlsTranscode = new HlsTranscode(srtFile, getFfmpegPath(), streamPath, this);
connect(hlsTranscode, SIGNAL(segmentAvailable(int)), hlsServer, SLOT(segmentAvailable(int)));
connect(hlsTranscode, SIGNAL(segmentAvailable(int)), this, SLOT(segmentAvailable(int)));
}
/*void HlsVideo::stateLoop()
{
switch (state)
{
case STATE_START_SERVER:
{
// start services
hlsServer = new HlsServer(videoFile, getFfmpegPath(), streamPath, 8888, this);
hlsTranscode = new HlsTranscode(srtFile, getFfmpegPath(), streamPath, this);
connect(hlsTranscode, SIGNAL(segmentAvailable(int)), hlsServer, SLOT(segmentAvailable(int)));
connect(hlsTranscode, SIGNAL(readyForData()), this, SIGNAL(readyForData()));
state = STATE_FLUSH_BUFFER;
break;
}
case STATE_FLUSH_BUFFER:
{
// write buffer
if (buffer.length() > 0)
{
hlsTranscode->pipeInput(&buffer);
buffer.clear();
}
//
// is complete?
if (hlsServer->getTotalSegments() > 0 &&
hlsTranscode->getTotalSegments() >= hlsServer->getTotalSegments()-2)
{
qDebug() << "transcode complete";
state = STATE_COMPLETE;
}
break;
}
case STATE_COMPLETE:
{
// make last segment available
hlsServer->segmentAvailable(hlsServer->getTotalSegments()-1);
// finish
hlsTranscode->stop();
timerStateLoop.stop();
}
default:
break;
}
}*/
QString HlsVideo::getFfmpegPath()
{
#ifdef QT_DEBUG
return "/Users/ajph/Documents/projects/StreamPlay/src/ffmpeg/ffmpeg";
#else
return QCoreApplication::applicationDirPath() + "/../Resources/ffmpeg";
#endif
}
void HlsVideo::encode(QByteArray *b)
{
hlsTranscode->pipeInput(b);
}
bool HlsVideo::isReadyForStreaming()
{
return ((hlsTranscode != NULL) &&
(hlsTranscode->getCompletedSegments() > 2));
}
bool HlsVideo::isReadyForInput()
{
return ((hlsTranscode != NULL) &&
(hlsTranscode->isReadyForData()));
}
int HlsVideo::getCurrentSegment() {
if (!hlsServer)
return 0;
else
return hlsServer->getCurrentSegment();
}
int HlsVideo::getTotalSegments() {
if (!hlsServer)
return 0;
else
return hlsServer->getTotalSegments();
}
void HlsVideo::segmentAvailable(int i)
{
if (hlsServer->getTotalSegments() > 0 && i >= hlsServer->getTotalSegments()-2)
{
qDebug() << "transcode complete";
hlsServer->segmentAvailable(hlsServer->getTotalSegments()-1);
hlsTranscode->stop();
}
}
void HlsVideo::stop()
{
if (hlsServer)
hlsServer->pause();
if (hlsTranscode)
hlsTranscode->stop();
}
HlsVideo::~HlsVideo()
{
stop();
}