From: Thibault Saunier Date: Fri, 3 Jul 2020 20:34:21 +0000 (-0400) Subject: uri*source: Factor out common logic into a GESUriSource private data X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=834345b1c8d94fb9631d55be85c5ceb298439895;p=platform%2Fupstream%2Fgst-editing-services.git uri*source: Factor out common logic into a GESUriSource private data The two classes are *very* close but have different hierarchy so this introduces a new GESUriSource structure that is used as private structure by both subclasses and makes most of the logic shared this way. Part-of: --- diff --git a/ges/ges-audio-uri-source.c b/ges/ges-audio-uri-source.c index 355d861..bc96a3b 100644 --- a/ges/ges-audio-uri-source.c +++ b/ges/ges-audio-uri-source.c @@ -30,13 +30,14 @@ #include "ges-utils.h" #include "ges-internal.h" #include "ges-track-element.h" +#include "ges-uri-source.h" #include "ges-audio-uri-source.h" #include "ges-uri-asset.h" #include "ges-extractable.h" struct _GESAudioUriSourcePrivate { - GstElement *decodebin; /* Reference owned by parent class */ + GESUriSource parent; }; enum @@ -45,49 +46,11 @@ enum PROP_URI }; -static void -ges_audio_uri_source_track_set_cb (GESAudioUriSource * self, - GParamSpec * arg G_GNUC_UNUSED, gpointer nothing) -{ - GESTrack *track; - const GstCaps *caps = NULL; - - if (!self->priv->decodebin) - return; - - track = ges_track_element_get_track (GES_TRACK_ELEMENT (self)); - if (!track) - return; - - caps = ges_track_get_caps (track); - - GST_INFO_OBJECT (self, "Setting caps to: %" GST_PTR_FORMAT, caps); - g_object_set (self->priv->decodebin, "caps", caps, NULL); -} - /* GESSource VMethod */ static GstElement * -ges_audio_uri_source_create_source (GESTrackElement * trksrc) +ges_audio_uri_source_create_source (GESTrackElement * element) { - GESAudioUriSource *self; - GESTrack *track; - GstElement *decodebin; - const GstCaps *caps = NULL; - - self = (GESAudioUriSource *) trksrc; - - track = ges_track_element_get_track (trksrc); - - self->priv->decodebin = decodebin = - gst_element_factory_make ("uridecodebin", NULL); - - if (track) - caps = ges_track_get_caps (track); - - g_object_set (decodebin, "caps", caps, - "expose-all-streams", FALSE, "uri", self->uri, NULL); - - return decodebin; + return ges_uri_source_create_source (GES_AUDIO_URI_SOURCE (element)->priv); } /* Extractable interface implementation */ @@ -151,7 +114,7 @@ ges_audio_uri_source_set_property (GObject * object, guint property_id, GST_WARNING_OBJECT (object, "Uri already set to %s", uriclip->uri); return; } - uriclip->uri = g_value_dup_string (value); + uriclip->priv->uri = uriclip->uri = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -197,9 +160,7 @@ static void ges_audio_uri_source_init (GESAudioUriSource * self) { self->priv = ges_audio_uri_source_get_instance_private (self); - - g_signal_connect (self, "notify::track", - G_CALLBACK (ges_audio_uri_source_track_set_cb), NULL); + ges_uri_source_init (GES_TRACK_ELEMENT (self), self->priv); } /** diff --git a/ges/ges-audio-uri-source.h b/ges/ges-audio-uri-source.h index a8a28bf..b62aed4 100644 --- a/ges/ges-audio-uri-source.h +++ b/ges/ges-audio-uri-source.h @@ -26,6 +26,7 @@ G_BEGIN_DECLS +typedef struct _GESUriSource GESUriSource; #define GES_TYPE_AUDIO_URI_SOURCE ges_audio_uri_source_get_type() GES_DECLARE_TYPE(AudioUriSource, audio_uri_source, AUDIO_URI_SOURCE); @@ -42,7 +43,7 @@ struct _GESAudioUriSource { gchar *uri; - GESAudioUriSourcePrivate *priv; + GESUriSource *priv; /* Padding for API extension */ gpointer _ges_reserved[GES_PADDING]; diff --git a/ges/ges-uri-source.c b/ges/ges-uri-source.c new file mode 100644 index 0000000..138b8b9 --- /dev/null +++ b/ges/ges-uri-source.c @@ -0,0 +1,94 @@ +/* GStreamer Editing Services + * Copyright (C) 2020 Ubicast S.A + * Author: Thibault Saunier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "ges-internal.h" +#include "ges-uri-source.h" + +GST_DEBUG_CATEGORY_STATIC (uri_source_debug); +#undef GST_CAT_DEFAULT +#define GST_CAT_DEFAULT uri_source_debug + + +GstElement * +ges_uri_source_create_source (GESUriSource * self) +{ + GESTrack *track; + GstElement *decodebin; + const GstCaps *caps = NULL; + + track = ges_track_element_get_track (self->element); + + self->decodebin = decodebin = gst_element_factory_make ("uridecodebin", NULL); + GST_DEBUG_OBJECT (self->element, + "%" GST_PTR_FORMAT " - Track! %" GST_PTR_FORMAT, self->decodebin, track); + + if (track) + caps = ges_track_get_caps (track); + + g_object_set (decodebin, "caps", caps, + "expose-all-streams", FALSE, "uri", self->uri, NULL); + + return decodebin; + +} + +static void +ges_uri_source_track_set_cb (GESTrackElement * element, + GParamSpec * arg G_GNUC_UNUSED, GESUriSource * self) +{ + GESTrack *track; + const GstCaps *caps = NULL; + + if (!self->decodebin) + return; + + track = ges_track_element_get_track (GES_TRACK_ELEMENT (element)); + if (!track) + return; + + caps = ges_track_get_caps (track); + + GST_INFO_OBJECT (element, + "Setting %" GST_PTR_FORMAT "caps to: %" GST_PTR_FORMAT, self->decodebin, + caps); + g_object_set (self->decodebin, "caps", caps, NULL); +} + + + +void +ges_uri_source_init (GESTrackElement * element, GESUriSource * self) +{ + static gsize once = 0; + + if (g_once_init_enter (&once)) { + GST_DEBUG_CATEGORY_INIT (uri_source_debug, "gesurisource", 0, + "GES uri source"); + g_once_init_leave (&once, 1); + } + + self->element = element; + g_signal_connect (element, "notify::track", + G_CALLBACK (ges_uri_source_track_set_cb), self); +} diff --git a/ges/ges-uri-source.h b/ges/ges-uri-source.h new file mode 100644 index 0000000..7a8fba2 --- /dev/null +++ b/ges/ges-uri-source.h @@ -0,0 +1,41 @@ +/* GStreamer Editing Services + * Copyright (C) 2020 Ubicast SAS + * Author: Thibault Saunier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include +#include + +G_BEGIN_DECLS + +typedef struct _GESUriSource GESUriSource; + +struct _GESUriSource +{ + GstElement *decodebin; /* Reference owned by parent class */ + gchar *uri; + + GESTrackElement *element; +}; + +G_GNUC_INTERNAL GstElement * ges_uri_source_create_source (GESUriSource *self); +G_GNUC_INTERNAL void ges_uri_source_init (GESTrackElement *element, GESUriSource *self); + +G_END_DECLS diff --git a/ges/ges-video-uri-source.c b/ges/ges-video-uri-source.c index 819ab5a..f7426b1 100644 --- a/ges/ges-video-uri-source.c +++ b/ges/ges-video-uri-source.c @@ -33,13 +33,14 @@ #include "ges-utils.h" #include "ges-internal.h" #include "ges-track-element.h" +#include "ges-uri-source.h" #include "ges-video-uri-source.h" #include "ges-uri-asset.h" #include "ges-extractable.h" struct _GESVideoUriSourcePrivate { - GstElement *decodebin; /* Reference owned by parent class */ + GESUriSource parent; }; enum @@ -48,48 +49,11 @@ enum PROP_URI }; -static void -ges_video_uri_source_track_set_cb (GESVideoUriSource * self, - GParamSpec * arg G_GNUC_UNUSED, gpointer nothing) -{ - GESTrack *track; - const GstCaps *caps = NULL; - - if (!self->priv->decodebin) - return; - - track = ges_track_element_get_track (GES_TRACK_ELEMENT (self)); - if (!track) - return; - - caps = ges_track_get_caps (track); - - GST_INFO_OBJECT (self, "Setting caps to: %" GST_PTR_FORMAT, caps); - g_object_set (self->priv->decodebin, "caps", caps, NULL); -} - /* GESSource VMethod */ static GstElement * -ges_video_uri_source_create_source (GESTrackElement * trksrc) +ges_video_uri_source_create_source (GESTrackElement * element) { - GESVideoUriSource *self; - GESTrack *track; - GstElement *decodebin; - const GstCaps *caps = NULL; - - self = (GESVideoUriSource *) trksrc; - - track = ges_track_element_get_track (trksrc); - if (track) - caps = ges_track_get_caps (track); - - decodebin = self->priv->decodebin = gst_element_factory_make ("uridecodebin", - NULL); - - g_object_set (decodebin, "caps", caps, - "expose-all-streams", FALSE, "uri", self->uri, NULL); - - return decodebin; + return ges_uri_source_create_source (GES_VIDEO_URI_SOURCE (element)->priv); } static gboolean @@ -312,7 +276,7 @@ ges_video_uri_source_set_property (GObject * object, guint property_id, GST_WARNING_OBJECT (object, "Uri already set to %s", urisource->uri); return; } - urisource->uri = g_value_dup_string (value); + urisource->priv->uri = urisource->uri = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -360,9 +324,7 @@ static void ges_video_uri_source_init (GESVideoUriSource * self) { self->priv = ges_video_uri_source_get_instance_private (self); - - g_signal_connect (self, "notify::track", - G_CALLBACK (ges_video_uri_source_track_set_cb), NULL); + ges_uri_source_init (GES_TRACK_ELEMENT (self), self->priv); } /** diff --git a/ges/ges-video-uri-source.h b/ges/ges-video-uri-source.h index 2000f6a..d024160 100644 --- a/ges/ges-video-uri-source.h +++ b/ges/ges-video-uri-source.h @@ -26,6 +26,10 @@ G_BEGIN_DECLS +/** + * GESUriSource: (attributes doc.skip=true): + */ +typedef struct _GESUriSource GESUriSource; #define GES_TYPE_VIDEO_URI_SOURCE ges_video_uri_source_get_type() GES_DECLARE_TYPE(VideoUriSource, video_uri_source, VIDEO_URI_SOURCE); @@ -42,7 +46,7 @@ struct _GESVideoUriSource { gchar *uri; - GESVideoUriSourcePrivate *priv; + GESUriSource *priv; /* Padding for API extension */ gpointer _ges_reserved[GES_PADDING]; diff --git a/ges/meson.build b/ges/meson.build index f2964f4..830a47e 100644 --- a/ges/meson.build +++ b/ges/meson.build @@ -11,6 +11,7 @@ ges_sources = files([ 'ges-base-effect-clip.c', 'ges-effect-clip.c', 'ges-uri-clip.c', + 'ges-uri-source.c', 'ges-operation-clip.c', 'ges-base-transition-clip.c', 'ges-transition-clip.c',