From bbfa46363cf3e7f896ac9ec7e4e3aabea58a59b0 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 15 Apr 2015 18:27:04 +0200 Subject: [PATCH] splitmuxsink: add a "format-location" signal that allows better control over filenames In certain applications, splitting into files named after a base location template and an incremental sequence number is not enough. This signal gives more fine-grained control to the application to decide how to name the files. https://bugzilla.gnome.org/show_bug.cgi?id=750106 --- gst/multifile/gstsplitmuxsink.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gst/multifile/gstsplitmuxsink.c b/gst/multifile/gstsplitmuxsink.c index 91d7fc4cd8..4fdfad7ab1 100644 --- a/gst/multifile/gstsplitmuxsink.c +++ b/gst/multifile/gstsplitmuxsink.c @@ -80,6 +80,14 @@ enum #define DEFAULT_MUXER "mp4mux" #define DEFAULT_SINK "filesink" +enum +{ + SIGNAL_FORMAT_LOCATION, + SIGNAL_LAST +}; + +static guint signals[SIGNAL_LAST]; + static GstStaticPadTemplate video_sink_template = GST_STATIC_PAD_TEMPLATE ("video", GST_PAD_SINK, @@ -202,6 +210,17 @@ gst_splitmux_sink_class_init (GstSplitMuxSinkClass * klass) g_param_spec_object ("sink", "Sink", "The sink element (or element chain) to use (NULL = default filesink)", GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * GstSplitMuxSink::format-location: + * @splitmux: the #GstSplitMuxSink + * @fragment_id: the sequence number of the file to be created + * + * Returns: the location to be used for the next output file + */ + signals[SIGNAL_FORMAT_LOCATION] = + g_signal_new ("format-location", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_STRING, 1, G_TYPE_UINT); } static void @@ -1416,10 +1435,16 @@ fail: static void set_next_filename (GstSplitMuxSink * splitmux) { - if (splitmux->location) { - gchar *fname; + gchar *fname = NULL; - fname = g_strdup_printf (splitmux->location, splitmux->fragment_id); + g_signal_emit (splitmux, signals[SIGNAL_FORMAT_LOCATION], 0, + splitmux->fragment_id, &fname); + + if (!fname) + fname = splitmux->location ? + g_strdup_printf (splitmux->location, splitmux->fragment_id) : NULL; + + if (fname) { GST_INFO_OBJECT (splitmux, "Setting file to %s", fname); g_object_set (splitmux->sink, "location", fname, NULL); g_free (fname);