2012-08-08 14:10:28 +00:00
|
|
|
/* GStreamer Wayland video sink
|
2011-11-02 09:02:11 +00:00
|
|
|
*
|
2012-03-07 23:48:56 +00:00
|
|
|
* Copyright (C) 2011 Intel Corporation
|
|
|
|
* Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
|
2012-05-23 10:07:14 +00:00
|
|
|
* Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
|
2014-03-07 14:16:30 +00:00
|
|
|
* Copyright (C) 2014 Collabora Ltd.
|
2012-05-23 10:07:14 +00:00
|
|
|
*
|
2011-11-02 09:02:11 +00:00
|
|
|
* 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
|
2012-08-18 19:31:17 +00:00
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA.
|
2011-11-02 09:02:11 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-07 23:48:56 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-waylandsink
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: waylandsink
|
2012-03-07 23:48:56 +00:00
|
|
|
*
|
|
|
|
* The waylandsink is creating its own window and render the decoded video frames to that.
|
|
|
|
* Setup the Wayland environment as described in
|
2019-08-23 17:56:35 +00:00
|
|
|
* [Wayland](http://wayland.freedesktop.org/building.html) home page.
|
|
|
|
*
|
|
|
|
* The current implementation is based on weston compositor.
|
2012-03-07 23:48:56 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Example pipelines
|
2012-03-07 23:48:56 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc ! waylandsink
|
2012-03-07 23:48:56 +00:00
|
|
|
* ]| test the video rendering in wayland
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2012-03-07 23:48:56 +00:00
|
|
|
*/
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstwaylandsink.h"
|
|
|
|
|
2023-07-28 19:56:32 +00:00
|
|
|
#include <drm_fourcc.h>
|
|
|
|
#include <gst/allocators/allocators.h>
|
2014-02-14 15:08:56 +00:00
|
|
|
#include <gst/video/videooverlay.h>
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
/* signals */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2017-02-23 10:48:13 +00:00
|
|
|
PROP_DISPLAY,
|
2022-06-02 14:38:55 +00:00
|
|
|
PROP_FULLSCREEN,
|
2022-06-02 12:22:21 +00:00
|
|
|
PROP_ROTATE_METHOD,
|
2023-02-16 21:21:33 +00:00
|
|
|
PROP_DRM_DEVICE,
|
2022-06-02 14:38:55 +00:00
|
|
|
PROP_LAST
|
2011-11-02 09:02:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gstwayland_debug);
|
|
|
|
#define GST_CAT_DEFAULT gstwayland_debug
|
|
|
|
|
2016-09-22 09:10:47 +00:00
|
|
|
#define WL_VIDEO_FORMATS \
|
|
|
|
"{ BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, " \
|
2019-11-09 10:37:10 +00:00
|
|
|
"RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, NV61, " \
|
2016-09-22 09:10:47 +00:00
|
|
|
"YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2016-09-22 09:10:47 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (WL_VIDEO_FORMATS) ";"
|
2023-07-25 03:37:02 +00:00
|
|
|
GST_VIDEO_DMA_DRM_CAPS_MAKE)
|
2013-06-18 11:47:54 +00:00
|
|
|
);
|
2012-03-07 23:48:56 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static void gst_wayland_sink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_wayland_sink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_wayland_sink_finalize (GObject * object);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2014-05-21 15:27:28 +00:00
|
|
|
static void gst_wayland_sink_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
static gboolean gst_wayland_sink_event (GstBaseSink * bsink, GstEvent * event);
|
2012-05-23 10:07:14 +00:00
|
|
|
static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
|
|
|
|
GstCaps * filter);
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
|
2012-08-08 14:10:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
|
2022-06-30 09:48:45 +00:00
|
|
|
static GstFlowReturn gst_wayland_sink_show_frame (GstVideoSink * vsink,
|
2011-11-02 09:02:11 +00:00
|
|
|
GstBuffer * buffer);
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
/* VideoOverlay interface */
|
|
|
|
static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
|
|
|
|
iface);
|
|
|
|
static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
|
|
|
|
guintptr handle);
|
2014-05-23 15:18:32 +00:00
|
|
|
static void gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
|
|
|
|
gint x, gint y, gint w, gint h);
|
2014-02-14 15:08:56 +00:00
|
|
|
static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
|
|
|
|
|
|
|
|
#define gst_wayland_sink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
|
2022-01-04 14:20:41 +00:00
|
|
|
gst_wayland_sink_videooverlay_init));
|
2021-02-24 17:56:55 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (waylandsink, "waylandsink", GST_RANK_MARGINAL,
|
|
|
|
GST_TYPE_WAYLAND_SINK);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
static void
|
2011-11-02 11:51:13 +00:00
|
|
|
gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-05-23 10:07:14 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2011-11-02 09:02:11 +00:00
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
2016-09-16 19:41:11 +00:00
|
|
|
GstVideoSinkClass *gstvideosink_class;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-23 10:07:14 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2011-11-02 09:02:11 +00:00
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
2016-09-16 19:41:11 +00:00
|
|
|
gstvideosink_class = (GstVideoSinkClass *) klass;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_wayland_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_wayland_sink_get_property;
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
|
2012-05-23 10:07:14 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-05-23 10:07:14 +00:00
|
|
|
"wayland video sink", "Sink/Video",
|
|
|
|
"Output to wayland surface",
|
2014-03-12 17:25:06 +00:00
|
|
|
"Sreerenj Balachandran <sreerenj.balachandran@intel.com>, "
|
|
|
|
"George Kiagiadakis <george.kiagiadakis@collabora.com>");
|
2012-05-23 10:07:14 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
|
2014-05-21 15:27:28 +00:00
|
|
|
gstelement_class->set_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_set_context);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-02 12:22:21 +00:00
|
|
|
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_wayland_sink_event);
|
2011-11-02 09:02:11 +00:00
|
|
|
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
|
|
|
|
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
|
2012-08-08 14:10:28 +00:00
|
|
|
gstbasesink_class->propose_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
|
2016-09-16 19:41:11 +00:00
|
|
|
|
|
|
|
gstvideosink_class->show_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_show_frame);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-26 12:56:21 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
|
|
|
g_param_spec_string ("display", "Wayland Display name", "Wayland "
|
2014-05-21 15:27:28 +00:00
|
|
|
"display name to connect to, if not supplied via the GstContext",
|
2014-02-26 12:56:21 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2017-02-23 10:48:13 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FULLSCREEN,
|
|
|
|
g_param_spec_boolean ("fullscreen", "Fullscreen",
|
|
|
|
"Whether the surface should be made fullscreen ", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2022-06-02 14:38:55 +00:00
|
|
|
|
2022-06-02 12:22:21 +00:00
|
|
|
/**
|
|
|
|
* waylandsink:rotate-method:
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ROTATE_METHOD,
|
|
|
|
g_param_spec_enum ("rotate-method",
|
|
|
|
"rotate method",
|
|
|
|
"rotate method",
|
|
|
|
GST_TYPE_VIDEO_ORIENTATION_METHOD, GST_VIDEO_ORIENTATION_IDENTITY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2023-02-16 21:21:33 +00:00
|
|
|
/**
|
|
|
|
* waylandsink:drm-device:
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DRM_DEVICE,
|
|
|
|
g_param_spec_string ("drm-device", "DRM Device", "Path of the "
|
|
|
|
"DRM device to use for dumb buffer allocation",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
|
2022-06-02 14:38:55 +00:00
|
|
|
/**
|
|
|
|
* waylandsink:render-rectangle:
|
|
|
|
*
|
|
|
|
* This helper installs the "render-rectangle" property into the
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
gst_video_overlay_install_properties (gobject_class, PROP_LAST);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_init (GstWaylandSink * self)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_init (&self->display_lock);
|
|
|
|
g_mutex_init (&self->render_lock);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 10:48:13 +00:00
|
|
|
static void
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_fullscreen (GstWaylandSink * self, gboolean fullscreen)
|
2017-02-23 10:48:13 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
if (fullscreen == self->fullscreen)
|
2017-02-23 10:48:13 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
self->fullscreen = fullscreen;
|
|
|
|
gst_wl_window_ensure_fullscreen (self->window, fullscreen);
|
|
|
|
g_mutex_unlock (&self->render_lock);
|
2017-02-23 10:48:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 12:22:21 +00:00
|
|
|
static void
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_rotate_method (GstWaylandSink * self,
|
2022-06-02 12:22:21 +00:00
|
|
|
GstVideoOrientationMethod method, gboolean from_tag)
|
|
|
|
{
|
|
|
|
GstVideoOrientationMethod new_method;
|
|
|
|
|
|
|
|
if (method == GST_VIDEO_ORIENTATION_CUSTOM) {
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_WARNING_OBJECT (self, "unsupported custom orientation");
|
2022-06-02 12:22:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
2022-06-02 12:22:21 +00:00
|
|
|
if (from_tag)
|
2022-06-30 09:48:45 +00:00
|
|
|
self->tag_rotate_method = method;
|
2022-06-02 12:22:21 +00:00
|
|
|
else
|
2022-06-30 09:48:45 +00:00
|
|
|
self->sink_rotate_method = method;
|
2022-06-02 12:22:21 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->sink_rotate_method == GST_VIDEO_ORIENTATION_AUTO)
|
|
|
|
new_method = self->tag_rotate_method;
|
2022-06-02 12:22:21 +00:00
|
|
|
else
|
2022-06-30 09:48:45 +00:00
|
|
|
new_method = self->sink_rotate_method;
|
2022-06-02 12:22:21 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (new_method != self->current_rotate_method) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Changing method from %d to %d",
|
|
|
|
self->current_rotate_method, new_method);
|
2022-06-02 12:22:21 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->window) {
|
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
gst_wl_window_set_rotate_method (self->window, new_method);
|
|
|
|
g_mutex_unlock (&self->render_lock);
|
2022-06-02 12:22:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
self->current_rotate_method = new_method;
|
2022-06-02 12:22:21 +00:00
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_UNLOCK (self);
|
2022-06-02 12:22:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2014-02-26 12:56:21 +00:00
|
|
|
case PROP_DISPLAY:
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_value_set_string (value, self->display_name);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2011-11-02 09:02:11 +00:00
|
|
|
break;
|
2017-02-23 10:48:13 +00:00
|
|
|
case PROP_FULLSCREEN:
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_value_set_boolean (value, self->fullscreen);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2017-02-23 10:48:13 +00:00
|
|
|
break;
|
2022-06-02 12:22:21 +00:00
|
|
|
case PROP_ROTATE_METHOD:
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_value_set_enum (value, self->current_rotate_method);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2022-06-02 12:22:21 +00:00
|
|
|
break;
|
2023-02-16 21:21:33 +00:00
|
|
|
case PROP_DRM_DEVICE:
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_value_set_string (value, self->drm_device);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
break;
|
2011-11-02 09:02:11 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2014-02-26 12:56:21 +00:00
|
|
|
case PROP_DISPLAY:
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
self->display_name = g_value_dup_string (value);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2011-11-02 09:02:11 +00:00
|
|
|
break;
|
2017-02-23 10:48:13 +00:00
|
|
|
case PROP_FULLSCREEN:
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
gst_wayland_sink_set_fullscreen (self, g_value_get_boolean (value));
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2017-02-23 10:48:13 +00:00
|
|
|
break;
|
2022-06-02 12:22:21 +00:00
|
|
|
case PROP_ROTATE_METHOD:
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_rotate_method (self, g_value_get_enum (value),
|
2022-06-02 12:22:21 +00:00
|
|
|
FALSE);
|
|
|
|
break;
|
2023-02-16 21:21:33 +00:00
|
|
|
case PROP_DRM_DEVICE:
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
self->drm_device = g_value_dup_string (value);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
break;
|
2011-11-02 09:02:11 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_finalize (GObject * object)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Finalizing the sink..");
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->last_buffer)
|
|
|
|
gst_buffer_unref (self->last_buffer);
|
|
|
|
if (self->display)
|
|
|
|
g_object_unref (self->display);
|
|
|
|
if (self->window)
|
|
|
|
g_object_unref (self->window);
|
|
|
|
if (self->pool)
|
|
|
|
gst_object_unref (self->pool);
|
2014-02-26 14:20:41 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
gst_clear_caps (&self->caps);
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_free (self->display_name);
|
2023-02-16 21:21:33 +00:00
|
|
|
g_free (self->drm_device);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_clear (&self->display_lock);
|
|
|
|
g_mutex_clear (&self->render_lock);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-06-06 10:04:44 +00:00
|
|
|
/* must be called with the display_lock */
|
|
|
|
static void
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_display_from_context (GstWaylandSink * self,
|
2014-06-06 10:04:44 +00:00
|
|
|
GstContext * context)
|
|
|
|
{
|
|
|
|
struct wl_display *display;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2022-01-04 14:20:41 +00:00
|
|
|
display = gst_wl_display_handle_context_get_handle (context);
|
2022-06-30 09:48:45 +00:00
|
|
|
self->display = gst_wl_display_new_existing (display, FALSE, &error);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
|
|
|
if (error) {
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_WARNING (self, RESOURCE, OPEN_READ_WRITE,
|
2014-06-06 10:04:44 +00:00
|
|
|
("Could not set display handle"),
|
|
|
|
("Failed to use the external wayland display: '%s'", error->message));
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 15:27:28 +00:00
|
|
|
static gboolean
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_find_display (GstWaylandSink * self)
|
2014-02-28 09:48:30 +00:00
|
|
|
{
|
2014-05-21 15:27:28 +00:00
|
|
|
GstQuery *query;
|
|
|
|
GstMessage *msg;
|
|
|
|
GstContext *context = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->display_lock);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (!self->display) {
|
2014-05-21 15:27:28 +00:00
|
|
|
/* first query upstream for the needed display handle */
|
2022-01-04 14:20:41 +00:00
|
|
|
query = gst_query_new_context (GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE);
|
2022-06-30 09:48:45 +00:00
|
|
|
if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (self), query)) {
|
2014-05-21 15:27:28 +00:00
|
|
|
gst_query_parse_context (query, &context);
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_display_from_context (self, context);
|
2014-05-21 15:27:28 +00:00
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_LIKELY (!self->display)) {
|
2014-05-21 15:27:28 +00:00
|
|
|
/* now ask the application to set the display handle */
|
2022-06-30 09:48:45 +00:00
|
|
|
msg = gst_message_new_need_context (GST_OBJECT_CAST (self),
|
2022-01-04 14:20:41 +00:00
|
|
|
GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (self), msg);
|
2014-05-21 15:27:28 +00:00
|
|
|
/* at this point we expect gst_wayland_sink_set_context
|
2022-06-30 09:48:45 +00:00
|
|
|
* to get called and fill self->display */
|
|
|
|
g_mutex_lock (&self->display_lock);
|
2014-03-12 12:28:44 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (!self->display) {
|
2014-05-21 15:27:28 +00:00
|
|
|
/* if the application didn't set a display, let's create it ourselves */
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
self->display = gst_wl_display_new (self->display_name, &error);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2014-06-06 10:10:24 +00:00
|
|
|
|
2014-05-21 15:27:28 +00:00
|
|
|
if (error) {
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_WARNING (self, RESOURCE, OPEN_READ_WRITE,
|
2014-03-12 12:28:44 +00:00
|
|
|
("Could not initialise Wayland output"),
|
|
|
|
("Failed to create GstWlDisplay: '%s'", error->message));
|
|
|
|
g_error_free (error);
|
2014-05-21 15:27:28 +00:00
|
|
|
ret = FALSE;
|
2014-03-12 12:28:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-21 15:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
2014-05-21 15:27:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (element);
|
2014-05-21 15:27:28 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2022-06-30 09:48:45 +00:00
|
|
|
if (!gst_wayland_sink_find_display (self))
|
2014-05-21 15:27:28 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2014-02-28 09:48:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_buffer_replace (&self->last_buffer, NULL);
|
|
|
|
if (self->window) {
|
|
|
|
if (gst_wl_window_is_toplevel (self->window)) {
|
|
|
|
g_clear_object (&self->window);
|
2014-06-16 16:03:51 +00:00
|
|
|
} else {
|
|
|
|
/* remove buffer from surface, show nothing */
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wl_window_render (self->window, NULL, NULL);
|
2014-06-16 16:03:51 +00:00
|
|
|
}
|
2014-03-12 12:28:44 +00:00
|
|
|
}
|
2020-12-15 10:11:08 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
if (self->callback) {
|
|
|
|
wl_callback_destroy (self->callback);
|
|
|
|
self->callback = NULL;
|
2020-12-15 10:11:08 +00:00
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
self->redraw_pending = FALSE;
|
|
|
|
g_mutex_unlock (&self->render_lock);
|
2014-03-12 12:28:44 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->display_lock);
|
2014-06-16 16:03:51 +00:00
|
|
|
/* If we had a toplevel window, we most likely have our own connection
|
|
|
|
* to the display too, and it is a good idea to disconnect and allow
|
|
|
|
* potentially the application to embed us with GstVideoOverlay
|
|
|
|
* (which requires to re-use the same display connection as the parent
|
|
|
|
* surface). If we didn't have a toplevel window, then the display
|
|
|
|
* connection that we have is definitely shared with the application
|
|
|
|
* and it's better to keep it around (together with the window handle)
|
|
|
|
* to avoid requesting them again from the application if/when we are
|
|
|
|
* restarted (GstVideoOverlay behaves like that in other sinks)
|
|
|
|
*/
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->display && !self->window) /* -> the window was toplevel */
|
|
|
|
g_clear_object (&self->display);
|
2020-12-15 10:11:08 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
|
|
|
g_clear_object (&self->pool);
|
2014-02-28 09:48:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-21 15:27:28 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (element);
|
2014-05-21 15:27:28 +00:00
|
|
|
|
|
|
|
if (gst_context_has_context_type (context,
|
2022-01-04 14:20:41 +00:00
|
|
|
GST_WL_DISPLAY_HANDLE_CONTEXT_TYPE)) {
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->display_lock);
|
|
|
|
if (G_LIKELY (!self->display)) {
|
|
|
|
gst_wayland_sink_set_display_from_context (self, context);
|
2015-04-09 04:17:01 +00:00
|
|
|
} else {
|
2014-06-06 10:04:44 +00:00
|
|
|
GST_WARNING_OBJECT (element, "changing display handle is not supported");
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
2015-04-09 04:17:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
2014-05-21 15:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->set_context)
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
|
|
|
|
}
|
|
|
|
|
2022-06-02 12:22:21 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_event (GstBaseSink * bsink, GstEvent * event)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (bsink);
|
2022-06-02 12:22:21 +00:00
|
|
|
GstTagList *taglist;
|
|
|
|
GstVideoOrientationMethod method;
|
|
|
|
gboolean ret;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "handling %s event", GST_EVENT_TYPE_NAME (event));
|
2022-06-02 12:22:21 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
gst_event_parse_tag (event, &taglist);
|
|
|
|
|
|
|
|
if (gst_video_orientation_from_tag (taglist, &method)) {
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wayland_sink_set_rotate_method (self, method, TRUE);
|
2022-06-02 12:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_BASE_SINK_CLASS (parent_class)->event (bsink, event);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstCaps *
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (bsink);;
|
2012-08-08 14:10:28 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (self));
|
2016-09-22 09:10:47 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->display_lock);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->display) {
|
2016-09-22 09:10:47 +00:00
|
|
|
GValue shm_list = G_VALUE_INIT, dmabuf_list = G_VALUE_INIT;
|
2014-03-12 12:13:49 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2023-07-25 03:37:02 +00:00
|
|
|
GArray *formats, *modifiers;
|
2014-03-12 12:13:49 +00:00
|
|
|
gint i;
|
2016-09-22 09:10:47 +00:00
|
|
|
guint fmt;
|
2019-09-08 19:25:44 +00:00
|
|
|
GstVideoFormat gfmt;
|
2023-07-25 03:37:02 +00:00
|
|
|
guint64 mod;
|
2014-03-12 12:13:49 +00:00
|
|
|
|
2016-09-22 09:10:47 +00:00
|
|
|
g_value_init (&shm_list, GST_TYPE_LIST);
|
|
|
|
g_value_init (&dmabuf_list, GST_TYPE_LIST);
|
2014-03-12 12:13:49 +00:00
|
|
|
|
2016-09-22 09:10:47 +00:00
|
|
|
/* Add corresponding shm formats */
|
2022-06-30 09:48:45 +00:00
|
|
|
formats = gst_wl_display_get_shm_formats (self->display);
|
2014-03-12 12:13:49 +00:00
|
|
|
for (i = 0; i < formats->len; i++) {
|
|
|
|
fmt = g_array_index (formats, uint32_t, i);
|
2019-09-08 19:25:44 +00:00
|
|
|
gfmt = gst_wl_shm_format_to_video_format (fmt);
|
|
|
|
if (gfmt != GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
g_value_set_static_string (&value, gst_video_format_to_string (gfmt));
|
|
|
|
gst_value_list_append_and_take_value (&shm_list, &value);
|
|
|
|
}
|
2014-03-12 12:13:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 19:49:21 +00:00
|
|
|
gst_structure_take_value (gst_caps_get_structure (caps, 0), "format",
|
2016-09-22 09:10:47 +00:00
|
|
|
&shm_list);
|
|
|
|
|
|
|
|
/* Add corresponding dmabuf formats */
|
2022-06-30 09:48:45 +00:00
|
|
|
formats = gst_wl_display_get_dmabuf_formats (self->display);
|
2023-07-25 03:37:02 +00:00
|
|
|
modifiers = gst_wl_display_get_dmabuf_modifiers (self->display);
|
2016-09-22 09:10:47 +00:00
|
|
|
for (i = 0; i < formats->len; i++) {
|
|
|
|
fmt = g_array_index (formats, uint32_t, i);
|
2019-09-08 19:25:44 +00:00
|
|
|
gfmt = gst_wl_dmabuf_format_to_video_format (fmt);
|
2023-07-25 03:37:02 +00:00
|
|
|
mod = g_array_index (modifiers, guint64, i);
|
2019-09-08 19:25:44 +00:00
|
|
|
if (gfmt != GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
2023-07-25 03:37:02 +00:00
|
|
|
g_value_take_string (&value, gst_wl_dmabuf_format_to_string (fmt, mod));
|
2019-09-08 19:25:44 +00:00
|
|
|
gst_value_list_append_and_take_value (&dmabuf_list, &value);
|
|
|
|
}
|
2016-09-22 09:10:47 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 03:37:02 +00:00
|
|
|
gst_structure_take_value (gst_caps_get_structure (caps, 1), "drm-format",
|
2016-09-22 09:10:47 +00:00
|
|
|
&dmabuf_list);
|
2014-03-12 12:13:49 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "display caps: %" GST_PTR_FORMAT, caps);
|
2014-03-12 12:13:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->display_lock);
|
2014-06-06 10:04:44 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection =
|
|
|
|
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
2014-03-12 12:13:49 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
return caps;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_update_pool (GstWaylandSink * self, GstAllocator * allocator)
|
2016-09-19 16:04:52 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
gsize size = self->video_info.size;
|
2023-02-16 18:54:42 +00:00
|
|
|
GstStructure *config;
|
2016-09-19 16:04:52 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
/* Pools with outstanding buffer cannot be reconfigured, so we must use
|
|
|
|
* a new pool. */
|
|
|
|
if (self->pool) {
|
|
|
|
gst_buffer_pool_set_active (self->pool, FALSE);
|
|
|
|
gst_object_unref (self->pool);
|
|
|
|
}
|
|
|
|
self->pool = gst_wl_video_buffer_pool_new ();
|
2016-09-19 16:04:52 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
config = gst_buffer_pool_get_config (self->pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, self->caps, size, 2, 0);
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, NULL);
|
2016-09-19 16:04:52 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
if (!gst_buffer_pool_set_config (self->pool, config))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gst_buffer_pool_set_active (self->pool, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wayland_activate_shm_pool (GstWaylandSink * self)
|
|
|
|
{
|
|
|
|
GstAllocator *alloc = NULL;
|
|
|
|
|
|
|
|
if (self->pool && gst_buffer_pool_is_active (self->pool)) {
|
|
|
|
GstStructure *config = gst_buffer_pool_get_config (self->pool);
|
|
|
|
gboolean is_shm = FALSE;
|
|
|
|
|
|
|
|
if (gst_buffer_pool_config_get_allocator (config, &alloc, NULL) && alloc)
|
|
|
|
is_shm = GST_IS_WL_SHM_ALLOCATOR (alloc);
|
|
|
|
|
|
|
|
gst_structure_free (config);
|
|
|
|
|
|
|
|
if (is_shm)
|
|
|
|
return TRUE;
|
2016-09-19 16:04:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
alloc = gst_wl_shm_allocator_get ();
|
|
|
|
gst_wayland_update_pool (self, alloc);
|
|
|
|
gst_object_unref (alloc);
|
|
|
|
|
|
|
|
return TRUE;
|
2016-09-19 16:04:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 21:21:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_activate_drm_dumb_pool (GstWaylandSink * self)
|
|
|
|
{
|
|
|
|
GstAllocator *alloc;
|
|
|
|
|
|
|
|
if (!self->drm_device)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (self->pool && gst_buffer_pool_is_active (self->pool)) {
|
|
|
|
GstStructure *config = gst_buffer_pool_get_config (self->pool);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
gboolean is_drm_dumb = FALSE;
|
|
|
|
|
|
|
|
ret = gst_buffer_pool_config_get_allocator (config, &alloc, NULL);
|
|
|
|
gst_structure_free (config);
|
|
|
|
|
|
|
|
if (ret && alloc)
|
|
|
|
is_drm_dumb = GST_IS_DRM_DUMB_ALLOCATOR (alloc);
|
|
|
|
|
|
|
|
if (is_drm_dumb)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
alloc = gst_drm_dumb_allocator_new_with_device_path (self->drm_device);
|
|
|
|
if (!alloc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_wayland_update_pool (self, alloc);
|
|
|
|
gst_object_unref (alloc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (bsink);;
|
2016-09-22 09:10:47 +00:00
|
|
|
gboolean use_dmabuf;
|
2012-08-08 14:10:28 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "set caps %" GST_PTR_FORMAT, caps);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2023-07-25 03:37:02 +00:00
|
|
|
if (gst_video_is_dma_drm_caps (caps)) {
|
2023-07-28 19:56:32 +00:00
|
|
|
if (!gst_video_info_dma_drm_from_caps (&self->drm_info, caps))
|
2023-07-25 03:37:02 +00:00
|
|
|
goto invalid_format;
|
|
|
|
|
2023-07-28 19:56:32 +00:00
|
|
|
if (!gst_video_info_dma_drm_to_video_info (&self->drm_info,
|
|
|
|
&self->video_info))
|
2023-07-25 03:37:02 +00:00
|
|
|
goto invalid_format;
|
|
|
|
} else {
|
|
|
|
/* extract info from caps */
|
|
|
|
if (!gst_video_info_from_caps (&self->video_info, caps))
|
|
|
|
goto invalid_format;
|
2023-07-28 19:56:32 +00:00
|
|
|
|
|
|
|
if (!gst_video_info_dma_drm_from_video_info (&self->drm_info,
|
|
|
|
&self->video_info, DRM_FORMAT_MOD_LINEAR))
|
|
|
|
gst_video_info_dma_drm_init (&self->drm_info);
|
2023-07-25 03:37:02 +00:00
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
self->video_info_changed = TRUE;
|
2023-02-16 21:21:33 +00:00
|
|
|
self->skip_dumb_buffer_copy = FALSE;
|
2013-06-18 11:47:54 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
/* free pooled buffer used with previous caps */
|
|
|
|
if (self->pool) {
|
|
|
|
gst_buffer_pool_set_active (self->pool, FALSE);
|
|
|
|
gst_clear_object (&self->pool);
|
|
|
|
}
|
2016-09-29 20:30:33 +00:00
|
|
|
|
2016-09-22 09:10:47 +00:00
|
|
|
use_dmabuf = gst_caps_features_contains (gst_caps_get_features (caps, 0),
|
|
|
|
GST_CAPS_FEATURE_MEMORY_DMABUF);
|
2013-06-18 11:47:54 +00:00
|
|
|
|
2016-09-29 20:30:33 +00:00
|
|
|
/* validate the format base on the memory type. */
|
|
|
|
if (use_dmabuf) {
|
2023-07-28 19:56:32 +00:00
|
|
|
if (!gst_wl_display_check_format_for_dmabuf (self->display,
|
|
|
|
&self->drm_info))
|
|
|
|
goto unsupported_drm_format;
|
|
|
|
} else if (!gst_wl_display_check_format_for_shm (self->display,
|
|
|
|
&self->video_info)) {
|
2022-11-28 14:00:27 +00:00
|
|
|
/* Note: we still support dmabuf in this case, but formats must also be
|
|
|
|
* supported on SHM interface to ensure a fallback is possible as we are
|
|
|
|
* not guarantied we'll get dmabuf in the buffers. */
|
2016-09-29 20:30:33 +00:00
|
|
|
goto unsupported_format;
|
2016-09-22 09:10:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
/* Will be used to create buffer pools */
|
|
|
|
gst_caps_replace (&self->caps, caps);
|
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
return TRUE;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
invalid_format:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ERROR_OBJECT (self,
|
2012-08-08 14:10:28 +00:00
|
|
|
"Could not locate image format from caps %" GST_PTR_FORMAT, caps);
|
2014-06-06 08:35:20 +00:00
|
|
|
return FALSE;
|
2014-02-28 09:48:30 +00:00
|
|
|
}
|
2023-07-28 19:56:32 +00:00
|
|
|
unsupported_drm_format:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (self, "DRM format %" GST_FOURCC_FORMAT
|
|
|
|
" is not available on the display",
|
|
|
|
GST_FOURCC_ARGS (self->drm_info.drm_fourcc));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-26 16:35:29 +00:00
|
|
|
unsupported_format:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Format %s is not available on the display",
|
2023-07-28 19:56:32 +00:00
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&self->video_info)));
|
2014-06-06 08:35:20 +00:00
|
|
|
return FALSE;
|
2014-02-28 09:48:30 +00:00
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-08-08 14:10:28 +00:00
|
|
|
gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (bsink);
|
2016-09-19 16:08:20 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
gboolean need_pool;
|
2017-11-01 09:05:26 +00:00
|
|
|
GstAllocator *alloc;
|
2012-08-08 14:10:28 +00:00
|
|
|
|
2016-09-19 16:08:20 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
2012-08-08 14:10:28 +00:00
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
if (need_pool) {
|
|
|
|
GstStructure *config;
|
|
|
|
pool = gst_wl_video_buffer_pool_new ();
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2023-07-27 07:53:55 +00:00
|
|
|
gst_buffer_pool_config_set_params (config,
|
|
|
|
caps, self->video_info.size, 2, 0);
|
2023-02-16 18:54:42 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config,
|
|
|
|
gst_wl_shm_allocator_get (), NULL);
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
}
|
2016-09-19 16:08:20 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_query_add_allocation_pool (query, pool, self->video_info.size, 2, 0);
|
2017-09-05 20:20:44 +00:00
|
|
|
if (pool)
|
2016-09-19 16:08:20 +00:00
|
|
|
g_object_unref (pool);
|
|
|
|
|
2017-11-01 09:05:26 +00:00
|
|
|
alloc = gst_wl_shm_allocator_get ();
|
2017-12-07 01:50:31 +00:00
|
|
|
gst_query_add_allocation_param (query, alloc, NULL);
|
2016-09-19 16:08:20 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
2017-11-01 09:05:26 +00:00
|
|
|
g_object_unref (alloc);
|
2015-01-23 11:44:22 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = data;
|
2014-03-07 15:25:00 +00:00
|
|
|
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self, "frame_redraw_cb");
|
2014-03-07 15:25:00 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
self->redraw_pending = FALSE;
|
2016-09-22 22:53:22 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->callback) {
|
2020-12-15 10:11:08 +00:00
|
|
|
wl_callback_destroy (callback);
|
2022-06-30 09:48:45 +00:00
|
|
|
self->callback = NULL;
|
2020-12-15 10:11:08 +00:00
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_callback_listener = {
|
|
|
|
frame_redraw_callback
|
|
|
|
};
|
|
|
|
|
2014-05-28 10:10:43 +00:00
|
|
|
/* must be called with the render lock */
|
2014-03-11 15:45:05 +00:00
|
|
|
static void
|
2022-06-30 09:48:45 +00:00
|
|
|
render_last_buffer (GstWaylandSink * self, gboolean redraw)
|
2014-03-11 15:45:05 +00:00
|
|
|
{
|
2014-06-20 11:47:57 +00:00
|
|
|
GstWlBuffer *wlbuffer;
|
2014-07-01 08:43:20 +00:00
|
|
|
const GstVideoInfo *info = NULL;
|
2014-03-11 15:45:05 +00:00
|
|
|
struct wl_surface *surface;
|
|
|
|
struct wl_callback *callback;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
wlbuffer = gst_buffer_get_wl_buffer (self->display, self->last_buffer);
|
|
|
|
surface = gst_wl_window_get_wl_surface (self->window);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
self->redraw_pending = TRUE;
|
2014-03-11 15:45:05 +00:00
|
|
|
callback = wl_surface_frame (surface);
|
2022-06-30 09:48:45 +00:00
|
|
|
self->callback = callback;
|
|
|
|
wl_callback_add_listener (callback, &frame_callback_listener, self);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_UNLIKELY (self->video_info_changed && !redraw)) {
|
|
|
|
info = &self->video_info;
|
|
|
|
self->video_info_changed = FALSE;
|
2014-07-01 08:43:20 +00:00
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wl_window_render (self->window, wlbuffer, info);
|
2014-03-11 15:45:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
static void
|
|
|
|
on_window_closed (GstWlWindow * window, gpointer user_data)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (user_data);
|
2019-03-01 08:56:24 +00:00
|
|
|
|
|
|
|
/* Handle window closure by posting an error on the bus */
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
|
2019-03-01 08:56:24 +00:00
|
|
|
("Output window was closed"), (NULL));
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstFlowReturn
|
2016-09-16 19:41:11 +00:00
|
|
|
gst_wayland_sink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (vsink);
|
2012-05-23 10:07:14 +00:00
|
|
|
GstBuffer *to_render;
|
2014-06-20 11:47:57 +00:00
|
|
|
GstWlBuffer *wlbuffer;
|
2016-09-29 20:30:33 +00:00
|
|
|
GstMemory *mem;
|
|
|
|
struct wl_buffer *wbuf = NULL;
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self, "render buffer %" GST_PTR_FORMAT "", buffer);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_UNLIKELY (!self->window)) {
|
2014-06-13 13:58:08 +00:00
|
|
|
/* ask for window handle. Unlock render_lock while doing that because
|
|
|
|
* set_window_handle & friends will lock it in this context */
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
|
|
|
gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (self));
|
|
|
|
g_mutex_lock (&self->render_lock);
|
2014-06-13 13:58:08 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (!self->window) {
|
2014-06-13 13:58:08 +00:00
|
|
|
/* if we were not provided a window, create one ourselves */
|
2022-06-30 09:48:45 +00:00
|
|
|
self->window = gst_wl_window_new_toplevel (self->display,
|
|
|
|
&self->video_info, self->fullscreen, &self->render_lock);
|
|
|
|
g_signal_connect_object (self->window, "closed",
|
|
|
|
G_CALLBACK (on_window_closed), self, 0);
|
|
|
|
gst_wl_window_set_rotate_method (self->window,
|
|
|
|
self->current_rotate_method);
|
2014-06-13 13:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 15:25:00 +00:00
|
|
|
/* drop buffers until we get a frame callback */
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->redraw_pending) {
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self, "buffer %" GST_PTR_FORMAT " dropped (redraw pending)",
|
|
|
|
buffer);
|
2023-02-15 18:11:36 +00:00
|
|
|
ret = GST_BASE_SINK_FLOW_DROPPED;
|
2014-03-07 15:25:00 +00:00
|
|
|
goto done;
|
2016-12-08 09:22:23 +00:00
|
|
|
}
|
2014-03-07 15:25:00 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
/* make sure that the application has called set_render_rectangle() */
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_UNLIKELY (gst_wl_window_get_render_rectangle (self->window)->w == 0))
|
2014-06-13 13:58:08 +00:00
|
|
|
goto no_window_size;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
wlbuffer = gst_buffer_get_wl_buffer (self->display, buffer);
|
2012-10-20 11:55:41 +00:00
|
|
|
|
2022-01-04 14:20:41 +00:00
|
|
|
if (G_LIKELY (wlbuffer &&
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wl_buffer_get_display (wlbuffer) == self->display)) {
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self,
|
|
|
|
"buffer %" GST_PTR_FORMAT " has a wl_buffer from our display, "
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
"writing directly", buffer);
|
2012-05-23 10:07:14 +00:00
|
|
|
to_render = buffer;
|
2016-09-29 20:30:33 +00:00
|
|
|
goto render;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update video info from video meta */
|
2017-01-30 10:04:32 +00:00
|
|
|
mem = gst_buffer_peek_memory (buffer, 0);
|
|
|
|
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self,
|
|
|
|
"buffer %" GST_PTR_FORMAT " does not have a wl_buffer from our "
|
2016-09-29 20:30:33 +00:00
|
|
|
"display, creating it", buffer);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2023-07-28 19:56:32 +00:00
|
|
|
if (gst_wl_display_check_format_for_dmabuf (self->display, &self->drm_info)) {
|
2016-09-29 20:30:33 +00:00
|
|
|
guint i, nb_dmabuf = 0;
|
2016-09-22 09:10:47 +00:00
|
|
|
|
2016-09-29 20:30:33 +00:00
|
|
|
for (i = 0; i < gst_buffer_n_memory (buffer); i++)
|
|
|
|
if (gst_is_dmabuf_memory (gst_buffer_peek_memory (buffer, i)))
|
|
|
|
nb_dmabuf++;
|
2016-09-22 09:10:47 +00:00
|
|
|
|
2016-09-29 20:30:33 +00:00
|
|
|
if (nb_dmabuf && (nb_dmabuf == gst_buffer_n_memory (buffer)))
|
2022-06-30 09:48:45 +00:00
|
|
|
wbuf = gst_wl_linux_dmabuf_construct_wl_buffer (buffer, self->display,
|
2023-07-28 19:56:32 +00:00
|
|
|
&self->drm_info);
|
2023-02-16 21:21:33 +00:00
|
|
|
|
|
|
|
/* DMABuf did not work, let try and make this a dmabuf, it does not matter
|
|
|
|
* if it was a SHM since the compositor needs to copy that anyway, and
|
|
|
|
* offloading the compositor from a copy helps maintaining a smoother
|
|
|
|
* desktop.
|
|
|
|
*/
|
|
|
|
if (!self->skip_dumb_buffer_copy) {
|
|
|
|
GstVideoFrame src, dst;
|
|
|
|
|
|
|
|
if (!gst_wayland_activate_drm_dumb_pool (self)) {
|
|
|
|
self->skip_dumb_buffer_copy = TRUE;
|
|
|
|
goto handle_shm;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_buffer_pool_acquire_buffer (self->pool, &to_render, NULL);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto no_buffer;
|
|
|
|
|
|
|
|
wlbuffer = gst_buffer_get_wl_buffer (self->display, to_render);
|
|
|
|
|
|
|
|
/* attach a wl_buffer if there isn't one yet */
|
|
|
|
if (G_UNLIKELY (!wlbuffer)) {
|
|
|
|
wbuf = gst_wl_linux_dmabuf_construct_wl_buffer (to_render,
|
2023-07-28 19:56:32 +00:00
|
|
|
self->display, &self->drm_info);
|
2023-02-16 21:21:33 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!wbuf)) {
|
|
|
|
GST_WARNING_OBJECT (self, "failed to import DRM Dumb dmabuf");
|
|
|
|
gst_clear_buffer (&to_render);
|
|
|
|
self->skip_dumb_buffer_copy = TRUE;
|
|
|
|
goto handle_shm;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlbuffer = gst_buffer_add_wl_buffer (to_render, wbuf, self->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&dst, &self->video_info, to_render,
|
|
|
|
GST_MAP_WRITE))
|
|
|
|
goto dst_map_failed;
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&src, &self->video_info, buffer, GST_MAP_READ)) {
|
|
|
|
gst_video_frame_unmap (&dst);
|
|
|
|
goto src_map_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_frame_copy (&dst, &src);
|
|
|
|
|
|
|
|
gst_video_frame_unmap (&src);
|
|
|
|
gst_video_frame_unmap (&dst);
|
|
|
|
|
|
|
|
goto render;
|
|
|
|
}
|
2016-09-29 20:30:33 +00:00
|
|
|
}
|
2012-08-08 14:10:28 +00:00
|
|
|
|
2023-02-16 21:21:33 +00:00
|
|
|
handle_shm:
|
2023-07-28 19:56:32 +00:00
|
|
|
if (!wbuf && gst_wl_display_check_format_for_shm (self->display,
|
|
|
|
&self->video_info)) {
|
2017-11-22 04:18:24 +00:00
|
|
|
if (gst_buffer_n_memory (buffer) == 1 && gst_is_fd_memory (mem))
|
2022-06-30 09:48:45 +00:00
|
|
|
wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, self->display,
|
|
|
|
&self->video_info);
|
2017-11-22 04:18:24 +00:00
|
|
|
|
|
|
|
/* If nothing worked, copy into our internal pool */
|
|
|
|
if (!wbuf) {
|
2016-09-19 16:11:59 +00:00
|
|
|
GstVideoFrame src, dst;
|
2017-11-23 03:27:04 +00:00
|
|
|
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
/* we don't know how to create a wl_buffer directly from the provided
|
2016-09-22 09:10:47 +00:00
|
|
|
* memory, so we have to copy the data to shm memory that we know how
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
* to handle... */
|
|
|
|
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_LOG_OBJECT (self,
|
|
|
|
"buffer %" GST_PTR_FORMAT " cannot have a wl_buffer, "
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
"copying to wl_shm memory", buffer);
|
|
|
|
|
2023-02-16 18:54:42 +00:00
|
|
|
/* ensure the internal pool is configured for SHM */
|
|
|
|
if (!gst_wayland_activate_shm_pool (self))
|
|
|
|
goto activate_failed;
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
ret = gst_buffer_pool_acquire_buffer (self->pool, &to_render, NULL);
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto no_buffer;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
wlbuffer = gst_buffer_get_wl_buffer (self->display, to_render);
|
2016-09-29 20:30:33 +00:00
|
|
|
|
|
|
|
/* attach a wl_buffer if there isn't one yet */
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
if (G_UNLIKELY (!wlbuffer)) {
|
|
|
|
mem = gst_buffer_peek_memory (to_render, 0);
|
2022-06-30 09:48:45 +00:00
|
|
|
wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, self->display,
|
|
|
|
&self->video_info);
|
2016-09-29 20:30:33 +00:00
|
|
|
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
if (G_UNLIKELY (!wbuf))
|
2016-09-22 09:10:47 +00:00
|
|
|
goto no_wl_buffer_shm;
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
wlbuffer = gst_buffer_add_wl_buffer (to_render, wbuf, self->display);
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
}
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (!gst_video_frame_map (&dst, &self->video_info, to_render,
|
2016-09-19 16:11:59 +00:00
|
|
|
GST_MAP_WRITE))
|
|
|
|
goto dst_map_failed;
|
|
|
|
|
2023-02-17 02:12:08 +00:00
|
|
|
if (!gst_video_frame_map (&src, &self->video_info, buffer, GST_MAP_READ)) {
|
2016-09-19 16:11:59 +00:00
|
|
|
gst_video_frame_unmap (&dst);
|
|
|
|
goto src_map_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_frame_copy (&dst, &src);
|
|
|
|
|
|
|
|
gst_video_frame_unmap (&src);
|
|
|
|
gst_video_frame_unmap (&dst);
|
2016-09-29 20:30:33 +00:00
|
|
|
|
|
|
|
goto render;
|
waylandsink: replace the custom buffer pool with an allocator
This reduces the complexity of having a custom buffer pool, as
we don't really need it. We only need the custom allocation part.
And since the wl_buffer is no longer saved in a GstMeta, we can
create it and add it on the buffers in the sink's render()
function, which removes the reference cycle caused by the pool
holding a reference to the display and also allows more generic
scenarios (the allocator being used in another pool, or buffers
being allocated without a pool [if anything stupid does that]).
This commit also simplifies the propose_allocation() function,
which doesn't really need to do all these complicated checks,
since there is always a correct buffer pool available, created
in set_caps().
The other side effect of this commit is that a new wl_shm_pool
is now created for every GstMemory, which means that we use
as much shm memory as we actually need and no more. Previously,
the created wl_shm_pool would allocate space for 15 buffers, no
matter if they were being used or not.
2014-06-23 13:40:02 +00:00
|
|
|
}
|
2012-05-23 10:07:14 +00:00
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2016-09-29 20:30:33 +00:00
|
|
|
if (!wbuf)
|
|
|
|
goto no_wl_buffer;
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
wlbuffer = gst_buffer_add_wl_buffer (buffer, wbuf, self->display);
|
2016-09-29 20:30:33 +00:00
|
|
|
to_render = buffer;
|
|
|
|
|
|
|
|
render:
|
2014-10-07 08:37:33 +00:00
|
|
|
/* drop double rendering */
|
2021-09-16 21:12:58 +00:00
|
|
|
if (G_UNLIKELY (wlbuffer ==
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_buffer_get_wl_buffer (self->display, self->last_buffer))) {
|
|
|
|
GST_LOG_OBJECT (self, "Buffer already being rendered");
|
2014-10-07 08:37:33 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_buffer_replace (&self->last_buffer, to_render);
|
|
|
|
render_last_buffer (self, FALSE);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (buffer != to_render)
|
|
|
|
gst_buffer_unref (to_render);
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
2012-05-23 10:07:14 +00:00
|
|
|
|
2014-05-21 15:27:28 +00:00
|
|
|
no_window_size:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
|
2014-05-21 15:27:28 +00:00
|
|
|
("Window has no size set"),
|
|
|
|
("Make sure you set the size after calling set_window_handle"));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-08-08 14:10:28 +00:00
|
|
|
no_buffer:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_WARNING_OBJECT (self, "could not create buffer");
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
2016-09-22 09:10:47 +00:00
|
|
|
no_wl_buffer_shm:
|
2012-05-23 10:07:14 +00:00
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ERROR_OBJECT (self, "could not create wl_buffer out of wl_shm memory");
|
2014-02-28 09:48:30 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
2016-09-22 09:10:47 +00:00
|
|
|
no_wl_buffer:
|
|
|
|
{
|
2022-08-01 11:04:47 +00:00
|
|
|
GST_ERROR_OBJECT (self,
|
|
|
|
"buffer %" GST_PTR_FORMAT " cannot have a wl_buffer", buffer);
|
2016-09-22 09:10:47 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-08-08 14:10:28 +00:00
|
|
|
activate_failed:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ERROR_OBJECT (self, "failed to activate bufferpool.");
|
2012-08-08 14:10:28 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2016-09-19 16:11:59 +00:00
|
|
|
src_map_failed:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, READ,
|
2016-09-19 16:11:59 +00:00
|
|
|
("Video memory can not be read from userspace."), (NULL));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
dst_map_failed:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
|
2016-09-19 16:11:59 +00:00
|
|
|
("Video memory can not be written from userspace."), (NULL));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2014-02-28 09:48:30 +00:00
|
|
|
done:
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
2012-08-08 14:10:28 +00:00
|
|
|
return ret;
|
2012-05-23 10:07:14 +00:00
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
|
|
|
|
{
|
|
|
|
iface->set_window_handle = gst_wayland_sink_set_window_handle;
|
2014-05-23 15:18:32 +00:00
|
|
|
iface->set_render_rectangle = gst_wayland_sink_set_render_rectangle;
|
2014-02-14 15:08:56 +00:00
|
|
|
iface->expose = gst_wayland_sink_expose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (overlay);
|
2014-05-21 15:27:28 +00:00
|
|
|
struct wl_surface *surface = (struct wl_surface *) handle;
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_return_if_fail (self != NULL);
|
2014-03-12 12:28:44 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
if (self->window != NULL) {
|
|
|
|
GST_WARNING_OBJECT (self, "changing window handle is not supported");
|
2015-11-03 10:42:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting window handle %" GST_PTR_FORMAT,
|
2014-02-28 09:48:30 +00:00
|
|
|
(void *) handle);
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_clear_object (&self->window);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
if (handle) {
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_LIKELY (gst_wayland_sink_find_display (self))) {
|
2014-05-21 15:27:28 +00:00
|
|
|
/* we cannot use our own display with an external window handle */
|
2022-06-30 09:48:45 +00:00
|
|
|
if (G_UNLIKELY (gst_wl_display_has_own_display (self->display))) {
|
|
|
|
GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ_WRITE,
|
2014-05-21 15:27:28 +00:00
|
|
|
("Application did not provide a wayland display handle"),
|
|
|
|
("waylandsink cannot use an externally-supplied surface without "
|
|
|
|
"an externally-supplied display handle. Consider providing a "
|
|
|
|
"display handle from your application with GstContext"));
|
|
|
|
} else {
|
2022-06-30 09:48:45 +00:00
|
|
|
self->window = gst_wl_window_new_in_surface (self->display, surface,
|
|
|
|
&self->render_lock);
|
|
|
|
gst_wl_window_set_rotate_method (self->window,
|
|
|
|
self->current_rotate_method);
|
2014-05-21 15:27:28 +00:00
|
|
|
}
|
2014-02-28 09:48:30 +00:00
|
|
|
} else {
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to find display handle, "
|
2014-05-21 15:27:28 +00:00
|
|
|
"ignoring window handle");
|
2014-02-28 09:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:18:32 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
|
|
|
|
gint x, gint y, gint w, gint h)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (overlay);
|
2014-05-23 15:18:32 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_return_if_fail (self != NULL);
|
2014-05-23 15:18:32 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
if (!self->window) {
|
|
|
|
g_mutex_unlock (&self->render_lock);
|
|
|
|
GST_WARNING_OBJECT (self,
|
2014-05-23 15:18:32 +00:00
|
|
|
"set_render_rectangle called without window, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "window geometry changed to (%d, %d) %d x %d",
|
2014-05-23 15:18:32 +00:00
|
|
|
x, y, w, h);
|
2022-06-30 09:48:45 +00:00
|
|
|
gst_wl_window_set_render_rectangle (self->window, x, y, w, h);
|
2014-05-26 11:13:56 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
2014-05-23 15:18:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_expose (GstVideoOverlay * overlay)
|
|
|
|
{
|
2022-06-30 09:48:45 +00:00
|
|
|
GstWaylandSink *self = GST_WAYLAND_SINK (overlay);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_return_if_fail (self != NULL);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "expose");
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_lock (&self->render_lock);
|
|
|
|
if (self->last_buffer && !self->redraw_pending) {
|
|
|
|
GST_DEBUG_OBJECT (self, "redrawing last buffer");
|
|
|
|
render_last_buffer (self, TRUE);
|
2014-03-11 15:45:05 +00:00
|
|
|
}
|
2022-06-30 09:48:45 +00:00
|
|
|
g_mutex_unlock (&self->render_lock);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
|
|
|
|
" wayland video sink");
|
|
|
|
|
2021-02-24 17:56:55 +00:00
|
|
|
return GST_ELEMENT_REGISTER (waylandsink, plugin);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
waylandsink,
|
2012-03-07 23:48:56 +00:00
|
|
|
"Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
|
|
|
GST_PACKAGE_ORIGIN)
|