mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
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.
This commit is contained in:
parent
e4e43cd842
commit
96ce1bc761
10 changed files with 69 additions and 38 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue