Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdykstra cmd4 #20

Open
wants to merge 16 commits into
base: streamlabs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(obs-browser)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)

include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/UI/obs-frontend-api")
#include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/UI/obs-frontend-api")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/deps")

Expand Down Expand Up @@ -53,6 +53,11 @@ set(obs-browser_LIBRARIES
# obs-frontend-api
)

if(WIN32)
list(APPEND obs-browser_LIBRARIES
Kernel32)
endif()

list(APPEND obs-browser_LIBRARIES
${CEF_LIBRARIES})

Expand Down
43 changes: 37 additions & 6 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

using namespace json11;

std::map<std::string, std::string> BrowserApp::parameters;

CefRefPtr<CefRenderProcessHandler> BrowserApp::GetRenderProcessHandler()
{
return this;
Expand All @@ -69,21 +71,31 @@ void BrowserApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar
#endif
}

void BrowserApp::AddFlag(bool flag)
// Returns if the browser needs to be restarted or not. Returning
// true means the browser should be restarted.
bool BrowserApp::TryUpdateCommandLineParameters(
std::map<std::string, std::string> params)
{
std::lock_guard<std::mutex> guard(flag_mutex);
this->media_flags.push(flag);
parameters = params;
return true;
}

void BrowserApp::AddFlag(bool flag)
{
std::lock_guard<std::mutex> guard(flag_mutex);
this->media_flags.push(flag);
}

void BrowserApp::OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line)
{
// There are two processes in CEF V1 (the one we're using). There's
// a server and a child process. The server is launched once and the
// child process is launched for new windows/tabs
#ifdef _WIN32
std::string pid = std::to_string(GetCurrentProcessId());
command_line->AppendSwitchWithValue("parent_pid", pid);
#else
#endif

std::lock_guard<std::mutex> guard(flag_mutex);
if (this->media_flag != -1) {
if (this->media_flag) {
Expand All @@ -98,10 +110,19 @@ void BrowserApp::OnBeforeChildProcessLaunch(
command_line->AppendSwitchWithValue("enable-media-stream", "1");
}
}

for (auto&& p : parameters) {
if (p.first == "")
continue;
if (p.second == "")
command_line->AppendSwitch(p.first);
else
command_line->AppendSwitchWithValue(p.first, p.second);
}
}

void BrowserApp::OnBeforeCommandLineProcessing(
const CefString &, CefRefPtr<CefCommandLine> command_line)
const CefString & processType, CefRefPtr<CefCommandLine> command_line)
{
if (!shared_texture_available) {
bool enableGPU = command_line->HasSwitch("enable-gpu");
Expand Down Expand Up @@ -140,6 +161,16 @@ void BrowserApp::OnBeforeCommandLineProcessing(
command_line->AppendSwitchWithValue("enable-media-stream", "1");
}
}

for (auto&& p : parameters) {
if (p.first == "")
continue;
if (p.second == "")
command_line->AppendSwitch(p.first);
else
command_line->AppendSwitchWithValue(p.first, p.second);

}
#ifdef __APPLE__
command_line->AppendSwitch("use-mock-keychain");
#endif
Expand Down
17 changes: 15 additions & 2 deletions browser-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,25 @@ class BrowserApp : public CefApp,
CallbackMap callbackMap;
int callbackId;

// we can only have a single instance of the browser, so parameters are shared between them.
static std::map<std::string, std::string> parameters;

// This is what the browser was launched with orriginally. The user may change this
CefMainArgs launchArgs;

// These change for each child instance process

public:
inline BrowserApp(bool shared_texture_available_ = false)
: shared_texture_available(shared_texture_available_), media_flag(-1)
inline BrowserApp( const CefMainArgs& args, bool shared_texture_available_ = false)
: shared_texture_available(shared_texture_available_),
launchArgs(args),
media_flag(-1)
{
}

// The browser will not be restarted if the command line parameters have not changed.
static bool TryUpdateCommandLineParameters(std::map<std::string, std::string> parameters);

void AddFlag(bool flag);
int media_flag;
std::mutex flag_mutex;
Expand Down
1 change: 1 addition & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FPS="FPS"
CSS="Custom CSS"
ShutdownSourceNotVisible="Shutdown source when not visible"
RefreshBrowserActive="Refresh browser when scene becomes active"
BrowserOptions="Browser options"
RefreshNoCache="Refresh cache of current page"
RestartCEF="Restart CEF"
BrowserSource="Browser"
Expand Down
2 changes: 1 addition & 1 deletion obs-browser-page/obs-browser-page-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(int argc, char *argv[])
#endif
CefMainArgs mainArgs(argc, argv);
#endif
CefRefPtr<BrowserApp> mainApp(new BrowserApp());
CefRefPtr<BrowserApp> mainApp(new BrowserApp(mainArgs));

int ret = CefExecuteProcess(mainArgs, mainApp.get(), NULL);

Expand Down
50 changes: 32 additions & 18 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ margin: 0px auto; \
overflow: hidden; \
}";

