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

Add segment tracing AWS XRay #372

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,34 @@ endif()
include(cmake/BuildMyCurl.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE libcurl)

include(cmake/BuildAWSSDK.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE libawscpp)

# if ${CMAKE_CURRENT_BINARY_DIR}/segment-tracing-credentials.h exists then remove it
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/segment-tracing-credentials.h)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/segment-tracing-credentials.h)
endif()
configure_file(src/segment-tracing/segment-tracing-credentials.h.in
${CMAKE_CURRENT_BINARY_DIR}/segment-tracing-credentials.h)

target_sources(
${CMAKE_PROJECT_NAME}
PRIVATE src/plugin-main.c
src/ort-utils/ort-session-utils.cpp
src/obs-utils/obs-utils.cpp
src/obs-utils/obs-config-utils.cpp
src/update-checker/github-utils.cpp
src/update-checker/update-checker.cpp
src/update-checker/UpdateDialog.cpp
src/background-filter-info.c
src/background-filter.cpp
src/enhance-filter.cpp
src/enhance-filter-info.c)
target_compile_options(${CMAKE_PROJECT_NAME}
PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-error=unused-command-line-argument>)
src/enhance-filter-info.c
src/segment-tracing/segment-tracing.cpp
src/segment-tracing/SegmentTracingDialog.cpp
${CMAKE_CURRENT_BINARY_DIR}/segment-tracing-credentials.h)
target_compile_options(
${CMAKE_PROJECT_NAME} PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-error=unused-command-line-argument
-Wno-error=newline-eof>)

set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})
3 changes: 3 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"CMAKE_OSX_DEPLOYMENT_TARGET": "11.0",
"CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}",
"CODESIGN_TEAM": "$penv{CODESIGN_TEAM}",
"AWS_API_ACCESS_KEY_ID": "$penv{AWS_API_ACCESS_KEY_ID}",
"AWS_API_SECRET_KEY": "$penv{AWS_API_SECRET_KEY}",
"AWS_REGION": "$penv{AWS_REGION}",
"ENABLE_FRONTEND_API": true,
"ENABLE_QT": true
}
Expand Down
78 changes: 78 additions & 0 deletions cmake/BuildAWSSDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
include(ExternalProject)

string(REPLACE ";" "$<SEMICOLON>" CMAKE_OSX_ARCHITECTURES_ "${CMAKE_OSX_ARCHITECTURES}")

if(MSVC)
if(${CMAKE_GENERATOR_PLATFORM} STREQUAL x64
AND ${MSVC_VERSION} GREATER_EQUAL 1910
AND ${MSVC_VERSION} LESS_EQUAL 1939)
set(AWS_SDK_LIB_PATH x64/vc17/staticlib)
else()
message(FATAL_ERROR "Unsupported MSVC!")
endif()
else()
set(AWS_SDK_LIB_PATH lib)
set(AWS_SDK_LIB_SUFFIX "")
endif()

if(UNIX AND NOT APPLE)
set(CURL_LIBRARY ${CMAKE_BINARY_DIR}/vendor/curl/lib/${CMAKE_BUILD_TYPE}/libcurl.a)
set(CURL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/vendor/curl/include)
endif()

