gstreamer/subprojects/gst-editing-services/plugins/ges/gessrc.c

169 lines
4.3 KiB
C
Raw Normal View History

/* GStreamer Editing Services GStreamer plugin
* Copyright (C) 2019 Thibault Saunier <tsaunier@igalia.com>
*
* gessrc.c
*
* 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.
*
**
2019-06-06 19:40:57 +00:00
* SECTION:element-gessrc
* @short_description: A GstBin subclasses use to use GESTimeline
* as sources inside any GstPipeline.
* @see_also: #GESTimeline
*
* The gessrc is a bin that will simply expose the track src pads
* and implements the GstUriHandler interface using a custom `ges://`
* uri scheme.
*
* NOTE: That to use it inside playbin and friends you **need** to
* set gessrc::timeline property yourself.
*
* Example with #playbin:
*
* {{../../examples/c/gessrc.c}}
*
* Example with #GstPlayer:
*
* {{../../examples/python/gst-player.py}}
**/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <ges/ges.h>
#include "gesbasebin.h"
GST_DEBUG_CATEGORY_STATIC (gessrc);
#define GST_CAT_DEFAULT gessrc
G_DECLARE_FINAL_TYPE (GESSrc, ges_src, GES, SRC, GESBaseBin);
struct _GESSrc
{
GESBaseBin parent;
gchar *uri;
};
#define GES_SRC(obj) ((GESSrc*) obj)
/*** GSTURIHANDLER INTERFACE *************************************************/
static GstURIType
ges_src_uri_get_type (GType type)
{
return GST_URI_SRC;
}
static const gchar *const *
ges_src_uri_get_protocols (GType type)
{
static const gchar *protocols[] = { "ges", NULL };
return protocols;
}
static gchar *
ges_src_uri_get_uri (GstURIHandler * handler)
{
GESSrc *self = GES_SRC (handler);
GESTimeline *timeline = ges_base_bin_get_timeline (GES_BASE_BIN (self));
GST_OBJECT_LOCK (self);
if (self->uri) {
gchar *uri = g_strdup (self->uri);
GST_OBJECT_UNLOCK (self);
return uri;
}
GST_OBJECT_UNLOCK (self);
return ges_command_line_formatter_get_timeline_uri (timeline);
}
static gboolean
ges_src_uri_set_uri (GstURIHandler * handler, const gchar * uristr,
GError ** error)
{
gboolean res = FALSE;
GESSrc *self = GES_SRC (handler);
GstUri *uri = gst_uri_from_string (uristr);
GESProject *project = NULL;
GESTimeline *timeline = NULL;
if (!gst_uri_get_path (uri)) {
GST_INFO_OBJECT (handler, "User need to specify the timeline");
res = TRUE;
goto done;
}
project = ges_project_new (uristr);
timeline = (GESTimeline *) ges_asset_extract (GES_ASSET (project), NULL);
if (timeline)
res = ges_base_bin_set_timeline (GES_BASE_BIN (handler), timeline);
done:
gst_uri_unref (uri);
gst_clear_object (&project);
GST_OBJECT_LOCK (handler);
g_free (self->uri);
self->uri = g_strdup (uristr);
GST_OBJECT_UNLOCK (handler);
return res;
}
static void
ges_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
{
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
iface->get_type = ges_src_uri_get_type;
iface->get_protocols = ges_src_uri_get_protocols;
iface->get_uri = ges_src_uri_get_uri;
iface->set_uri = ges_src_uri_set_uri;
}
G_DEFINE_TYPE_WITH_CODE (GESSrc, ges_src, ges_base_bin_get_type (),
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, ges_src_uri_handler_init));
static void
ges_src_class_init (GESSrcClass * self_class)
{
GstElementClass *gstelement_klass = GST_ELEMENT_CLASS (self_class);
GST_DEBUG_CATEGORY_INIT (gessrc, "gessrc", 0, "ges src element");
gst_element_class_set_static_metadata (gstelement_klass,
"GStreamer Editing Services based 'source'",
"Codec/Source/Editing",
"Source for GESTimeline.", "Thibault Saunier <tsaunier@igalia.com");
}
static void
ges_src_init (GESSrc * self)
{
ges: fix G_DECLARE_FINAL_TYPE -Werror with clang Also fix wrong casing the `G_DECLARE` for GESDemux. ../subprojects/gst-editing-services/plugins/ges/gessrc.c:56:1: warning: unused function 'GES_SRC' [-Wunused-function] G_DECLARE_FINAL_TYPE (GESSrc, ges_src, GES, SRC, GESBaseBin); ^ /usr/include/glib-2.0/gobject/gtype.h:1405:33: note: expanded from macro 'G_DECLARE_FINAL_TYPE' static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \ ^ <scratch space>:39:1: note: expanded from here GES_SRC ^ ../subprojects/gst-editing-services/plugins/ges/gessrc.c:56:1: warning: unused function 'GES_IS_SRC' [-Wunused-function] /usr/include/glib-2.0/gobject/gtype.h:1407:26: note: expanded from macro 'G_DECLARE_FINAL_TYPE' static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \ ^ <scratch space>:42:1: note: expanded from here GES_IS_SRC ^ ../subprojects/gst-editing-services/plugins/ges/gesdemux.c:50:1: warning: unused function 'GES_Demux' [-Wunused-function] G_DECLARE_FINAL_TYPE (GESDemux, ges_demux, GES, Demux, GESBaseBin); ^ /usr/include/glib-2.0/gobject/gtype.h:1405:33: note: expanded from macro 'G_DECLARE_FINAL_TYPE' static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \ ^ <scratch space>:72:1: note: expanded from here GES_Demux ^ ../subprojects/gst-editing-services/plugins/ges/gesdemux.c:50:1: warning: unused function 'GES_IS_Demux' [-Wunused-function] /usr/include/glib-2.0/gobject/gtype.h:1407:26: note: expanded from macro 'G_DECLARE_FINAL_TYPE' static inline gboolean MODULE##_IS_##OBJ_NAME (gpointer ptr) { \ ^ <scratch space>:75:1: note: expanded from here GES_IS_Demux ^
2019-08-27 14:02:04 +00:00
SUPRESS_UNUSED_WARNING (GES_SRC);
SUPRESS_UNUSED_WARNING (GES_IS_SRC);
build: also suppress unused-function warnings about g_autoptr ../plugins/ges/gesdemux.c:50:1: error: unused function 'glib_autoptr_cleanup_GESDemux' [-Werror,-Wunused-function] G_DECLARE_FINAL_TYPE (GESDemux, ges_demux, GES, DEMUX, GESBaseBin); ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/gobject/gtype.h:1401:3: note: expanded from macro 'G_DECLARE_FINAL_TYPE' _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \ ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/glib/gmacros.h:451:22: note: expanded from macro '_GLIB_DEFINE_AUTOPTR_CHAINUP' static inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName) (ModuleObjName **_ptr) { \ ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/glib/gmacros.h:441:43: note: expanded from macro '_GLIB_AUTOPTR_FUNC_NAME' #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName ^ <scratch space>:81:1: note: expanded from here glib_autoptr_cleanup_GESDemux ^ ../plugins/ges/gessrc.c:56:1: error: unused function 'glib_autoptr_cleanup_GESSrc' [-Werror,-Wunused-function] G_DECLARE_FINAL_TYPE (GESSrc, ges_src, GES, SRC, GESBaseBin); ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/gobject/gtype.h:1401:3: note: expanded from macro 'G_DECLARE_FINAL_TYPE' _GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \ ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/glib/gmacros.h:451:22: note: expanded from macro '_GLIB_DEFINE_AUTOPTR_CHAINUP' static inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName) (ModuleObjName **_ptr) { \ ^ /home/matt/Projects/cerbero/build/dist/android_universal/x86_64/include/glib-2.0/glib/gmacros.h:441:43: note: expanded from macro '_GLIB_AUTOPTR_FUNC_NAME' #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName ^ <scratch space>:158:1: note: expanded from here glib_autoptr_cleanup_GESSrc ^
2019-08-28 08:13:06 +00:00
#if defined(g_autoptr)
SUPRESS_UNUSED_WARNING (glib_autoptr_cleanup_GESSrc);
#endif
}