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

Make frontend-api integration optional #126

Open
wants to merge 3 commits into
base: master
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
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ if(NOT CEF_FOUND)
return()
endif()

option(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED "Enable shared texture support for the browser plugin (Win32)" ON)
option(BROWSER_PANEL_SUPPORT_ENABLED "Enables Qt web browser panel support" ON)
option(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT "Enable shared texture support for the browser plugin (Win32)" ON)
option(BROWSER_PANEL_SUPPORT "Enables Qt web browser panel support" ON)
option(BROWSER_FRONTEND_API_SUPPORT "Enables integration with obs-frontend-api library" ON)

if (EXPERIMENTAL_SHARED_TEXTURE_SUPPORT)
set(EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED)
endif()

if (BROWSER_FRONTEND_API_SUPPORT)
set(BROWSER_FRONTEND_API_SUPPORT_ENABLED)
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/browser-config.h.in"
Expand Down Expand Up @@ -84,7 +93,7 @@ set(obs-browser_HEADERS

# only allow browser panels on win32 for now -- other operating systems
# need more testing
if(WIN32 AND BROWSER_PANEL_SUPPORT_ENABLED)
if(WIN32 AND BROWSER_PANEL_SUPPORT AND BROWSER_FRONTEND_API_SUPPORT)
if(DEFINED QTDIR${_lib_suffix})
list(APPEND CMAKE_PREFIX_PATH "${QTDIR${_lib_suffix}}")
elseif(DEFINED QTDIR)
Expand Down
11 changes: 9 additions & 2 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include "obs-browser-source.hpp"
#include "base64/base64.hpp"
#include "json11/json11.hpp"

#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
#include <obs-frontend-api.h>
#endif

using namespace json11;

Expand Down Expand Up @@ -106,14 +109,18 @@ bool BrowserClient::OnProcessMessageReceived(
{"height", (int)obs_source_get_height(bs->source)}
};

} else if (name == "getStatus") {
}
#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
else if (name == "getStatus") {
json = Json::object {
{"recording", obs_frontend_recording_active()},
{"streaming", obs_frontend_streaming_active()},
{"replaybuffer", obs_frontend_replay_buffer_active()}
};

} else {
}
#endif
else {
return false;
}

Expand Down
23 changes: 3 additions & 20 deletions browser-config.h.in
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
#pragma once

#ifndef ON
#define ON true
#endif

#ifndef OFF
#define OFF false
#endif

#ifndef TRUE
#define TRUE true
#endif

#ifndef FALSE
#define FALSE false
#endif

#ifdef _WIN32
#define EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED \
@EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED@
#else
#define EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED false
#cmakedefine01 EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
#endif

#cmakedefine01 BROWSER_FRONTEND_API_SUPPORT_ENABLED
11 changes: 10 additions & 1 deletion obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include <obs-frontend-api.h>
#include <util/threading.h>
#include <util/platform.h>
#include <util/util.hpp>
Expand All @@ -40,6 +39,10 @@
#include <d3d11.h>
#endif

#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
#include <obs-frontend-api.h>
#endif

OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-browser", "en-US")

Expand Down Expand Up @@ -315,6 +318,7 @@ void RegisterBrowserSource()

extern void DispatchJSEvent(const char *eventName, const char *jsonString);

#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
{
switch (event) {
Expand Down Expand Up @@ -363,6 +367,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
default:;
}
}
#endif

#ifdef _WIN32
static inline void EnumAdapterCount()
Expand Down Expand Up @@ -401,7 +406,11 @@ bool obs_module_load(void)
EnumAdapterCount();
#endif
RegisterBrowserSource();

#if BROWSER_FRONTEND_API_SUPPORT_ENABLED
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);
#endif


#if EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED
obs_data_t *private_data = obs_get_private_data();
Expand Down