2022-01-04 14:20:41 +00:00
|
|
|
/* GStreamer Wayland Library
|
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
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Intel Corporation
|
|
|
|
* Copyright (C) 2012 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
|
|
|
|
* Copyright (C) 2014 Collabora Ltd.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2022-01-04 14:20:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstwlshmallocator.h"
|
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
|
|
|
|
|
|
|
|
2017-11-22 04:18:24 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wl_shm_validate_video_info (const GstVideoInfo * vinfo)
|
|
|
|
{
|
|
|
|
gint height = GST_VIDEO_INFO_HEIGHT (vinfo);
|
|
|
|
gint base_stride = GST_VIDEO_INFO_PLANE_STRIDE (vinfo, 0);
|
|
|
|
gsize base_offs = GST_VIDEO_INFO_PLANE_OFFSET (vinfo, 0);
|
|
|
|
gint i;
|
|
|
|
gsize offs = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (vinfo); i++) {
|
|
|
|
guint32 estride;
|
|
|
|
|
|
|
|
/* Overwrite the video info's stride and offset using the pitch calculcated
|
|
|
|
* by the kms driver. */
|
2022-01-25 19:08:47 +00:00
|
|
|
estride = gst_video_format_info_extrapolate_stride (vinfo->finfo, i,
|
|
|
|
base_stride);
|
2017-11-22 04:18:24 +00:00
|
|
|
|
|
|
|
if (estride != GST_VIDEO_INFO_PLANE_STRIDE (vinfo, i))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_PLANE_OFFSET (vinfo, i) - base_offs != offs)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Note that we cannot negotiate special padding betweem each planes,
|
|
|
|
* hence using the display height here. */
|
|
|
|
offs +=
|
|
|
|
estride * GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (vinfo->finfo, i, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vinfo->size < offs)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct wl_buffer *
|
|
|
|
gst_wl_shm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
|
|
|
|
const GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
gint width, height, stride;
|
2016-09-29 18:34:18 +00:00
|
|
|
gsize offset, size, memsize, maxsize;
|
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
|
|
|
enum wl_shm_format format;
|
|
|
|
struct wl_shm_pool *wl_pool;
|
|
|
|
struct wl_buffer *wbuffer;
|
|
|
|
|
2017-11-22 04:18:24 +00:00
|
|
|
if (!gst_wl_shm_validate_video_info (info)) {
|
|
|
|
GST_DEBUG_OBJECT (display, "Unsupported strides and offsets.");
|
|
|
|
return 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
|
|
|
width = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (info);
|
|
|
|
stride = GST_VIDEO_INFO_PLANE_STRIDE (info, 0);
|
|
|
|
size = GST_VIDEO_INFO_SIZE (info);
|
2014-06-20 13:24:36 +00:00
|
|
|
format = gst_video_format_to_wl_shm_format (GST_VIDEO_INFO_FORMAT (info));
|
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
|
|
|
|
2016-09-29 18:34:18 +00:00
|
|
|
memsize = gst_memory_get_sizes (mem, &offset, &maxsize);
|
2017-11-22 04:18:24 +00:00
|
|
|
offset += GST_VIDEO_INFO_PLANE_OFFSET (info, 0);
|
2016-09-29 18:34:18 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (gst_is_fd_memory (mem), NULL);
|
|
|
|
g_return_val_if_fail (size <= memsize, NULL);
|
2023-07-28 19:56:32 +00:00
|
|
|
g_return_val_if_fail (gst_wl_display_check_format_for_shm (display, info),
|
|
|
|
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
|
|
|
|
2016-09-29 20:30:33 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "Creating wl_buffer from SHM of size %"
|
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
|
|
|
G_GSSIZE_FORMAT " (%d x %d, stride %d), format %s", size, width, height,
|
2014-06-20 13:24:36 +00:00
|
|
|
stride, gst_wl_shm_format_to_string (format));
|
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-01-04 14:20:41 +00:00
|
|
|
wl_pool = wl_shm_create_pool (gst_wl_display_get_shm (display),
|
|
|
|
gst_fd_memory_get_fd (mem), memsize);
|
2016-09-29 18:34:18 +00:00
|
|
|
wbuffer = wl_shm_pool_create_buffer (wl_pool, offset, width, height, stride,
|
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
|
|
|
format);
|
|
|
|
wl_shm_pool_destroy (wl_pool);
|
|
|
|
|
|
|
|
return wbuffer;
|
|
|
|
}
|