2010-03-04 17:39:01 +00:00
|
|
|
/*
|
|
|
|
* gstvaapiimage.c - VA image abstraction
|
|
|
|
*
|
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) 2011-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-04 17:39:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +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-04 17:39:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-04 17:39:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-05-03 07:07:27 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-04 17:39:01 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +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-04 17:39:01 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
2010-03-24 08:16:32 +00:00
|
|
|
* SECTION:gstvaapiimage
|
|
|
|
* @short_description: VA image abstraction
|
2010-03-19 15:45:21 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-24 16:25:56 +00:00
|
|
|
#include "gstvaapicompat.h"
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
#include "gstvaapiimage.h"
|
2013-07-26 10:57:19 +00:00
|
|
|
#include "gstvaapiimage_priv.h"
|
2013-04-30 15:22:15 +00:00
|
|
|
#include "gstvaapiobject_priv.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-16 17:57:23 +00:00
|
|
|
#define SWAP_UINT(a, b) do { \
|
2010-03-18 08:02:25 +00:00
|
|
|
guint v = a; \
|
2010-03-16 17:57:23 +00:00
|
|
|
a = b; \
|
|
|
|
b = v; \
|
|
|
|
} while (0)
|
|
|
|
|
2010-03-18 12:59:55 +00:00
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_map (GstVaapiImage * image, GstVaapiImageRaw * raw_image);
|
2010-03-18 12:59:55 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
static gboolean _gst_vaapi_image_unmap (GstVaapiImage * image);
|
2010-03-18 12:59:55 +00:00
|
|
|
|
2010-03-18 15:28:59 +00:00
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_set_image (GstVaapiImage * image, const VAImage * va_image);
|
2010-03-18 15:28:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VAImage wrapper
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
vaapi_image_is_linear (const VAImage * va_image)
|
2010-03-18 15:28:59 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guint i, width, height, width2, height2, data_size;
|
|
|
|
|
|
|
|
for (i = 1; i < va_image->num_planes; i++)
|
|
|
|
if (va_image->offsets[i] < va_image->offsets[i - 1])
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
width = va_image->width;
|
|
|
|
height = va_image->height;
|
|
|
|
width2 = (width + 1) / 2;
|
|
|
|
height2 = (height + 1) / 2;
|
|
|
|
|
|
|
|
switch (va_image->format.fourcc) {
|
|
|
|
case VA_FOURCC ('N', 'V', '1', '2'):
|
|
|
|
case VA_FOURCC ('Y', 'V', '1', '2'):
|
|
|
|
case VA_FOURCC ('I', '4', '2', '0'):
|
|
|
|
data_size = width * height + 2 * width2 * height2;
|
|
|
|
break;
|
|
|
|
case VA_FOURCC ('Y', 'U', 'Y', '2'):
|
|
|
|
case VA_FOURCC ('U', 'Y', 'V', 'Y'):
|
2019-04-08 10:29:35 +00:00
|
|
|
case VA_FOURCC ('R', 'G', '1', '6'):
|
2016-02-03 10:50:13 +00:00
|
|
|
data_size = 2 * width * height;
|
|
|
|
break;
|
|
|
|
case VA_FOURCC ('Y', '8', '0', '0'):
|
|
|
|
data_size = width * height;
|
|
|
|
break;
|
|
|
|
case VA_FOURCC ('A', 'Y', 'U', 'V'):
|
|
|
|
case VA_FOURCC ('A', 'R', 'G', 'B'):
|
|
|
|
case VA_FOURCC ('R', 'G', 'B', 'A'):
|
|
|
|
case VA_FOURCC ('A', 'B', 'G', 'R'):
|
|
|
|
case VA_FOURCC ('B', 'G', 'R', 'A'):
|
|
|
|
case VA_FOURCC ('X', 'R', 'G', 'B'):
|
|
|
|
case VA_FOURCC ('R', 'G', 'B', 'X'):
|
|
|
|
case VA_FOURCC ('X', 'B', 'G', 'R'):
|
|
|
|
case VA_FOURCC ('B', 'G', 'R', 'X'):
|
2018-10-24 18:18:37 +00:00
|
|
|
case VA_FOURCC ('Y', '2', '1', '0'):
|
2018-11-27 14:47:44 +00:00
|
|
|
case VA_FOURCC ('Y', '4', '1', '0'):
|
2016-02-03 10:50:13 +00:00
|
|
|
data_size = 4 * width * height;
|
|
|
|
break;
|
2016-03-29 11:34:00 +00:00
|
|
|
case VA_FOURCC ('P', '0', '1', '0'):
|
|
|
|
data_size = 2 * (width * height + 2 * width2 * height2);
|
|
|
|
break;
|
2019-04-16 10:33:54 +00:00
|
|
|
case VA_FOURCC ('R', 'G', '2', '4'):
|
2019-05-30 13:48:51 +00:00
|
|
|
case VA_FOURCC ('4', '4', '4', 'P'):
|
2019-04-16 10:33:54 +00:00
|
|
|
data_size = 3 * width * height;
|
|
|
|
break;
|
2010-03-18 15:28:59 +00:00
|
|
|
default:
|
2018-10-09 15:23:55 +00:00
|
|
|
GST_ERROR ("FIXME: incomplete formats %" GST_FOURCC_FORMAT,
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_FOURCC_ARGS (va_image->format.fourcc));
|
2018-10-09 15:23:55 +00:00
|
|
|
data_size = G_MAXUINT;
|
2016-02-03 10:50:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return va_image->data_size == data_size;
|
2010-03-18 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_destroy (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (image);
|
|
|
|
VAImageID image_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
_gst_vaapi_image_unmap (image);
|
|
|
|
|
|
|
|
image_id = GST_VAAPI_OBJECT_ID (image);
|
|
|
|
GST_DEBUG ("image %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (image_id));
|
|
|
|
|
|
|
|
if (image_id != VA_INVALID_ID) {
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaDestroyImage (GST_VAAPI_DISPLAY_VADISPLAY (display), image_id);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaDestroyImage()"))
|
2018-10-09 15:23:30 +00:00
|
|
|
GST_WARNING ("failed to destroy image %" GST_VAAPI_ID_FORMAT,
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_VAAPI_ID_ARGS (image_id));
|
|
|
|
GST_VAAPI_OBJECT_ID (image) = VA_INVALID_ID;
|
|
|
|
}
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_create (GstVaapiImage * image, GstVideoFormat format)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (image);
|
|
|
|
const VAImageFormat *va_format;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
if (!gst_vaapi_display_has_image_format (display, format))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
va_format = gst_vaapi_video_format_to_va_format (format);
|
|
|
|
if (!va_format)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaCreateImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
(VAImageFormat *) va_format,
|
|
|
|
image->width, image->height, &image->internal_image);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (status != VA_STATUS_SUCCESS ||
|
|
|
|
image->internal_image.format.fourcc != va_format->fourcc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
image->internal_format = format;
|
|
|
|
return TRUE;
|
2010-03-16 08:43:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 10:43:02 +00:00
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_create (GstVaapiImage * image, GstVideoFormat format,
|
2013-04-30 15:22:15 +00:00
|
|
|
guint width, guint height)
|
2010-03-17 10:43:02 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
const VAImageFormat *va_format;
|
|
|
|
VAImageID image_id;
|
|
|
|
|
|
|
|
image->format = format;
|
|
|
|
image->width = width;
|
|
|
|
image->height = height;
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_create (image, format)) {
|
|
|
|
switch (format) {
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
format = GST_VIDEO_FORMAT_YV12;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
format = GST_VIDEO_FORMAT_I420;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = 0;
|
|
|
|
break;
|
2010-03-17 10:43:02 +00:00
|
|
|
}
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!format || !_gst_vaapi_image_create (image, format))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
image->image = image->internal_image;
|
|
|
|
image_id = image->image.image_id;
|
|
|
|
|
|
|
|
if (image->format != image->internal_format) {
|
|
|
|
switch (image->format) {
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
va_format = gst_vaapi_video_format_to_va_format (image->format);
|
|
|
|
if (!va_format)
|
|
|
|
return FALSE;
|
|
|
|
image->image.format = *va_format;
|
|
|
|
SWAP_UINT (image->image.offsets[1], image->image.offsets[2]);
|
|
|
|
SWAP_UINT (image->image.pitches[1], image->image.pitches[2]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-03-17 10:43:02 +00:00
|
|
|
}
|
2016-02-03 10:50:13 +00:00
|
|
|
}
|
|
|
|
image->is_linear = vaapi_image_is_linear (&image->image);
|
2010-03-24 13:19:58 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_DEBUG ("image %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (image_id));
|
|
|
|
GST_VAAPI_OBJECT_ID (image) = image_id;
|
|
|
|
return TRUE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_init (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
image->internal_image.image_id = VA_INVALID_ID;
|
|
|
|
image->internal_image.buf = VA_INVALID_ID;
|
|
|
|
image->image.image_id = VA_INVALID_ID;
|
|
|
|
image->image.buf = VA_INVALID_ID;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_class_init (GstVaapiImageClass * klass)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiObjectClass *const object_class = GST_VAAPI_OBJECT_CLASS (klass);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
object_class->init = (GstVaapiObjectInitFunc) gst_vaapi_image_init;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
#define gst_vaapi_image_finalize gst_vaapi_image_destroy
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE (GstVaapiImage,
|
|
|
|
gst_vaapi_image, gst_vaapi_image_class_init (&g_class))
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_new:
|
|
|
|
* @display: a #GstVaapiDisplay
|
2013-07-09 12:03:01 +00:00
|
|
|
* @format: a #GstVideoFormat
|
2010-03-19 15:45:21 +00:00
|
|
|
* @width: the requested image width
|
|
|
|
* @height: the requested image height
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiImage with the specified format and
|
|
|
|
* dimensions.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiImage object
|
|
|
|
*/
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImage *gst_vaapi_image_new (GstVaapiDisplay * display,
|
|
|
|
GstVideoFormat format, guint width, guint height)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImage *image;
|
2010-03-18 12:56:53 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
2010-03-10 13:13:51 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_DEBUG ("format %s, size %ux%u", gst_vaapi_video_format_to_string (format),
|
|
|
|
width, height);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
image = gst_vaapi_object_new (gst_vaapi_image_class (), display);
|
|
|
|
if (!image)
|
|
|
|
return NULL;
|
2010-03-18 12:56:53 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!gst_vaapi_image_create (image, format, width, height))
|
|
|
|
goto error;
|
|
|
|
return image;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2013-04-30 15:22:15 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
|
|
|
gst_vaapi_object_unref (image);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_new_with_image:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @va_image: a VA image
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiImage from a foreign VA image. The image
|
|
|
|
* format and dimensions will be extracted from @va_image. This
|
|
|
|
* function is mainly used by gst_vaapi_surface_derive_image() to bind
|
|
|
|
* a VA image to a #GstVaapiImage object.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiImage object
|
|
|
|
*/
|
2010-03-18 15:28:59 +00:00
|
|
|
GstVaapiImage *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_new_with_image (GstVaapiDisplay * display, VAImage * va_image)
|
2010-03-18 15:28:59 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImage *image;
|
2010-03-18 15:28:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (va_image, NULL);
|
|
|
|
g_return_val_if_fail (va_image->image_id != VA_INVALID_ID, NULL);
|
|
|
|
g_return_val_if_fail (va_image->buf != VA_INVALID_ID, NULL);
|
2010-03-18 15:28:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_DEBUG ("VA image 0x%08x, format %" GST_FOURCC_FORMAT ", size %ux%u",
|
|
|
|
va_image->image_id,
|
|
|
|
GST_FOURCC_ARGS (va_image->format.fourcc),
|
|
|
|
va_image->width, va_image->height);
|
2010-03-18 15:28:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
image = gst_vaapi_object_new (gst_vaapi_image_class (), display);
|
|
|
|
if (!image)
|
|
|
|
return NULL;
|
2010-03-18 15:28:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_set_image (image, va_image))
|
|
|
|
goto error;
|
|
|
|
return image;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2013-04-30 15:22:15 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
|
|
|
gst_vaapi_object_unref (image);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-18 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 09:49:17 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_id:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Returns the underlying VAImageID of the @image.
|
|
|
|
*
|
|
|
|
* Return value: the underlying VA image id
|
|
|
|
*/
|
2010-03-30 07:39:16 +00:00
|
|
|
GstVaapiID
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_id (GstVaapiImage * image)
|
2010-03-25 09:49:17 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, VA_INVALID_ID);
|
2010-03-25 09:49:17 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return GST_VAAPI_OBJECT_ID (image);
|
2010-03-25 09:49:17 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_image:
|
|
|
|
* @image: a #GstVaapiImage
|
2010-03-23 13:32:36 +00:00
|
|
|
* @va_image: a VA image
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
|
|
|
* Fills @va_image with the VA image used internally.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-16 17:57:23 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_image (GstVaapiImage * image, VAImage * va_image)
|
2010-03-16 17:57:23 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2010-03-16 17:57:23 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (va_image)
|
|
|
|
*va_image = image->image;
|
2010-03-16 17:57:23 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return TRUE;
|
2010-03-16 17:57:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/*
|
|
|
|
* _gst_vaapi_image_set_image:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @va_image: a VA image
|
|
|
|
*
|
|
|
|
* Initializes #GstVaapiImage with a foreign VA image. This function
|
|
|
|
* will try to "linearize" the VA image. i.e. making sure that the VA
|
|
|
|
* image offsets into the data buffer are in increasing order with the
|
|
|
|
* number of planes available in the image.
|
|
|
|
*
|
|
|
|
* This is an internal function used by gst_vaapi_image_new_with_image().
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-18 15:28:59 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_set_image (GstVaapiImage * image, const VAImage * va_image)
|
2010-03-18 15:28:59 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
VAImage alt_va_image;
|
|
|
|
const VAImageFormat *alt_va_format;
|
|
|
|
|
|
|
|
format = gst_vaapi_video_format_from_va_format (&va_image->format);
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
image->internal_image = *va_image;
|
|
|
|
image->internal_format = format;
|
|
|
|
image->is_linear = vaapi_image_is_linear (va_image);
|
|
|
|
image->image = *va_image;
|
|
|
|
image->format = format;
|
|
|
|
image->width = va_image->width;
|
|
|
|
image->height = va_image->height;
|
|
|
|
|
|
|
|
GST_VAAPI_OBJECT_ID (image) = va_image->image_id;
|
|
|
|
|
|
|
|
/* Try to linearize image */
|
|
|
|
if (!image->is_linear) {
|
|
|
|
switch (format) {
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
format = GST_VIDEO_FORMAT_YV12;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
format = GST_VIDEO_FORMAT_I420;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = 0;
|
|
|
|
break;
|
2010-03-18 15:28:59 +00:00
|
|
|
}
|
2016-02-03 10:50:13 +00:00
|
|
|
if (format &&
|
|
|
|
(alt_va_format = gst_vaapi_video_format_to_va_format (format))) {
|
|
|
|
alt_va_image = *va_image;
|
|
|
|
alt_va_image.format = *alt_va_format;
|
|
|
|
SWAP_UINT (alt_va_image.offsets[1], alt_va_image.offsets[2]);
|
|
|
|
SWAP_UINT (alt_va_image.pitches[1], alt_va_image.pitches[2]);
|
|
|
|
if (vaapi_image_is_linear (&alt_va_image)) {
|
|
|
|
image->image = alt_va_image;
|
|
|
|
image->format = format;
|
|
|
|
image->is_linear = TRUE;
|
|
|
|
GST_DEBUG ("linearized image to %s format",
|
|
|
|
gst_vaapi_video_format_to_string (format));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-03-18 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_format:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
2013-07-09 12:03:01 +00:00
|
|
|
* Returns the #GstVideoFormat the @image was created with.
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
2013-07-09 12:03:01 +00:00
|
|
|
* Return value: the #GstVideoFormat
|
2010-03-19 15:45:21 +00:00
|
|
|
*/
|
2013-07-09 12:03:01 +00:00
|
|
|
GstVideoFormat
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_format (GstVaapiImage * image)
|
2010-03-15 15:55:20 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
2010-03-15 15:55:20 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->format;
|
2010-03-15 15:55:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_width:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Returns the @image width.
|
|
|
|
*
|
|
|
|
* Return value: the image width, in pixels
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_width (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->width;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_height:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Returns the @image height.
|
|
|
|
*
|
|
|
|
* Return value: the image height, in pixels.
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_height (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->height;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_size:
|
|
|
|
* @image: a #GstVaapiImage
|
2010-03-23 13:32:36 +00:00
|
|
|
* @pwidth: return location for the width, or %NULL
|
|
|
|
* @pheight: return location for the height, or %NULL
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
|
|
|
* Retrieves the dimensions of a #GstVaapiImage.
|
|
|
|
*/
|
2010-03-15 11:49:03 +00:00
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_size (GstVaapiImage * image, guint * pwidth,
|
|
|
|
guint * pheight)
|
2010-03-15 11:49:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_if_fail (image != NULL);
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (pwidth)
|
|
|
|
*pwidth = image->width;
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (pheight)
|
|
|
|
*pheight = image->height;
|
2010-03-15 11:49:03 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_is_linear:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Checks whether the @image has data planes allocated from a single
|
|
|
|
* buffer and offsets into that buffer are in increasing order with
|
|
|
|
* the number of planes.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if image data planes are allocated from a single buffer
|
|
|
|
*/
|
2010-03-16 17:57:23 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_is_linear (GstVaapiImage * image)
|
2010-03-16 17:57:23 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2010-03-16 17:57:23 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->is_linear;
|
2010-03-16 17:57:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_is_mapped:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Checks whether the @image is currently mapped or not.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the @image is mapped
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
static inline gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_is_mapped (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->image_data != NULL;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_is_mapped (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return _gst_vaapi_image_is_mapped (image);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_map:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Maps the image data buffer. The actual pixels are returned by the
|
|
|
|
* gst_vaapi_image_get_plane() function.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_map (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return _gst_vaapi_image_map (image, NULL);
|
2010-03-18 12:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_map (GstVaapiImage * image, GstVaapiImageRaw * raw_image)
|
2010-03-18 12:59:55 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAStatus status;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (_gst_vaapi_image_is_mapped (image))
|
|
|
|
goto map_success;
|
|
|
|
|
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY (image);
|
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaMapBuffer (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
image->image.buf, (void **) &image->image_data);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaMapBuffer()"))
|
|
|
|
return FALSE;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2012-11-20 13:36:29 +00:00
|
|
|
map_success:
|
2016-02-03 10:50:13 +00:00
|
|
|
if (raw_image) {
|
|
|
|
const VAImage *const va_image = &image->image;
|
|
|
|
raw_image->format = image->format;
|
|
|
|
raw_image->width = va_image->width;
|
|
|
|
raw_image->height = va_image->height;
|
|
|
|
raw_image->num_planes = va_image->num_planes;
|
|
|
|
for (i = 0; i < raw_image->num_planes; i++) {
|
|
|
|
raw_image->pixels[i] = (guchar *) image->image_data +
|
|
|
|
va_image->offsets[i];
|
|
|
|
raw_image->stride[i] = va_image->pitches[i];
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
2016-02-03 10:50:13 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_unmap:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Unmaps the image data buffer. Pointers to pixels returned by
|
|
|
|
* gst_vaapi_image_get_plane() are then no longer valid.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_unmap (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return _gst_vaapi_image_unmap (image);
|
2010-03-18 12:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_unmap (GstVaapiImage * image)
|
2010-03-18 12:59:55 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_is_mapped (image))
|
2010-03-04 17:39:01 +00:00
|
|
|
return TRUE;
|
2016-02-03 10:50:13 +00:00
|
|
|
|
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY (image);
|
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaUnmapBuffer (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
image->image.buf);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaUnmapBuffer()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
image->image_data = NULL;
|
|
|
|
return TRUE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_plane_count:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Retrieves the number of planes available in the @image. The @image
|
|
|
|
* must be mapped for this function to work properly.
|
|
|
|
*
|
|
|
|
* Return value: the number of planes available in the @image
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_plane_count (GstVaapiImage * image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
|
|
|
g_return_val_if_fail (_gst_vaapi_image_is_mapped (image), 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->image.num_planes;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_plane:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @plane: the requested plane number
|
|
|
|
*
|
|
|
|
* Retrieves the pixels data to the specified @plane. The @image must
|
|
|
|
* be mapped for this function to work properly.
|
|
|
|
*
|
|
|
|
* Return value: the pixels data of the specified @plane
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guchar *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_plane (GstVaapiImage * image, guint plane)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, NULL);
|
|
|
|
g_return_val_if_fail (_gst_vaapi_image_is_mapped (image), NULL);
|
|
|
|
g_return_val_if_fail (plane < image->image.num_planes, NULL);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->image_data + image->image.offsets[plane];
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_pitch:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @plane: the requested plane number
|
|
|
|
*
|
|
|
|
* Retrieves the line size (stride) of the specified @plane. The
|
|
|
|
* @image must be mapped for this function to work properly.
|
|
|
|
*
|
|
|
|
* Return value: the line size (stride) of the specified plane
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_pitch (GstVaapiImage * image, guint plane)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
|
|
|
g_return_val_if_fail (_gst_vaapi_image_is_mapped (image), 0);
|
|
|
|
g_return_val_if_fail (plane < image->image.num_planes, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->image.pitches[plane];
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_data_size:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Retrieves the underlying image data size. This function could be
|
|
|
|
* used to determine whether the image has a compatible layout with
|
|
|
|
* another image structure.
|
|
|
|
*
|
|
|
|
* Return value: the whole image data size of the @image
|
|
|
|
*/
|
2010-03-16 17:57:23 +00:00
|
|
|
guint
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_data_size (GstVaapiImage * image)
|
2010-03-16 17:57:23 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, 0);
|
2010-03-16 17:57:23 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return image->image.data_size;
|
2010-03-16 17:57:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:12:18 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
|
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
init_image_from_video_meta (GstVaapiImageRaw * raw_image, GstVideoMeta * vmeta)
|
2012-09-04 12:12:18 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_FIXME ("map from GstVideoMeta + add fini_image_from_buffer()");
|
|
|
|
return FALSE;
|
2012-09-04 12:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
init_image_from_buffer (GstVaapiImageRaw * raw_image, GstBuffer * buffer)
|
2012-09-04 12:12:18 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVideoMeta *const vmeta = gst_buffer_get_video_meta (buffer);
|
2012-09-04 12:12:18 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return vmeta ? init_image_from_video_meta (raw_image, vmeta) : FALSE;
|
2012-09-04 12:12:18 +00:00
|
|
|
}
|
2012-01-04 10:34:34 +00:00
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
/* Copy N lines of an image */
|
|
|
|
static inline void
|
2016-02-03 10:50:13 +00:00
|
|
|
memcpy_pic (guchar * dst,
|
|
|
|
guint dst_stride,
|
|
|
|
const guchar * src, guint src_stride, guint len, guint height)
|
2011-12-12 13:34:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guint i;
|
2011-12-12 13:34:03 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
memcpy (dst, src, len);
|
|
|
|
dst += dst_stride;
|
|
|
|
src += src_stride;
|
|
|
|
}
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy NV12 images */
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_NV12 (GstVaapiImageRaw * dst_image,
|
|
|
|
GstVaapiImageRaw * src_image, const GstVaapiRectangle * rect)
|
2011-12-12 13:34:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guchar *dst, *src;
|
|
|
|
guint dst_stride, src_stride;
|
|
|
|
|
|
|
|
/* Y plane */
|
|
|
|
dst_stride = dst_image->stride[0];
|
|
|
|
dst = dst_image->pixels[0] + rect->y * dst_stride + rect->x;
|
|
|
|
src_stride = src_image->stride[0];
|
|
|
|
src = src_image->pixels[0] + rect->y * src_stride + rect->x;
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, rect->width, rect->height);
|
|
|
|
|
|
|
|
/* UV plane */
|
|
|
|
dst_stride = dst_image->stride[1];
|
|
|
|
dst = dst_image->pixels[1] + (rect->y / 2) * dst_stride + (rect->x & -2);
|
|
|
|
src_stride = src_image->stride[1];
|
|
|
|
src = src_image->pixels[1] + (rect->y / 2) * src_stride + (rect->x & -2);
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, rect->width, rect->height / 2);
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy YV12 images */
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_YV12 (GstVaapiImageRaw * dst_image,
|
|
|
|
GstVaapiImageRaw * src_image, const GstVaapiRectangle * rect)
|
2011-12-12 13:34:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guchar *dst, *src;
|
|
|
|
guint dst_stride, src_stride;
|
|
|
|
guint i, x, y, w, h;
|
|
|
|
|
|
|
|
/* Y plane */
|
|
|
|
dst_stride = dst_image->stride[0];
|
|
|
|
dst = dst_image->pixels[0] + rect->y * dst_stride + rect->x;
|
|
|
|
src_stride = src_image->stride[0];
|
|
|
|
src = src_image->pixels[0] + rect->y * src_stride + rect->x;
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, rect->width, rect->height);
|
|
|
|
|
|
|
|
/* U/V planes */
|
|
|
|
x = rect->x / 2;
|
|
|
|
y = rect->y / 2;
|
|
|
|
w = rect->width / 2;
|
|
|
|
h = rect->height / 2;
|
|
|
|
for (i = 1; i < dst_image->num_planes; i++) {
|
|
|
|
dst_stride = dst_image->stride[i];
|
|
|
|
dst = dst_image->pixels[i] + y * dst_stride + x;
|
|
|
|
src_stride = src_image->stride[i];
|
|
|
|
src = src_image->pixels[i] + y * src_stride + x;
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, w, h);
|
|
|
|
}
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 02:39:03 +00:00
|
|
|
/* Copy YUY2 images */
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_YUY2 (GstVaapiImageRaw * dst_image,
|
|
|
|
GstVaapiImageRaw * src_image, const GstVaapiRectangle * rect)
|
2013-04-24 02:39:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guchar *dst, *src;
|
|
|
|
guint dst_stride, src_stride;
|
|
|
|
|
|
|
|
/* YUV 4:2:2, full vertical resolution */
|
|
|
|
dst_stride = dst_image->stride[0];
|
|
|
|
dst = dst_image->pixels[0] + rect->y * dst_stride + rect->x * 2;
|
|
|
|
src_stride = src_image->stride[0];
|
|
|
|
src = src_image->pixels[0] + rect->y * src_stride + rect->x * 2;
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, rect->width * 2, rect->height);
|
2013-04-24 02:39:03 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
/* Copy RGBA images */
|
|
|
|
static void
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_RGBA (GstVaapiImageRaw * dst_image,
|
|
|
|
GstVaapiImageRaw * src_image, const GstVaapiRectangle * rect)
|
2011-12-12 13:34:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
guchar *dst, *src;
|
|
|
|
guint dst_stride, src_stride;
|
|
|
|
|
|
|
|
dst_stride = dst_image->stride[0];
|
|
|
|
dst = dst_image->pixels[0] + rect->y * dst_stride + rect->x;
|
|
|
|
src_stride = src_image->stride[0];
|
|
|
|
src = src_image->pixels[0] + rect->y * src_stride + rect->x;
|
|
|
|
memcpy_pic (dst, dst_stride, src, src_stride, 4 * rect->width, rect->height);
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image (GstVaapiImageRaw * dst_image,
|
|
|
|
GstVaapiImageRaw * src_image, const GstVaapiRectangle * rect)
|
2011-12-12 13:34:03 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiRectangle default_rect;
|
|
|
|
|
|
|
|
if (dst_image->format != src_image->format ||
|
|
|
|
dst_image->width != src_image->width ||
|
|
|
|
dst_image->height != src_image->height)
|
|
|
|
return FALSE;
|
2011-12-12 13:34:03 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (rect) {
|
|
|
|
if (rect->x >= src_image->width ||
|
|
|
|
rect->x + rect->width > src_image->width ||
|
|
|
|
rect->y >= src_image->height ||
|
|
|
|
rect->y + rect->height > src_image->height)
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
default_rect.x = 0;
|
|
|
|
default_rect.y = 0;
|
|
|
|
default_rect.width = src_image->width;
|
|
|
|
default_rect.height = src_image->height;
|
|
|
|
rect = &default_rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dst_image->format) {
|
2013-07-09 12:03:01 +00:00
|
|
|
case GST_VIDEO_FORMAT_NV12:
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_NV12 (dst_image, src_image, rect);
|
|
|
|
break;
|
2013-07-09 12:03:01 +00:00
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_YV12 (dst_image, src_image, rect);
|
|
|
|
break;
|
2013-04-24 02:39:03 +00:00
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_YUY2 (dst_image, src_image, rect);
|
|
|
|
break;
|
2013-07-09 12:03:01 +00:00
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
2016-02-03 10:50:13 +00:00
|
|
|
copy_image_RGBA (dst_image, src_image, rect);
|
|
|
|
break;
|
2011-12-12 13:34:03 +00:00
|
|
|
default:
|
2016-02-03 10:50:13 +00:00
|
|
|
GST_ERROR ("unsupported image format for copy");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 09:29:48 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_buffer:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
|
|
|
|
* whole image
|
|
|
|
*
|
|
|
|
* Transfers pixels data contained in the @image into the #GstBuffer.
|
|
|
|
* Both image structures shall have the same format.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_buffer (GstVaapiImage * image,
|
|
|
|
GstBuffer * buffer, GstVaapiRectangle * rect)
|
2012-01-05 09:29:48 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImageRaw dst_image, src_image;
|
|
|
|
gboolean success;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!init_image_from_buffer (&dst_image, buffer))
|
|
|
|
return FALSE;
|
|
|
|
if (dst_image.format != image->format)
|
|
|
|
return FALSE;
|
|
|
|
if (dst_image.width != image->width || dst_image.height != image->height)
|
|
|
|
return FALSE;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_map (image, &src_image))
|
|
|
|
return FALSE;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
success = copy_image (&dst_image, &src_image, rect);
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_unmap (image))
|
|
|
|
return FALSE;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return success;
|
2012-01-05 09:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_raw:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @dst_image: a #GstVaapiImageRaw
|
|
|
|
* @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
|
|
|
|
* whole image
|
|
|
|
*
|
|
|
|
* Transfers pixels data contained in the @image into the #GstVaapiImageRaw.
|
|
|
|
* Both image structures shall have the same format.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_get_raw (GstVaapiImage * image,
|
|
|
|
GstVaapiImageRaw * dst_image, GstVaapiRectangle * rect)
|
2012-01-05 09:29:48 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImageRaw src_image;
|
|
|
|
gboolean success;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_map (image, &src_image))
|
|
|
|
return FALSE;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
success = copy_image (dst_image, &src_image, rect);
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_unmap (image))
|
|
|
|
return FALSE;
|
2012-01-05 09:29:48 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return success;
|
2012-01-05 09:29:48 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_update_from_buffer:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @buffer: a #GstBuffer
|
2011-12-12 13:34:03 +00:00
|
|
|
* @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
|
|
|
|
* whole image
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
|
|
|
* Transfers pixels data contained in the #GstBuffer into the
|
|
|
|
* @image. Both image structures shall have the same format.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-15 10:27:10 +00:00
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_update_from_buffer (GstVaapiImage * image,
|
|
|
|
GstBuffer * buffer, GstVaapiRectangle * rect)
|
2010-03-15 10:27:10 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImageRaw dst_image, src_image;
|
|
|
|
gboolean success;
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!init_image_from_buffer (&src_image, buffer))
|
|
|
|
return FALSE;
|
|
|
|
if (src_image.format != image->format)
|
|
|
|
return FALSE;
|
|
|
|
if (src_image.width != image->width || src_image.height != image->height)
|
|
|
|
return FALSE;
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_map (image, &dst_image))
|
|
|
|
return FALSE;
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
success = copy_image (&dst_image, &src_image, rect);
|
2011-12-12 13:34:03 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_unmap (image))
|
|
|
|
return FALSE;
|
2010-03-15 10:27:10 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return success;
|
2010-03-15 10:27:10 +00:00
|
|
|
}
|
2011-12-12 15:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_image_update_from_raw:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
* @src_image: a #GstVaapiImageRaw
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
|
|
|
|
* whole image
|
|
|
|
*
|
|
|
|
* Transfers pixels data contained in the #GstVaapiImageRaw into the
|
|
|
|
* @image. Both image structures shall have the same format.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_update_from_raw (GstVaapiImage * image,
|
|
|
|
GstVaapiImageRaw * src_image, GstVaapiRectangle * rect)
|
2011-12-12 15:34:07 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImageRaw dst_image;
|
|
|
|
gboolean success;
|
2011-12-12 15:34:07 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
2011-12-12 15:34:07 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_map (image, &dst_image))
|
|
|
|
return FALSE;
|
2011-12-12 15:34:07 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
success = copy_image (&dst_image, src_image, rect);
|
2011-12-12 15:34:07 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_unmap (image))
|
|
|
|
return FALSE;
|
2011-12-12 15:34:07 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
return success;
|
2011-12-12 15:34:07 +00:00
|
|
|
}
|
2013-07-26 09:43:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_image_copy:
|
|
|
|
* @dst_image: the target #GstVaapiImage
|
|
|
|
* @src_image: the source #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Copies pixels data from @src_image to @dst_image. Both images shall
|
|
|
|
* have the same format and size.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_image_copy (GstVaapiImage * dst_image, GstVaapiImage * src_image)
|
2013-07-26 09:43:49 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiImageRaw dst_image_raw, src_image_raw;
|
|
|
|
gboolean success = FALSE;
|
2013-07-26 09:43:49 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
g_return_val_if_fail (dst_image != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (src_image != NULL, FALSE);
|
2013-07-26 09:43:49 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
if (!_gst_vaapi_image_map (dst_image, &dst_image_raw))
|
|
|
|
goto end;
|
|
|
|
if (!_gst_vaapi_image_map (src_image, &src_image_raw))
|
|
|
|
goto end;
|
2013-07-26 09:43:49 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
success = copy_image (&dst_image_raw, &src_image_raw, NULL);
|
2013-07-26 09:43:49 +00:00
|
|
|
|
|
|
|
end:
|
2016-02-03 10:50:13 +00:00
|
|
|
_gst_vaapi_image_unmap (src_image);
|
|
|
|
_gst_vaapi_image_unmap (dst_image);
|
|
|
|
return success;
|
2013-07-26 09:43:49 +00:00
|
|
|
}
|