1 /* Copyright (C) <2018> Philippe Normand <philn@igalia.com>
2 * Copyright (C) <2018> Žan Doberšek <zdobersek@igalia.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * SECTION:element-wpesrc
24 * FIXME The wpesrc element is used to produce a video texture representing a
25 * web page rendered off-screen by WPE.
29 #include "gstwpesrcbin.h"
30 #include "gstwpevideosrc.h"
31 #include "WPEThreadedView.h"
37 GstElement *video_src;
53 static guint gst_wpe_video_src_signals[LAST_SIGNAL] = { 0 };
55 static void gst_wpe_src_uri_handler_init (gpointer iface, gpointer data);
57 #define gst_wpe_src_parent_class parent_class
58 G_DEFINE_TYPE_WITH_CODE (GstWpeSrc, gst_wpe_src, GST_TYPE_BIN,
59 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_wpe_src_uri_handler_init));
61 static GstStaticPadTemplate video_src_factory =
62 GST_STATIC_PAD_TEMPLATE ("video_src", GST_PAD_SRC, GST_PAD_ALWAYS,
63 GST_STATIC_CAPS ("video/x-raw(memory:GLMemory), "
64 "format = (string) RGBA, "
65 "width = " GST_VIDEO_SIZE_RANGE ", "
66 "height = " GST_VIDEO_SIZE_RANGE ", "
67 "framerate = " GST_VIDEO_FPS_RANGE ", "
68 "pixel-aspect-ratio = (fraction)1/1,"
69 "texture-target = (string)2D"
70 #if ENABLE_SHM_BUFFER_SUPPORT
72 "format = (string) BGRA, "
73 "width = " GST_VIDEO_SIZE_RANGE ", "
74 "height = " GST_VIDEO_SIZE_RANGE ", "
75 "framerate = " GST_VIDEO_FPS_RANGE ", "
76 "pixel-aspect-ratio = (fraction)1/1"
81 gst_wpe_src_load_bytes (GstWpeVideoSrc * src, GBytes * bytes)
83 GstWpeSrc *self = GST_WPE_SRC (src);
86 g_signal_emit_by_name (self->video_src, "load-bytes", bytes, NULL);
90 gst_wpe_src_get_property (GObject * object, guint prop_id,
91 GValue * value, GParamSpec * pspec)
93 GstWpeSrc *self = GST_WPE_SRC (object);
96 g_object_get_property (G_OBJECT (self->video_src), pspec->name, value);
100 gst_wpe_src_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * pspec)
103 GstWpeSrc *self = GST_WPE_SRC (object);
106 g_object_set_property (G_OBJECT (self->video_src), pspec->name, value);
110 gst_wpe_src_uri_get_type (GType)
115 static const gchar *const *
116 gst_wpe_src_get_protocols (GType)
118 static const char *protocols[] = { "wpe", NULL };
123 gst_wpe_src_get_uri (GstURIHandler * handler)
125 GstWpeSrc *src = GST_WPE_SRC (handler);
126 const gchar *location;
127 g_object_get (src->video_src, "location", &location, NULL);
128 return g_strdup_printf ("wpe://%s", location);
132 gst_wpe_src_set_uri (GstURIHandler * handler, const gchar * uri,
135 GstWpeSrc *src = GST_WPE_SRC (handler);
137 g_object_set (src->video_src, "location", uri + 6, NULL);
142 gst_wpe_src_uri_handler_init (gpointer iface_ptr, gpointer data)
144 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) iface_ptr;
146 iface->get_type = gst_wpe_src_uri_get_type;
147 iface->get_protocols = gst_wpe_src_get_protocols;
148 iface->get_uri = gst_wpe_src_get_uri;
149 iface->set_uri = gst_wpe_src_set_uri;
153 gst_wpe_src_init (GstWpeSrc * src)
155 src->video_src = gst_element_factory_make ("wpevideosrc", NULL);
157 gst_bin_add (GST_BIN_CAST (src), src->video_src);
160 gst_element_get_static_pad (GST_ELEMENT_CAST (src->video_src), "src");
162 GstPad *ghost_pad = gst_ghost_pad_new_from_template ("video_src", pad,
163 gst_static_pad_template_get (&video_src_factory));
164 GstProxyPad *proxy_pad =
165 gst_proxy_pad_get_internal (GST_PROXY_PAD (ghost_pad));
166 gst_pad_set_active (GST_PAD_CAST (proxy_pad), TRUE);
167 gst_object_unref (proxy_pad);
169 gst_element_add_pad (GST_ELEMENT_CAST (src), GST_PAD_CAST (ghost_pad));
171 gst_object_unref (pad);
175 gst_wpe_src_class_init (GstWpeSrcClass * klass)
177 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
178 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
180 gobject_class->set_property = gst_wpe_src_set_property;
181 gobject_class->get_property = gst_wpe_src_get_property;
183 g_object_class_install_property (gobject_class, PROP_LOCATION,
184 g_param_spec_string ("location", "location", "The URL to display", "",
185 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
186 g_object_class_install_property (gobject_class, PROP_DRAW_BACKGROUND,
187 g_param_spec_boolean ("draw-background", "Draws the background",
188 "Whether to draw the WebView background", TRUE,
189 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
191 gst_element_class_set_static_metadata (element_class, "WPE source",
192 "Source/Video", "Creates a video stream from a WPE browser",
193 "Philippe Normand <philn@igalia.com>, Žan Doberšek "
194 "<zdobersek@igalia.com>");
197 * GstWpeSrc::load-bytes:
198 * @src: the object which received the signal
199 * @bytes: the GBytes data to load
201 * Load the specified bytes into the internal webView.
203 gst_wpe_video_src_signals[SIGNAL_LOAD_BYTES] =
204 g_signal_new_class_handler ("load-bytes", G_TYPE_FROM_CLASS (klass),
205 static_cast < GSignalFlags > (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
206 G_CALLBACK (gst_wpe_src_load_bytes), NULL, NULL, NULL, G_TYPE_NONE, 1,
209 gst_element_class_set_static_metadata (element_class, "WPE source",
210 "Source/Video", "Creates a video stream from a WPE browser",
211 "Philippe Normand <philn@igalia.com>, Žan Doberšek "
212 "<zdobersek@igalia.com>");
214 gst_element_class_add_static_pad_template (element_class, &video_src_factory);