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: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/198>
This commit is contained in:
Thibault Saunier 2020-07-03 16:34:21 -04:00
parent 135707290e
commit 834345b1c8
7 changed files with 155 additions and 91 deletions

View file

@ -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);
}
/**

View file

@ -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];

94
ges/ges-uri-source.c Normal file
View file

@ -0,0 +1,94 @@
/* GStreamer Editing Services
* Copyright (C) 2020 Ubicast S.A
* Author: Thibault Saunier <tsaunier@igalia.com>
*
* 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);
}

41
ges/ges-uri-source.h Normal file
View file

@ -0,0 +1,41 @@
/* GStreamer Editing Services
* Copyright (C) 2020 Ubicast SAS
* Author: Thibault Saunier <tsaunier@igalia.com>
*
* 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 <glib-object.h>
#include <ges/ges.h>
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

View file

@ -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);
}
/**

View file

@ -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];

View file

@ -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',