Skip to content

Commit

Permalink
Add a property to clear texture at disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed Apr 16, 2024
1 parent a918df0 commit 0f2d9d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions doc/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Specifies when to connect to the server and when to disconnect from the server.
- Disconnect at inactive: When the source is not shown on the Program, the connection will be disconnected.
The default is Always.

### Clear texture at disconnection
If enabled, the texture will be cleared when the VNC connection is disconnected.
If disabled, the texture will remain unchanged.

### Skip update (left, right, top, bottom)
This property requests the server to send only inside the specified area.
It will help to reduce the amount of data transferred from the VNC server.
Expand Down
2 changes: 2 additions & 0 deletions src/obs-vnc-source-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static void vncsrc_update(void *data, obs_data_t *settings)
UPDATE_NOTIFY(src, int, quality, encoding_updated, (int)obs_data_get_int(settings, "quality"));
UPDATE_NOTIFY(src, int, qosdscp, dscp_updated, (int)obs_data_get_int(settings, "qosdscp"));
src->config.connect_opt = (int)obs_data_get_int(settings, "connect_opt");
src->config.clear_at_disconnect = obs_data_get_bool(settings, "clear_at_disconnect");

UPDATE_NOTIFY(src, int, skip_update_l, skip_updated, (int)obs_data_get_int(settings, "skip_update_l"));
UPDATE_NOTIFY(src, int, skip_update_r, skip_updated, (int)obs_data_get_int(settings, "skip_update_r"));
Expand Down Expand Up @@ -200,6 +201,7 @@ static obs_properties_t *vncsrc_get_properties(void *unused)
connect_at_active_disconnect_at_hidden);
obs_property_list_add_int(prop, obs_module_text("Connect at activated, disconnect at inactive"),
connect_at_active_disconnect_at_inactive);
obs_properties_add_bool(props, "clear_at_disconnect", obs_module_text("Clear texture at disconnection"));

obs_properties_add_int(props, "skip_update_l", obs_module_text("Skip update (left)"), 0, 32767, 1);
obs_properties_add_int(props, "skip_update_r", obs_module_text("Skip update (right)"), 0, 32767, 1);
Expand Down
25 changes: 14 additions & 11 deletions src/obs-vnc-source-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ static inline bool rfbc_poll(rfbClient *client)
return 0; // success
}

static void rfbc_disconnect(struct vnc_source *src, rfbClient **client)
{
if (*client) {
rfbClientCleanup(*client);
*client = NULL;
}
if (src->config.clear_at_disconnect)
obs_source_output_video(src->source, NULL);
}

struct vncsrc_keymouse_state_s
{
int buttonMask;
Expand Down Expand Up @@ -710,10 +720,7 @@ static void *thread_main(void *data)
bool just_wait = false;
int display_flags = os_atomic_load_long(&src->display_flags);
if (src->need_reconnect) {
if (client) {
rfbClientCleanup(client);
client = NULL;
}
rfbc_disconnect(src, &client);
cnt_failure = 0;
n_wait = 0;
src->need_reconnect = false;
Expand Down Expand Up @@ -758,8 +765,7 @@ static void *thread_main(void *data)
to_disconnect = true;
}
if (to_disconnect) {
rfbClientCleanup(client);
client = NULL;
rfbc_disconnect(src, &client);
just_wait = true;
}
}
Expand Down Expand Up @@ -809,8 +815,7 @@ static void *thread_main(void *data)
client->updateRect.w, client->updateRect.h, 0);
}
if (rfbc_poll(client)) {
rfbClientCleanup(client);
client = NULL;
rfbc_disconnect(src, &client);
}
}

Expand All @@ -822,9 +827,7 @@ static void *thread_main(void *data)
rfbc_interact(src, client, &state);
}

if (client)
rfbClientCleanup(client);
client = NULL;
rfbc_disconnect(src, &client);
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions src/obs-vnc-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct vncsrc_conig
connect_at_active_disconnect_at_hidden = 2 + 4,
connect_at_active_disconnect_at_inactive = 2 + 8,
} connect_opt;
bool clear_at_disconnect;

int skip_update_l, skip_update_r, skip_update_t, skip_update_b;
};
Expand Down

0 comments on commit 0f2d9d1

Please sign in to comment.