From 6edffb9a4bb14a05436e0f1213b09fcb43287073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 2 May 2024 20:54:23 +0200 Subject: [PATCH] clapper-app: Add command line options to set GStreamer elements Allows setting audio/video filters and sinks. By setting value to "none" default filter can be disabled. --- src/bin/clapper-app/clapper-app-application.c | 44 ++++++++++++++++++- src/bin/clapper-app/clapper-app-utils.c | 26 +++++++++++ src/bin/clapper-app/clapper-app-utils.h | 3 ++ src/bin/clapper-app/po/POTFILES | 1 + 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/bin/clapper-app/clapper-app-application.c b/src/bin/clapper-app/clapper-app-application.c index d5d5206b..d983aaac 100644 --- a/src/bin/clapper-app/clapper-app-application.c +++ b/src/bin/clapper-app/clapper-app-application.c @@ -18,6 +18,7 @@ #include "config.h" #include +#include #include #include @@ -57,6 +58,15 @@ struct ClapperPluginData struct ClapperPluginFeatureData features[10]; }; +struct ClapperAppOptions +{ + gchar *video_filter; + gchar *audio_filter; + + gchar *video_sink; + gchar *audio_sink; +}; + typedef struct { const gchar *action; @@ -66,6 +76,18 @@ typedef struct #define parent_class clapper_app_application_parent_class G_DEFINE_TYPE (ClapperAppApplication, clapper_app_application, GTK_TYPE_APPLICATION); +static struct ClapperAppOptions app_opts = { 0, }; + +static inline void +_app_opts_free (void) +{ + g_free (app_opts.video_filter); + g_free (app_opts.audio_filter); + + g_free (app_opts.video_sink); + g_free (app_opts.audio_sink); +} + static inline void _set_initial_plugin_feature_ranks (void) { @@ -233,6 +255,15 @@ _restore_settings_to_window (ClapperAppApplication *self, ClapperAppWindow *app_ GST_DEBUG ("Restoring saved GSettings values to: %" GST_PTR_FORMAT, app_window); + if (app_opts.video_filter) + clapper_player_set_video_filter (player, clapper_app_utils_make_element (app_opts.video_filter)); + if (app_opts.audio_filter) + clapper_player_set_audio_filter (player, clapper_app_utils_make_element (app_opts.audio_filter)); + if (app_opts.video_sink) + clapper_player_set_video_sink (player, clapper_app_utils_make_element (app_opts.video_sink)); + if (app_opts.audio_sink) + clapper_player_set_audio_sink (player, clapper_app_utils_make_element (app_opts.audio_sink)); + clapper_player_set_volume (player, PERCENTAGE_ROUND (g_settings_get_double (self->settings, "volume"))); clapper_player_set_mute (player, g_settings_get_boolean (self->settings, "mute")); clapper_player_set_speed (player, PERCENTAGE_ROUND (g_settings_get_double (self->settings, "speed"))); @@ -512,7 +543,14 @@ clapper_app_application_constructed (GObject *object) GApplication *app = G_APPLICATION (self); guint i; - static const GActionEntry app_entries[] = { + const GOptionEntry app_options[] = { + { "video-filter", 0, 0, G_OPTION_ARG_STRING, &app_opts.video_filter, _("Video filter to use (\"none\" to disable)"), NULL }, + { "audio-filter", 0, 0, G_OPTION_ARG_STRING, &app_opts.audio_filter, _("Audio filter to use (\"none\" to disable)"), NULL }, + { "video-sink", 0, 0, G_OPTION_ARG_STRING, &app_opts.video_sink, _("Video sink to use"), NULL }, + { "audio-sink", 0, 0, G_OPTION_ARG_STRING, &app_opts.audio_sink, _("Audio sink to use"), NULL }, + { NULL } + }; + static const GActionEntry app_actions[] = { { "add-files", add_files, NULL, NULL, NULL }, { "add-uri", add_uri, NULL, NULL, NULL }, { "info", show_info, NULL, NULL, NULL }, @@ -542,11 +580,12 @@ clapper_app_application_constructed (GObject *object) plugin_feature_ranks_settings_changed_cb (self->settings, NULL, NULL); g_action_map_add_action_entries (G_ACTION_MAP (app), - app_entries, G_N_ELEMENTS (app_entries), app); + app_actions, G_N_ELEMENTS (app_actions), app); for (i = 0; i < G_N_ELEMENTS (app_shortcuts); ++i) gtk_application_set_accels_for_action (GTK_APPLICATION (app), app_shortcuts[i].action, app_shortcuts[i].accels); + g_application_add_main_option_entries (app, app_options); g_application_add_option_group (app, gst_init_get_option_group ()); G_OBJECT_CLASS (parent_class)->constructed (object); @@ -560,6 +599,7 @@ clapper_app_application_finalize (GObject *object) GST_TRACE ("Finalize"); g_object_unref (self->settings); + _app_opts_free (); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/src/bin/clapper-app/clapper-app-utils.c b/src/bin/clapper-app/clapper-app-utils.c index b328ef72..1aaf9eea 100644 --- a/src/bin/clapper-app/clapper-app-utils.c +++ b/src/bin/clapper-app/clapper-app-utils.c @@ -324,3 +324,29 @@ parse_overrides: g_free (stored_overrides); } + +GstElement * +clapper_app_utils_make_element (const gchar *string) +{ + gchar *char_loc; + + if (strcmp (string, "none") == 0) + return NULL; + + char_loc = strchr (string, ' '); + + if (char_loc) { + GstElement *element; + GError *error = NULL; + + element = gst_parse_bin_from_description (string, TRUE, &error); + if (error) { + GST_ERROR ("Bin parse error: \"%s\", reason: %s", string, error->message); + g_error_free (error); + } + + return element; + } + + return gst_element_factory_make (string, NULL); +} diff --git a/src/bin/clapper-app/clapper-app-utils.h b/src/bin/clapper-app/clapper-app-utils.h index cf854bd8..54dbbc0e 100644 --- a/src/bin/clapper-app/clapper-app-utils.h +++ b/src/bin/clapper-app/clapper-app-utils.h @@ -59,4 +59,7 @@ void clapper_app_utils_files_free (GFile **files); G_GNUC_INTERNAL void clapper_app_utils_iterate_plugin_feature_ranks (GSettings *settings, ClapperAppUtilsIterRanks callback, gpointer user_data); +G_GNUC_INTERNAL +GstElement * clapper_app_utils_make_element (const gchar *string); + G_END_DECLS diff --git a/src/bin/clapper-app/po/POTFILES b/src/bin/clapper-app/po/POTFILES index 025c0a8f..d5312691 100644 --- a/src/bin/clapper-app/po/POTFILES +++ b/src/bin/clapper-app/po/POTFILES @@ -10,6 +10,7 @@ src/bin/clapper-app/ui/clapper-app-uri-dialog.ui src/bin/clapper-app/ui/clapper-app-video-stream-list-item.ui src/bin/clapper-app/clapper-app-about-window.c +src/bin/clapper-app/clapper-app-application.c src/bin/clapper-app/clapper-app-info-window.c src/bin/clapper-app/clapper-app-list-item-utils.c src/bin/clapper-app/clapper-app-preferences-window.c