Skip to content

Commit

Permalink
get rid of internal _overlay and better video resize handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Zabrimus committed Jul 30, 2023
1 parent c428b16 commit 48c1a21
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 45 deletions.
2 changes: 2 additions & 0 deletions browserclient.cpp
Expand Up @@ -90,11 +90,13 @@ void BrowserClient::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type
// fffe2e9a => 00fe2e9a

// delete parts of the OSD where a video shall be visible
/*
for (uint32_t i = 0; i < (uint32_t) (r.width * r.height); ++i) {
if (outbuffer[i] == 0xfffe2e9a) {
outbuffer[i] = 0x00fe2e9a;
}
}
*/

if (osdqoi == QOI) {
/*
Expand Down
3 changes: 3 additions & 0 deletions mainapp.cpp
Expand Up @@ -386,6 +386,9 @@ void BrowserApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefF

bool BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) {
TRACE("BrowserApp::OnProcessMessageReceived");

DEBUG("===> Render message: {}", message->GetName().ToString());

return false;
}

3 changes: 1 addition & 2 deletions requestresponse.cpp
Expand Up @@ -72,8 +72,7 @@ std::string readPostJavascript(std::string browserIp, int browserPort) {
_dynamic << result << std::endl;
_dynamic.close();

std::string post = "\n<div id=\"_video_color_overlay_\" style=\"visibility:hidden;position: absolute; background-color: rgb(254, 46, 154); z-index: 999;\"></div>\n";
post += "\n<script type=\"text/javascript\" src=\"http://" + browserIp + ":" + std::to_string(browserPort) + "/js/_dynamic_body.js\"></script>\n";
std::string post = "\n<script type=\"text/javascript\" src=\"http://" + browserIp + ":" + std::to_string(browserPort) + "/js/_dynamic_body.js\"></script>\n";

return post;
}
Expand Down
16 changes: 14 additions & 2 deletions static-content/js/video_quirks.js
Expand Up @@ -34,25 +34,37 @@ function activate_quirks(isStart) {
// Arte.tv
if (document.location.href.search("www.arte.tv") > 0) {
if (isStart) {
_quirk_style_id('_video_color_overlay_', 'visibility', 'hidden');
_quirk_style_id('player', 'visibility', 'hidden');
} else {
_quirk_style_id('_video_color_overlay_', 'visibility', 'visible');
_quirk_style_id('player', 'visibility', 'visible');
}
} else if (document.location.href.search("hbbtv.redbutton.de/extern/redorbit/hbbtv/apps/") > 0) {
if (isStart) {
_quirk_style_id('contentHub-home', 'visibility', 'hidden');
_quirk_style_id('stage', 'visibility', 'hidden');
_quirk_style_id('screen', 'background', 'transparent');
_quirk_body_background('transparent');

/*
_quirk_style_id('content', 'visibility', 'hidden');
_quirk_style_id('footer', 'visibility', 'hidden');
_quirk_body_background('transparent');
_quirk_save_set('HBBTV_SAVE_CONTENT_HUB_HOME', 'contentHub-home', 'background', 'transparent');
_quirk_save_set('HBBTV_SAVE_SCREEN', 'screen', 'background', 'transparent');
*/
} else {
_quirk_style_id('contentHub-home', 'visibility', 'visible');
_quirk_style_id('stage', 'visibility', 'visible');
_quirk_style_id('screen', 'background', '#efefef');
_quirk_body_background('#2c2c2c');

/*
_quirk_style_id('content', 'visibility', 'visible');
_quirk_style_id('footer', 'visibility', 'visible');
_quirk_body_background('#2c2c2c');
_quirk_restore_set('HBBTV_SAVE_CONTENT_HUB_HOME', 'contentHub-home', 'background');
_quirk_restore_set('HBBTV_SAVE_SCREEN', 'screen', 'background');
*/
}
}
}
Expand Down
30 changes: 12 additions & 18 deletions static-content/js/videoobserver.js
Expand Up @@ -11,7 +11,6 @@ const PLAY_STATES = {
window.promoteVideoSize = (node, considerLayer) => {
let position = node.getBoundingClientRect();
let bodyPos = document.getElementsByTagName('body')[0].getBoundingClientRect();
let overlay = document.getElementById('_video_color_overlay_');

/*
console.log("In PromoteVideoSize: body (" + bodyPos.x + "," + bodyPos.y + "," + bodyPos.width + "," + bodyPos.height + ")");
Expand All @@ -21,33 +20,22 @@ window.promoteVideoSize = (node, considerLayer) => {

// if width or height of body is 0, then set values to the maximum size
if (bodyPos.width == 0 || bodyPos.height == 0) {
bodyPos.width = 1280;
bodyPos.height = 720;
// bodyPos.width = 1280;
// bodyPos.height = 720;
}

if ((position.width == 300) && (position.height == 150)) {
// sometimes the wrong size is requested. Ignore this to prevent flickering
// console.log("Size 300x150 requested");

overlay.style.visibility = "hidden";
window.cefVideoFullscreen();
return;
// overlay.style.visibility = "hidden";
// window.cefVideoFullscreen();
// return;
}

if ((position.x === bodyPos.x) && (position.y === bodyPos.y) && (position.height === bodyPos.height) && (position.width === bodyPos.width)) {
overlay.style.visibility = "hidden";

window.cefVideoFullscreen();
} else {
if (overlay && considerLayer) {
overlay.style.visibility = "visible";
overlay.style.left = position.x.toString() + "px";
overlay.style.top = position.y.toString() + "px";
overlay.style.width = position.width.toString() + "px";
overlay.style.height = position.height.toString() + "px";
overlay.style.backgroundColor = "rgb(254, 46, 154)";
}

window.cefVideoSize(position.x | 0, position.y | 0, position.width | 0, position.height | 0);
}
}
Expand Down Expand Up @@ -242,7 +230,7 @@ function watchAndHandleVideoObjectMutations() {

video.autoplay = true;
video.src = url;
video.style = 'top:0px; left:0px; width:100%; height:100%;background-color:rgb(254, 46, 154)';
video.style = 'top:0px; left:0px; width:100%; height:100%;';

node.replaceChildren(video);
}
Expand Down Expand Up @@ -297,6 +285,7 @@ function watchAndHandleVideoObjectMutations() {
// console.log("All Cookies: " + document.cookie);

let newUrl = window.cefStreamVideo(node.data);

addVideoNode(node, newUrl);
node.data = newUrl;
node.style.visibility = 'hidden';
Expand Down Expand Up @@ -368,13 +357,18 @@ function watchAndHandleVideoObjectMutations() {
}
};

const handleAttributeChanged = (mutation) => {
// console.log("Target: " + mutation.target);
};

const handleMutation = (mutationList) => {
mutationList.forEach((mutation) => {
switch (mutation.type) {
case 'childList':
handleChildAddedRemoved(mutation);
break;
case 'attributes':
// handleAttributeChanged(mutation);
break;
}
});
Expand Down
56 changes: 38 additions & 18 deletions v8handler.cpp
Expand Up @@ -5,6 +5,7 @@
#include "logger.h"

bool startVideo;
bool videoReset;

void V8Handler::stopVdrVideo() {
int waitTime = 5; // ms
Expand All @@ -17,8 +18,10 @@ void V8Handler::stopVdrVideo() {

if (startVideo) {
vdrRemoteClient->ResetVideo();
videoReset = true;
} else {
vdrRemoteClient->StopVideo();
videoReset = false;
}
}

Expand All @@ -27,18 +30,21 @@ V8Handler::V8Handler(std::string bIp, int bPort, std::string tIp, int tPort, std
{
transcoderRemoteClient = new TranscoderRemoteClient(tIp, tPort, bIp, bPort);
vdrRemoteClient = new VdrRemoteClient(vdrIp, vdrPort);

lastVideoX = lastVideoY = lastVideoW = lastVideoH = 0;
lastFullscreen = false;
}

V8Handler::~V8Handler() {
delete transcoderRemoteClient;
delete vdrRemoteClient;
}

void V8Handler::sendMessageToBrowser(std::string message) {
sendMessageToBrowser(message, "");
void V8Handler::sendMessageToProcess(std::string message, CefProcessId target_process) {
sendMessageToProcess(message, "", target_process);
}

void V8Handler::sendMessageToBrowser(std::string message, std::string parameter) {
void V8Handler::sendMessageToProcess(std::string message, std::string parameter, CefProcessId target_process) {
CefRefPtr<CefV8Context> ctx = CefV8Context::GetCurrentContext();
CefRefPtr<CefBrowser> browser = ctx->GetBrowser();

Expand All @@ -48,10 +54,10 @@ void V8Handler::sendMessageToBrowser(std::string message, std::string parameter)
args->SetString(0, parameter);
}

browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, msg);
browser->GetMainFrame()->SendProcessMessage(target_process, msg);
}

void V8Handler::sendMessageToBrowser(std::string message, std::vector<std::string>& parameter) {
void V8Handler::sendMessageToProcess(std::string message, std::vector<std::string>& parameter, CefProcessId target_process) {
CefRefPtr<CefV8Context> ctx = CefV8Context::GetCurrentContext();
CefRefPtr<CefBrowser> browser = ctx->GetBrowser();

Expand All @@ -64,7 +70,7 @@ void V8Handler::sendMessageToBrowser(std::string message, std::vector<std::strin
idx++;
}

browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, msg);
browser->GetMainFrame()->SendProcessMessage(target_process, msg);
}

bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, const CefV8ValueList &arguments, CefRefPtr<CefV8Value> &retval, CefString &exception) {
Expand All @@ -83,7 +89,9 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
return false;
}

vdrRemoteClient->StartVideo();
if (!videoReset) {
vdrRemoteClient->StartVideo();
}
}

retval = CefV8Value::CreateString("http://"+ transcoderIp + ":" + std::to_string(transcoderPort) + "/movie/transparent-video-" + browserIp + "_" + std::to_string(browserPort) + ".webm");
Expand Down Expand Up @@ -138,7 +146,7 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con

DEBUG("V8Handler::Execute RedButton Argument ChannelId {}", channelId);

sendMessageToBrowser("RedButton", channelId);
sendMessageToProcess("RedButton", channelId, PID_BROWSER);
}

retval = CefV8Value::CreateBool(true);
Expand All @@ -150,7 +158,7 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con

DEBUG("V8Handler::Execute LoadUrl {}", url);

sendMessageToBrowser("LoadUrl", url);
sendMessageToProcess("LoadUrl", url, PID_BROWSER);
}

retval = CefV8Value::CreateBool(true);
Expand All @@ -168,20 +176,32 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
return true;
}

std::vector<std::string> params;
params.push_back(std::to_string(x));
params.push_back(std::to_string(y));
params.push_back(std::to_string(w));
params.push_back(std::to_string(h));
if ((x != lastVideoX) || (y != lastVideoY) || (w != lastVideoW) || (h != lastVideoH)) {
// send new VideoSize to Browser
lastVideoX = x;
lastVideoY = y;
lastVideoH = h;
lastVideoW = w;
lastFullscreen = false;

sendMessageToBrowser("SetDirtyOSD");
vdrRemoteClient->VideoSize(x, y, w, h);
vdrRemoteClient->VideoSize(x, y, w, h);
}

sendMessageToProcess("SetDirtyOSD", PID_BROWSER);
}

retval = CefV8Value::CreateBool(true);
return true;
} else if (name == "VideoFullscreen") {
vdrRemoteClient->VideoFullscreen();
if (!lastFullscreen) {
lastVideoX = 0;
lastVideoY = 0;
lastVideoH = 0;
lastVideoW = 0;
lastFullscreen = true;

vdrRemoteClient->VideoFullscreen();
}

retval = CefV8Value::CreateBool(true);
return true;
Expand All @@ -196,7 +216,7 @@ bool V8Handler::Execute(const CefString &name, CefRefPtr<CefV8Value> object, con
params.push_back(appId);
params.push_back(args);

sendMessageToBrowser("StartApp", params);
sendMessageToProcess("StartApp", params, PID_BROWSER);
}

retval = CefV8Value::CreateBool(true);
Expand Down
9 changes: 6 additions & 3 deletions v8handler.h
Expand Up @@ -24,10 +24,13 @@ class V8Handler : public CefV8Handler {
VdrRemoteClient* vdrRemoteClient;
TranscoderRemoteClient* transcoderRemoteClient;

int lastVideoX, lastVideoY, lastVideoW, lastVideoH;
bool lastFullscreen;

private:
void sendMessageToBrowser(std::string message);
void sendMessageToBrowser(std::string message, std::string parameter);
void sendMessageToBrowser(std::string message, std::vector<std::string>& parameter);
void sendMessageToProcess(std::string message, CefProcessId target_process);
void sendMessageToProcess(std::string message, std::string parameter, CefProcessId target_process);
void sendMessageToProcess(std::string message, std::vector<std::string>& parameter, CefProcessId target_process);

void stopVdrVideo();

Expand Down

0 comments on commit 48c1a21

Please sign in to comment.