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-wpevideosrc
24 * The wpevideosrc element is used to produce a video texture representing a web page
25 * rendered off-screen by WPE.
27 * Starting from WPEBackend-FDO 1.6.x, software rendering support is available. This
28 * features allows wpevideosrc to be used on machines without GPU, and/or for testing
29 * purpose. To enable it, set the `LIBGL_ALWAYS_SOFTWARE=true` environment
30 * variable and make sure `video/x-raw, format=BGRA` caps are negotiated by the
31 * wpevideosrc element.
33 * As the webview loading is usually not instantaneous, the wpevideosrc element emits
34 * messages indicating the load progress, in percent. The value is an estimate
35 * based on the total number of bytes expected to be received for a document,
36 * including all its possible subresources and child documents. The application
37 * can handle these `element` messages synchronously for instance, in order to
38 * display a progress bar or other visual load indicator. The load percent value
39 * is stored in the message structure as a double value named
40 * `estimated-load-progress` and the structure name is `wpe-stats`.
42 * ## Example launch lines
45 * gst-launch-1.0 -v wpevideosrc location="https://gstreamer.freedesktop.org" ! queue ! glimagesink
47 * Shows the GStreamer website homepage
50 * LIBGL_ALWAYS_SOFTWARE=true gst-launch-1.0 -v wpevideosrc num-buffers=50 location="https://gstreamer.freedesktop.org" \
51 * videoconvert ! pngenc ! multifilesink location=/tmp/snapshot-%05d.png
53 * Saves the first 50 video frames generated for the GStreamer website as PNG files in /tmp.
56 * gst-play-1.0 --videosink gtkglsink web+https://gstreamer.freedesktop.org
58 * Shows the GStreamer website homepage as played with GstPlayer in a GTK+ window.
61 * gst-launch-1.0 glvideomixer name=m sink_1::zorder=0 ! glimagesink wpevideosrc location="file:///tmp/asset.html" draw-background=0 \
62 * ! m. videotestsrc ! queue ! glupload ! glcolorconvert ! m.
64 * Composite WPE with a video stream in a single OpenGL scene.
67 * gst-launch-1.0 glvideomixer name=m sink_1::zorder=0 sink_0::height=818 sink_0::width=1920 ! gtkglsink \
68 * wpevideosrc location="file:///tmp/asset.html" draw-background=0 ! m.
69 * uridecodebin uri="http://example.com/Sintel.2010.1080p.mkv" name=d d. ! queue ! glupload ! glcolorconvert ! m.
71 * Composite WPE with a video stream, sink_0 pad properties have to match the video dimensions.
78 * - DMABuf support (requires changes in WPEBackend-fdo to expose DMABuf planes and fds)
79 * - Custom EGLMemory allocator
80 * - Better navigation events handling (would require a new GstNavigation API)
88 #include "gstwpevideosrc.h"
89 #include <gst/gl/gl.h>
90 #include <gst/gl/egl/gstglmemoryegl.h>
91 #include <gst/gl/wayland/gstgldisplay_wayland.h>
92 #include <gst/video/video.h>
93 #include <xkbcommon/xkbcommon.h>
95 #include "WPEThreadedView.h"
97 #define DEFAULT_WIDTH 1920
98 #define DEFAULT_HEIGHT 1080
99 #define DEFAULT_FPS_N 30
100 #define DEFAULT_FPS_D 1
101 #define DEFAULT_DRAW_BACKGROUND TRUE
112 SIGNAL_CONFIGURE_WEB_VIEW,
114 SIGNAL_RUN_JAVASCRIPT,
117 static guint gst_wpe_video_src_signals[LAST_SIGNAL] = { 0 };
119 struct _GstWpeVideoSrc
125 gboolean draw_background;
130 gint64 n_frames; /* total frames sent */
134 GArray *touch_points;
135 struct wpe_input_touch_event_raw *last_touch;
140 #define WPE_LOCK(o) g_mutex_lock(&(o)->lock)
141 #define WPE_UNLOCK(o) g_mutex_unlock(&(o)->lock)
143 GST_DEBUG_CATEGORY_EXTERN (wpe_video_src_debug);
144 #define GST_CAT_DEFAULT wpe_video_src_debug
146 #define gst_wpe_video_src_parent_class parent_class
147 G_DEFINE_TYPE (GstWpeVideoSrc, gst_wpe_video_src, GST_TYPE_GL_BASE_SRC);
149 #define WPE_RAW_CAPS "video/x-raw, " \
150 "format = (string) BGRA, " \
151 "width = " GST_VIDEO_SIZE_RANGE ", " \
152 "height = " GST_VIDEO_SIZE_RANGE ", " \
153 "framerate = " GST_VIDEO_FPS_RANGE ", " \
154 "pixel-aspect-ratio = (fraction)1/1"
156 #define WPE_GL_CAPS "video/x-raw(memory:GLMemory), " \
157 "format = (string) RGBA, " \
158 "width = " GST_VIDEO_SIZE_RANGE ", " \
159 "height = " GST_VIDEO_SIZE_RANGE ", " \
160 "framerate = " GST_VIDEO_FPS_RANGE ", " \
161 "pixel-aspect-ratio = (fraction)1/1, texture-target = (string)2D"
163 #define WPE_VIDEO_SRC_CAPS WPE_GL_CAPS "; " WPE_RAW_CAPS
164 #define WPE_VIDEO_SRC_DOC_CAPS WPE_GL_CAPS "; video/x-raw, format = (string) BGRA"
166 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
169 GST_STATIC_CAPS (WPE_VIDEO_SRC_CAPS));
172 gst_wpe_video_src_create (GstBaseSrc * bsrc, guint64 offset, guint length,
175 GstGLBaseSrc *gl_src = GST_GL_BASE_SRC (bsrc);
176 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (bsrc);
177 GstFlowReturn ret = GST_FLOW_ERROR;
178 GstBuffer *locked_buffer;
179 GstClockTime next_time;
180 gint64 ts_offset = 0;
183 if (src->gl_enabled) {
185 return GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, create, (bsrc,
186 offset, length, buf), ret);
189 locked_buffer = src->view->buffer ();
190 if (locked_buffer == NULL) {
192 GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
193 ("WPE View did not render a buffer"), (NULL));
196 *buf = gst_buffer_copy_deep (locked_buffer);
198 g_object_get (gl_src, "timestamp-offset", &ts_offset, NULL);
200 /* The following code mimics the behaviour of GLBaseSrc::fill */
201 GST_BUFFER_TIMESTAMP (*buf) = ts_offset + gl_src->running_time;
202 GST_BUFFER_OFFSET (*buf) = src->n_frames;
204 GST_BUFFER_OFFSET_END (*buf) = src->n_frames;
205 if (gl_src->out_info.fps_n) {
206 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
207 gl_src->out_info.fps_d, gl_src->out_info.fps_n);
208 GST_BUFFER_DURATION (*buf) = next_time - gl_src->running_time;
210 next_time = ts_offset;
211 GST_BUFFER_DURATION (*buf) = GST_CLOCK_TIME_NONE;
214 GST_LOG_OBJECT (src, "Created buffer from SHM %" GST_PTR_FORMAT, *buf);
216 gl_src->running_time = next_time;
224 _egl_image_quark (void)
226 static GQuark quark = 0;
229 quark = g_quark_from_static_string ("GstWPEEGLImage");
234 gst_wpe_video_src_fill_memory (GstGLBaseSrc * bsrc, GstGLMemory * memory)
236 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (bsrc);
237 const GstGLFuncs *gl;
239 GstEGLImage *locked_image;
241 if (!gst_gl_context_check_feature (GST_GL_CONTEXT (bsrc->context),
242 "EGL_KHR_image_base")) {
243 GST_ERROR_OBJECT (src, "EGL_KHR_image_base is not supported");
249 gl = bsrc->context->gl_vtable;
250 tex_id = gst_gl_memory_get_texture_id (memory);
251 locked_image = src->view->image ();
258 // The EGLImage is implicitely associated with the memory we're filling, so we
259 // need to ensure their life cycles are tied.
260 gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (memory), _egl_image_quark (),
261 gst_egl_image_ref (locked_image), (GDestroyNotify) gst_egl_image_unref);
263 gl->ActiveTexture (GL_TEXTURE0 + memory->plane);
264 gl->BindTexture (GL_TEXTURE_2D, tex_id);
265 gl->EGLImageTargetTexture2D (GL_TEXTURE_2D,
266 gst_egl_image_get_image (locked_image));
273 gst_wpe_video_src_start (GstWpeVideoSrc * src)
275 GstGLContext *context = NULL;
276 GstGLDisplay *display = NULL;
277 GstGLBaseSrc *base_src = GST_GL_BASE_SRC (src);
278 gboolean created_view = FALSE;
281 GST_INFO_OBJECT (src, "Starting up");
284 if (src->gl_enabled) {
285 context = base_src->context;
286 display = base_src->display;
289 GST_DEBUG_OBJECT (src, "Will %sfill GLMemories",
290 src->gl_enabled ? "" : "NOT ");
292 auto & thread = WPEContextThread::singleton ();
295 src->view = thread.createWPEView (src, context, display,
296 GST_VIDEO_INFO_WIDTH (&base_src->out_info),
297 GST_VIDEO_INFO_HEIGHT (&base_src->out_info));
299 GST_DEBUG_OBJECT (src, "created view %p", src->view);
304 GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
305 ("WPEBackend-FDO EGL display initialisation failed"), (NULL));
309 GST_OBJECT_LOCK (src);
312 GST_OBJECT_UNLOCK (src);
315 src->view->loadData (bytes);
316 g_bytes_unref (bytes);
327 gst_wpe_video_src_decide_allocation (GstBaseSrc * base_src, GstQuery * query)
329 GstGLBaseSrc *gl_src = GST_GL_BASE_SRC (base_src);
330 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
331 GstCapsFeatures *caps_features;
334 caps_features = gst_caps_get_features (gl_src->out_caps, 0);
335 if (caps_features != NULL
336 && gst_caps_features_contains (caps_features,
337 GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) {
338 src->gl_enabled = TRUE;
340 src->gl_enabled = FALSE;
343 if (src->gl_enabled) {
345 return GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, decide_allocation,
346 (base_src, query), FALSE);
349 return gst_wpe_video_src_start (src);
353 gst_wpe_video_src_gl_start (GstGLBaseSrc * base_src)
355 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
356 return gst_wpe_video_src_start (src);
360 gst_wpe_video_src_stop_unlocked (GstWpeVideoSrc * src)
363 GST_DEBUG_OBJECT (src, "deleting view %p", src->view);
370 gst_wpe_video_src_gl_stop (GstGLBaseSrc * base_src)
372 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
375 gst_wpe_video_src_stop_unlocked (src);
380 gst_wpe_video_src_stop (GstBaseSrc * base_src)
382 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
384 /* we can call this always, GstGLBaseSrc is smart enough to not crash if
385 * gst_gl_base_src_gl_start() has not been called from chaining up
386 * gst_wpe_video_src_decide_allocation() */
387 if (!GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, stop, (base_src),
393 /* if gl-enabled, gst_wpe_video_src_stop_unlocked() would have already been called
394 * inside gst_wpe_video_src_gl_stop() from the base class stopping the OpenGL
396 if (!src->gl_enabled)
397 gst_wpe_video_src_stop_unlocked (src);
404 gst_wpe_video_src_fixate (GstBaseSrc * base_src, GstCaps * combined_caps)
406 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
407 GstStructure *structure;
411 /* In situation where software GL support is explicitly requested, select raw
412 * caps, otherwise perform default caps negotiation. Unfortunately at this
413 * point we don't know yet if a GL context will be usable or not, so we can't
414 * check the element GstContext.
416 if (!g_strcmp0 (g_getenv ("LIBGL_ALWAYS_SOFTWARE"), "true")) {
417 caps = gst_caps_from_string (WPE_RAW_CAPS);
419 caps = gst_caps_make_writable (combined_caps);
422 structure = gst_caps_get_structure (caps, 0);
424 gst_structure_fixate_field_nearest_int (structure, "width", DEFAULT_WIDTH);
425 gst_structure_fixate_field_nearest_int (structure, "height", DEFAULT_HEIGHT);
427 if (gst_structure_has_field (structure, "framerate"))
428 gst_structure_fixate_field_nearest_fraction (structure, "framerate",
429 DEFAULT_FPS_N, DEFAULT_FPS_D);
431 gst_structure_set (structure, "framerate", GST_TYPE_FRACTION, DEFAULT_FPS_N,
432 DEFAULT_FPS_D, NULL);
434 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (base_src, caps);
435 GST_INFO_OBJECT (base_src, "Fixated caps to %" GST_PTR_FORMAT, caps);
438 gst_structure_get (structure, "width", G_TYPE_INT, &width, "height",
439 G_TYPE_INT, &height, NULL);
440 src->view->resize (width, height);
446 gst_wpe_video_src_configure_web_view (GstWpeVideoSrc * src,
447 WebKitWebView * webview)
449 GValue args[2] = { {0}, {0} };
451 g_value_init (&args[0], GST_TYPE_ELEMENT);
452 g_value_set_object (&args[0], src);
453 g_value_init (&args[1], G_TYPE_OBJECT);
454 g_value_set_object (&args[1], webview);
456 g_signal_emitv (args, gst_wpe_video_src_signals[SIGNAL_CONFIGURE_WEB_VIEW], 0,
459 g_value_unset (&args[0]);
460 g_value_unset (&args[1]);
464 gst_wpe_video_src_run_javascript (GstWpeVideoSrc * src, const gchar * script)
466 if (src->view && GST_STATE (GST_ELEMENT_CAST (src)) > GST_STATE_NULL) {
467 GST_INFO_OBJECT (src, "running javascript");
468 src->view->runJavascript (script);
473 gst_wpe_video_src_load_bytes (GstWpeVideoSrc * src, GBytes * bytes)
475 if (src->view && GST_STATE (GST_ELEMENT_CAST (src)) > GST_STATE_NULL) {
476 src->view->loadData (bytes);
478 GST_OBJECT_LOCK (src);
480 g_bytes_unref (src->bytes);
481 src->bytes = g_bytes_ref (bytes);
482 GST_OBJECT_UNLOCK (src);
487 gst_wpe_video_src_set_location (GstWpeVideoSrc * src, const gchar * location,
490 GST_OBJECT_LOCK (src);
491 g_free (src->location);
492 src->location = g_strdup (location);
493 GST_OBJECT_UNLOCK (src);
496 src->view->loadUri (location);
502 gst_wpe_video_src_set_draw_background (GstWpeVideoSrc * src,
503 gboolean draw_background)
505 GST_OBJECT_LOCK (src);
506 src->draw_background = draw_background;
507 GST_OBJECT_UNLOCK (src);
510 src->view->setDrawBackground (draw_background);
514 gst_wpe_video_src_set_property (GObject * object, guint prop_id,
515 const GValue * value, GParamSpec * pspec)
517 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (object);
522 const gchar *location;
524 location = g_value_get_string (value);
525 if (location == NULL) {
526 GST_WARNING_OBJECT (src, "location property cannot be NULL");
530 if (!gst_wpe_video_src_set_location (src, location, NULL)) {
531 GST_WARNING_OBJECT (src, "badly formatted location");
536 case PROP_DRAW_BACKGROUND:
537 gst_wpe_video_src_set_draw_background (src, g_value_get_boolean (value));
545 gst_wpe_video_src_get_property (GObject * object, guint prop_id, GValue * value,
548 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (object);
552 GST_OBJECT_LOCK (src);
553 g_value_set_string (value, src->location);
554 GST_OBJECT_UNLOCK (src);
556 case PROP_DRAW_BACKGROUND:
557 GST_OBJECT_LOCK (src);
558 g_value_set_boolean (value, src->draw_background);
559 GST_OBJECT_UNLOCK (src);
562 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
568 _set_touch_point (struct wpe_input_touch_event_raw * point,
569 GstEvent * event, enum wpe_input_touch_event_type type, guint id, gdouble x,
573 point->time = GST_TIME_AS_MSECONDS (GST_EVENT_TIMESTAMP (event));
575 point->id = (int) id;
576 point->x = (int32_t) x;
577 point->y = (int32_t) y;
581 _gst_modifiers_to_wpe (GstEvent * ev)
583 GstNavigationModifierType modifier_state;
584 uint32_t modifiers = 0;
586 if (gst_navigation_event_parse_modifier_state (ev, &modifier_state)) {
587 if (modifier_state & GST_NAVIGATION_MODIFIER_CONTROL_MASK)
588 modifiers |= wpe_input_keyboard_modifier_control;
589 if (modifier_state & GST_NAVIGATION_MODIFIER_SHIFT_MASK)
590 modifiers |= wpe_input_keyboard_modifier_shift;
591 if (modifier_state & GST_NAVIGATION_MODIFIER_MOD1_MASK)
592 modifiers |= wpe_input_keyboard_modifier_alt;
593 if (modifier_state & GST_NAVIGATION_MODIFIER_META_MASK)
594 modifiers |= wpe_input_keyboard_modifier_meta;
595 if (modifier_state & GST_NAVIGATION_MODIFIER_BUTTON1_MASK)
596 modifiers |= wpe_input_pointer_modifier_button1;
597 if (modifier_state & GST_NAVIGATION_MODIFIER_BUTTON2_MASK)
598 modifiers |= wpe_input_pointer_modifier_button2;
599 if (modifier_state & GST_NAVIGATION_MODIFIER_BUTTON3_MASK)
600 modifiers |= wpe_input_pointer_modifier_button3;
601 if (modifier_state & GST_NAVIGATION_MODIFIER_BUTTON4_MASK)
602 modifiers |= wpe_input_pointer_modifier_button4;
603 if (modifier_state & GST_NAVIGATION_MODIFIER_BUTTON5_MASK)
604 modifiers |= wpe_input_pointer_modifier_button5;
611 gst_wpe_video_src_event (GstBaseSrc * base_src, GstEvent * event)
613 gboolean ret = FALSE;
614 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (base_src);
616 if (src->view && GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION) {
620 gdouble x, y, delta_x, delta_y;
622 GST_DEBUG_OBJECT (src, "Processing event %" GST_PTR_FORMAT, event);
623 switch (gst_navigation_event_get_type (event)) {
624 case GST_NAVIGATION_EVENT_KEY_PRESS:
625 case GST_NAVIGATION_EVENT_KEY_RELEASE:
626 if (gst_navigation_event_parse_key_event (event, &key)) {
627 /* FIXME: This is wrong... The GstNavigation API should pass
628 hardware-level information, not high-level keysym strings */
632 struct wpe_input_keyboard_event wpe_event = { 0 };
634 unichar = g_utf8_to_ucs4_fast (key, -1, &items_written);
635 if (items_written == 1)
636 keysym = (uint32_t) xkb_utf32_to_keysym (*unichar);
639 (uint32_t) xkb_keysym_from_name (key, XKB_KEYSYM_NO_FLAGS);
641 wpe_event.key_code = keysym;
643 gst_navigation_event_get_type (event) ==
644 GST_NAVIGATION_EVENT_KEY_PRESS;
645 wpe_event.modifiers = _gst_modifiers_to_wpe (event);
646 src->view->dispatchKeyboardEvent (wpe_event);
650 case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
651 case GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE:
652 if (gst_navigation_event_parse_mouse_button_event (event, &button, &x,
654 struct wpe_input_pointer_event wpe_event;
655 wpe_event.time = GST_TIME_AS_MSECONDS (GST_EVENT_TIMESTAMP (event));
656 wpe_event.type = wpe_input_pointer_event_type_button;
657 wpe_event.x = (int) x;
658 wpe_event.y = (int) y;
659 wpe_event.modifiers = _gst_modifiers_to_wpe (event);
660 wpe_event.button = button;
662 gst_navigation_event_get_type (event) ==
663 GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS;
664 src->view->dispatchPointerEvent (wpe_event);
668 case GST_NAVIGATION_EVENT_MOUSE_MOVE:
669 if (gst_navigation_event_parse_mouse_move_event (event, &x, &y)) {
670 struct wpe_input_pointer_event wpe_event;
671 wpe_event.time = GST_TIME_AS_MSECONDS (GST_EVENT_TIMESTAMP (event));
672 wpe_event.type = wpe_input_pointer_event_type_motion;
673 wpe_event.x = (int) x;
674 wpe_event.y = (int) y;
675 wpe_event.modifiers = _gst_modifiers_to_wpe (event);
676 src->view->dispatchPointerEvent (wpe_event);
680 case GST_NAVIGATION_EVENT_MOUSE_SCROLL:
681 if (gst_navigation_event_parse_mouse_scroll_event (event, &x, &y,
682 &delta_x, &delta_y)) {
683 struct wpe_input_axis_event wpe_event;
686 wpe_event.value = delta_x;
689 wpe_event.value = delta_y;
691 wpe_event.time = GST_TIME_AS_MSECONDS (GST_EVENT_TIMESTAMP (event));
692 wpe_event.type = wpe_input_axis_event_type_motion;
693 wpe_event.x = (int) x;
694 wpe_event.y = (int) y;
695 src->view->dispatchAxisEvent (wpe_event);
699 case GST_NAVIGATION_EVENT_TOUCH_DOWN:
700 if (gst_navigation_event_parse_touch_event (event, &touch_id, &x, &y,
702 struct wpe_input_touch_event_raw *point = g_new
703 (struct wpe_input_touch_event_raw, 1);
705 _set_touch_point (point, event, wpe_input_touch_event_type_down,
707 src->touch_points = g_array_append_vals(src->touch_points, point, 1);
708 src->last_touch = point;
712 case GST_NAVIGATION_EVENT_TOUCH_MOTION:
713 if (gst_navigation_event_parse_touch_event (event, &touch_id, &x, &y,
715 struct wpe_input_touch_event_raw *touch_points;
718 touch_points = (struct wpe_input_touch_event_raw *)
719 src->touch_points->data;
720 for (idx = 0; idx < src->touch_points->len; idx++) {
721 if (touch_points[idx].id == (int32_t) touch_id) {
722 _set_touch_point (&touch_points[idx], event,
723 wpe_input_touch_event_type_motion, touch_id, x, y);
724 src->last_touch = &touch_points[idx];
731 case GST_NAVIGATION_EVENT_TOUCH_UP:
732 if (gst_navigation_event_parse_touch_up_event (event, &touch_id, &x,
734 struct wpe_input_touch_event_raw *touch_points;
737 touch_points = (struct wpe_input_touch_event_raw *)
738 src->touch_points->data;
739 for (idx = 0; idx < src->touch_points->len; idx++) {
740 if (touch_points[idx].id == (int32_t) touch_id) {
741 _set_touch_point (&touch_points[idx], event,
742 wpe_input_touch_event_type_up, touch_id, x, y);
743 src->last_touch = &touch_points[idx];
750 case GST_NAVIGATION_EVENT_TOUCH_FRAME:
751 if (src->last_touch && src->touch_points->len > 0)
753 struct wpe_input_touch_event_raw *touch_points;
754 struct wpe_input_touch_event wpe_event;
757 wpe_event.touchpoints =
758 (struct wpe_input_touch_event_raw *) src->touch_points->data;
759 wpe_event.touchpoints_length = src->touch_points->len;
760 wpe_event.type = src->last_touch->type;
761 wpe_event.id = src->last_touch->id;
762 wpe_event.modifiers = _gst_modifiers_to_wpe (event);
763 wpe_event.time = src->last_touch->time;
764 src->view->dispatchTouchEvent (wpe_event);
766 touch_points = (struct wpe_input_touch_event_raw *)
767 src->touch_points->data;
768 for (idx = 0; idx < src->touch_points->len; idx++) {
769 if (touch_points[idx].type == wpe_input_touch_event_type_up ||
770 touch_points[idx].type == wpe_input_touch_event_type_null) {
771 g_array_remove_index_fast(src->touch_points, idx);
775 src->last_touch = NULL;
779 case GST_NAVIGATION_EVENT_TOUCH_CANCEL:
788 GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_SRC_CLASS, event, (base_src,
795 gst_wpe_video_src_init (GstWpeVideoSrc * src)
797 src->draw_background = DEFAULT_DRAW_BACKGROUND;
798 src->location = g_strdup (DEFAULT_LOCATION);
800 gst_base_src_set_live (GST_BASE_SRC_CAST (src), TRUE);
802 src->touch_points = g_array_sized_new (FALSE, FALSE, sizeof (void *), 10);
803 g_mutex_init (&src->lock);
807 gst_wpe_video_src_finalize (GObject * object)
809 GstWpeVideoSrc *src = GST_WPE_VIDEO_SRC (object);
811 g_free (src->location);
812 g_clear_pointer (&src->bytes, g_bytes_unref);
813 g_array_unref (src->touch_points);
814 g_mutex_clear (&src->lock);
816 G_OBJECT_CLASS (parent_class)->finalize (object);
820 gst_wpe_video_src_class_init (GstWpeVideoSrcClass * klass)
822 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
823 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
824 GstGLBaseSrcClass *gl_base_src_class = GST_GL_BASE_SRC_CLASS (klass);
825 GstBaseSrcClass *base_src_class = GST_BASE_SRC_CLASS (klass);
826 GstPadTemplate *tmpl;
829 gobject_class->set_property = gst_wpe_video_src_set_property;
830 gobject_class->get_property = gst_wpe_video_src_get_property;
831 gobject_class->finalize = gst_wpe_video_src_finalize;
833 g_object_class_install_property (gobject_class, PROP_LOCATION,
834 g_param_spec_string ("location", "location",
835 "The URL to display",
836 DEFAULT_LOCATION, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
837 g_object_class_install_property (gobject_class, PROP_DRAW_BACKGROUND,
838 g_param_spec_boolean ("draw-background", "Draws the background",
839 "Whether to draw the WebView background", DEFAULT_DRAW_BACKGROUND,
840 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
842 gst_element_class_set_static_metadata (gstelement_class,
843 "WPE source", "Source/Video",
844 "Creates a video stream from a WPE browser",
845 "Philippe Normand <philn@igalia.com>, Žan Doberšek <zdobersek@igalia.com>");
847 tmpl = gst_static_pad_template_get (&src_factory);
848 gst_element_class_add_pad_template (gstelement_class, tmpl);
850 base_src_class->fixate = GST_DEBUG_FUNCPTR (gst_wpe_video_src_fixate);
851 base_src_class->create = GST_DEBUG_FUNCPTR (gst_wpe_video_src_create);
852 base_src_class->decide_allocation =
853 GST_DEBUG_FUNCPTR (gst_wpe_video_src_decide_allocation);
854 base_src_class->stop = GST_DEBUG_FUNCPTR (gst_wpe_video_src_stop);
855 base_src_class->event = GST_DEBUG_FUNCPTR (gst_wpe_video_src_event);
857 gl_base_src_class->supported_gl_api =
858 static_cast < GstGLAPI >
859 (GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2);
860 gl_base_src_class->gl_start = GST_DEBUG_FUNCPTR (gst_wpe_video_src_gl_start);
861 gl_base_src_class->gl_stop = GST_DEBUG_FUNCPTR (gst_wpe_video_src_gl_stop);
862 gl_base_src_class->fill_gl_memory =
863 GST_DEBUG_FUNCPTR (gst_wpe_video_src_fill_memory);
865 doc_caps = gst_caps_from_string (WPE_VIDEO_SRC_DOC_CAPS);
866 gst_pad_template_set_documentation_caps (tmpl, doc_caps);
867 gst_clear_caps (&doc_caps);
870 * GstWpeVideoSrc::configure-web-view:
871 * @src: the object which received the signal
872 * @webview: the webView
874 * Allow application to configure the webView settings.
876 gst_wpe_video_src_signals[SIGNAL_CONFIGURE_WEB_VIEW] =
877 g_signal_new ("configure-web-view", G_TYPE_FROM_CLASS (klass),
878 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT);
881 * GstWpeVideoSrc::load-bytes:
882 * @src: the object which received the signal
883 * @bytes: the GBytes data to load
885 * Load the specified bytes into the internal webView.
887 gst_wpe_video_src_signals[SIGNAL_LOAD_BYTES] =
888 g_signal_new_class_handler ("load-bytes", G_TYPE_FROM_CLASS (klass),
889 static_cast < GSignalFlags > (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
890 G_CALLBACK (gst_wpe_video_src_load_bytes), NULL, NULL, NULL,
891 G_TYPE_NONE, 1, G_TYPE_BYTES);
894 * GstWpeSrc::run-javascript:
895 * @src: the object which received the signal
896 * @script: the script to run
898 * Asynchronously run script in the context of the current page on the
903 gst_wpe_video_src_signals[SIGNAL_RUN_JAVASCRIPT] =
904 g_signal_new_class_handler ("run-javascript", G_TYPE_FROM_CLASS (klass),
905 static_cast < GSignalFlags > (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
906 G_CALLBACK (gst_wpe_video_src_run_javascript), NULL, NULL, NULL,
907 G_TYPE_NONE, 1, G_TYPE_STRING);