2010-03-12 17:45:18 +00:00
|
|
|
/*
|
|
|
|
* gstvaapisurfacepool.c - Gst VA surface pool
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2013-11-22 05:37:12 +00:00
|
|
|
* Copyright (C) 2012-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-12 17:45:18 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-12 17:45:18 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-12 17:45:18 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-14 11:51:41 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-12 17:45:18 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-12 17:45:18 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-19 16:08:48 +00:00
|
|
|
/**
|
2010-03-24 08:16:32 +00:00
|
|
|
* SECTION:gstvaapisurfacepool
|
|
|
|
* @short_description: VA surface pool
|
2010-03-19 16:08:48 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-12 17:45:18 +00:00
|
|
|
#include "gstvaapisurfacepool.h"
|
2013-05-03 09:01:12 +00:00
|
|
|
#include "gstvaapivideopool_priv.h"
|
2010-03-12 17:45:18 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-03-12 17:45:18 +00:00
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
/**
|
|
|
|
* GstVaapiSurfacePool:
|
|
|
|
*
|
|
|
|
* A pool of lazily allocated #GstVaapiSurface objects.
|
|
|
|
*/
|
2015-01-26 22:21:56 +00:00
|
|
|
struct _GstVaapiSurfacePool
|
|
|
|
{
|
2016-02-02 16:50:19 +00:00
|
|
|
/*< private > */
|
2015-01-26 22:21:56 +00:00
|
|
|
GstVaapiVideoPool parent_instance;
|
|
|
|
|
|
|
|
GstVaapiChromaType chroma_type;
|
2015-01-27 10:44:12 +00:00
|
|
|
GstVideoInfo video_info;
|
|
|
|
guint alloc_flags;
|
2010-03-12 17:45:18 +00:00
|
|
|
};
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
static gboolean
|
2015-01-27 10:44:12 +00:00
|
|
|
surface_pool_init (GstVaapiSurfacePool * pool, const GstVideoInfo * vip,
|
|
|
|
guint flags)
|
2010-03-12 17:45:18 +00:00
|
|
|
{
|
2015-01-27 10:44:12 +00:00
|
|
|
const GstVideoFormat format = GST_VIDEO_INFO_FORMAT (vip);
|
2015-01-26 22:21:56 +00:00
|
|
|
|
2015-01-27 10:44:12 +00:00
|
|
|
pool->video_info = *vip;
|
|
|
|
pool->alloc_flags = flags;
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
2015-01-26 22:21:56 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2015-01-27 10:44:12 +00:00
|
|
|
if (format == GST_VIDEO_FORMAT_ENCODED)
|
2015-01-26 22:21:56 +00:00
|
|
|
pool->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
|
|
|
|
else
|
2015-01-27 10:44:12 +00:00
|
|
|
pool->chroma_type = gst_vaapi_video_format_get_chroma_type (format);
|
2015-01-26 22:21:56 +00:00
|
|
|
if (!pool->chroma_type)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2010-03-12 17:45:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
static gpointer
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_surface_pool_alloc_object (GstVaapiVideoPool * base_pool)
|
2010-03-12 17:45:18 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
GstVaapiSurfacePool *const pool = GST_VAAPI_SURFACE_POOL (base_pool);
|
|
|
|
|
|
|
|
/* Try to allocate a surface with an explicit pixel format first */
|
2015-01-27 10:44:12 +00:00
|
|
|
if (GST_VIDEO_INFO_FORMAT (&pool->video_info) != GST_VIDEO_FORMAT_ENCODED) {
|
2015-01-26 22:21:56 +00:00
|
|
|
GstVaapiSurface *const surface =
|
2015-01-27 10:44:12 +00:00
|
|
|
gst_vaapi_surface_new_full (base_pool->display, &pool->video_info,
|
|
|
|
pool->alloc_flags);
|
2015-01-26 22:21:56 +00:00
|
|
|
if (surface)
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, fallback to the original interface, based on chroma format */
|
|
|
|
return gst_vaapi_surface_new (base_pool->display,
|
2015-01-27 10:44:12 +00:00
|
|
|
pool->chroma_type, GST_VIDEO_INFO_WIDTH (&pool->video_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&pool->video_info));
|
2010-03-12 17:45:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:01:12 +00:00
|
|
|
static inline const GstVaapiMiniObjectClass *
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_surface_pool_class (void)
|
2010-03-12 17:45:18 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
static const GstVaapiVideoPoolClass GstVaapiSurfacePoolClass = {
|
|
|
|
{sizeof (GstVaapiSurfacePool),
|
|
|
|
(GDestroyNotify) gst_vaapi_video_pool_finalize},
|
|
|
|
.alloc_object = gst_vaapi_surface_pool_alloc_object
|
|
|
|
};
|
|
|
|
return GST_VAAPI_MINI_OBJECT_CLASS (&GstVaapiSurfacePoolClass);
|
2010-03-12 17:45:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 16:08:48 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_pool_new:
|
|
|
|
* @display: a #GstVaapiDisplay
|
2015-01-27 10:44:12 +00:00
|
|
|
* @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
|
2013-07-10 11:07:37 +00:00
|
|
|
* @vip: a #GstVideoInfo
|
2015-01-27 10:44:12 +00:00
|
|
|
* @flags: (optional) allocation flags
|
2010-03-19 16:08:48 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiVideoPool of #GstVaapiSurface with the
|
2013-07-10 11:07:37 +00:00
|
|
|
* specified format and dimensions in @vip.
|
2010-03-19 16:08:48 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiVideoPool
|
|
|
|
*/
|
2010-03-12 23:47:47 +00:00
|
|
|
GstVaapiVideoPool *
|
2015-01-27 10:44:12 +00:00
|
|
|
gst_vaapi_surface_pool_new_full (GstVaapiDisplay * display,
|
|
|
|
const GstVideoInfo * vip, guint flags)
|
2010-03-12 17:45:18 +00:00
|
|
|
{
|
2015-01-26 22:21:56 +00:00
|
|
|
GstVaapiVideoPool *pool;
|
2013-05-03 09:01:12 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
g_return_val_if_fail (display != NULL, NULL);
|
|
|
|
g_return_val_if_fail (vip != NULL, NULL);
|
2013-05-03 09:01:12 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
pool = (GstVaapiVideoPool *)
|
|
|
|
gst_vaapi_mini_object_new (gst_vaapi_surface_pool_class ());
|
|
|
|
if (!pool)
|
|
|
|
return NULL;
|
2013-05-03 09:01:12 +00:00
|
|
|
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_video_pool_init (pool, display,
|
|
|
|
GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_SURFACE);
|
2015-01-27 10:44:12 +00:00
|
|
|
if (!surface_pool_init (GST_VAAPI_SURFACE_POOL (pool), vip, flags))
|
2015-01-26 22:21:56 +00:00
|
|
|
goto error;
|
|
|
|
return pool;
|
2013-05-03 09:01:12 +00:00
|
|
|
|
|
|
|
error:
|
2015-01-26 22:21:56 +00:00
|
|
|
gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (pool));
|
|
|
|
return NULL;
|
2010-03-12 17:45:18 +00:00
|
|
|
}
|
2001-01-01 02:59:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_pool_new_with_chroma_type:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @chroma_type: a #GstVaapiChromatype
|
|
|
|
* @width: the desired width, in pixels
|
|
|
|
* @height: the desired height, in pixels
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiVideoPool of #GstVaapiSurface with the specified
|
|
|
|
* chroam type and dimensions. The underlying format of the surfaces is
|
|
|
|
* implementation (driver) defined.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiVideoPool
|
|
|
|
*/
|
|
|
|
GstVaapiVideoPool *
|
|
|
|
gst_vaapi_surface_pool_new_with_chroma_type (GstVaapiDisplay * display,
|
|
|
|
GstVaapiChromaType chroma_type, guint width, guint height)
|
|
|
|
{
|
|
|
|
GstVaapiVideoPool *pool;
|
|
|
|
GstVideoInfo vi;
|
|
|
|
|
|
|
|
g_return_val_if_fail (display != NULL, NULL);
|
|
|
|
g_return_val_if_fail (chroma_type > 0, NULL);
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
|
|
|
|
|
|
|
gst_video_info_set_format (&vi, GST_VIDEO_FORMAT_ENCODED, width, height);
|
|
|
|
|
|
|
|
pool = gst_vaapi_surface_pool_new_full (display, &vi, 0);
|
|
|
|
if (!pool)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_VAAPI_SURFACE_POOL (pool)->chroma_type = chroma_type;
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|