[gtk/wip/gstmediafile-input] wip: Add a bin to handle input streams
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/gstmediafile-input] wip: Add a bin to handle input streams
- Date: Sat, 17 Jul 2021 18:11:33 +0000 (UTC)
commit a811070ef0dfff576d2957a336553520d789e992
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 17 14:09:44 2021 -0400
wip: Add a bin to handle input streams
We want to use GstPlayer with input streams. The way
to do that is to work around the uri-based GstPlayer
api with a custom bin and a custom uri. Go gstreamer!
modules/media/gtkgstbin.c | 99 ++++++++++++++++++++++++++++++++++++++++
modules/media/gtkgstbinprivate.h | 28 ++++++++++++
modules/media/gtkgstmediafile.c | 17 ++++++-
modules/media/meson.build | 1 +
4 files changed, 144 insertions(+), 1 deletion(-)
---
diff --git a/modules/media/gtkgstbin.c b/modules/media/gtkgstbin.c
new file mode 100644
index 0000000000..1815db4d5f
--- /dev/null
+++ b/modules/media/gtkgstbin.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include "gtkgstbinprivate.h"
+
+struct _GtkGstBin {
+ GstBin parent;
+
+ GstElement *src;
+ char *uri;
+};
+
+struct _GtkGstBinClass {
+ GstBinClass parent_class;
+};
+
+static GstURIType
+gtk_gst_uri_handler_get_type (GType type)
+{
+ return GST_URI_SRC;
+}
+
+static const char * const *
+gtk_gst_uri_handler_get_protocols (GType type)
+{
+ static const char *protocols[] = { "gtk-media-stream", NULL };
+
+ return protocols;
+}
+
+static char *
+gtk_gst_uri_handler_get_uri (GstURIHandler *handler)
+{
+ GtkGstBin *self = GTK_GST_BIN (handler);
+
+ return g_strdup (self->uri);
+}
+
+static gboolean
+gtk_gst_uri_handler_set_uri (GstURIHandler *handler,
+ const char *uri,
+ GError **error)
+{
+ GtkGstBin *self = GTK_GST_BIN (handler);
+
+ g_free (self->uri);
+ self->uri = g_strdup (uri);
+
+ return TRUE;
+}
+
+static void
+gtk_gst_uri_handler_iface_init (GstURIHandlerInterface *iface)
+{
+ iface->get_type = gtk_gst_uri_handler_get_type;
+ iface->get_protocols = gtk_gst_uri_handler_get_protocols;
+ iface->get_uri = gtk_gst_uri_handler_get_uri;
+ iface->set_uri = gtk_gst_uri_handler_set_uri;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GtkGstBin, gtk_gst_bin, GST_TYPE_BIN,
+ G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gtk_gst_uri_handler_iface_init))
+
+static void
+gtk_gst_bin_init (GtkGstBin *self)
+{
+ self->src = gst_element_factory_make ("giostreamsrc", "src");
+ g_object_ref_sink (self->src);
+
+ gst_bin_add (GST_BIN (self), self->src);
+}
+
+static void
+gtk_gst_bin_class_init (GtkGstBinClass *class)
+{
+ g_print ("calling gst_element_class_set_static_metadata\n");
+ gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (class),
+ "GtkGstBin",
+ "Source", "Handles GtkMediaFile sources",
+ "Matthias Clasen");
+}
diff --git a/modules/media/gtkgstbinprivate.h b/modules/media/gtkgstbinprivate.h
new file mode 100644
index 0000000000..af3a693350
--- /dev/null
+++ b/modules/media/gtkgstbinprivate.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2021 Red Hat, Inc
+ *
+ * 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.
+ */
+
+#ifndef __GTK_GST_BIN_PRIVATE_H__
+#define __GTK_GST_BIN_PRIVATE_H__
+
+#include <gst/gst.h>
+
+#define GTK_TYPE_GST_BIN (gtk_gst_bin_get_type ())
+G_DECLARE_FINAL_TYPE (GtkGstBin, gtk_gst_bin, GTK, GST_BIN, GstBin);
+
+#endif /* __GTK_GST_BIN_PRIVATE_H__ */
diff --git a/modules/media/gtkgstmediafile.c b/modules/media/gtkgstmediafile.c
index 6f09d1dbc8..d275374ea0 100644
--- a/modules/media/gtkgstmediafile.c
+++ b/modules/media/gtkgstmediafile.c
@@ -21,6 +21,7 @@
#include "gtkgstmediafileprivate.h"
#include "gtkgstpaintableprivate.h"
+#include "gtkgstbinprivate.h"
#include <gst/player/gstplayer.h>
#include <gst/player/gstplayer-g-main-context-signal-dispatcher.h>
@@ -225,10 +226,19 @@ gtk_gst_media_file_destroy_player (GtkGstMediaFile *self)
self->player = NULL;
}
+static void
+gtk_gst_media_file_source_setup_cb (GstElement *playbin,
+ GstElement *source,
+ gpointer user_data)
+{
+ g_print ("source setup\n");
+}
+
static void
gtk_gst_media_file_create_player (GtkGstMediaFile *file)
{
GtkGstMediaFile *self = GTK_GST_MEDIA_FILE (file);
+ GstElement *pipeline;
if (self->player != NULL)
return;
@@ -239,6 +249,9 @@ gtk_gst_media_file_create_player (GtkGstMediaFile *file)
g_signal_connect (self->player, "end-of-stream", G_CALLBACK (gtk_gst_media_file_end_of_stream_cb), self);
g_signal_connect (self->player, "seek-done", G_CALLBACK (gtk_gst_media_file_seek_done_cb), self);
g_signal_connect (self->player, "error", G_CALLBACK (gtk_gst_media_file_error_cb), self);
+
+ pipeline = gst_player_get_pipeline (self->player);
+ g_signal_connect (pipeline, "source-setup", G_CALLBACK (gtk_gst_media_file_source_setup_cb), self);
}
static void
@@ -359,6 +372,9 @@ gtk_gst_media_file_class_init (GtkGstMediaFileClass *klass)
GtkMediaStreamClass *stream_class = GTK_MEDIA_STREAM_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ g_type_ensure (GTK_TYPE_GST_BIN);
+ gst_element_register (NULL, "GtkGstBin", GST_RANK_PRIMARY, GTK_TYPE_GST_BIN);
+
file_class->open = gtk_gst_media_file_open;
file_class->close = gtk_gst_media_file_close;
@@ -379,4 +395,3 @@ gtk_gst_media_file_init (GtkGstMediaFile *self)
g_signal_connect_swapped (self->paintable, "invalidate-size", G_CALLBACK (gdk_paintable_invalidate_size),
self);
g_signal_connect_swapped (self->paintable, "invalidate-contents", G_CALLBACK
(gdk_paintable_invalidate_contents), self);
}
-
diff --git a/modules/media/meson.build b/modules/media/meson.build
index 1bd91821d8..7c0ab8fc2a 100644
--- a/modules/media/meson.build
+++ b/modules/media/meson.build
@@ -69,6 +69,7 @@ if gstplayer_dep.found() and gstgl_dep.found()
'gtkgstmediafile.c',
'gtkgstpaintable.c',
'gtkgstsink.c',
+ 'gtkgstbin.c',
],
c_args: extra_c_args + extra_win_cflags,
dependencies: [ libm, libgtk_dep, gstplayer_dep, gstgl_dep ],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]