Skip to content

Commit ed982fa

Browse files
committed
refactor: Add ENABLE_OBS_WEBSOCKET option for vendor request integration
Submodule presence is checked only when the option is ON, with FATAL_ERROR on absence. Includes accumulated input validation, lifetime annotation, and Security documentation refinements.
1 parent 9561086 commit ed982fa

11 files changed

Lines changed: 348 additions & 123 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
!screenshot2.jpg
3131
!build.ps1
3232
!/lib
33+
/lib/*
34+
!/lib/obs-websocket
3335
!.gitmodules
3436
!README_ja.md
3537
!API.md

API.md

Lines changed: 110 additions & 36 deletions
Large diffs are not rendered by default.

API_ja.md

Lines changed: 109 additions & 36 deletions
Large diffs are not rendered by default.

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ include(compilerconfig)
1111
include(defaults)
1212
include(helpers)
1313

14+
option(ENABLE_OBS_WEBSOCKET "Enable obs-websocket vendor request integration" ON)
15+
16+
if(ENABLE_OBS_WEBSOCKET AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket/lib/obs-websocket-api.h")
17+
message(
18+
FATAL_ERROR
19+
"ENABLE_OBS_WEBSOCKET is ON but lib/obs-websocket submodule is missing. Run: git submodule update --init --recursive (or pass -DENABLE_OBS_WEBSOCKET=OFF to disable obs-websocket vendor request integration)"
20+
)
21+
endif()
22+
1423
add_library(${CMAKE_PROJECT_NAME} MODULE)
1524

1625
find_package(libobs REQUIRED)
@@ -34,19 +43,18 @@ if(ENABLE_QT)
3443
AUTORCC ON)
3544
endif()
3645

37-
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket/lib/obs-websocket-api.h")
38-
message(FATAL_ERROR "lib/obs-websocket submodule not found. Run: git submodule update --init --recursive")
46+
if(ENABLE_OBS_WEBSOCKET)
47+
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket/lib)
48+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ENABLE_OBS_WEBSOCKET)
49+
target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-websocket.cpp)
3950
endif()
4051

41-
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket/lib)
42-
4352
target_sources(
4453
${CMAKE_PROJECT_NAME}
4554
PRIVATE src/plugin-main.cpp
4655
src/plugin-streaming.cpp
4756
src/plugin-stream-recording.cpp
4857
src/plugin-replay-buffer.cpp
49-
src/plugin-websocket.cpp
5058
src/plugin-ui.cpp
5159
src/utils.cpp
5260
src/audio/audio-capture.cpp

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,17 @@ git submodule update --init --recursive
136136

137137
If you cloned with `--recurse-submodules`, this step is unnecessary.
138138

139+
The submodule is pinned to a specific release tag of obs-websocket. Do **not** run
140+
`git submodule update --remote`, which would move the submodule to the upstream default branch
141+
and silently introduce unintended changes. To bump the pinned version, fetch the submodule's
142+
upstream, check out the desired release tag, then stage and commit the new pointer:
143+
144+
```bash
145+
cd lib/obs-websocket
146+
git fetch --tags origin
147+
git checkout <new-tag>
148+
cd ../..
149+
git add lib/obs-websocket
150+
git commit -m "Bump obs-websocket submodule to <new-tag>"
151+
```
152+

README_ja.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,17 @@ git submodule update --init --recursive
137137

138138
`--recurse-submodules` 付きでクローンした場合は、この手順は不要です。
139139

140+
このサブモジュールは obs-websocket の特定のリリースタグに固定されています。`git submodule update --remote`
141+
は実行しないでください。アップストリームのデフォルトブランチへサブモジュールを移動させ、意図しない変更が
142+
混入します。固定バージョンを更新する場合は、サブモジュールのアップストリームを fetch し、目的のリリースタグを
143+
チェックアウトしたうえで、新しいポインタをステージしてコミットしてください。
144+
145+
```bash
146+
cd lib/obs-websocket
147+
git fetch --tags origin
148+
git checkout <new-tag>
149+
cd ../..
150+
git add lib/obs-websocket
151+
git commit -m "Bump obs-websocket submodule to <new-tag>"
152+
```
153+

build-aux/.run-format.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ invoke_formatter() {
7070

7171
local -a source_files=(**/(CMakeLists.txt|*.cmake)(.N))
7272
source_files=(${source_files:#(build_*)/*})
73-
# Exclude vendored submodules under lib/ from cmake-format (nested paths included)
73+
# Exclude vendored submodules: drop every file at any depth under lib/
7474
source_files=(${source_files:#lib/**/*})
7575

7676
local -a format_args=()

build.ps1

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@ Param (
22
[switch]$installer
33
)
44

5-
$BuildSpec = Get-Content -Path ./buildspec.json -Raw | ConvertFrom-Json
6-
$ProductName = $BuildSpec.name
7-
$ProductVersion = $BuildSpec.version
5+
try {
6+
Push-Location $PSScriptRoot
87

9-
$OutputName = "${ProductName}-${ProductVersion}-windows-x64"
8+
$BuildSpec = Get-Content -Path ./buildspec.json -Raw | ConvertFrom-Json
9+
$ProductName = $BuildSpec.name
10+
$ProductVersion = $BuildSpec.version
1011

11-
if (-not (Test-Path "lib/obs-websocket/lib/obs-websocket-api.h")) {
12-
git submodule update --init --recursive lib/obs-websocket
13-
if (-not $?) { exit 1 }
14-
}
12+
$OutputName = "${ProductName}-${ProductVersion}-windows-x64"
1513

16-
cmake --fresh -S . -B build_x64 -Wdev -Wdeprecated -DCMAKE_SYSTEM_VERSION="10.0.18363.657" -G "Visual Studio 17 2022" -A x64
17-
cmake --build build_x64 --config RelWithDebInfo --target ALL_BUILD --
18-
cmake --install build_x64 --prefix release/Package --config RelWithDebInfo
14+
if (-not (Test-Path "lib/obs-websocket/lib/obs-websocket-api.h")) {
15+
git submodule update --init --recursive lib/obs-websocket
16+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
17+
}
1918

20-
if ($installer) {
21-
iscc build_x64/installer-Windows.generated.iss /O"release" /F"${OutputName}-Installer-signed"
19+
cmake --fresh -S . -B build_x64 -Wdev -Wdeprecated -DCMAKE_SYSTEM_VERSION="10.0.18363.657" -G "Visual Studio 17 2022" -A x64
20+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
21+
cmake --build build_x64 --config RelWithDebInfo --target ALL_BUILD --
22+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
23+
cmake --install build_x64 --prefix release/Package --config RelWithDebInfo
24+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
25+
26+
if ($installer) {
27+
iscc build_x64/installer-Windows.generated.iss /O"release" /F"${OutputName}-Installer-signed"
28+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
29+
}
30+
} finally {
31+
Pop-Location
2232
}

cmake/linux/defaults.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ set(CPACK_SOURCE_IGNORE_FILES
3434
\\.git/
3535
\\.github/
3636
\\.gitignore
37-
\\.gitmodules
3837
build_.*
3938
cmake/\\.CMakeBuildNumber
39+
lib/
4040
release/)
4141

4242
set(CPACK_VERBATIM_VARIABLES YES)

src/plugin-main.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
3434
#include "video/filter-video-capture.hpp"
3535
#include "plugin-support.h"
3636
#include "plugin-main.hpp"
37+
#ifdef ENABLE_OBS_WEBSOCKET
3738
#include "plugin-websocket.hpp"
39+
#endif
3840
#include "utils.hpp"
3941

4042
#define SETTINGS_JSON_NAME "recently.json"
@@ -146,9 +148,12 @@ BranchOutputFilter::BranchOutputFilter(obs_data_t *settings, obs_source_t *sourc
146148
// FIXME: libobs has no proc_handler_remove(). If it gains one, pair
147149
// unregistration with ~BranchOutputFilter().
148150
proc_handler_t *ph = obs_source_get_proc_handler(filterSource);
149-
auto replayBufferProcDecl =
151+
// static: proc_handler_add() does not document whether it copies the decl string,
152+
// so the buffer must outlive every registered handler.
153+
static const std::string replayBufferProcDecl =
150154
std::string("void ") + PROC_OVERRIDE_REPLAY_BUFFER_FILENAME_FORMAT + "(in string format)";
151-
auto recordingProcDecl = std::string("void ") + PROC_OVERRIDE_RECORDING_FILENAME_FORMAT + "(in string format)";
155+
static const std::string recordingProcDecl =
156+
std::string("void ") + PROC_OVERRIDE_RECORDING_FILENAME_FORMAT + "(in string format)";
152157
proc_handler_add(ph, replayBufferProcDecl.c_str(), onOverrideReplayBufferFilenameFormat, this);
153158
proc_handler_add(ph, recordingProcDecl.c_str(), onOverrideRecordingFilenameFormat, this);
154159

@@ -1929,26 +1934,27 @@ void obs_module_post_load()
19291934
proc_handler_t *ph = obs_get_proc_handler();
19301935
proc_handler_add(ph, "void osi_branch_output_get_filter_list(out string json)", onGetFilterList, nullptr);
19311936

1937+
#ifdef ENABLE_OBS_WEBSOCKET
19321938
registerWebSocketVendorRequests();
1939+
#endif
19331940
}
19341941

19351942
void obs_module_unload()
19361943
{
1937-
// Publish nullptr before unregistering vendor requests so that any
1938-
// vendor callback already in flight observes a null dock and bails out
1939-
// of the UI dispatch path. Doing this first shrinks (but does not
1940-
// close) the worker race window.
1944+
// Stop accepting new vendor dispatches before tearing down the dock so
1945+
// a worker cannot start a fresh UI invocation against a destroyed dock.
19411946
//
1942-
// FIXME: narrow worker race remains. Proper fixes are an in-flight
1943-
// counter (wait for zero before remove_dock) or QPointer + deleteLater
1944-
// + processEvents drain. Current code accepts the race because the
1945-
// worst observable effect is a silent empty result.
1947+
// FIXME: narrow worker race remains for a callback that already loaded
1948+
// a non-null dock pointer. Proper fixes are an in-flight counter or
1949+
// QPointer + deleteLater + processEvents drain.
1950+
#ifdef ENABLE_OBS_WEBSOCKET
1951+
unregisterWebSocketVendorRequests();
1952+
#endif
1953+
19461954
if (statusDock.exchange(nullptr) != nullptr) {
19471955
obs_frontend_remove_dock("BranchOutputStatusDock");
19481956
}
19491957

1950-
unregisterWebSocketVendorRequests();
1951-
19521958
pthread_mutex_destroy(&pluginMutex);
19531959

19541960
obs_log(LOG_INFO, "Plugin unloaded");

0 commit comments

Comments
 (0)