From c1a1584ddec0d4714b60176bc4ed84034bfffc96 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 12 Jul 2024 11:09:14 +1000 Subject: [PATCH] splitmuxsrc: Don't create part reader elements initially Only create the part reader elements internally the first time the part is activated. Saves some startup time when preloading a large number of fragments Part-of: --- .../gst/multifile/gstsplitmuxpartreader.c | 41 +++++++++++-------- .../gst/multifile/gstsplitmuxpartreader.h | 1 + 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.c b/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.c index 99fe86dac3..2feffd9a2c 100644 --- a/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.c +++ b/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.c @@ -710,25 +710,11 @@ gst_splitmux_part_reader_class_init (GstSplitMuxPartReaderClass * klass) } static void -gst_splitmux_part_reader_init (GstSplitMuxPartReader * reader) +create_elements (GstSplitMuxPartReader * reader) { + /* Called on the first state change to create our internal elements */ GstElement *typefind; - reader->prep_state = PART_STATE_NULL; - reader->need_duration_measuring = TRUE; - - reader->loaded = FALSE; - reader->playing = FALSE; - reader->smallest_ts_offset = GST_CLOCK_TIME_NONE; - reader->info.start_offset = GST_CLOCK_TIME_NONE; - reader->info.duration = GST_CLOCK_TIME_NONE; - - g_cond_init (&reader->inactive_cond); - g_mutex_init (&reader->lock); - g_mutex_init (&reader->type_lock); - g_mutex_init (&reader->msg_lock); - - /* FIXME: Create elements on a state change */ reader->src = gst_element_factory_make ("filesrc", NULL); if (reader->src == NULL) { GST_ERROR_OBJECT (reader, "Failed to create filesrc element"); @@ -756,6 +742,25 @@ gst_splitmux_part_reader_init (GstSplitMuxPartReader * reader) reader); } +static void +gst_splitmux_part_reader_init (GstSplitMuxPartReader * reader) +{ + reader->prep_state = PART_STATE_NULL; + reader->need_duration_measuring = TRUE; + + reader->created = FALSE; + reader->loaded = FALSE; + reader->playing = FALSE; + reader->smallest_ts_offset = GST_CLOCK_TIME_NONE; + reader->info.start_offset = GST_CLOCK_TIME_NONE; + reader->info.duration = GST_CLOCK_TIME_NONE; + + g_cond_init (&reader->inactive_cond); + g_mutex_init (&reader->lock); + g_mutex_init (&reader->type_lock); + g_mutex_init (&reader->msg_lock); +} + static void splitmux_part_reader_dispose (GObject * object) { @@ -1216,6 +1221,10 @@ gst_splitmux_part_reader_change_state (GstElement * element, } case GST_STATE_CHANGE_READY_TO_PAUSED:{ SPLITMUX_PART_LOCK (reader); + if (!reader->created) { + create_elements (reader); + reader->created = TRUE; + } g_object_set (reader->src, "location", reader->path, NULL); reader->prep_state = PART_STATE_PREPARING_COLLECT_STREAMS; gst_splitmux_part_reader_set_flushing_locked (reader, FALSE); diff --git a/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.h b/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.h index dc847aaa04..dc387921ec 100644 --- a/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.h +++ b/subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.h @@ -76,6 +76,7 @@ struct _GstSplitMuxPartReader gboolean async_pending; + gboolean created; gboolean loaded; gboolean playing;