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
|
2012-01-16 10:03:51 +00:00
|
|
|
* Copyright (C) 2011-2012 Intel Corporation
|
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-04 17:39:01 +00:00
|
|
|
#include <string.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-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
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
typedef struct _GstVaapiImageClass GstVaapiImageClass;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
/**
|
|
|
|
* GstVaapiImage:
|
|
|
|
*
|
|
|
|
* A VA image wrapper
|
|
|
|
*/
|
|
|
|
struct _GstVaapiImage {
|
|
|
|
/*< private >*/
|
|
|
|
GstVaapiObject parent_instance;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-17 10:43:02 +00:00
|
|
|
VAImage internal_image;
|
2010-03-04 17:39:01 +00:00
|
|
|
VAImage image;
|
|
|
|
guchar *image_data;
|
2010-03-16 08:43:16 +00:00
|
|
|
GstVaapiImageFormat internal_format;
|
2010-03-15 10:27:10 +00:00
|
|
|
GstVaapiImageFormat format;
|
2010-03-04 17:39:01 +00:00
|
|
|
guint width;
|
|
|
|
guint height;
|
2010-03-17 10:43:02 +00:00
|
|
|
guint is_linear : 1;
|
2010-03-04 17:39:01 +00:00
|
|
|
};
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
/**
|
|
|
|
* GstVaapiImageClass:
|
|
|
|
*
|
|
|
|
* A VA image wrapper class
|
|
|
|
*/
|
|
|
|
struct _GstVaapiImageClass {
|
|
|
|
/*< private >*/
|
|
|
|
GstVaapiObjectClass parent_class;
|
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
|
2011-12-12 13:34:03 +00:00
|
|
|
_gst_vaapi_image_map(GstVaapiImage *image, GstVaapiImageRaw *raw_image);
|
2010-03-18 12:59:55 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gst_vaapi_image_unmap(GstVaapiImage *image);
|
|
|
|
|
2010-03-18 15:28:59 +00:00
|
|
|
static gboolean
|
|
|
|
_gst_vaapi_image_set_image(GstVaapiImage *image, const VAImage *va_image);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VAImage wrapper
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
vaapi_image_is_linear(const VAImage *va_image)
|
|
|
|
{
|
|
|
|
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;
|
2010-03-24 14:46:33 +00:00
|
|
|
case VA_FOURCC('A','Y','U','V'):
|
2010-03-18 15:28:59 +00:00
|
|
|
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'):
|
|
|
|
data_size = 4 * width * height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error("FIXME: incomplete formats");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return va_image->data_size == data_size;
|
|
|
|
}
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_image_destroy(GstVaapiImage *image)
|
|
|
|
{
|
2010-03-24 17:40:19 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(image);
|
2010-03-24 13:19:58 +00:00
|
|
|
VAImageID image_id;
|
2010-03-04 17:39:01 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-18 12:59:55 +00:00
|
|
|
_gst_vaapi_image_unmap(image);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
image_id = GST_VAAPI_OBJECT_ID(image);
|
|
|
|
GST_DEBUG("image %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(image_id));
|
2010-03-23 10:49:33 +00:00
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
if (image_id != VA_INVALID_ID) {
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-24 13:19:58 +00:00
|
|
|
status = vaDestroyImage(GST_VAAPI_DISPLAY_VADISPLAY(display), image_id);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!vaapi_check_status(status, "vaDestroyImage()"))
|
2010-03-24 15:12:56 +00:00
|
|
|
g_warning("failed to destroy image %" GST_VAAPI_ID_FORMAT,
|
2010-03-24 13:19:58 +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
|
2010-03-16 08:43:16 +00:00
|
|
|
_gst_vaapi_image_create(GstVaapiImage *image, GstVaapiImageFormat format)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2010-03-24 17:40:19 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(image);
|
2010-03-16 08:43:16 +00:00
|
|
|
const VAImageFormat *va_format;
|
2010-03-04 17:39:01 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!gst_vaapi_display_has_image_format(display, format))
|
2010-03-04 17:39:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-03-16 08:43:16 +00:00
|
|
|
va_format = gst_vaapi_image_format_get_va_format(format);
|
|
|
|
if (!va_format)
|
|
|
|
return FALSE;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
status = vaCreateImage(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-16 08:43:16 +00:00
|
|
|
(VAImageFormat *)va_format,
|
2013-04-30 15:22:15 +00:00
|
|
|
image->width,
|
|
|
|
image->height,
|
|
|
|
&image->internal_image
|
2010-03-04 17:39:01 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-17 10:43:02 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS ||
|
2013-04-30 15:22:15 +00:00
|
|
|
image->internal_image.format.fourcc != va_format->fourcc)
|
2010-03-17 10:43:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
image->internal_format = format;
|
2010-03-17 10:43:02 +00:00
|
|
|
return TRUE;
|
2010-03-16 08:43:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 10:43:02 +00:00
|
|
|
static gboolean
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_image_create(GstVaapiImage *image, GstVaapiImageFormat format,
|
|
|
|
guint width, guint height)
|
2010-03-17 10:43:02 +00:00
|
|
|
{
|
|
|
|
const VAImageFormat *va_format;
|
2010-03-24 13:19:58 +00:00
|
|
|
VAImageID image_id;
|
2010-03-17 10:43:02 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
image->format = format;
|
|
|
|
image->width = width;
|
|
|
|
image->height = height;
|
2010-03-18 15:52:20 +00:00
|
|
|
|
2010-03-17 10:43:02 +00:00
|
|
|
if (!_gst_vaapi_image_create(image, format)) {
|
|
|
|
switch (format) {
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
|
|
|
format = GST_VAAPI_IMAGE_YV12;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
format = GST_VAAPI_IMAGE_I420;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!format || !_gst_vaapi_image_create(image, format))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-30 15:22:15 +00:00
|
|
|
image->image = image->internal_image;
|
|
|
|
image_id = image->image.image_id;
|
2010-03-17 10:43:02 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (image->format != image->internal_format) {
|
|
|
|
switch (image->format) {
|
2010-03-17 10:43:02 +00:00
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
2013-04-30 15:22:15 +00:00
|
|
|
va_format = gst_vaapi_image_format_get_va_format(image->format);
|
2010-03-17 10:43:02 +00:00
|
|
|
if (!va_format)
|
|
|
|
return FALSE;
|
2013-04-30 15:22:15 +00:00
|
|
|
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]);
|
2010-03-17 10:43:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 15:22:15 +00:00
|
|
|
image->is_linear = vaapi_image_is_linear(&image->image);
|
2010-03-24 13:19:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG("image %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(image_id));
|
|
|
|
GST_VAAPI_OBJECT_ID(image) = image_id;
|
2010-03-04 17:39:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_image_init(GstVaapiImage *image)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_class_init(GstVaapiImageClass *klass)
|
|
|
|
{
|
2013-04-30 15:22:15 +00:00
|
|
|
GstVaapiObjectClass * const object_class =
|
|
|
|
GST_VAAPI_OBJECT_CLASS(klass);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE(
|
|
|
|
GstVaapiImage,
|
|
|
|
gst_vaapi_image,
|
|
|
|
gst_vaapi_image_class_init(&g_class))
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_new:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @format: a #GstVaapiImageFormat
|
|
|
|
* @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
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
GstVaapiImage *
|
|
|
|
gst_vaapi_image_new(
|
|
|
|
GstVaapiDisplay *display,
|
2010-03-15 10:27:10 +00:00
|
|
|
GstVaapiImageFormat format,
|
2010-03-04 17:39:01 +00:00
|
|
|
guint width,
|
2010-03-15 10:27:10 +00:00
|
|
|
guint height
|
2010-03-04 17:39:01 +00:00
|
|
|
)
|
|
|
|
{
|
2010-03-18 12:56:53 +00:00
|
|
|
GstVaapiImage *image;
|
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
g_return_val_if_fail(width > 0, NULL);
|
|
|
|
g_return_val_if_fail(height > 0, NULL);
|
|
|
|
|
2010-03-15 16:13:37 +00:00
|
|
|
GST_DEBUG("format %" GST_FOURCC_FORMAT ", size %ux%u",
|
|
|
|
GST_FOURCC_ARGS(format), width, height);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
image = gst_vaapi_object_new(gst_vaapi_image_class(), display);
|
2010-03-18 12:56:53 +00:00
|
|
|
if (!image)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!gst_vaapi_image_create(image, format, width, height))
|
|
|
|
goto error;
|
2010-03-18 12:56:53 +00:00
|
|
|
return image;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
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 *
|
|
|
|
gst_vaapi_image_new_with_image(GstVaapiDisplay *display, VAImage *va_image)
|
|
|
|
{
|
|
|
|
GstVaapiImage *image;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
image = gst_vaapi_object_new(gst_vaapi_image_class(), display);
|
2010-03-18 15:28:59 +00:00
|
|
|
if (!image)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!_gst_vaapi_image_set_image(image, va_image))
|
|
|
|
goto error;
|
2010-03-18 15:28:59 +00:00
|
|
|
return image;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
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
|
2010-03-25 09:49:17 +00:00
|
|
|
gst_vaapi_image_get_id(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), VA_INVALID_ID);
|
|
|
|
|
|
|
|
return GST_VAAPI_OBJECT_ID(image);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_image_get_image(GstVaapiImage *image, VAImage *va_image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
2010-03-17 10:43:02 +00:00
|
|
|
if (va_image)
|
2013-04-30 15:22:15 +00:00
|
|
|
*va_image = image->image;
|
2010-03-16 17:57:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
_gst_vaapi_image_set_image(GstVaapiImage *image, const VAImage *va_image)
|
|
|
|
{
|
|
|
|
GstVaapiImageFormat format;
|
|
|
|
VAImage alt_va_image;
|
|
|
|
const VAImageFormat *alt_va_format;
|
|
|
|
|
|
|
|
format = gst_vaapi_image_format(&va_image->format);
|
|
|
|
if (!format)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
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;
|
2010-03-18 15:28:59 +00:00
|
|
|
|
|
|
|
/* Try to linearize image */
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!image->is_linear) {
|
2010-03-18 15:28:59 +00:00
|
|
|
switch (format) {
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
|
|
|
format = GST_VAAPI_IMAGE_YV12;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
format = GST_VAAPI_IMAGE_I420;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (format &&
|
|
|
|
(alt_va_format = gst_vaapi_image_format_get_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)) {
|
2013-04-30 15:22:15 +00:00
|
|
|
image->image = alt_va_image;
|
|
|
|
image->format = format;
|
|
|
|
image->is_linear = TRUE;
|
2010-03-18 15:28:59 +00:00
|
|
|
GST_DEBUG("linearized image to %" GST_FOURCC_FORMAT " format",
|
|
|
|
GST_FOURCC_ARGS(format));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_image_get_format:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiImageFormat the @image was created with.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiImageFormat
|
|
|
|
*/
|
2010-03-15 15:55:20 +00:00
|
|
|
GstVaapiImageFormat
|
|
|
|
gst_vaapi_image_get_format(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_get_width(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_get_height(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_get_size(GstVaapiImage *image, guint *pwidth, guint *pheight)
|
|
|
|
{
|
2010-03-15 14:57:30 +00:00
|
|
|
g_return_if_fail(GST_VAAPI_IS_IMAGE(image));
|
2010-03-15 11:49:03 +00:00
|
|
|
|
|
|
|
if (pwidth)
|
2013-04-30 15:22:15 +00:00
|
|
|
*pwidth = image->width;
|
2010-03-15 11:49:03 +00:00
|
|
|
|
|
|
|
if (pheight)
|
2013-04-30 15:22:15 +00:00
|
|
|
*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
|
|
|
|
gst_vaapi_image_is_linear(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
_gst_vaapi_image_is_mapped(GstVaapiImage *image)
|
|
|
|
{
|
2013-04-30 15:22:15 +00:00
|
|
|
return image->image_data != NULL;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_image_is_mapped(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
|
|
|
return _gst_vaapi_image_is_mapped(image);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_image_map(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
return _gst_vaapi_image_map(image, NULL);
|
2010-03-18 12:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-12-12 13:34:03 +00:00
|
|
|
_gst_vaapi_image_map(GstVaapiImage *image, GstVaapiImageRaw *raw_image)
|
2010-03-18 12:59:55 +00:00
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-18 12:59:55 +00:00
|
|
|
VAStatus status;
|
2011-12-12 13:34:03 +00:00
|
|
|
guint i;
|
2010-03-18 12:59:55 +00:00
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
if (_gst_vaapi_image_is_mapped(image))
|
2012-11-20 13:36:29 +00:00
|
|
|
goto map_success;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(image);
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
status = vaMapBuffer(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2013-04-30 15:22:15 +00:00
|
|
|
image->image.buf,
|
|
|
|
(void **)&image->image_data
|
2010-03-04 17:39:01 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!vaapi_check_status(status, "vaMapBuffer()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-11-20 13:36:29 +00:00
|
|
|
map_success:
|
2011-12-12 13:34:03 +00:00
|
|
|
if (raw_image) {
|
2013-04-30 15:22:15 +00:00
|
|
|
const VAImage * const va_image = &image->image;
|
|
|
|
raw_image->format = image->format;
|
2011-12-12 13:34:03 +00:00
|
|
|
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++) {
|
2013-04-30 15:22:15 +00:00
|
|
|
raw_image->pixels[i] = (guchar *)image->image_data +
|
2012-11-20 13:36:29 +00:00
|
|
|
va_image->offsets[i];
|
2011-12-12 13:34:03 +00:00
|
|
|
raw_image->stride[i] = va_image->pitches[i];
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 17:39:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_image_unmap(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
2010-03-18 12:59:55 +00:00
|
|
|
return _gst_vaapi_image_unmap(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gst_vaapi_image_unmap(GstVaapiImage *image)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-18 12:59:55 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!_gst_vaapi_image_is_mapped(image))
|
2012-11-20 13:36:29 +00:00
|
|
|
return TRUE;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(image);
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
status = vaUnmapBuffer(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2013-04-30 15:22:15 +00:00
|
|
|
image->image.buf
|
2010-03-04 17:39:01 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!vaapi_check_status(status, "vaUnmapBuffer()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
image->image_data = NULL;
|
2010-03-04 17:39:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_image_get_plane_count(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), 0);
|
|
|
|
|
2013-04-30 15:22:15 +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 *
|
|
|
|
gst_vaapi_image_get_plane(GstVaapiImage *image, guint plane)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
|
|
|
|
g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), NULL);
|
2013-04-30 15:22:15 +00:00
|
|
|
g_return_val_if_fail(plane < image->image.num_planes, NULL);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_get_pitch(GstVaapiImage *image, guint plane)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), 0);
|
2013-04-30 15:22:15 +00:00
|
|
|
g_return_val_if_fail(plane < image->image.num_planes, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +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
|
|
|
|
gst_vaapi_image_get_data_size(GstVaapiImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
return image->image.data_size;
|
2010-03-16 17:57:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:12:18 +00:00
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
init_image_from_video_meta(GstVaapiImageRaw *raw_image, GstVideoMeta *vmeta)
|
|
|
|
{
|
|
|
|
GST_FIXME("map from GstVideoMeta + add fini_image_from_buffer()");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
init_image_from_buffer(GstVaapiImageRaw *raw_image, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstVideoMeta * const vmeta = gst_buffer_get_video_meta(buffer);
|
|
|
|
|
|
|
|
return vmeta ? init_image_from_video_meta(raw_image, vmeta) : FALSE;
|
|
|
|
}
|
|
|
|
#else
|
2012-01-04 10:34:34 +00:00
|
|
|
static gboolean
|
|
|
|
init_image_from_buffer(GstVaapiImageRaw *raw_image, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstVaapiImageFormat format;
|
|
|
|
guint width2, height2, size2;
|
|
|
|
gint width, height;
|
|
|
|
guchar *data;
|
|
|
|
guint32 data_size;
|
|
|
|
|
|
|
|
data = GST_BUFFER_DATA(buffer);
|
|
|
|
data_size = GST_BUFFER_SIZE(buffer);
|
|
|
|
caps = GST_BUFFER_CAPS(buffer);
|
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
format = gst_vaapi_image_format_from_caps(caps);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure(caps, 0);
|
|
|
|
gst_structure_get_int(structure, "width", &width);
|
|
|
|
gst_structure_get_int(structure, "height", &height);
|
|
|
|
|
|
|
|
/* XXX: copied from gst_video_format_get_row_stride() -- no NV12? */
|
|
|
|
raw_image->format = format;
|
|
|
|
raw_image->width = width;
|
|
|
|
raw_image->height = height;
|
|
|
|
width2 = (width + 1) / 2;
|
|
|
|
height2 = (height + 1) / 2;
|
|
|
|
size2 = 0;
|
|
|
|
switch (format) {
|
|
|
|
case GST_VAAPI_IMAGE_NV12:
|
|
|
|
raw_image->num_planes = 2;
|
|
|
|
raw_image->pixels[0] = data;
|
|
|
|
raw_image->stride[0] = GST_ROUND_UP_4(width);
|
|
|
|
size2 += height * raw_image->stride[0];
|
|
|
|
raw_image->pixels[1] = data + size2;
|
|
|
|
raw_image->stride[1] = raw_image->stride[0];
|
|
|
|
size2 += height2 * raw_image->stride[1];
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
|
|
|
raw_image->num_planes = 3;
|
|
|
|
raw_image->pixels[0] = data;
|
|
|
|
raw_image->stride[0] = GST_ROUND_UP_4(width);
|
|
|
|
size2 += height * raw_image->stride[0];
|
|
|
|
raw_image->pixels[1] = data + size2;
|
|
|
|
raw_image->stride[1] = GST_ROUND_UP_4(width2);
|
|
|
|
size2 += height2 * raw_image->stride[1];
|
|
|
|
raw_image->pixels[2] = data + size2;
|
|
|
|
raw_image->stride[2] = raw_image->stride[1];
|
|
|
|
size2 += height2 * raw_image->stride[2];
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_ARGB:
|
|
|
|
case GST_VAAPI_IMAGE_RGBA:
|
|
|
|
case GST_VAAPI_IMAGE_ABGR:
|
|
|
|
case GST_VAAPI_IMAGE_BGRA:
|
|
|
|
raw_image->num_planes = 1;
|
|
|
|
raw_image->pixels[0] = data;
|
|
|
|
raw_image->stride[0] = width * 4;
|
|
|
|
size2 += height * raw_image->stride[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error("could not compute row-stride for %" GST_FOURCC_FORMAT,
|
|
|
|
GST_FOURCC_ARGS(format));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size2 != data_size) {
|
|
|
|
g_error("data_size mismatch %d / %u", size2, data_size);
|
|
|
|
if (size2 > data_size)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-09-04 12:12:18 +00:00
|
|
|
#endif
|
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
|
|
|
|
memcpy_pic(
|
|
|
|
guchar *dst,
|
|
|
|
guint dst_stride,
|
|
|
|
const guchar *src,
|
|
|
|
guint src_stride,
|
|
|
|
guint len,
|
|
|
|
guint height
|
|
|
|
)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
memcpy(dst, src, len);
|
|
|
|
dst += dst_stride;
|
2012-02-15 13:08:44 +00:00
|
|
|
src += src_stride;
|
2011-12-12 13:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy NV12 images */
|
|
|
|
static void
|
|
|
|
copy_image_NV12(
|
|
|
|
GstVaapiImageRaw *dst_image,
|
|
|
|
GstVaapiImageRaw *src_image,
|
|
|
|
const GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy YV12 images */
|
|
|
|
static void
|
|
|
|
copy_image_YV12(
|
|
|
|
GstVaapiImageRaw *dst_image,
|
|
|
|
GstVaapiImageRaw *src_image,
|
|
|
|
const GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy RGBA images */
|
|
|
|
static void
|
|
|
|
copy_image_RGBA(
|
|
|
|
GstVaapiImageRaw *dst_image,
|
|
|
|
GstVaapiImageRaw *src_image,
|
|
|
|
const GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
copy_image(
|
|
|
|
GstVaapiImageRaw *dst_image,
|
|
|
|
GstVaapiImageRaw *src_image,
|
|
|
|
const GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiRectangle default_rect;
|
|
|
|
|
|
|
|
if (dst_image->format != src_image->format ||
|
|
|
|
dst_image->width != src_image->width ||
|
|
|
|
dst_image->height != src_image->height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
if (rect->x >= src_image->width ||
|
|
|
|
rect->x + src_image->width > src_image->width ||
|
|
|
|
rect->y >= src_image->height ||
|
|
|
|
rect->y + src_image->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) {
|
|
|
|
case GST_VAAPI_IMAGE_NV12:
|
|
|
|
copy_image_NV12(dst_image, src_image, rect);
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
|
|
|
copy_image_YV12(dst_image, src_image, rect);
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_ARGB:
|
|
|
|
case GST_VAAPI_IMAGE_RGBA:
|
|
|
|
case GST_VAAPI_IMAGE_ABGR:
|
|
|
|
case GST_VAAPI_IMAGE_BGRA:
|
|
|
|
copy_image_RGBA(dst_image, src_image, rect);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ERROR("unsupported image format for copy");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_image_get_buffer(
|
|
|
|
GstVaapiImage *image,
|
|
|
|
GstBuffer *buffer,
|
|
|
|
GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiImageRaw dst_image, src_image;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
g_return_val_if_fail(GST_IS_BUFFER(buffer), FALSE);
|
|
|
|
|
|
|
|
if (!init_image_from_buffer(&dst_image, buffer))
|
|
|
|
return FALSE;
|
2013-04-30 15:22:15 +00:00
|
|
|
if (dst_image.format != image->format)
|
2012-01-05 09:29:48 +00:00
|
|
|
return FALSE;
|
2013-04-30 15:22:15 +00:00
|
|
|
if (dst_image.width != image->width || dst_image.height != image->height)
|
2012-01-05 09:29:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_map(image, &src_image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
success = copy_image(&dst_image, &src_image, rect);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_unmap(image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
gst_vaapi_image_get_raw(
|
|
|
|
GstVaapiImage *image,
|
|
|
|
GstVaapiImageRaw *dst_image,
|
|
|
|
GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiImageRaw src_image;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_map(image, &src_image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
success = copy_image(dst_image, &src_image, rect);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_unmap(image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
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
|
2011-12-12 13:34:03 +00:00
|
|
|
gst_vaapi_image_update_from_buffer(
|
|
|
|
GstVaapiImage *image,
|
|
|
|
GstBuffer *buffer,
|
|
|
|
GstVaapiRectangle *rect
|
|
|
|
)
|
2010-03-15 10:27:10 +00:00
|
|
|
{
|
2011-12-12 13:34:03 +00:00
|
|
|
GstVaapiImageRaw dst_image, src_image;
|
|
|
|
gboolean success;
|
2010-03-15 10:27:10 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
g_return_val_if_fail(GST_IS_BUFFER(buffer), FALSE);
|
|
|
|
|
2012-01-04 10:34:34 +00:00
|
|
|
if (!init_image_from_buffer(&src_image, buffer))
|
2010-03-15 10:27:10 +00:00
|
|
|
return FALSE;
|
2013-04-30 15:22:15 +00:00
|
|
|
if (src_image.format != image->format)
|
2010-03-15 10:27:10 +00:00
|
|
|
return FALSE;
|
2013-04-30 15:22:15 +00:00
|
|
|
if (src_image.width != image->width || src_image.height != image->height)
|
2010-03-15 10:27:10 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
if (!_gst_vaapi_image_map(image, &dst_image))
|
2010-03-15 10:27:10 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-12-12 13:34:03 +00:00
|
|
|
success = copy_image(&dst_image, &src_image, rect);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_unmap(image))
|
2010-03-15 10:27:10 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-12-12 13:34:03 +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
|
|
|
|
gst_vaapi_image_update_from_raw(
|
|
|
|
GstVaapiImage *image,
|
|
|
|
GstVaapiImageRaw *src_image,
|
|
|
|
GstVaapiRectangle *rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiImageRaw dst_image;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_map(image, &dst_image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
success = copy_image(&dst_image, src_image, rect);
|
|
|
|
|
|
|
|
if (!_gst_vaapi_image_unmap(image))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|