diff --git a/audio-move.c b/audio-move.c index c11150c..b3f2399 100644 --- a/audio-move.c +++ b/audio-move.c @@ -85,6 +85,27 @@ void audio_move_volmeter_updated(void *data, (1.0 - audio_move->easing) * v; } +void audio_move_item_remove(void *data, calldata_t *call_data) +{ + struct audio_move_info *audio_move = data; + obs_scene_t *scene = NULL; + calldata_get_ptr(call_data, "scene", &scene); + obs_sceneitem_t *item = NULL; + calldata_get_ptr(call_data, "item", &item); + if (item == audio_move->sceneitem) { + audio_move->sceneitem = NULL; + obs_source_t *parent = obs_scene_get_source(scene); + if (parent) { + signal_handler_t *sh = + obs_source_get_signal_handler(parent); + if (sh) + signal_handler_disconnect( + sh, "item_remove", + audio_move_item_remove, audio_move); + } + } +} + void audio_move_update(void *data, obs_data_t *settings) { struct audio_move_info *audio_move = data; @@ -117,9 +138,24 @@ void audio_move_update(void *data, obs_data_t *settings) obs_source_t *source = obs_get_source_by_name(scene_name); obs_source_release(source); obs_scene_t *scene = obs_scene_from_source(source); + if (audio_move->sceneitem) { + signal_handler_t *sh = obs_source_get_signal_handler(source); + if (sh) + signal_handler_disconnect(sh, "item_remove", + audio_move_item_remove, + audio_move); + } audio_move->sceneitem = scene ? obs_scene_find_source(scene, sceneitem_name) : NULL; + if (audio_move->sceneitem && source) { + signal_handler_t *sh = obs_source_get_signal_handler(source); + if (sh) + signal_handler_connect(sh, "item_remove", + audio_move_item_remove, + audio_move); + } + obs_source_release(audio_move->target_source); audio_move->target_source = NULL; if (audio_move->action == VALUE_ACTION_FILTER_ENABLE) { @@ -150,7 +186,7 @@ void audio_move_update(void *data, obs_data_t *settings) audio_move->target_source = filter; obs_source_release(source); } else { - audio_move->target_source = filter; + audio_move->target_source = source; } } } @@ -186,7 +222,10 @@ static void audio_move_destroy(void *data) obs_volmeter_remove_callback(audio_move->volmeter, audio_move_volmeter_updated, audio_move); obs_volmeter_destroy(audio_move->volmeter); + audio_move->volmeter = NULL; obs_source_release(audio_move->target_source); + audio_move->target_source = NULL; + audio_move->sceneitem = NULL; bfree(audio_move->setting_name); bfree(audio_move); } @@ -687,7 +726,7 @@ void audio_move_tick(void *data, float seconds) obs_data_item_set_int(&setting, val); } else if (num_type == OBS_DATA_NUM_DOUBLE) { obs_data_item_set_double(&setting, val); - } + } obs_data_item_release(&setting); } else { obs_data_set_double(settings, filter->setting_name, diff --git a/move-source-filter.c b/move-source-filter.c index 6785493..c76e483 100644 --- a/move-source-filter.c +++ b/move-source-filter.c @@ -70,7 +70,6 @@ void move_source_item_remove(void *data, calldata_t *call_data) obs_sceneitem_t *item = NULL; calldata_get_ptr(call_data, "item", &item); if (item == move_source->scene_item) { - obs_sceneitem_release(move_source->scene_item); move_source->scene_item = NULL; obs_source_t *parent = obs_scene_get_source(scene); if (parent) { @@ -91,7 +90,6 @@ bool find_sceneitem(obs_scene_t *scene, obs_sceneitem_t *scene_item, void *data) const char *name = obs_source_get_name(obs_sceneitem_get_source(scene_item)); if (name && strcmp(name, move_source->source_name) == 0) { - obs_sceneitem_addref(scene_item); move_source->scene_item = scene_item; obs_source_t *parent = obs_scene_get_source(scene); if (parent) { @@ -620,7 +618,6 @@ void move_source_source_media_ended(void *data, calldata_t *call_data) void move_source_source_remove(void *data, calldata_t *call_data) { struct move_source_info *move_source = data; - obs_sceneitem_release(move_source->scene_item); move_source->scene_item = NULL; UNUSED_PARAMETER(call_data); } @@ -702,8 +699,6 @@ void move_source_update(void *data, obs_data_t *settings) } obs_source_release(source); } - - obs_sceneitem_release(move_source->scene_item); move_source->scene_item = NULL; if (parent) { signal_handler_t *sh = @@ -862,6 +857,16 @@ void move_source_source_rename(void *data, calldata_t *call_data) obs_data_release(settings); } +static void move_source_frontend_event(enum obs_frontend_event event, + void *private_data) +{ + if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { + int i = 0; + } else if (event == OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED) { + int i = 0; + } +} + static void *move_source_create(obs_data_t *settings, obs_source_t *source) { struct move_source_info *move_source = @@ -871,12 +876,17 @@ static void *move_source_create(obs_data_t *settings, obs_source_t *source) move_source_update(move_source, settings); signal_handler_connect(obs_get_signal_handler(), "source_rename", move_source_source_rename, move_source); + + obs_frontend_add_event_callback(move_source_frontend_event, + move_source); return move_source; } static void move_source_destroy(void *data) { struct move_source_info *move_source = data; + obs_frontend_remove_event_callback(move_source_frontend_event, + move_source); signal_handler_disconnect(obs_get_signal_handler(), "source_rename", move_source_source_rename, move_source); @@ -909,9 +919,16 @@ static void move_source_destroy(void *data) sh, "show", move_source_source_show, data); signal_handler_disconnect( sh, "hide", move_source_source_hide, data); + signal_handler_disconnect( + sh, "media_started", + move_source_source_media_started, data); + signal_handler_disconnect( + sh, "media_ended", + move_source_source_media_ended, data); + signal_handler_disconnect( + sh, "remove", move_source_source_remove, data); } } - obs_sceneitem_release(move_source->scene_item); move_source->scene_item = NULL; if (move_source->move_start_hotkey != OBS_INVALID_HOTKEY_ID) obs_hotkey_unregister(move_source->move_start_hotkey); @@ -1022,7 +1039,6 @@ bool move_source_changed(void *data, obs_properties_t *props, return refresh; bfree(move_source->source_name); move_source->source_name = bstrdup(source_name); - obs_sceneitem_release(move_source->scene_item); move_source->scene_item = NULL; obs_source_t *parent = obs_filter_get_parent(move_source->source); if (parent) {