2013-07-22 08:00:21 +00:00
|
|
|
/*
|
|
|
|
* gstvaapipixmap.c - Pixmap abstraction
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2013-07-22 08:00:21 +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.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstvaapipixmap
|
|
|
|
* @short_description: Pixmap abstraction
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
#include "gstvaapipixmap.h"
|
|
|
|
#include "gstvaapipixmap_priv.h"
|
|
|
|
#include "gstvaapisurface_priv.h"
|
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
|
|
|
|
|
|
|
/* Ensure those symbols are actually defined in the resulting libraries */
|
|
|
|
#undef gst_vaapi_pixmap_ref
|
|
|
|
#undef gst_vaapi_pixmap_unref
|
|
|
|
#undef gst_vaapi_pixmap_replace
|
|
|
|
|
|
|
|
static inline GstVaapiPixmap *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_new_internal (const GstVaapiPixmapClass * pixmap_class,
|
|
|
|
GstVaapiDisplay * display)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_assert (pixmap_class->create != NULL);
|
|
|
|
g_assert (pixmap_class->render != NULL);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return gst_vaapi_object_new (GST_VAAPI_OBJECT_CLASS (pixmap_class), display);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstVaapiPixmap *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_new (const GstVaapiPixmapClass * pixmap_class,
|
|
|
|
GstVaapiDisplay * display, GstVideoFormat format, guint width, guint height)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiPixmap *pixmap;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN &&
|
|
|
|
format != GST_VIDEO_FORMAT_ENCODED, NULL);
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
pixmap = gst_vaapi_pixmap_new_internal (pixmap_class, display);
|
|
|
|
if (!pixmap)
|
|
|
|
return NULL;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
pixmap->format = format;
|
|
|
|
pixmap->width = width;
|
|
|
|
pixmap->height = height;
|
|
|
|
if (!pixmap_class->create (pixmap))
|
|
|
|
goto error;
|
|
|
|
return pixmap;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
|
|
|
error:
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_unref_internal (pixmap);
|
|
|
|
return NULL;
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstVaapiPixmap *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_new_from_native (const GstVaapiPixmapClass * pixmap_class,
|
|
|
|
GstVaapiDisplay * display, gpointer native_pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiPixmap *pixmap;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
pixmap = gst_vaapi_pixmap_new_internal (pixmap_class, display);
|
|
|
|
if (!pixmap)
|
|
|
|
return NULL;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_VAAPI_OBJECT_ID (pixmap) = GPOINTER_TO_SIZE (native_pixmap);
|
|
|
|
pixmap->use_foreign_pixmap = TRUE;
|
|
|
|
if (!pixmap_class->create (pixmap))
|
|
|
|
goto error;
|
|
|
|
return pixmap;
|
2013-07-22 08:00:21 +00:00
|
|
|
|
|
|
|
error:
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_unref_internal (pixmap);
|
|
|
|
return NULL;
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_ref:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Atomically increases the reference count of the given @pixmap by one.
|
|
|
|
*
|
|
|
|
* Returns: The same @pixmap argument
|
|
|
|
*/
|
|
|
|
GstVaapiPixmap *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_ref (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
return gst_vaapi_pixmap_ref_internal (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_unref:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Atomically decreases the reference count of the @pixmap by one. If
|
|
|
|
* the reference count reaches zero, the pixmap will be free'd.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_unref (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_unref_internal (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_replace:
|
|
|
|
* @old_pixmap_ptr: a pointer to a #GstVaapiPixmap
|
|
|
|
* @new_pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Atomically replaces the pixmap pixmap held in @old_pixmap_ptr with
|
|
|
|
* @new_pixmap. This means that @old_pixmap_ptr shall reference a
|
|
|
|
* valid pixmap. However, @new_pixmap can be NULL.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_replace (GstVaapiPixmap ** old_pixmap_ptr,
|
|
|
|
GstVaapiPixmap * new_pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_replace_internal (old_pixmap_ptr, new_pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_get_display:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiDisplay this @pixmap is bound to.
|
|
|
|
*
|
|
|
|
* Return value: the parent #GstVaapiDisplay object
|
|
|
|
*/
|
|
|
|
GstVaapiDisplay *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_get_display (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (pixmap != NULL, NULL);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return GST_VAAPI_OBJECT_DISPLAY (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_get_format:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Retrieves the format of a #GstVaapiPixmap.
|
|
|
|
*
|
|
|
|
* Return value: the format of the @pixmap
|
|
|
|
*/
|
|
|
|
GstVideoFormat
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_get_format (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (pixmap != NULL, GST_VIDEO_FORMAT_UNKNOWN);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return GST_VAAPI_PIXMAP_FORMAT (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_get_width:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Retrieves the width of a #GstVaapiPixmap.
|
|
|
|
*
|
|
|
|
* Return value: the width of the @pixmap, in pixels
|
|
|
|
*/
|
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_get_width (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (pixmap != NULL, 0);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return GST_VAAPI_PIXMAP_WIDTH (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_get_height:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Retrieves the height of a #GstVaapiPixmap
|
|
|
|
*
|
|
|
|
* Return value: the height of the @pixmap, in pixels
|
|
|
|
*/
|
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_get_height (GstVaapiPixmap * pixmap)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (pixmap != NULL, 0);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return GST_VAAPI_PIXMAP_HEIGHT (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_get_size:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
* @width: return location for the width, or %NULL
|
|
|
|
* @height: return location for the height, or %NULL
|
|
|
|
*
|
|
|
|
* Retrieves the dimensions of a #GstVaapiPixmap.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_get_size (GstVaapiPixmap * pixmap, guint * width,
|
|
|
|
guint * height)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_if_fail (pixmap != NULL);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (width)
|
|
|
|
*width = GST_VAAPI_PIXMAP_WIDTH (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (height)
|
|
|
|
*height = GST_VAAPI_PIXMAP_HEIGHT (pixmap);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_pixmap_put_surface:
|
|
|
|
* @pixmap: a #GstVaapiPixmap
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @crop_rect: the video cropping rectangle, or %NULL if the entire
|
|
|
|
* surface is to be used.
|
|
|
|
* @flags: postprocessing flags. See #GstVaapiSurfaceRenderFlags
|
|
|
|
*
|
|
|
|
* Renders the whole @surface, or a cropped region defined with
|
|
|
|
* @crop_rect, into the @pixmap, while scaling to fit the target
|
|
|
|
* pixmap. The @flags specify how de-interlacing (if needed), color
|
|
|
|
* space conversion, scaling and other postprocessing transformations
|
|
|
|
* are performed.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_pixmap_put_surface (GstVaapiPixmap * pixmap,
|
|
|
|
GstVaapiSurface * surface, const GstVaapiRectangle * crop_rect, guint flags)
|
2013-07-22 08:00:21 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiRectangle src_rect;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pixmap != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!crop_rect) {
|
|
|
|
src_rect.x = 0;
|
|
|
|
src_rect.y = 0;
|
|
|
|
src_rect.width = GST_VAAPI_SURFACE_WIDTH (surface);
|
|
|
|
src_rect.height = GST_VAAPI_SURFACE_HEIGHT (surface);
|
|
|
|
crop_rect = &src_rect;
|
|
|
|
}
|
|
|
|
return GST_VAAPI_PIXMAP_GET_CLASS (pixmap)->render (pixmap, surface,
|
|
|
|
crop_rect, flags);
|
2013-07-22 08:00:21 +00:00
|
|
|
}
|