From 96ce1bc761b35d1dd49f99adc33c8c6ec451f37f Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Tue, 27 Jan 2015 11:44:12 +0100 Subject: [PATCH] videopool: add optional flags for surface pool allocation. Reword surface pool allocation helpers so that to allow for a simple form, e.g. gst_vaapi_surface_pool_new(format, width, height); and a somewhat more elaborated/flexible form with optional allocation flags and precise GstVideoInfo specification. This is an API/ABI change, and SONAME version needs to be bumped. --- gst-libs/gst/vaapi/gstvaapicontext.c | 6 +- gst-libs/gst/vaapi/gstvaapisurfacepool.c | 64 +++++++++++++++------ gst-libs/gst/vaapi/gstvaapisurfacepool.h | 8 ++- gst-libs/gst/vaapi/gstvaapiwindow_wayland.c | 6 +- gst/vaapi/gstvaapipostproc.c | 5 +- gst/vaapi/gstvaapiuploader.c | 2 +- gst/vaapi/gstvaapivideobufferpool.c | 2 +- gst/vaapi/gstvaapivideomemory.c | 6 +- gst/vaapi/gstvaapivideomemory.h | 2 +- tests/test-surfaces.c | 6 +- 10 files changed, 69 insertions(+), 38 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c index 185ed7fdb8..a2c68a328a 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.c +++ b/gst-libs/gst/vaapi/gstvaapicontext.c @@ -134,7 +134,6 @@ static gboolean context_create_surfaces (GstVaapiContext * context) { const GstVaapiContextInfo *const cip = &context->info; - GstVideoInfo vi; guint num_surfaces; if (!gst_vaapi_context_overlay_reset (context)) @@ -149,10 +148,9 @@ context_create_surfaces (GstVaapiContext * context) } if (!context->surfaces_pool) { - gst_video_info_set_format (&vi, GST_VIDEO_FORMAT_ENCODED, - cip->width, cip->height); context->surfaces_pool = - gst_vaapi_surface_pool_new (GST_VAAPI_OBJECT_DISPLAY (context), &vi); + gst_vaapi_surface_pool_new (GST_VAAPI_OBJECT_DISPLAY (context), + GST_VIDEO_FORMAT_ENCODED, cip->width, cip->height); if (!context->surfaces_pool) return FALSE; } diff --git a/gst-libs/gst/vaapi/gstvaapisurfacepool.c b/gst-libs/gst/vaapi/gstvaapisurfacepool.c index 8af8eac9a9..02c0606041 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfacepool.c +++ b/gst-libs/gst/vaapi/gstvaapisurfacepool.c @@ -45,25 +45,26 @@ struct _GstVaapiSurfacePool GstVaapiVideoPool parent_instance; GstVaapiChromaType chroma_type; - GstVideoFormat format; - guint width; - guint height; + GstVideoInfo video_info; + guint alloc_flags; }; static gboolean -surface_pool_init (GstVaapiSurfacePool * pool, const GstVideoInfo * vip) +surface_pool_init (GstVaapiSurfacePool * pool, const GstVideoInfo * vip, + guint flags) { - pool->format = GST_VIDEO_INFO_FORMAT (vip); - pool->width = GST_VIDEO_INFO_WIDTH (vip); - pool->height = GST_VIDEO_INFO_HEIGHT (vip); + const GstVideoFormat format = GST_VIDEO_INFO_FORMAT (vip); - if (pool->format == GST_VIDEO_FORMAT_UNKNOWN) + pool->video_info = *vip; + pool->alloc_flags = flags; + + if (format == GST_VIDEO_FORMAT_UNKNOWN) return FALSE; - if (pool->format == GST_VIDEO_FORMAT_ENCODED) + if (format == GST_VIDEO_FORMAT_ENCODED) pool->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420; else - pool->chroma_type = gst_vaapi_video_format_get_chroma_type (pool->format); + pool->chroma_type = gst_vaapi_video_format_get_chroma_type (format); if (!pool->chroma_type) return FALSE; return TRUE; @@ -75,17 +76,18 @@ gst_vaapi_surface_pool_alloc_object (GstVaapiVideoPool * base_pool) GstVaapiSurfacePool *const pool = GST_VAAPI_SURFACE_POOL (base_pool); /* Try to allocate a surface with an explicit pixel format first */ - if (pool->format != GST_VIDEO_FORMAT_ENCODED) { + if (GST_VIDEO_INFO_FORMAT (&pool->video_info) != GST_VIDEO_FORMAT_ENCODED) { GstVaapiSurface *const surface = - gst_vaapi_surface_new_with_format (base_pool->display, pool->format, - pool->width, pool->height); + gst_vaapi_surface_new_full (base_pool->display, &pool->video_info, + pool->alloc_flags); if (surface) return surface; } /* Otherwise, fallback to the original interface, based on chroma format */ return gst_vaapi_surface_new (base_pool->display, - pool->chroma_type, pool->width, pool->height); + pool->chroma_type, GST_VIDEO_INFO_WIDTH (&pool->video_info), + GST_VIDEO_INFO_HEIGHT (&pool->video_info)); } static inline const GstVaapiMiniObjectClass * @@ -102,7 +104,36 @@ gst_vaapi_surface_pool_class (void) /** * gst_vaapi_surface_pool_new: * @display: a #GstVaapiDisplay + * @format: a #GstVideoFormat + * @width: the desired width, in pixels + * @height: the desired height, in pixels + * + * Creates a new #GstVaapiVideoPool of #GstVaapiSurface with the specified + * format and dimensions. If @format is GST_VIDEO_FORMAT_ENCODED, then + * surfaces with best "native" format would be created. Typically, this is + * NV12 format, but this is implementation (driver) defined. + * + * Return value: the newly allocated #GstVaapiVideoPool + */ +GstVaapiVideoPool * +gst_vaapi_surface_pool_new (GstVaapiDisplay * display, GstVideoFormat format, + guint width, guint height) +{ + GstVideoInfo vi; + + g_return_val_if_fail (display != NULL, NULL); + g_return_val_if_fail (width > 0, NULL); + g_return_val_if_fail (height > 0, NULL); + + gst_video_info_set_format (&vi, format, width, height); + return gst_vaapi_surface_pool_new_full (display, &vi, 0); +} + +/** + * gst_vaapi_surface_pool_new_full: + * @display: a #GstVaapiDisplay * @vip: a #GstVideoInfo + * @flags: (optional) allocation flags * * Creates a new #GstVaapiVideoPool of #GstVaapiSurface with the * specified format and dimensions in @vip. @@ -110,7 +141,8 @@ gst_vaapi_surface_pool_class (void) * Return value: the newly allocated #GstVaapiVideoPool */ GstVaapiVideoPool * -gst_vaapi_surface_pool_new (GstVaapiDisplay * display, const GstVideoInfo * vip) +gst_vaapi_surface_pool_new_full (GstVaapiDisplay * display, + const GstVideoInfo * vip, guint flags) { GstVaapiVideoPool *pool; @@ -124,7 +156,7 @@ gst_vaapi_surface_pool_new (GstVaapiDisplay * display, const GstVideoInfo * vip) gst_vaapi_video_pool_init (pool, display, GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE); - if (!surface_pool_init (GST_VAAPI_SURFACE_POOL (pool), vip)) + if (!surface_pool_init (GST_VAAPI_SURFACE_POOL (pool), vip, flags)) goto error; return pool; diff --git a/gst-libs/gst/vaapi/gstvaapisurfacepool.h b/gst-libs/gst/vaapi/gstvaapisurfacepool.h index 82d623b11f..e0529a22f4 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfacepool.h +++ b/gst-libs/gst/vaapi/gstvaapisurfacepool.h @@ -37,8 +37,12 @@ G_BEGIN_DECLS typedef struct _GstVaapiSurfacePool GstVaapiSurfacePool; GstVaapiVideoPool * -gst_vaapi_surface_pool_new (GstVaapiDisplay * display, - const GstVideoInfo * vip); +gst_vaapi_surface_pool_new (GstVaapiDisplay * display, GstVideoFormat format, + guint width, guint height); + +GstVaapiVideoPool * +gst_vaapi_surface_pool_new_full (GstVaapiDisplay * display, + const GstVideoInfo * vip, guint flags); G_END_DECLS diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c index 2c40e48895..9846063d9d 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c @@ -348,14 +348,12 @@ vpp_convert (GstVaapiWindow * window, GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (window); GstVaapiSurface *vpp_surface = NULL; GstVaapiFilterStatus status; - GstVideoInfo vi; /* Ensure VA surface pool is created */ /* XXX: optimize the surface format to use. e.g. YUY2 */ if (!priv->surface_pool) { - gst_video_info_set_format (&vi, priv->surface_format, - window->width, window->height); - priv->surface_pool = gst_vaapi_surface_pool_new (display, &vi); + priv->surface_pool = gst_vaapi_surface_pool_new (display, + priv->surface_format, window->width, window->height); if (!priv->surface_pool) return NULL; gst_vaapi_filter_replace (&priv->filter, NULL); diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index 756491b3c6..e701b8cdff 100644 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -1310,8 +1310,9 @@ ensure_srcpad_buffer_pool (GstVaapiPostproc * postproc, GstCaps * caps) return TRUE; postproc->filter_pool_info = vi; - pool = gst_vaapi_surface_pool_new (GST_VAAPI_PLUGIN_BASE_DISPLAY (postproc), - &postproc->filter_pool_info); + pool = + gst_vaapi_surface_pool_new_full (GST_VAAPI_PLUGIN_BASE_DISPLAY (postproc), + &postproc->filter_pool_info, 0); if (!pool) return FALSE; diff --git a/gst/vaapi/gstvaapiuploader.c b/gst/vaapi/gstvaapiuploader.c index 6c702b929c..c4e5d14943 100644 --- a/gst/vaapi/gstvaapiuploader.c +++ b/gst/vaapi/gstvaapiuploader.c @@ -243,7 +243,7 @@ ensure_surface_pool (GstVaapiUploader * uploader, GstCaps * caps, } } - pool = gst_vaapi_surface_pool_new (priv->display, &vi); + pool = gst_vaapi_surface_pool_new_full (priv->display, &vi, 0); if (!pool) return FALSE; diff --git a/gst/vaapi/gstvaapivideobufferpool.c b/gst/vaapi/gstvaapivideobufferpool.c index 4c642e7d50..84be8e3058 100644 --- a/gst/vaapi/gstvaapivideobufferpool.c +++ b/gst/vaapi/gstvaapivideobufferpool.c @@ -153,7 +153,7 @@ gst_vaapi_video_buffer_pool_set_config (GstBufferPool * pool, GST_VIDEO_INFO_HEIGHT (cur_vip) != GST_VIDEO_INFO_HEIGHT (new_vip); if (changed_caps) { - allocator = gst_vaapi_video_allocator_new (priv->display, new_vip); + allocator = gst_vaapi_video_allocator_new (priv->display, new_vip, 0); if (!allocator) goto error_create_allocator; gst_object_replace ((GstObject **) & priv->allocator, diff --git a/gst/vaapi/gstvaapivideomemory.c b/gst/vaapi/gstvaapivideomemory.c index 184d78d27f..33674f5e8a 100644 --- a/gst/vaapi/gstvaapivideomemory.c +++ b/gst/vaapi/gstvaapivideomemory.c @@ -650,7 +650,7 @@ gst_video_info_update_from_image (GstVideoInfo * vip, GstVaapiImage * image) GstAllocator * gst_vaapi_video_allocator_new (GstVaapiDisplay * display, - const GstVideoInfo * vip) + const GstVideoInfo * vip, guint flags) { GstVaapiVideoAllocator *allocator; GstVaapiSurface *surface; @@ -695,8 +695,8 @@ gst_vaapi_video_allocator_new (GstVaapiDisplay * display, gst_vaapi_object_unref (image); } - allocator->surface_pool = gst_vaapi_surface_pool_new (display, - &allocator->surface_info); + allocator->surface_pool = gst_vaapi_surface_pool_new_full (display, + &allocator->surface_info, flags); if (!allocator->surface_pool) goto error_create_surface_pool; diff --git a/gst/vaapi/gstvaapivideomemory.h b/gst/vaapi/gstvaapivideomemory.h index 5681a1c065..ba29564a25 100644 --- a/gst/vaapi/gstvaapivideomemory.h +++ b/gst/vaapi/gstvaapivideomemory.h @@ -187,7 +187,7 @@ gst_vaapi_video_allocator_get_type (void) G_GNUC_CONST; G_GNUC_INTERNAL GstAllocator * gst_vaapi_video_allocator_new (GstVaapiDisplay * display, - const GstVideoInfo * vip); + const GstVideoInfo * vip, guint flags); G_END_DECLS diff --git a/tests/test-surfaces.c b/tests/test-surfaces.c index c958e0754e..734774f567 100644 --- a/tests/test-surfaces.c +++ b/tests/test-surfaces.c @@ -36,7 +36,6 @@ main(int argc, char *argv[]) GstVaapiID surface_id; GstVaapiSurface *surfaces[MAX_SURFACES]; GstVaapiVideoPool *pool; - GstVideoInfo vi; gint i; static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420; @@ -60,9 +59,8 @@ main(int argc, char *argv[]) gst_vaapi_object_unref(surface); - gst_video_info_set_format(&vi, GST_VIDEO_FORMAT_ENCODED, width, height); - - pool = gst_vaapi_surface_pool_new(display, &vi); + pool = gst_vaapi_surface_pool_new(display, GST_VIDEO_FORMAT_ENCODED, + width, height); if (!pool) g_error("could not create Gst/VA surface pool");