diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index b3c0d4b8aa..0a371284ec 100644 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -95,7 +95,6 @@ static void frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time); static void create_window (GstWaylandSink * sink, GstWlDisplay * display, int width, int height); -static void shm_pool_destroy (struct shm_pool *pool); typedef struct { @@ -183,7 +182,6 @@ gst_wayland_sink_init (GstWaylandSink * sink) { sink->display = NULL; sink->window = NULL; - sink->shm_pool = NULL; sink->pool = NULL; g_mutex_init (&sink->wayland_lock); @@ -236,14 +234,6 @@ destroy_window (struct window *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 gst_wayland_sink_finalize (GObject * object) { @@ -255,8 +245,6 @@ gst_wayland_sink_finalize (GObject * object) destroy_window (sink->window); if (sink->display) g_object_unref (sink->display); - if (sink->shm_pool) - shm_pool_destroy (sink->shm_pool); g_mutex_clear (&sink->wayland_lock); diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h index 133762fd68..c5a1057d9c 100644 --- a/ext/wayland/gstwaylandsink.h +++ b/ext/wayland/gstwaylandsink.h @@ -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 _GstWaylandSinkClass GstWaylandSinkClass; @@ -89,7 +82,6 @@ struct _GstWaylandSink GstWlDisplay *display; struct window *window; - struct shm_pool *shm_pool; GstBufferPool *pool; diff --git a/ext/wayland/waylandpool.c b/ext/wayland/waylandpool.c index 0310e89383..34b1282605 100644 --- a/ext/wayland/waylandpool.c +++ b/ext/wayland/waylandpool.c @@ -73,57 +73,15 @@ gst_wl_meta_get_info (void) return wl_meta_info; } -/* bufferpool */ -static void gst_wayland_buffer_pool_finalize (GObject * object); +/* shm pool */ -#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) +struct shm_pool { - 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; - } -} + struct wl_shm_pool *pool; + size_t size; + size_t used; + void *data; +}; static struct wl_shm_pool * make_shm_pool (GstWlDisplay * display, int size, void **data) @@ -181,6 +139,14 @@ shm_pool_create (GstWlDisplay * display, size_t size) 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 * 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; } +/* 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 * 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); /*Fixme: size calculation should be more grcefull, have to consider the padding */ - if (!sink->shm_pool) { - sink->shm_pool = shm_pool_create (sink->display, size * 15); - shm_pool_reset (sink->shm_pool); + if (!wpool->shm_pool) { + wpool->shm_pool = shm_pool_create (sink->display, size * 15); + shm_pool_reset (wpool->shm_pool); } - if (!sink->shm_pool) { + if (!wpool->shm_pool) { GST_ERROR ("Failed to create shm_pool"); return NULL; } - data = shm_pool_allocate (sink->shm_pool, size, &offset); + data = shm_pool_allocate (wpool->shm_pool, size, &offset); if (!data) 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); wmeta->data = data; @@ -306,6 +324,9 @@ gst_wayland_buffer_pool_finalize (GObject * object) { GstWaylandBufferPool *pool = GST_WAYLAND_BUFFER_POOL_CAST (object); + if (pool->shm_pool) + shm_pool_destroy (pool->shm_pool); + gst_object_unref (pool->sink); G_OBJECT_CLASS (gst_wayland_buffer_pool_parent_class)->finalize (object); diff --git a/ext/wayland/waylandpool.h b/ext/wayland/waylandpool.h index 269f59bef6..ac64c242b7 100644 --- a/ext/wayland/waylandpool.h +++ b/ext/wayland/waylandpool.h @@ -25,6 +25,8 @@ G_BEGIN_DECLS +struct shm_pool; + /* buffer meta */ typedef struct _GstWlMeta GstWlMeta; @@ -64,6 +66,7 @@ struct _GstWaylandBufferPool /*Fixme: keep all these in GstWaylandBufferPoolPrivate*/ guint width; guint height; + struct shm_pool *shm_pool; }; struct _GstWaylandBufferPoolClass