2010-04-23 16:00:50 +00:00
|
|
|
/*
|
|
|
|
* gstvaapisurfaceproxy.c - VA surface proxy
|
|
|
|
*
|
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>
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-04-23 16:00:50 +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-04-23 16:00:50 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-04-23 16:00:50 +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-04-23 16:00:50 +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-04-23 16:00:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstvaapisurfaceproxy
|
|
|
|
* @short_description: VA surface proxy
|
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-04-23 16:00:50 +00:00
|
|
|
#include "gstvaapisurfaceproxy.h"
|
2013-04-16 16:35:48 +00:00
|
|
|
#include "gstvaapisurfaceproxy_priv.h"
|
2013-05-03 09:01:12 +00:00
|
|
|
#include "gstvaapivideopool_priv.h"
|
2010-04-23 16:00:50 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
|
|
|
|
|
|
|
static void
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_finalize (GstVaapiSurfaceProxy * proxy)
|
2010-04-23 16:00:50 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
if (proxy->surface) {
|
|
|
|
if (proxy->pool && !proxy->parent)
|
|
|
|
gst_vaapi_video_pool_put_object (proxy->pool, proxy->surface);
|
|
|
|
gst_vaapi_object_unref (proxy->surface);
|
|
|
|
proxy->surface = NULL;
|
|
|
|
}
|
|
|
|
gst_vaapi_video_pool_replace (&proxy->pool, NULL);
|
|
|
|
gst_vaapi_surface_proxy_replace (&proxy->parent, NULL);
|
|
|
|
|
|
|
|
/* Notify the user function that the object is now destroyed */
|
|
|
|
if (proxy->destroy_func)
|
|
|
|
proxy->destroy_func (proxy->destroy_data);
|
2010-04-23 16:00:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 12:46:28 +00:00
|
|
|
static inline const GstVaapiMiniObjectClass *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_class (void)
|
2010-04-23 16:00:50 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
static const GstVaapiMiniObjectClass GstVaapiSurfaceProxyClass = {
|
|
|
|
sizeof (GstVaapiSurfaceProxy),
|
|
|
|
(GDestroyNotify) gst_vaapi_surface_proxy_finalize
|
|
|
|
};
|
|
|
|
return &GstVaapiSurfaceProxyClass;
|
2010-04-23 16:00:50 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 16:25:05 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_new_from_pool:
|
|
|
|
* @pool: a #GstVaapiSurfacePool
|
|
|
|
*
|
|
|
|
* Allocates a new surface from the supplied surface @pool and creates
|
|
|
|
* the wrapped surface proxy object from it. When the last reference
|
|
|
|
* to the proxy object is released, then the underlying VA surface is
|
|
|
|
* pushed back to its parent pool.
|
|
|
|
*
|
|
|
|
* Returns: The same newly allocated @proxy object, or %NULL on error
|
|
|
|
*/
|
2013-04-03 09:37:44 +00:00
|
|
|
GstVaapiSurfaceProxy *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_new_from_pool (GstVaapiSurfacePool * pool)
|
2013-04-03 09:37:44 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
GstVaapiSurfaceProxy *proxy;
|
2013-04-03 09:37:44 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (pool != NULL, NULL);
|
|
|
|
|
|
|
|
proxy = (GstVaapiSurfaceProxy *)
|
|
|
|
gst_vaapi_mini_object_new (gst_vaapi_surface_proxy_class ());
|
|
|
|
if (!proxy)
|
2013-04-03 09:37:44 +00:00
|
|
|
return NULL;
|
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
proxy->parent = NULL;
|
|
|
|
proxy->destroy_func = NULL;
|
|
|
|
proxy->pool = gst_vaapi_video_pool_ref (pool);
|
|
|
|
proxy->surface = gst_vaapi_video_pool_get_object (proxy->pool);
|
|
|
|
if (!proxy->surface)
|
|
|
|
goto error;
|
|
|
|
proxy->view_id = 0;
|
|
|
|
proxy->timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
proxy->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
proxy->has_crop_rect = FALSE;
|
|
|
|
gst_vaapi_object_ref (proxy->surface);
|
|
|
|
return proxy;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gst_vaapi_surface_proxy_unref (proxy);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-28 16:25:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_copy:
|
|
|
|
* @proxy: the parent #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Creates are new VA surface proxy object from the supplied parent
|
|
|
|
* @proxy object with the same initial information, e.g. timestamp,
|
|
|
|
* duration.
|
|
|
|
*
|
|
|
|
* Note: the destroy notify function is not copied into the new
|
|
|
|
* surface proxy object.
|
|
|
|
*
|
|
|
|
* Returns: The same newly allocated @proxy object, or %NULL on error
|
|
|
|
*/
|
|
|
|
GstVaapiSurfaceProxy *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_copy (GstVaapiSurfaceProxy * proxy)
|
2013-11-28 16:25:05 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
GstVaapiSurfaceProxy *copy;
|
|
|
|
|
|
|
|
g_return_val_if_fail (proxy != NULL, NULL);
|
|
|
|
|
|
|
|
copy = (GstVaapiSurfaceProxy *)
|
|
|
|
gst_vaapi_mini_object_new (gst_vaapi_surface_proxy_class ());
|
|
|
|
if (!copy)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_VAAPI_SURFACE_PROXY_FLAGS (copy) = GST_VAAPI_SURFACE_PROXY_FLAGS (proxy);
|
|
|
|
|
|
|
|
copy->parent = gst_vaapi_surface_proxy_ref (proxy->parent ?
|
|
|
|
proxy->parent : proxy);
|
|
|
|
copy->pool = gst_vaapi_video_pool_ref (proxy->pool);
|
|
|
|
copy->surface = gst_vaapi_object_ref (proxy->surface);
|
|
|
|
copy->view_id = proxy->view_id;
|
|
|
|
copy->timestamp = proxy->timestamp;
|
|
|
|
copy->duration = proxy->duration;
|
|
|
|
copy->destroy_func = NULL;
|
|
|
|
copy->has_crop_rect = proxy->has_crop_rect;
|
|
|
|
if (copy->has_crop_rect)
|
|
|
|
copy->crop_rect = proxy->crop_rect;
|
|
|
|
return copy;
|
2013-11-28 16:25:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 12:46:28 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_ref:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Atomically increases the reference count of the given @proxy by one.
|
|
|
|
*
|
|
|
|
* Returns: The same @proxy argument
|
|
|
|
*/
|
|
|
|
GstVaapiSurfaceProxy *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_ref (GstVaapiSurfaceProxy * proxy)
|
2012-12-03 12:46:28 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, NULL);
|
2012-12-03 12:46:28 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
return
|
|
|
|
GST_VAAPI_SURFACE_PROXY (gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT
|
|
|
|
(proxy)));
|
2012-12-03 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_unref:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Atomically decreases the reference count of the @proxy by one. If
|
|
|
|
* the reference count reaches zero, the object will be free'd.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_unref (GstVaapiSurfaceProxy * proxy)
|
2012-12-03 12:46:28 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_if_fail (proxy != NULL);
|
2012-12-03 12:46:28 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (proxy));
|
2012-12-03 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_replace:
|
|
|
|
* @old_proxy_ptr: a pointer to a #GstVaapiSurfaceProxy
|
|
|
|
* @new_proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Atomically replaces the proxy object held in @old_proxy_ptr with
|
|
|
|
* @new_proxy. This means that @old_proxy_ptr shall reference a valid
|
|
|
|
* object. However, @new_proxy can be NULL.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_replace (GstVaapiSurfaceProxy ** old_proxy_ptr,
|
|
|
|
GstVaapiSurfaceProxy * new_proxy)
|
2012-12-03 12:46:28 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_if_fail (old_proxy_ptr != NULL);
|
2012-12-03 12:46:28 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) old_proxy_ptr,
|
|
|
|
GST_VAAPI_MINI_OBJECT (new_proxy));
|
2012-12-03 12:46:28 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:00:50 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_surface:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiSurface stored in the @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiSurface
|
|
|
|
*/
|
|
|
|
GstVaapiSurface *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_surface (GstVaapiSurfaceProxy * proxy)
|
2010-04-23 16:00:50 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, NULL);
|
2010-04-23 16:00:50 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
return GST_VAAPI_SURFACE_PROXY_SURFACE (proxy);
|
2013-04-16 16:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_flags:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiSurfaceProxyFlags associated with this surface
|
|
|
|
* @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the set of #GstVaapiSurfaceProxyFlags
|
|
|
|
*/
|
|
|
|
guint
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_flags (GstVaapiSurfaceProxy * proxy)
|
2013-04-16 16:35:48 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, 0);
|
|
|
|
|
|
|
|
return GST_VAAPI_SURFACE_PROXY_FLAGS (proxy);
|
2010-04-23 16:00:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 15:59:57 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_surface_id:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the VA surface ID stored in the @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiID
|
|
|
|
*/
|
|
|
|
GstVaapiID
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_surface_id (GstVaapiSurfaceProxy * proxy)
|
2012-01-05 15:59:57 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, VA_INVALID_ID);
|
|
|
|
g_return_val_if_fail (proxy->surface != NULL, VA_INVALID_ID);
|
2012-01-05 15:59:57 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
return GST_VAAPI_SURFACE_PROXY_SURFACE_ID (proxy);
|
2013-04-16 16:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 17:01:35 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_view_id:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the decoded view-id stored in the @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiID
|
|
|
|
*/
|
|
|
|
guintptr
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_view_id (GstVaapiSurfaceProxy * proxy)
|
2014-06-30 17:01:35 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, 0);
|
2014-06-30 17:01:35 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
return GST_VAAPI_SURFACE_PROXY_VIEW_ID (proxy);
|
2014-06-30 17:01:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 16:35:48 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_timestamp:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the presentation timestamp for this surface @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the presentation timestamp
|
|
|
|
*/
|
|
|
|
GstClockTime
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_timestamp (GstVaapiSurfaceProxy * proxy)
|
2013-04-16 16:35:48 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, 0);
|
|
|
|
|
|
|
|
return GST_VAAPI_SURFACE_PROXY_TIMESTAMP (proxy);
|
2013-04-16 16:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_duration:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the presentation duration for this surface @proxy.
|
|
|
|
*
|
|
|
|
* Return value: the presentation duration
|
|
|
|
*/
|
|
|
|
GstClockTime
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_duration (GstVaapiSurfaceProxy * proxy)
|
2013-04-16 16:35:48 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, 0);
|
|
|
|
|
|
|
|
return GST_VAAPI_SURFACE_PROXY_DURATION (proxy);
|
2012-01-05 15:59:57 +00:00
|
|
|
}
|
2013-04-16 11:48:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_set_destroy_notify:
|
|
|
|
* @proxy: a @GstVaapiSurfaceProxy
|
|
|
|
* @destroy_func: a #GDestroyNotify function
|
|
|
|
* @user_data: some extra data to pass to the @destroy_func function
|
|
|
|
*
|
|
|
|
* Sets @destroy_func as the function to call when the surface @proxy
|
|
|
|
* was released. At this point, the proxy object is considered
|
|
|
|
* released, i.e. the underlying data storage is no longer valid and
|
|
|
|
* the callback function shall not expect anything from that.
|
|
|
|
*/
|
|
|
|
void
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_set_destroy_notify (GstVaapiSurfaceProxy * proxy,
|
2013-04-16 11:48:00 +00:00
|
|
|
GDestroyNotify destroy_func, gpointer user_data)
|
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_if_fail (proxy != NULL);
|
2013-04-16 11:48:00 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
proxy->destroy_func = destroy_func;
|
|
|
|
proxy->destroy_data = user_data;
|
2013-04-16 11:48:00 +00:00
|
|
|
}
|
2013-02-15 16:42:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_get_crop_rect:
|
|
|
|
* @proxy: a #GstVaapiSurfaceProxy
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiRectangle stored in the @proxy and that
|
|
|
|
* represents the cropping rectangle for the underlying surface to be
|
|
|
|
* used for rendering.
|
|
|
|
*
|
2013-07-08 12:47:24 +00:00
|
|
|
* If no cropping rectangle was associated with the @proxy, then this
|
|
|
|
* function returns %NULL.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiRectangle, or %NULL if none was
|
|
|
|
* associated with the surface proxy
|
2013-02-15 16:42:12 +00:00
|
|
|
*/
|
|
|
|
const GstVaapiRectangle *
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_get_crop_rect (GstVaapiSurfaceProxy * proxy)
|
2013-02-15 16:42:12 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_val_if_fail (proxy != NULL, NULL);
|
2013-02-15 16:42:12 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
return GST_VAAPI_SURFACE_PROXY_CROP_RECT (proxy);
|
2013-02-15 16:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_proxy_set_crop_rect:
|
|
|
|
* @proxy: #GstVaapiSurfaceProxy
|
|
|
|
* @crop_rect: the #GstVaapiRectangle to be stored in @proxy
|
|
|
|
*
|
|
|
|
* Associates the @crop_rect with the @proxy
|
|
|
|
*/
|
|
|
|
void
|
2015-01-23 15:37:06 +00:00
|
|
|
gst_vaapi_surface_proxy_set_crop_rect (GstVaapiSurfaceProxy * proxy,
|
|
|
|
const GstVaapiRectangle * crop_rect)
|
2013-02-15 16:42:12 +00:00
|
|
|
{
|
2015-01-23 15:37:06 +00:00
|
|
|
g_return_if_fail (proxy != NULL);
|
2013-02-15 16:42:12 +00:00
|
|
|
|
2015-01-23 15:37:06 +00:00
|
|
|
proxy->has_crop_rect = crop_rect != NULL;
|
|
|
|
if (proxy->has_crop_rect)
|
|
|
|
proxy->crop_rect = *crop_rect;
|
2013-02-15 16:42:12 +00:00
|
|
|
}
|