From 530f694366895da941f10d8b349b78574904bf03 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 19 Nov 2020 18:29:15 -0300 Subject: [PATCH] uritranscodebin: Add `setup-source` and `element-setup` signals The same way as playbinX does it as it is often quite useful --- docs/plugins/gst_plugins_cache.json | 24 +++++++++++- gst/transcode/gsturitranscodebin.c | 59 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index ce17f55f1c..a91d22cd53 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -220850,7 +220850,29 @@ "writable": true } }, - "rank": "none" + "rank": "none", + "signals": { + "element-setup": { + "args": [ + { + "name": "arg0", + "type": "GstElement" + } + ], + "return-type": "void", + "when": "last" + }, + "source-setup": { + "args": [ + { + "name": "arg0", + "type": "GstElement" + } + ], + "return-type": "void", + "when": "last" + } + } } }, "filename": "gsttranscode", diff --git a/gst/transcode/gsturitranscodebin.c b/gst/transcode/gsturitranscodebin.c index fc21df48dc..c51ea37ac5 100644 --- a/gst/transcode/gsturitranscodebin.c +++ b/gst/transcode/gsturitranscodebin.c @@ -89,6 +89,15 @@ enum LAST_PROP }; +/* signals */ +enum +{ + SIGNAL_SOURCE_SETUP, + SIGNAL_ELEMENT_SETUP, + LAST_SIGNAL +}; +static guint signals[LAST_SIGNAL] = { 0 }; + static void post_missing_plugin_error (GstElement * dec, const gchar * element_name) { @@ -287,6 +296,13 @@ src_pad_removed_cb (GstElement * element, GstPad * pad, /* FIXME : IMPLEMENT */ } +static void +source_setup_cb (GstElement * element, GstElement * source, + GstUriTranscodeBin * self) +{ + g_signal_emit (self, signals[SIGNAL_SOURCE_SETUP], 0, source); +} + static gboolean make_source (GstUriTranscodeBin * self) { @@ -306,6 +322,8 @@ make_source (GstUriTranscodeBin * self) g_signal_connect (self->src, "pad-added", (GCallback) src_pad_added_cb, self); g_signal_connect (self->src, "pad-removed", (GCallback) src_pad_removed_cb, self); + g_signal_connect (self->src, "source-setup", + G_CALLBACK (source_setup_cb), self); return TRUE; @@ -393,6 +411,7 @@ deep_element_added (GstBin * bin, GstBin * sub_bin, GstElement * child) GstUriTranscodeBin *self = GST_URI_TRANSCODE_BIN (bin); set_location_on_muxer_if_sink (self, child); + g_signal_emit (bin, signals[SIGNAL_ELEMENT_SETUP], 0, child); GST_BIN_CLASS (parent_class)->deep_element_added (bin, sub_bin, child); } @@ -680,6 +699,46 @@ gst_uri_transcode_bin_class_init (GstUriTranscodeBinClass * klass) g_param_spec_object ("audio-filter", "Audio filter", "the audio filter(s) to apply, if possible", GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * GstUriTranscodeBin::source-setup: + * @uritranscodebin: a #GstUriTranscodeBin + * @source: source element + * + * This signal is emitted after the source element has been created, so + * it can be configured by setting additional properties (e.g. set a + * proxy server for an http source, or set the device and read speed for + * an audio cd source). This is functionally equivalent to connecting to + * the notify::source signal, but more convenient. + * + * This signal is usually emitted from the context of a GStreamer streaming + * thread. + * + * Since: 1.20 + */ + signals[SIGNAL_SOURCE_SETUP] = + g_signal_new ("source-setup", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT); + + /** + * GstUriTranscodeBin::element-setup: + * @uritranscodebin: a #GstUriTranscodeBin + * @element: an element that was added to the uritranscodebin hierarchy + * + * This signal is emitted when a new element is added to uritranscodebin or any of + * its sub-bins. This signal can be used to configure elements, e.g. to set + * properties on decoders. This is functionally equivalent to connecting to + * the deep-element-added signal, but more convenient. + * + * This signal is usually emitted from the context of a GStreamer streaming + * thread, so might be called at the same time as code running in the main + * application thread. + * + * Since: 1.20 + */ + signals[SIGNAL_ELEMENT_SETUP] = + g_signal_new ("element-setup", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT); } static void