Skip to content

Commit

Permalink
Use auto release refs
Browse files Browse the repository at this point in the history
This sets the refs in the browser source to be automatically
released.
  • Loading branch information
cg2121 authored and WizardCM committed Jul 17, 2022
1 parent 64c1796 commit cfad34d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
19 changes: 6 additions & 13 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool BrowserClient::OnProcessMessageReceived(
} else if (name == "setCurrentScene") {
const std::string scene_name =
input_args->GetString(1).ToString();
obs_source_t *source =
OBSSourceAutoRelease source =
obs_get_source_by_name(scene_name.c_str());
if (!source) {
blog(LOG_WARNING,
Expand All @@ -165,18 +165,16 @@ bool BrowserClient::OnProcessMessageReceived(
"Browser source '%s' tried to switch to '%s' which isn't a scene",
obs_source_get_name(bs->source),
scene_name.c_str());
obs_source_release(source);
} else {
obs_frontend_set_current_scene(source);
obs_source_release(source);
}
} else if (name == "setCurrentTransition") {
const std::string transition_name =
input_args->GetString(1).ToString();
obs_frontend_source_list transitions = {};
obs_frontend_get_transitions(&transitions);

obs_source_t *transition = nullptr;
OBSSourceAutoRelease transition;
for (size_t i = 0; i < transitions.sources.num; i++) {
obs_source_t *source =
transitions.sources.array[i];
Expand All @@ -189,15 +187,13 @@ bool BrowserClient::OnProcessMessageReceived(

obs_frontend_source_list_free(&transitions);

if (transition) {
if (transition)
obs_frontend_set_current_transition(transition);
obs_source_release(transition);
} else {
else
blog(LOG_WARNING,
"Browser source '%s' tried to change the current transition to '%s' which doesn't exist",
obs_source_get_name(bs->source),
transition_name.c_str());
}
}
[[fallthrough]];
case ControlLevel::Basic:
Expand All @@ -218,9 +214,8 @@ bool BrowserClient::OnProcessMessageReceived(
json = scenes_vector;
obs_frontend_source_list_free(&list);
} else if (name == "getCurrentScene") {
OBSSource current_scene =
OBSSourceAutoRelease current_scene =
obs_frontend_get_current_scene();
obs_source_release(current_scene);

if (!current_scene)
return false;
Expand All @@ -247,10 +242,9 @@ bool BrowserClient::OnProcessMessageReceived(
json = transitions_vector;
obs_frontend_source_list_free(&list);
} else if (name == "getCurrentTransition") {
obs_source_t *source =
OBSSourceAutoRelease source =
obs_frontend_get_current_transition();
json = obs_source_get_name(source);
obs_source_release(source);
}
[[fallthrough]];
case ControlLevel::ReadObs:
Expand Down Expand Up @@ -594,7 +588,6 @@ void BrowserClient::OnAudioStreamStarted(CefRefPtr<CefBrowser> browser, int id,
if (!stream.source) {
stream.source = obs_source_create_private("audio_line", nullptr,
nullptr);
obs_source_release(stream.source);

obs_source_add_active_child(bs->source, stream.source);

Expand Down
13 changes: 4 additions & 9 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,9 @@ static void missing_file_callback(void *src, const char *new_path, void *data)

if (bs) {
obs_source_t *source = bs->source;
obs_data_t *settings = obs_source_get_settings(source);
OBSDataAutoRelease settings = obs_source_get_settings(source);
obs_data_set_string(settings, "local_file", new_path);
obs_source_update(source, settings);
obs_data_release(settings);
}

UNUSED_PARAMETER(data);
Expand All @@ -269,7 +268,7 @@ static obs_missing_files_t *browser_source_missingfiles(void *data)

if (bs) {
obs_source_t *source = bs->source;
obs_data_t *settings = obs_source_get_settings(source);
OBSDataAutoRelease settings = obs_source_get_settings(source);

bool enabled = obs_data_get_bool(settings, "is_local_file");
const char *path = obs_data_get_string(settings, "local_file");
Expand All @@ -285,8 +284,6 @@ static obs_missing_files_t *browser_source_missingfiles(void *data)
obs_missing_files_add_file(files, file);
}
}

obs_data_release(settings);
}

return files;
Expand Down Expand Up @@ -596,8 +593,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
DispatchJSEvent("obsVirtualcamStopped", "");
break;
case OBS_FRONTEND_EVENT_SCENE_CHANGED: {
OBSSource source = obs_frontend_get_current_scene();
obs_source_release(source);
OBSSourceAutoRelease source = obs_frontend_get_current_scene();

if (!source)
break;
Expand Down Expand Up @@ -734,13 +730,12 @@ bool obs_module_load(void)
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);

#ifdef ENABLE_BROWSER_SHARED_TEXTURE
obs_data_t *private_data = obs_get_private_data();
OBSDataAutoRelease private_data = obs_get_private_data();
hwaccel = obs_data_get_bool(private_data, "BrowserHWAccel");

if (hwaccel) {
check_hwaccel_support();
}
obs_data_release(private_data);
#endif

#if defined(__APPLE__) && CHROME_VERSION_BUILD < 4183
Expand Down
2 changes: 1 addition & 1 deletion obs-browser-source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <vector>

struct AudioStream {
OBSSource source;
OBSSourceAutoRelease source;
speaker_layout speakers;
int channels;
int sample_rate;
Expand Down

0 comments on commit cfad34d

Please sign in to comment.