ExternalProject_Add(
libawscpp-download
GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp.git
GIT_TAG 1.11.113
LIST_SEPARATOR "|"
CMAKE_GENERATOR ${CMAKE_GENERATOR}
BUILD_BYPRODUCTS
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-auth${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-cal${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-common${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-compression${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-event-stream${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-http${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-io${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-mqtt${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-s3${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-sdkutils${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-checksums${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-core${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-xray${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-crt-cpp${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_}
-DBUILD_ONLY=xray
-DAWS_COMPILER_WARNINGS=-Wno-shorten-64-to-32
-DMINIMIZE_SIZE=ON
-DENABLE_TESTING=OFF
TEST_COMMAND ""
BUILD_ALWAYS OFF)

ExternalProject_Get_Property(libawscpp-download INSTALL_DIR)

add_library(libawscpp INTERFACE)
add_dependencies(libawscpp libawscpp-download)
target_link_libraries(
OpenCV
INTERFACE
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-auth${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-cal${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-common${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-compression${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-event-stream${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-http${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-io${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-mqtt${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-s3${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-sdkutils${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-checksums${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-core${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-xray${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
${INSTALL_DIR}/${AWS_SDK_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}aws-crt-cpp${AWS_SDK_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
)
set_target_properties(libawscpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
4 changes: 3 additions & 1 deletion data/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"check_for_updates": true
"check_for_updates": true,
"segment_tracing": false,
"show_segment_tracing_dialog": true
}
1 change: 1 addition & 0 deletions src/background-filter-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ struct obs_source_info background_removal_filter_info = {
.deactivate = background_filter_deactivate,
.video_tick = background_filter_video_tick,
.video_render = background_filter_video_render,
.filter_remove = background_filter_remove,
};
21 changes: 20 additions & 1 deletion src/background-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <new>
#include <mutex>

#include <plugin-support.h>
#include "plugin-support.h"
#include "models/ModelSINET.h"
#include "models/ModelMediapipe.h"
#include "models/ModelSelfie.h"
Expand All @@ -26,6 +26,7 @@
#include "ort-utils/ort-session-utils.h"
#include "obs-utils/obs-utils.h"
#include "consts.h"
#include "segment-tracing/segment-tracing.h"

struct background_removal_filter : public filter_data {
bool enableThreshold = true;
Expand Down Expand Up @@ -255,13 +256,15 @@ void background_filter_activate(void *data)
struct background_removal_filter *tf =
reinterpret_cast<background_removal_filter *>(data);
tf->isDisabled = false;
send_segment_trace(SEGMENT_TYPE_FILTER_ACTIVATED, -1);
}

void background_filter_deactivate(void *data)
{
struct background_removal_filter *tf =
reinterpret_cast<background_removal_filter *>(data);
tf->isDisabled = true;
send_segment_trace(SEGMENT_TYPE_FILTER_DEACTIVATED, -1);
}

/** FILTER CORE */
Expand All @@ -272,6 +275,8 @@ void *background_filter_create(obs_data_t *settings, obs_source_t *source)
struct background_removal_filter *tf = new (data)
background_removal_filter();

send_segment_trace(SEGMENT_TYPE_FILTER_CREATE, -1);

tf->source = source;
tf->texrender = gs_texrender_create(GS_BGRA, GS_ZS_NONE);

Expand All @@ -290,6 +295,8 @@ void background_filter_destroy(void *data)
struct background_removal_filter *tf =
reinterpret_cast<background_removal_filter *>(data);

send_segment_trace(SEGMENT_TYPE_FILTER_DESTROY, -1);

if (tf) {
obs_enter_graphics();
gs_texrender_destroy(tf->texrender);
Expand All @@ -299,6 +306,7 @@ void background_filter_destroy(void *data)
gs_effect_destroy(tf->effect);
gs_effect_destroy(tf->kawaseBlurEffect);
obs_leave_graphics();

tf->~background_removal_filter();
bfree(tf);
}
Expand Down Expand Up @@ -443,9 +451,11 @@ void background_filter_video_tick(void *data, float seconds)
}
} catch (const Ort::Exception &e) {
blog(LOG_ERROR, "ONNXRuntime Exception: %s", e.what());
send_segment_trace(SEGMENT_TYPE_FILTER_ERROR, -1);
// TODO: Fall back to CPU if it makes sense
} catch (const std::exception &e) {
blog(LOG_ERROR, "%s", e.what());
send_segment_trace(SEGMENT_TYPE_FILTER_ERROR, -1);
}

UNUSED_PARAMETER(seconds);
Expand Down Expand Up @@ -539,6 +549,7 @@ void background_filter_video_render(void *data, gs_effect_t *_effect)
if (!alphaTexture) {
blog(LOG_ERROR, "Failed to create alpha texture");
obs_source_skip_video_filter(tf->source);
send_segment_trace(SEGMENT_TYPE_FILTER_ERROR, -1);
return;
}
}
Expand Down Expand Up @@ -584,3 +595,11 @@ void background_filter_video_render(void *data, gs_effect_t *_effect)
gs_texture_destroy(alphaTexture);
gs_texture_destroy(blurredTexture);
}

void background_filter_remove(void *data, obs_source_t *source)
{
UNUSED_PARAMETER(source);
UNUSED_PARAMETER(data);

send_segment_trace(SEGMENT_TYPE_FILTER_REMOVE, -1);
}
1 change: 1 addition & 0 deletions src/background-filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void background_filter_activate(void *data);
void background_filter_deactivate(void *data);
void background_filter_video_tick(void *data, float seconds);
void background_filter_video_render(void *data, gs_effect_t *_effect);
void background_filter_remove(void *data, obs_source_t *source);

#ifdef __cplusplus
}
Expand Down
49 changes: 49 additions & 0 deletions src/obs-utils/obs-config-utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "obs-config-utils.h"

#include <obs-module.h>

int getFlagFromConfig(const char *name, bool *returnValue)
{
// Check configuration to see if update checks are disabled
char *config_file = obs_module_file("config.json");
if (!config_file) {
blog(LOG_INFO, "Unable to find config file");
return OBS_BGREMOVAL_CONFIG_FAIL;
}

obs_data_t *data = obs_data_create_from_json_file(config_file);
if (!data) {
blog(LOG_INFO, "Failed to parse config file");
return OBS_BGREMOVAL_CONFIG_FAIL;
}

*returnValue = obs_data_get_bool(data, name);
obs_data_release(data);

return OBS_BGREMOVAL_CONFIG_SUCCESS;
}

int setFlagFromConfig(const char *name, const bool value)
{
// Get the config file
char *config_file = obs_module_file("config.json");
if (!config_file) {
blog(LOG_INFO, "Unable to find config file");
return OBS_BGREMOVAL_CONFIG_FAIL;
}

// Parse the config file
obs_data_t *json_data = obs_data_create_from_json_file(config_file);
if (!json_data) {
blog(LOG_INFO, "Failed to parse config file");
return OBS_BGREMOVAL_CONFIG_FAIL;
}

// Update the config
obs_data_set_bool(json_data, name, value);
obs_data_save_json(json_data, config_file);

obs_data_release(json_data);

return OBS_BGREMOVAL_CONFIG_SUCCESS;
}
12 changes: 12 additions & 0 deletions src/obs-utils/obs-config-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef OBS_CONFIG_UTILS_H
#define OBS_CONFIG_UTILS_H

enum {
OBS_BGREMOVAL_CONFIG_SUCCESS = 0,
OBS_BGREMOVAL_CONFIG_FAIL = 1,
};

int getFlagFromConfig(const char *name, bool *returnValue);
int setFlagFromConfig(const char *name, const bool value);

#endif /* OBS_CONFIG_UTILS_H */
8 changes: 8 additions & 0 deletions src/plugin-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>

#include "update-checker/github-utils.h"
#include "update-checker/update-checker.h"
#include "segment-tracing/segment-tracing.h"
#include "obs-utils/obs-config-utils.h"

OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE(PLUGIN_NAME, "en-US")
Expand All @@ -40,15 +42,21 @@ bool obs_module_load(void)
obs_register_source(&enhance_filter_info);
obs_log(LOG_INFO, "plugin loaded successfully (version %s)",
PLUGIN_VERSION);

const char *latestRelease = github_utils_get_release();
if (latestRelease != NULL) {
obs_log(LOG_INFO, "latest release is %s", latestRelease);
check_update(latestRelease);
}

segment_tracing_init();
send_segment_trace(SEGMENT_TYPE_PLUGIN_LOAD, -1);
return true;
}

void obs_module_unload()
{
obs_log(LOG_INFO, "plugin unloaded");
send_segment_trace(SEGMENT_TYPE_PLUGIN_UNLOAD, -1);
segment_tracing_deinit();
}
Loading