static const char *default_browser_options = "";

static void browser_source_get_defaults(obs_data_t *settings)
{
obs_data_set_default_string(settings, "url",
Expand All @@ -138,6 +140,7 @@ static void browser_source_get_defaults(obs_data_t *settings)
obs_data_set_default_int(settings, "webpage_control_level",
(int)DEFAULT_CONTROL_LEVEL);
obs_data_set_default_string(settings, "css", default_css);
obs_data_set_default_string(settings, "browser_options", default_browser_options);

#ifdef __APPLE__
obs_data_set_default_bool(settings, "reroute_audio", true);
Expand All @@ -158,10 +161,10 @@ static bool is_local_file_modified(obs_properties_t *props, obs_property_t *,
return true;
}

static bool is_mediaflag_modified(obs_properties_t *props, obs_property_t *,
obs_data_t *settings)
static bool on_browser_media_flag_modified(obs_properties_t* props, obs_property_t* property, obs_data_t* settings)
{
bool enabled = obs_data_get_bool(settings, "is_media_flag");
// TODO: This is a command line option and will have to change the command line properties.
obs_properties_t *new_flags = props;
return true;
}

Expand Down Expand Up @@ -197,7 +200,8 @@ static obs_properties_t *browser_source_get_properties(void *data)
}

obs_property_set_modified_callback(prop, is_local_file_modified);
obs_property_set_modified_callback(is_media_flag_prop, is_mediaflag_modified);
obs_property_set_modified_callback(is_media_flag_prop, on_browser_media_flag_modified);

obs_properties_add_path(props, "local_file",
obs_module_text("LocalFile"), OBS_PATH_FILE,
"*.*", path->array);
Expand All @@ -222,6 +226,12 @@ static obs_properties_t *browser_source_get_properties(void *data)
obs_property_t *p = obs_properties_add_text(
props, "css", obs_module_text("CSS"), OBS_TEXT_MULTILINE);
obs_property_text_set_monospace(p, true);

obs_property_t *browser_options_prop =
obs_properties_add_text(props, "browser_options",
obs_module_text("BrowserOptions"), OBS_TEXT_DEFAULT);
obs_property_set_visible(browser_options_prop, false);

obs_properties_add_bool(props, "shutdown",
obs_module_text("ShutdownSourceNotVisible"));
obs_properties_add_bool(props, "restart_when_active",
Expand Down Expand Up @@ -310,11 +320,11 @@ static CefRefPtr<BrowserApp> app;

static void BrowserInit(obs_data_t *settings_obs)
{
blog(LOG_INFO, "BrowserInit - 0");
blog(LOG_INFO, "BrowserInit - 0 Starting Browser Initialization");
#if defined(__APPLE__) && defined(USE_UI_LOOP)
ExecuteTask([settings_obs]() {
#endif
blog(LOG_INFO, "BrowserInit - 1");
blog(LOG_INFO, "BrowserInit - 1 Finding browser executable");
string path = obs_get_module_binary_path(obs_current_module());
path = path.substr(0, path.find_last_of('/') + 1);
path += "//obs-browser-page";
Expand All @@ -326,8 +336,8 @@ static void BrowserInit(obs_data_t *settings_obs)
* CEF */
struct obs_cmdline_args cmdline_args = obs_get_cmdline_args();
CefMainArgs args(cmdline_args.argc, cmdline_args.argv);
blog(LOG_INFO, "BrowserInit - 2");
#endif
blog(LOG_INFO, "BrowserInit - 2 - (Mac Only), pass through command line parameters from OBS onto Browser");

CefSettings settings;
settings.log_severity = LOGSEVERITY_VERBOSE;
Expand All @@ -339,7 +349,7 @@ static void BrowserInit(obs_data_t *settings_obs)
uint32_t obs_min = (obs_ver >> 16) & 0xFF;
uint32_t obs_pat = obs_ver & 0xFFFF;

blog(LOG_INFO, "BrowserInit - 3");
blog(LOG_INFO, "BrowserInit - 3 - Setting browser setttings (no window, no sandboxing)");
/* This allows servers the ability to determine that browser panels and
* browser sources are coming from OBS. */
std::stringstream prod_ver;
Expand All @@ -358,8 +368,9 @@ static void BrowserInit(obs_data_t *settings_obs)
CefString(&settings.product_version) = prod_ver.str();
#endif

blog(LOG_INFO, "BrowserInit - 4");
blog(LOG_INFO, "BrowserInit - 4 - Telling browser about OBS version number");
#ifdef USE_UI_LOOP
blog(LOG_WARN, "BrowserInit - Using external UI message pump. Note, this avoids race conditions at the cost of performance.");
settings.external_message_pump = true;
settings.multi_threaded_message_loop = false;
#endif
Expand All @@ -376,14 +387,13 @@ static void BrowserInit(obs_data_t *settings_obs)
#if defined(__APPLE__)
blog(LOG_INFO, "CEF_LIBRARY %s", CEF_LIBRARY);


std::string binPath = getExecutablePath();
binPath = binPath.substr(0, binPath.find_last_of('/'));
binPath += "/Frameworks/Chromium\ Embedded\ Framework.framework";
CefString(&settings.framework_dir_path) = binPath;
blog(LOG_INFO, "binPath: %s", binPath.c_str());
#endif
blog(LOG_INFO, "BrowserInit - 5");
blog(LOG_INFO, "BrowserInit - 5 - Informing browser about it's framework language modules (OS specific)");
std::string obs_locale = obs_get_locale();
std::string accepted_languages;
if (obs_locale != "en-US") {
Expand All @@ -408,7 +418,7 @@ static void BrowserInit(obs_data_t *settings_obs)

bool tex_sharing_avail = false;

blog(LOG_INFO, "BrowserInit - 6");
blog(LOG_INFO, "BrowserInit - 6 - Setting Languge of Browser");
#ifdef SHARED_TEXTURE_SUPPORT_ENABLED
if (hwaccel) {
obs_enter_graphics();
Expand All @@ -417,30 +427,35 @@ static void BrowserInit(obs_data_t *settings_obs)
}
#endif

blog(LOG_INFO, "BrowserInit - 7");
app = new BrowserApp(hwaccel);
blog(LOG_INFO, "BrowserInit - 7 - Creating BrowserApp with hardware acceleration to %s", hwaccel ? "true" : "false");
app = new BrowserApp(args, hwaccel);

#ifdef _WIN32
blog(LOG_INFO, "BrowserInit - 8 - Setting hardware acceleration to %s", hwaccel ? "true" : "false");
CefExecuteProcess(args, app, nullptr);
/* Massive (but amazing) hack to prevent chromium from modifying our
* process tokens and permissions, which caused us problems with winrt,
* used with window capture. Note, the structure internally is just
* two pointers normally. If it causes problems with future versions
* we'll just switch back to the static library but I doubt we'll need
* to. */
blog(LOG_INFO, "BrowserInit - 9 - Initializing browser with sandbox hack (winrt workargound)");
uintptr_t zeroed_memory_lol[32] = {};
CefInitialize(args, settings, app, zeroed_memory_lol);
#else
blog(LOG_INFO, "BrowserInit - 8");
blog(LOG_INFO, "BrowserInit - 9 - Initializing browser with no sandbox information");
CefInitialize(args, settings, app, nullptr);
blog(LOG_INFO, "BrowserInit - 9");
blog(LOG_INFO, "BrowserInit - 10 - Initilization complete");
#endif
blog(LOG_INFO, "BrowserInit - 11 - Setting custom URL handler to %s (local file workaround for some versions)", ENABLE_LOCAL_FILE_URL_SCHEME ? "true" : "false");
#if !ENABLE_LOCAL_FILE_URL_SCHEME

/* Register http://absolute/ scheme handler for older
* CEF builds which do not support file:// URLs */
CefRegisterSchemeHandlerFactory("http", "absolute",
new BrowserSchemeHandlerFactory());
#endif
blog(LOG_INFO, "BrowserInit - 12 - Signaling browser is ready to OBS");
os_event_signal(cef_started_event);
#if defined(__APPLE__) && defined(USE_UI_LOOP)
});
Expand Down Expand Up @@ -511,7 +526,7 @@ void RegisterBrowserSource()
info.get_name = [](void *) { return obs_module_text("BrowserSource"); };
blog(LOG_INFO, "RegisterBrowserSource");
info.create = [](obs_data_t *settings, obs_source_t *source) -> void * {
blog(LOG_INFO, "Browser Source, INIT via info.create , settings %p source %p", settings, source);
blog(LOG_INFO, "Browser Source, INIT via info.create , settings %p source %p", settings, source);

obs_browser_initialize(settings);
if (manager_initialized && app) {
Expand Down Expand Up @@ -802,7 +817,6 @@ bool obs_module_load(void)
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);
#endif


#ifdef SHARED_TEXTURE_SUPPORT_ENABLED
obs_data_t *private_data = obs_get_private_data();
hwaccel = obs_data_get_bool(private_data, "BrowserHWAccel");
Expand Down
Loading