Skip to content

Commit 8c01b41

Browse files
committed
send videoInfo (from transcoder) to VDR
1 parent fb23c43 commit 8c01b41

7 files changed

+43
-21
lines changed

Diff for: mainapp.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ void startHttpServer(std::string browserIp, int browserPort, std::string vdrIp,
311311
}
312312
});
313313

314+
svr.Get("/StopVideo", [&transcoderRemoteClient](const httplib::Request &req, httplib::Response &res) {
315+
transcoderRemoteClient.Stop();
316+
317+
res.status = 200;
318+
res.set_content("ok", "text/plain");
319+
});
320+
314321
svr.set_exception_handler([](const auto& req, auto& res, std::exception_ptr ep) {
315322
auto fmt = "<h1>Error 500</h1><p>%s</p>";
316323
char buf[BUFSIZ];

Diff for: test-tools/ffmpeghandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool FFmpegHandler::streamVideo(std::string url) {
6969

7070
// TODO: Evt. Transcoding durchführen. Die Commandline muss generischer werden.
7171
DEBUG("Start transcoder");
72-
client->StartVideo();
72+
client->StartVideo(std::string());
7373

7474
std::string cmdLine = "ffmpeg -re -y -i " + url + " -c copy -f mpegts " + fifoFilename;
7575
streamHandler = new TinyProcessLib::Process(cmdLine, "",

Diff for: transcoderremoteclient.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TranscoderRemoteClient::~TranscoderRemoteClient() {
1010
delete client;
1111
}
1212

13-
bool TranscoderRemoteClient::Probe(std::string url, std::string cookies, std::string referer, std::string userAgent, std::string postfix) {
13+
std::string TranscoderRemoteClient::Probe(std::string url, std::string cookies, std::string referer, std::string userAgent, std::string postfix) {
1414
httplib::Params params;
1515
params.emplace("url", url);
1616
params.emplace("cookies", cookies);
@@ -23,17 +23,16 @@ bool TranscoderRemoteClient::Probe(std::string url, std::string cookies, std::st
2323
if (auto res = client->Post("/Probe", params)) {
2424
if (res->status != 200) {
2525
TRACE("Http result: {}", res->status);
26-
return false;
26+
return "";
2727
} else {
2828
TRACE("Probe sent: {}", res->status);
29+
return res->body;
2930
}
3031
} else {
3132
auto err = res.error();
3233
ERROR("Http error: {}", httplib::to_string(err));
33-
return false;
34+
return "";
3435
}
35-
36-
return true;
3736
}
3837

3938
bool TranscoderRemoteClient::StreamUrl(std::string url, std::string cookies, std::string referer, std::string userAgent) {

Diff for: transcoderremoteclient.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class TranscoderRemoteClient {
88
explicit TranscoderRemoteClient(std::string transcoderIp, int transcoderPort, std::string browserIp, int browserPort);
99
~TranscoderRemoteClient();
1010

11-
bool Probe(std::string url, std::string cookies, std::string referer, std::string userAgent, std::string postfix);
11+
std::string
12+
Probe(std::string url, std::string cookies, std::string referer, std::string userAgent, std::string postfix);
1213
bool StreamUrl(std::string url, std::string cookies, std::string referer, std::string userAgent);
1314
bool Pause();
1415
bool Seek(std::string seekTo);

Diff for: v8handler.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
bool startVideo;
99
bool videoReset;
1010

11+
std::string videoInfo;
12+
1113
void V8Handler::stopVdrVideo() {
12-
int waitTime = 50; // ms
13-
int count = 1000 / waitTime;
14+
int waitTime = 10; // ms
15+
int count = 5000 / waitTime;
1416
startVideo = false;
1517

1618
while (count-- > 0 && !startVideo) {
1719
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
1820
}
1921

2022
if (startVideo) {
21-
vdrRemoteClient->ResetVideo();
23+
vdrRemoteClient->ResetVideo(videoInfo);
2224
videoReset = true;
2325
} else {
26+
videoInfo = "";
2427
vdrRemoteClient->StopVideo();
2528
videoReset = false;
2629
}
@@ -34,6 +37,8 @@ V8Handler::V8Handler(std::string bIp, int bPort, std::string tIp, int tPort, std
3437

3538
lastVideoX = lastVideoY = lastVideoW = lastVideoH = 0;
3639
lastFullscreen = false;
40+
41+
videoInfo = "";
3742
}
3843

3944
V8Handler::~V8Handler() {
@@ -80,8 +85,6 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
8085

8186
if (name == "StreamVideo") {
8287
if (!arguments.empty()) {
83-
startVideo = true;
84-
8588
const auto& urlParam = arguments.at(0);
8689
auto url = urlParam.get()->GetStringValue();
8790

@@ -97,9 +100,14 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
97100
TRACE("Video URL: {}", url.ToString());
98101

99102
// 1. Step call Probe
100-
if (!transcoderRemoteClient->Probe(url, cookies, referer, userAgent, std::to_string(now))) {
103+
videoInfo = transcoderRemoteClient->Probe(url, cookies, referer, userAgent, std::to_string(now));
104+
startVideo = true;
105+
106+
TRACE("Video Info: {}", videoInfo);
107+
108+
if (videoInfo.empty()) {
101109
// transcoder not available
102-
ERROR("Probe failed: Encrypted stream or transcoder not available.");
110+
ERROR("Probe failed: Transcoder not available, wrong video URL or another error.");
103111
return false;
104112
}
105113

@@ -111,7 +119,7 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
111119
}
112120

113121
if (!videoReset) {
114-
vdrRemoteClient->StartVideo();
122+
vdrRemoteClient->StartVideo(videoInfo);
115123
}
116124
}
117125

@@ -188,6 +196,7 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
188196
const auto w = arguments.at(2)->GetIntValue();
189197
const auto h = arguments.at(3)->GetIntValue();
190198

199+
// TODO: Ist das noch notwendig? Aufgrund der Änderungen auf mutation-summary sollte das nicht mehr passieren.
191200
if ((w <= 160 || h <= 100) || (w == 300 && h == 150 && x == 0)) {
192201
// ignore these video sizes
193202
retval = CefV8Value::CreateBool(true);

Diff for: vdrremoteclient.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ bool VdrRemoteClient::ProcessTSPacket(std::string packets) const {
8787
return true;
8888
}
8989

90-
bool VdrRemoteClient::StartVideo() {
90+
bool VdrRemoteClient::StartVideo(std::string videoInfo) {
9191
const std::lock_guard<std::mutex> lock(httpMutex);
9292

9393
TRACE("Call VdrRemoteClient::StartVideo");
9494

95-
if (auto res = client->Get("/StartVideo")) {
95+
httplib::Params params;
96+
params.emplace("videoInfo", videoInfo);
97+
98+
if (auto res = client->Post("/StartVideo", params)) {
9699
if (res->status != 200) {
97100
ERROR("Http result: {}", res->status);
98101
return false;
@@ -226,12 +229,15 @@ bool VdrRemoteClient::SendHello() {
226229
return true;
227230
}
228231

229-
bool VdrRemoteClient::ResetVideo() {
232+
bool VdrRemoteClient::ResetVideo(std::string videoInfo) {
230233
const std::lock_guard<std::mutex> lock(httpMutex);
231234

232235
TRACE("Call VdrRemoteClient::ResetVideo");
233236

234-
if (auto res = client->Get("/ResetVideo")) {
237+
httplib::Params params;
238+
params.emplace("videoInfo", videoInfo);
239+
240+
if (auto res = client->Post("/ResetVideo", params)) {
235241
if (res->status != 200) {
236242
ERROR("Http result: {}", res->status);
237243
return false;

Diff for: vdrremoteclient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class VdrRemoteClient {
1212
bool ProcessOsdUpdateQoi(int disp_width, int disp_height, int x, int y, const std::string& imageQoi);
1313
bool ProcessTSPacket(std::string packets) const;
1414

15-
bool StartVideo();
15+
bool StartVideo(std::string videoInfo);
1616
bool StopVideo();
1717
bool Pause();
1818
bool Resume();
19-
bool ResetVideo();
19+
bool ResetVideo(std::string videoInfo);
2020

2121
bool VideoSize(int x, int y, int w, int h);
2222
bool VideoFullscreen();

0 commit comments

Comments
 (0)