commit f136f66efbdd65dc17fc3f3c985d54147a3cd33d
parent 18426ed4cd6c98148390d268fa36e8918c9ac94e
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 8 Aug 2024 21:27:31 +0200
Implement button to switch on/off camera streaming
Diffstat:
4 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/src/discourse.c b/src/discourse.c
@@ -572,7 +572,7 @@ _setup_video_gst_pipelines(MESSENGER_DiscourseInfo *info)
if (-1 != fd)
g_object_set(info->video_record_sink, "fd", fd, NULL);
- gst_element_set_state(info->video_record_pipeline, GST_STATE_PLAYING);
+ gst_element_set_state(info->video_record_pipeline, GST_STATE_NULL);
}
}
@@ -861,30 +861,43 @@ discourse_set_mute(struct GNUNET_CHAT_Discourse *discourse,
{
MESSENGER_DiscourseInfo* info = GNUNET_CHAT_discourse_get_user_pointer(discourse);
- if ((!info) || (!(info->audio_record_pipeline)))
+ if (!info)
return;
- gst_element_set_state(
- info->audio_record_pipeline,
- mute? GST_STATE_NULL : GST_STATE_PLAYING
- );
+ const GstState state = mute? GST_STATE_NULL : GST_STATE_PLAYING;
+
+ if (info->audio_record_pipeline)
+ gst_element_set_state(info->audio_record_pipeline, state);
+
+ if (info->video_record_pipeline)
+ gst_element_set_state(info->video_record_pipeline, state);
}
bool
-discourse_is_mute(struct GNUNET_CHAT_Discourse *discourse)
+discourse_is_mute(const struct GNUNET_CHAT_Discourse *discourse)
{
MESSENGER_DiscourseInfo* info = GNUNET_CHAT_discourse_get_user_pointer(discourse);
- if ((!info) || (!(info->audio_record_pipeline)))
+ if (!info)
return TRUE;
- GstState state;
- gst_element_get_state(
- info->audio_record_pipeline,
- &state,
- NULL,
- GST_CLOCK_TIME_NONE
- );
+ GstState state = GST_STATE_NULL;
+
+ if (info->audio_record_pipeline)
+ gst_element_get_state(
+ info->audio_record_pipeline,
+ &state,
+ NULL,
+ GST_CLOCK_TIME_NONE
+ );
+
+ if (info->video_record_pipeline)
+ gst_element_get_state(
+ info->video_record_pipeline,
+ &state,
+ NULL,
+ GST_CLOCK_TIME_NONE
+ );
return (GST_STATE_PLAYING != state);
}
diff --git a/src/discourse.h b/src/discourse.h
@@ -187,7 +187,7 @@ discourse_set_mute(struct GNUNET_CHAT_Discourse *discourse,
* @return #TRUE if muted, #FALSE otherwise
*/
bool
-discourse_is_mute(struct GNUNET_CHAT_Discourse *discourse);
+discourse_is_mute(const struct GNUNET_CHAT_Discourse *discourse);
/**
* Links a widget from the video pipeline of a discourse
diff --git a/src/ui/discourse.c b/src/ui/discourse.c
@@ -105,6 +105,19 @@ handle_microphone_button_click(UNUSED GtkButton *button,
}
static void
+handle_camera_button_click(UNUSED GtkButton *button,
+ gpointer user_data)
+{
+ g_assert(user_data);
+
+ UI_DISCOURSE_Handle *handle = (UI_DISCOURSE_Handle*) user_data;
+
+ handle->stream_camera = !(handle->stream_camera);
+ if (handle->video_discourse)
+ discourse_set_mute(handle->video_discourse, !(handle->stream_camera));
+}
+
+static void
handle_speakers_button_value_changed(UNUSED GtkScaleButton *button,
gdouble value,
gpointer user_data)
@@ -204,7 +217,10 @@ ui_discourse_window_init(MESSENGER_Application *app,
handle->context = NULL;
handle->voice_discourse = NULL;
+ handle->video_discourse = NULL;
+
handle->muted = TRUE;
+ handle->stream_camera = FALSE;
handle->parent = GTK_WINDOW(app->ui.messenger.main_window);
@@ -303,6 +319,13 @@ ui_discourse_window_init(MESSENGER_Application *app,
);
g_signal_connect(
+ handle->camera_button,
+ "clicked",
+ G_CALLBACK(handle_camera_button_click),
+ handle
+ );
+
+ g_signal_connect(
handle->speakers_button,
"value-changed",
G_CALLBACK(handle_speakers_button_value_changed),
@@ -510,7 +533,7 @@ iterate_ui_discourse_update_discourse_video(void *cls,
GTK_CONTAINER(panel->video_box)
);
- if (linked)
+ if ((linked) && (!discourse_is_mute(discourse)))
gtk_stack_set_visible_child(panel->panel_stack, panel->video_box);
else
gtk_stack_set_visible_child(panel->panel_stack, panel->avatar_box);
diff --git a/src/ui/discourse.h b/src/ui/discourse.h
@@ -42,6 +42,7 @@ typedef struct UI_DISCOURSE_Handle
struct GNUNET_CHAT_Discourse *video_discourse;
gboolean muted;
+ gboolean stream_camera;
GtkWindow *parent;