mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
waylandsink: move struct shm_pool and its related functions to waylandpool.c
And also make the instance of this struct to be owned by the buffer pool instead of the element, for the sake of isolation
This commit is contained in:
parent
549bdb4a09
commit
1e45b1480c
4 changed files with 79 additions and 75 deletions
|
@ -95,7 +95,6 @@ static void frame_redraw_callback (void *data,
|
||||||
struct wl_callback *callback, uint32_t time);
|
struct wl_callback *callback, uint32_t time);
|
||||||
static void create_window (GstWaylandSink * sink, GstWlDisplay * display,
|
static void create_window (GstWaylandSink * sink, GstWlDisplay * display,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
static void shm_pool_destroy (struct shm_pool *pool);
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -183,7 +182,6 @@ gst_wayland_sink_init (GstWaylandSink * sink)
|
||||||
{
|
{
|
||||||
sink->display = NULL;
|
sink->display = NULL;
|
||||||
sink->window = NULL;
|
sink->window = NULL;
|
||||||
sink->shm_pool = NULL;
|
|
||||||
sink->pool = NULL;
|
sink->pool = NULL;
|
||||||
|
|
||||||
g_mutex_init (&sink->wayland_lock);
|
g_mutex_init (&sink->wayland_lock);
|
||||||
|
@ -236,14 +234,6 @@ destroy_window (struct window *window)
|
||||||
free (window);
|
free (window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
shm_pool_destroy (struct shm_pool *pool)
|
|
||||||
{
|
|
||||||
munmap (pool->data, pool->size);
|
|
||||||
wl_shm_pool_destroy (pool->pool);
|
|
||||||
free (pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_wayland_sink_finalize (GObject * object)
|
gst_wayland_sink_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
|
@ -255,8 +245,6 @@ gst_wayland_sink_finalize (GObject * object)
|
||||||
destroy_window (sink->window);
|
destroy_window (sink->window);
|
||||||
if (sink->display)
|
if (sink->display)
|
||||||
g_object_unref (sink->display);
|
g_object_unref (sink->display);
|
||||||
if (sink->shm_pool)
|
|
||||||
shm_pool_destroy (sink->shm_pool);
|
|
||||||
|
|
||||||
g_mutex_clear (&sink->wayland_lock);
|
g_mutex_clear (&sink->wayland_lock);
|
||||||
|
|
||||||
|
|
|
@ -69,13 +69,6 @@ struct window
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct shm_pool {
|
|
||||||
struct wl_shm_pool *pool;
|
|
||||||
size_t size;
|
|
||||||
size_t used;
|
|
||||||
void *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _GstWaylandSink GstWaylandSink;
|
typedef struct _GstWaylandSink GstWaylandSink;
|
||||||
typedef struct _GstWaylandSinkClass GstWaylandSinkClass;
|
typedef struct _GstWaylandSinkClass GstWaylandSinkClass;
|
||||||
|
|
||||||
|
@ -89,7 +82,6 @@ struct _GstWaylandSink
|
||||||
|
|
||||||
GstWlDisplay *display;
|
GstWlDisplay *display;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
struct shm_pool *shm_pool;
|
|
||||||
|
|
||||||
GstBufferPool *pool;
|
GstBufferPool *pool;
|
||||||
|
|
||||||
|
|
|
@ -73,57 +73,15 @@ gst_wl_meta_get_info (void)
|
||||||
return wl_meta_info;
|
return wl_meta_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bufferpool */
|
/* shm pool */
|
||||||
static void gst_wayland_buffer_pool_finalize (GObject * object);
|
|
||||||
|
|
||||||
#define gst_wayland_buffer_pool_parent_class parent_class
|
struct shm_pool
|
||||||
G_DEFINE_TYPE (GstWaylandBufferPool, gst_wayland_buffer_pool,
|
|
||||||
GST_TYPE_BUFFER_POOL);
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
wayland_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|
||||||
{
|
{
|
||||||
GstWaylandBufferPool *wpool = GST_WAYLAND_BUFFER_POOL_CAST (pool);
|
struct wl_shm_pool *pool;
|
||||||
GstVideoInfo info;
|
size_t size;
|
||||||
GstCaps *caps;
|
size_t used;
|
||||||
|
void *data;
|
||||||
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
|
};
|
||||||
goto wrong_config;
|
|
||||||
|
|
||||||
if (caps == NULL)
|
|
||||||
goto no_caps;
|
|
||||||
|
|
||||||
/* now parse the caps from the config */
|
|
||||||
if (!gst_video_info_from_caps (&info, caps))
|
|
||||||
goto wrong_caps;
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height,
|
|
||||||
caps);
|
|
||||||
|
|
||||||
/*Fixme: Enable metadata checking handling based on the config of pool */
|
|
||||||
|
|
||||||
wpool->width = info.width;
|
|
||||||
wpool->height = info.height;
|
|
||||||
|
|
||||||
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
|
||||||
/* ERRORS */
|
|
||||||
wrong_config:
|
|
||||||
{
|
|
||||||
GST_WARNING_OBJECT (pool, "invalid config");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
no_caps:
|
|
||||||
{
|
|
||||||
GST_WARNING_OBJECT (pool, "no caps in config");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
wrong_caps:
|
|
||||||
{
|
|
||||||
GST_WARNING_OBJECT (pool,
|
|
||||||
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wl_shm_pool *
|
static struct wl_shm_pool *
|
||||||
make_shm_pool (GstWlDisplay * display, int size, void **data)
|
make_shm_pool (GstWlDisplay * display, int size, void **data)
|
||||||
|
@ -181,6 +139,14 @@ shm_pool_create (GstWlDisplay * display, size_t size)
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shm_pool_destroy (struct shm_pool *pool)
|
||||||
|
{
|
||||||
|
munmap (pool->data, pool->size);
|
||||||
|
wl_shm_pool_destroy (pool->pool);
|
||||||
|
free (pool);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
shm_pool_allocate (struct shm_pool *pool, size_t size, int *offset)
|
shm_pool_allocate (struct shm_pool *pool, size_t size, int *offset)
|
||||||
{
|
{
|
||||||
|
@ -200,6 +166,58 @@ shm_pool_reset (struct shm_pool *pool)
|
||||||
pool->used = 0;
|
pool->used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* bufferpool */
|
||||||
|
static void gst_wayland_buffer_pool_finalize (GObject * object);
|
||||||
|
|
||||||
|
#define gst_wayland_buffer_pool_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE (GstWaylandBufferPool, gst_wayland_buffer_pool,
|
||||||
|
GST_TYPE_BUFFER_POOL);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
wayland_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
|
{
|
||||||
|
GstWaylandBufferPool *wpool = GST_WAYLAND_BUFFER_POOL_CAST (pool);
|
||||||
|
GstVideoInfo info;
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
|
||||||
|
goto wrong_config;
|
||||||
|
|
||||||
|
if (caps == NULL)
|
||||||
|
goto no_caps;
|
||||||
|
|
||||||
|
/* now parse the caps from the config */
|
||||||
|
if (!gst_video_info_from_caps (&info, caps))
|
||||||
|
goto wrong_caps;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height,
|
||||||
|
caps);
|
||||||
|
|
||||||
|
/*Fixme: Enable metadata checking handling based on the config of pool */
|
||||||
|
|
||||||
|
wpool->width = info.width;
|
||||||
|
wpool->height = info.height;
|
||||||
|
|
||||||
|
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
||||||
|
/* ERRORS */
|
||||||
|
wrong_config:
|
||||||
|
{
|
||||||
|
GST_WARNING_OBJECT (pool, "invalid config");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_caps:
|
||||||
|
{
|
||||||
|
GST_WARNING_OBJECT (pool, "no caps in config");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
wrong_caps:
|
||||||
|
{
|
||||||
|
GST_WARNING_OBJECT (pool,
|
||||||
|
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static GstWlMeta *
|
static GstWlMeta *
|
||||||
gst_buffer_add_wayland_meta (GstBuffer * buffer, GstWaylandBufferPool * wpool)
|
gst_buffer_add_wayland_meta (GstBuffer * buffer, GstWaylandBufferPool * wpool)
|
||||||
{
|
{
|
||||||
|
@ -218,21 +236,21 @@ gst_buffer_add_wayland_meta (GstBuffer * buffer, GstWaylandBufferPool * wpool)
|
||||||
wmeta->sink = gst_object_ref (sink);
|
wmeta->sink = gst_object_ref (sink);
|
||||||
|
|
||||||
/*Fixme: size calculation should be more grcefull, have to consider the padding */
|
/*Fixme: size calculation should be more grcefull, have to consider the padding */
|
||||||
if (!sink->shm_pool) {
|
if (!wpool->shm_pool) {
|
||||||
sink->shm_pool = shm_pool_create (sink->display, size * 15);
|
wpool->shm_pool = shm_pool_create (sink->display, size * 15);
|
||||||
shm_pool_reset (sink->shm_pool);
|
shm_pool_reset (wpool->shm_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sink->shm_pool) {
|
if (!wpool->shm_pool) {
|
||||||
GST_ERROR ("Failed to create shm_pool");
|
GST_ERROR ("Failed to create shm_pool");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = shm_pool_allocate (sink->shm_pool, size, &offset);
|
data = shm_pool_allocate (wpool->shm_pool, size, &offset);
|
||||||
if (!data)
|
if (!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wmeta->wbuffer = wl_shm_pool_create_buffer (sink->shm_pool->pool, offset,
|
wmeta->wbuffer = wl_shm_pool_create_buffer (wpool->shm_pool->pool, offset,
|
||||||
sink->video_width, sink->video_height, stride, sink->format);
|
sink->video_width, sink->video_height, stride, sink->format);
|
||||||
|
|
||||||
wmeta->data = data;
|
wmeta->data = data;
|
||||||
|
@ -306,6 +324,9 @@ gst_wayland_buffer_pool_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstWaylandBufferPool *pool = GST_WAYLAND_BUFFER_POOL_CAST (object);
|
GstWaylandBufferPool *pool = GST_WAYLAND_BUFFER_POOL_CAST (object);
|
||||||
|
|
||||||
|
if (pool->shm_pool)
|
||||||
|
shm_pool_destroy (pool->shm_pool);
|
||||||
|
|
||||||
gst_object_unref (pool->sink);
|
gst_object_unref (pool->sink);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_wayland_buffer_pool_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_wayland_buffer_pool_parent_class)->finalize (object);
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
struct shm_pool;
|
||||||
|
|
||||||
/* buffer meta */
|
/* buffer meta */
|
||||||
typedef struct _GstWlMeta GstWlMeta;
|
typedef struct _GstWlMeta GstWlMeta;
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ struct _GstWaylandBufferPool
|
||||||
/*Fixme: keep all these in GstWaylandBufferPoolPrivate*/
|
/*Fixme: keep all these in GstWaylandBufferPoolPrivate*/
|
||||||
guint width;
|
guint width;
|
||||||
guint height;
|
guint height;
|
||||||
|
struct shm_pool *shm_pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstWaylandBufferPoolClass
|
struct _GstWaylandBufferPoolClass
|
||||||
|
|
Loading…
Reference in a new issue