2010-01-25 16:15:01 +00:00
|
|
|
/*
|
2010-03-16 09:18:57 +00:00
|
|
|
* gstvaapiutils.c - VA-API utilities
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-01-25 16:15:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-14 11:51:41 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-01-25 16:15:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-01-25 16:15:01 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-24 16:17:49 +00:00
|
|
|
#include "gstvaapicompat.h"
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-03-21 08:38:17 +00:00
|
|
|
#include "gstvaapisurface.h"
|
2013-01-04 08:41:25 +00:00
|
|
|
#include "gstvaapisubpicture.h"
|
2013-07-29 01:23:50 +00:00
|
|
|
#include "gstvaapifilter.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2013-07-29 01:23:50 +00:00
|
|
|
#if USE_VA_VPP
|
|
|
|
# include <va/va_vpp.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-30 12:55:27 +00:00
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2012-01-13 11:09:07 +00:00
|
|
|
#define CONCAT(a, b) CONCAT_(a, b)
|
|
|
|
#define CONCAT_(a, b) a##b
|
|
|
|
#define STRINGIFY(x) STRINGIFY_(x)
|
|
|
|
#define STRINGIFY_(x) #x
|
|
|
|
#define STRCASEP(p, x) STRCASE(CONCAT(p, x))
|
|
|
|
#define STRCASE(x) case x: return STRINGIFY(x)
|
|
|
|
|
2017-01-12 11:49:55 +00:00
|
|
|
#if VA_CHECK_VERSION (0,40,0)
|
2017-01-11 15:04:24 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_log (const char *message)
|
|
|
|
{
|
|
|
|
gchar *msg;
|
|
|
|
|
|
|
|
msg = g_strdup (message);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
g_strchomp (msg);
|
|
|
|
GST_INFO ("%s", msg);
|
|
|
|
g_free (msg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
vaapi_initialize (VADisplay dpy)
|
|
|
|
{
|
|
|
|
gint major_version, minor_version;
|
|
|
|
VAStatus status;
|
|
|
|
|
2017-01-12 11:49:55 +00:00
|
|
|
#if VA_CHECK_VERSION (0,40,0)
|
2017-01-11 15:04:24 +00:00
|
|
|
vaSetInfoCallback (gst_vaapi_log);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
status = vaInitialize (dpy, &major_version, &minor_version);
|
|
|
|
if (!vaapi_check_status (status, "vaInitialize()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_INFO ("VA-API version %d.%d", major_version, minor_version);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
/* Check VA status for success or print out an error */
|
2010-03-30 12:55:27 +00:00
|
|
|
gboolean
|
2014-01-23 16:41:02 +00:00
|
|
|
vaapi_check_status (VAStatus status, const gchar * msg)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
|
|
|
GST_DEBUG ("%s: %s", msg, vaErrorStr (status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 15:29:41 +00:00
|
|
|
/* Maps VA buffer */
|
2014-01-23 16:41:02 +00:00
|
|
|
gpointer
|
|
|
|
vaapi_map_buffer (VADisplay dpy, VABufferID buf_id)
|
2011-08-04 15:29:41 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
VAStatus status;
|
|
|
|
gpointer data = NULL;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
status = vaMapBuffer (dpy, buf_id, &data);
|
|
|
|
if (!vaapi_check_status (status, "vaMapBuffer()"))
|
|
|
|
return NULL;
|
|
|
|
return data;
|
2011-08-04 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unmaps VA buffer */
|
|
|
|
void
|
2014-01-23 16:41:02 +00:00
|
|
|
vaapi_unmap_buffer (VADisplay dpy, VABufferID buf_id, gpointer * pbuf)
|
2011-08-04 15:29:41 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
VAStatus status;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (pbuf)
|
|
|
|
*pbuf = NULL;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
status = vaUnmapBuffer (dpy, buf_id);
|
|
|
|
if (!vaapi_check_status (status, "vaUnmapBuffer()"))
|
|
|
|
return;
|
2011-08-04 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates and maps VA buffer */
|
2012-01-30 09:15:32 +00:00
|
|
|
gboolean
|
2014-01-23 16:41:02 +00:00
|
|
|
vaapi_create_buffer (VADisplay dpy, VAContextID ctx, int type, guint size,
|
|
|
|
gconstpointer buf, VABufferID * buf_id_ptr, gpointer * mapped_data)
|
2011-08-04 15:29:41 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
VABufferID buf_id;
|
|
|
|
VAStatus status;
|
|
|
|
gpointer data = (gpointer) buf;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
status = vaCreateBuffer (dpy, ctx, type, size, 1, data, &buf_id);
|
|
|
|
if (!vaapi_check_status (status, "vaCreateBuffer()"))
|
|
|
|
return FALSE;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (mapped_data) {
|
|
|
|
data = vaapi_map_buffer (dpy, buf_id);
|
|
|
|
if (!data)
|
|
|
|
goto error;
|
|
|
|
*mapped_data = data;
|
|
|
|
}
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
*buf_id_ptr = buf_id;
|
|
|
|
return TRUE;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2011-08-04 15:29:41 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
|
|
|
vaapi_destroy_buffer (dpy, &buf_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-04 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroy VA buffer */
|
|
|
|
void
|
2014-01-23 16:41:02 +00:00
|
|
|
vaapi_destroy_buffer (VADisplay dpy, VABufferID * buf_id_ptr)
|
2011-08-04 15:29:41 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
if (!buf_id_ptr || *buf_id_ptr == VA_INVALID_ID)
|
|
|
|
return;
|
2011-08-04 15:29:41 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
vaDestroyBuffer (dpy, *buf_id_ptr);
|
|
|
|
*buf_id_ptr = VA_INVALID_ID;
|
2011-08-04 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
/* Return a string representation of a VAProfile */
|
2014-01-23 16:41:02 +00:00
|
|
|
const gchar *
|
|
|
|
string_of_VAProfile (VAProfile profile)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (profile) {
|
2012-01-13 11:09:07 +00:00
|
|
|
#define MAP(profile) \
|
|
|
|
STRCASEP(VAProfile, profile)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (MPEG2Simple);
|
|
|
|
MAP (MPEG2Main);
|
|
|
|
MAP (MPEG4Simple);
|
|
|
|
MAP (MPEG4AdvancedSimple);
|
|
|
|
MAP (MPEG4Main);
|
2012-01-06 16:51:59 +00:00
|
|
|
#if VA_CHECK_VERSION(0,32,0)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (JPEGBaseline);
|
|
|
|
MAP (H263Baseline);
|
|
|
|
MAP (H264ConstrainedBaseline);
|
2012-01-06 16:51:59 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (H264Baseline);
|
|
|
|
MAP (H264Main);
|
|
|
|
MAP (H264High);
|
2013-12-18 05:47:32 +00:00
|
|
|
#if VA_CHECK_VERSION(0,35,2)
|
|
|
|
MAP (H264MultiviewHigh);
|
|
|
|
MAP (H264StereoHigh);
|
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (VC1Simple);
|
|
|
|
MAP (VC1Main);
|
|
|
|
MAP (VC1Advanced);
|
2014-06-02 14:25:03 +00:00
|
|
|
#if VA_CHECK_VERSION(0,35,0)
|
|
|
|
MAP (VP8Version0_3);
|
|
|
|
#endif
|
2016-06-28 13:48:39 +00:00
|
|
|
#if VA_CHECK_VERSION(0,37,0)
|
|
|
|
MAP (VP9Profile0);
|
|
|
|
#endif
|
|
|
|
#if VA_CHECK_VERSION(0,39,0)
|
|
|
|
MAP (VP9Profile1);
|
|
|
|
MAP (VP9Profile2);
|
|
|
|
MAP (VP9Profile3);
|
|
|
|
#endif
|
2012-01-13 11:09:07 +00:00
|
|
|
#undef MAP
|
2014-01-23 16:41:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string representation of a VAEntrypoint */
|
2014-01-23 16:41:02 +00:00
|
|
|
const gchar *
|
|
|
|
string_of_VAEntrypoint (VAEntrypoint entrypoint)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (entrypoint) {
|
2012-01-13 11:09:07 +00:00
|
|
|
#define MAP(entrypoint) \
|
|
|
|
STRCASEP(VAEntrypoint, entrypoint)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (VLD);
|
|
|
|
MAP (IZZ);
|
|
|
|
MAP (IDCT);
|
|
|
|
MAP (MoComp);
|
|
|
|
MAP (Deblocking);
|
2012-01-13 11:09:07 +00:00
|
|
|
#undef MAP
|
2014-01-23 16:41:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
2010-03-21 08:38:17 +00:00
|
|
|
|
2012-07-31 10:22:48 +00:00
|
|
|
/* Return a string representation of a VADisplayAttributeType */
|
2014-01-23 16:41:02 +00:00
|
|
|
const gchar *
|
|
|
|
string_of_VADisplayAttributeType (VADisplayAttribType attribute_type)
|
2012-07-31 10:22:48 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (attribute_type) {
|
2012-07-31 10:22:48 +00:00
|
|
|
#define MAP(attribute_type) \
|
|
|
|
STRCASEP(VADisplayAttrib, attribute_type)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (Brightness);
|
|
|
|
MAP (Contrast);
|
|
|
|
MAP (Hue);
|
|
|
|
MAP (Saturation);
|
|
|
|
MAP (BackgroundColor);
|
2012-07-31 10:22:48 +00:00
|
|
|
#if !VA_CHECK_VERSION(0,34,0)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (DirectSurface);
|
2012-07-31 10:22:48 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (Rotation);
|
|
|
|
MAP (OutofLoopDeblock);
|
2012-07-31 10:22:48 +00:00
|
|
|
#if VA_CHECK_VERSION(0,31,1) && !VA_CHECK_VERSION(0,34,0)
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (BLEBlackMode);
|
|
|
|
MAP (BLEWhiteMode);
|
|
|
|
MAP (BlueStretch);
|
|
|
|
MAP (SkinColorCorrection);
|
2012-07-31 10:22:48 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
MAP (CSCMatrix);
|
|
|
|
MAP (BlendColor);
|
|
|
|
MAP (OverlayAutoPaintColorKey);
|
|
|
|
MAP (OverlayColorKey);
|
|
|
|
MAP (RenderMode);
|
|
|
|
MAP (RenderDevice);
|
|
|
|
MAP (RenderRect);
|
2012-07-31 10:22:48 +00:00
|
|
|
#undef MAP
|
2014-01-23 16:41:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
2014-05-10 04:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string representation of a VA chroma format */
|
|
|
|
const gchar *
|
|
|
|
string_of_va_chroma_format (guint chroma_format)
|
|
|
|
{
|
|
|
|
switch (chroma_format) {
|
|
|
|
#define MAP(value) \
|
|
|
|
STRCASEP(VA_RT_FORMAT_, value)
|
|
|
|
MAP (YUV420);
|
|
|
|
MAP (YUV422);
|
|
|
|
MAP (YUV444);
|
|
|
|
#if VA_CHECK_VERSION(0,34,0)
|
|
|
|
MAP (YUV400);
|
|
|
|
MAP (RGB16);
|
|
|
|
MAP (RGB32);
|
|
|
|
MAP (RGBP);
|
|
|
|
#endif
|
2015-12-07 17:06:28 +00:00
|
|
|
#if VA_CHECK_VERSION(0,38,1)
|
|
|
|
MAP (YUV420_10BPP);
|
|
|
|
#endif
|
2014-05-10 04:23:29 +00:00
|
|
|
#undef MAP
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
2012-07-31 10:22:48 +00:00
|
|
|
}
|
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
const gchar *
|
|
|
|
string_of_VARateControl (guint rate_control)
|
2013-07-12 13:33:32 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (rate_control) {
|
|
|
|
case VA_RC_NONE:
|
|
|
|
return "None";
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_CQP
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_CQP:
|
|
|
|
return "CQP";
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_CBR:
|
|
|
|
return "CBR";
|
|
|
|
case VA_RC_VCM:
|
|
|
|
return "VCM";
|
|
|
|
case VA_RC_VBR:
|
|
|
|
return "VBR";
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_VBR_CONSTRAINED
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_VBR_CONSTRAINED:
|
|
|
|
return "VBR-Constrained";
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
2013-07-12 13:33:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:13:39 +00:00
|
|
|
/**
|
|
|
|
* from_GstVaapiChromaType:
|
|
|
|
* @chroma_type: the #GstVaapiChromaType
|
|
|
|
*
|
|
|
|
* Converts #GstVaapiChromaType to a chroma format suitable for
|
|
|
|
* vaCreateSurfaces().
|
|
|
|
*/
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiChromaType (guint chroma_type)
|
2013-07-09 17:13:39 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint format;
|
2013-07-09 17:13:39 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (chroma_type) {
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV420:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_YUV420;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV422:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_YUV422;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV444:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_YUV444;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
#if VA_CHECK_VERSION(0,34,0)
|
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV411:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_YUV411;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV400:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_YUV400;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_RGB32:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_RGB32;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
case GST_VAAPI_CHROMA_TYPE_RGB16:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = VA_RT_FORMAT_RGB16;
|
|
|
|
break;
|
2015-12-07 17:06:28 +00:00
|
|
|
#endif
|
|
|
|
#if VA_CHECK_VERSION(0,38,1)
|
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV420_10BPP:
|
|
|
|
format = VA_RT_FORMAT_YUV420_10BPP;
|
|
|
|
break;
|
2013-07-09 17:13:39 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2014-01-23 16:41:02 +00:00
|
|
|
format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return format;
|
2013-07-09 17:13:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:41:25 +00:00
|
|
|
/**
|
|
|
|
* from_GstVaapiSubpictureFlags:
|
|
|
|
* @flags: the #GstVaapiSubpictureFlags
|
|
|
|
*
|
|
|
|
* Converts #GstVaapiSubpictureFlags to flags suitable for
|
|
|
|
* vaAssociateSubpicture().
|
|
|
|
*/
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiSubpictureFlags (guint flags)
|
2013-01-04 08:41:25 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint va_flags = 0;
|
2013-01-04 08:41:25 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA)
|
|
|
|
va_flags |= VA_SUBPICTURE_GLOBAL_ALPHA;
|
2013-01-04 08:41:25 +00:00
|
|
|
#ifdef VA_SUBPICTURE_PREMULTIPLIED_ALPHA
|
2014-01-23 16:41:02 +00:00
|
|
|
if (flags & GST_VAAPI_SUBPICTURE_FLAG_PREMULTIPLIED_ALPHA)
|
|
|
|
flags |= VA_SUBPICTURE_PREMULTIPLIED_ALPHA;
|
2013-01-04 08:41:25 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
return va_flags;
|
2013-01-04 08:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* to_GstVaapiSubpictureFlags:
|
|
|
|
* @flags: the #GstVaapiSubpictureFlags flags to translate
|
|
|
|
*
|
|
|
|
* Converts vaQuerySubpictureFormats() @flags to #GstVaapiSubpictureFlags
|
|
|
|
* flags.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiSubpictureFlags flags
|
|
|
|
*/
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
to_GstVaapiSubpictureFlags (guint va_flags)
|
2013-01-04 08:41:25 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint flags = 0;
|
2013-01-04 08:41:25 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (va_flags & VA_SUBPICTURE_GLOBAL_ALPHA)
|
|
|
|
flags |= GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA;
|
2013-01-04 08:41:25 +00:00
|
|
|
#ifdef VA_SUBPICTURE_PREMULTIPLIED_ALPHA
|
2014-01-23 16:41:02 +00:00
|
|
|
if (va_flags & VA_SUBPICTURE_PREMULTIPLIED_ALPHA)
|
|
|
|
flags |= GST_VAAPI_SUBPICTURE_FLAG_PREMULTIPLIED_ALPHA;
|
2013-01-04 08:41:25 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
return flags;
|
2013-01-04 08:41:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 08:24:08 +00:00
|
|
|
/**
|
|
|
|
* from_GstVideoOverlayFormatFlags:
|
|
|
|
* @flags: the #GstVideoOverlayFormatFlags flags to translate
|
|
|
|
*
|
|
|
|
* Converts #GstVaapiSubpictureFlags to #GstVaapiSubpictureFlags.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiSubpictureFlags flags
|
|
|
|
*/
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVideoOverlayFormatFlags (guint ovl_flags)
|
2012-05-15 08:24:08 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint flags = 0;
|
2012-05-15 08:24:08 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (ovl_flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA)
|
|
|
|
flags |= GST_VAAPI_SUBPICTURE_FLAG_PREMULTIPLIED_ALPHA;
|
|
|
|
if (ovl_flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
|
|
|
|
flags |= GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA;
|
|
|
|
return flags;
|
2012-05-15 08:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* to_GstVideoOverlayFormatFlags:
|
|
|
|
* @flags: the #GstVaapiSubpictureFlags flags to translate
|
|
|
|
*
|
|
|
|
* Converts #GstVaapiSubpictureFlags to #GstVideoOverlayFormatFlags.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVideoOverlayFormatFlags flags
|
|
|
|
*/
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
to_GstVideoOverlayFormatFlags (guint flags)
|
2012-05-15 08:24:08 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint ovl_flags = 0;
|
2012-05-15 08:24:08 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (flags & GST_VAAPI_SUBPICTURE_FLAG_PREMULTIPLIED_ALPHA)
|
|
|
|
ovl_flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA;
|
|
|
|
if (flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA)
|
|
|
|
ovl_flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
|
|
|
|
return ovl_flags;
|
2012-05-15 08:24:08 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 08:38:17 +00:00
|
|
|
/**
|
2010-03-30 08:13:34 +00:00
|
|
|
* from_GstVaapiSurfaceRenderFlags:
|
|
|
|
* @flags: the #GstVaapiSurfaceRenderFlags
|
2010-03-21 08:38:17 +00:00
|
|
|
*
|
|
|
|
* Converts #GstVaapiSurfaceRenderFlags to flags suitable for
|
|
|
|
* vaPutSurface().
|
|
|
|
*/
|
2010-03-30 12:55:27 +00:00
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiSurfaceRenderFlags (guint flags)
|
2010-03-21 08:38:17 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint va_fields, va_csc;
|
2010-03-21 08:38:17 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
/* Picture structure */
|
|
|
|
switch (flags & GST_VAAPI_PICTURE_STRUCTURE_MASK) {
|
2012-03-28 13:05:26 +00:00
|
|
|
case GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_fields = VA_TOP_FIELD;
|
|
|
|
break;
|
2012-03-28 13:05:26 +00:00
|
|
|
case GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_fields = VA_BOTTOM_FIELD;
|
|
|
|
break;
|
2012-03-28 13:05:26 +00:00
|
|
|
default:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_fields = VA_FRAME_PICTURE;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-21 08:38:17 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
/* Color standard */
|
|
|
|
switch (flags & GST_VAAPI_COLOR_STANDARD_MASK) {
|
2010-03-24 16:17:49 +00:00
|
|
|
#ifdef VA_SRC_BT601
|
2012-03-28 13:05:26 +00:00
|
|
|
case GST_VAAPI_COLOR_STANDARD_ITUR_BT_601:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_csc = VA_SRC_BT601;
|
|
|
|
break;
|
2010-03-24 16:17:49 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VA_SRC_BT709
|
2012-03-28 13:05:26 +00:00
|
|
|
case GST_VAAPI_COLOR_STANDARD_ITUR_BT_709:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_csc = VA_SRC_BT709;
|
|
|
|
break;
|
2010-03-24 16:17:49 +00:00
|
|
|
#endif
|
2012-03-28 13:05:26 +00:00
|
|
|
#ifdef VA_SRC_SMPTE_240
|
|
|
|
case GST_VAAPI_COLOR_STANDARD_SMPTE_240M:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_csc = VA_SRC_SMPTE_240;
|
|
|
|
break;
|
2012-03-28 13:05:26 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2014-01-23 16:41:02 +00:00
|
|
|
va_csc = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return va_fields | va_csc;
|
2010-03-21 08:38:17 +00:00
|
|
|
}
|
2010-03-30 08:11:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* to_GstVaapiSurfaceStatus:
|
|
|
|
* @flags: the #GstVaapiSurfaceStatus flags to translate
|
|
|
|
*
|
|
|
|
* Converts vaQuerySurfaceStatus() @flags to #GstVaapiSurfaceStatus
|
|
|
|
* flags.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiSurfaceStatus flags
|
|
|
|
*/
|
2010-03-30 12:55:27 +00:00
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
to_GstVaapiSurfaceStatus (guint va_flags)
|
2010-03-30 08:11:50 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint flags;
|
|
|
|
const guint va_flags_mask = (VASurfaceReady |
|
|
|
|
VASurfaceRendering | VASurfaceDisplaying);
|
2010-03-30 08:11:50 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
/* Check for core status */
|
|
|
|
switch (va_flags & va_flags_mask) {
|
2010-03-30 08:11:50 +00:00
|
|
|
case VASurfaceReady:
|
2014-01-23 16:41:02 +00:00
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_IDLE;
|
|
|
|
break;
|
2010-03-30 08:11:50 +00:00
|
|
|
case VASurfaceRendering:
|
2014-01-23 16:41:02 +00:00
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_RENDERING;
|
|
|
|
break;
|
2010-03-30 08:11:50 +00:00
|
|
|
case VASurfaceDisplaying:
|
2014-01-23 16:41:02 +00:00
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_DISPLAYING;
|
|
|
|
break;
|
2010-03-30 08:11:50 +00:00
|
|
|
default:
|
2014-01-23 16:41:02 +00:00
|
|
|
flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-30 08:11:50 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
/* Check for encoder status */
|
2010-03-30 13:05:31 +00:00
|
|
|
#if VA_CHECK_VERSION(0,30,0)
|
2014-01-23 16:41:02 +00:00
|
|
|
if (va_flags & VASurfaceSkipped)
|
|
|
|
flags |= GST_VAAPI_SURFACE_STATUS_SKIPPED;
|
2010-03-30 13:05:31 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
return flags;
|
2010-03-30 08:11:50 +00:00
|
|
|
}
|
2012-08-22 06:18:11 +00:00
|
|
|
|
|
|
|
/* Translate GstVaapiRotation value to VA-API rotation value */
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiRotation (guint value)
|
2012-08-22 06:18:11 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (value) {
|
|
|
|
case GST_VAAPI_ROTATION_0:
|
|
|
|
return VA_ROTATION_NONE;
|
|
|
|
case GST_VAAPI_ROTATION_90:
|
|
|
|
return VA_ROTATION_90;
|
|
|
|
case GST_VAAPI_ROTATION_180:
|
|
|
|
return VA_ROTATION_180;
|
|
|
|
case GST_VAAPI_ROTATION_270:
|
|
|
|
return VA_ROTATION_270;
|
|
|
|
}
|
|
|
|
GST_ERROR ("unsupported GstVaapiRotation value %d", value);
|
|
|
|
return VA_ROTATION_NONE;
|
2012-08-22 06:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate VA-API rotation value to GstVaapiRotation value */
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
to_GstVaapiRotation (guint value)
|
2012-08-22 06:18:11 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (value) {
|
|
|
|
case VA_ROTATION_NONE:
|
|
|
|
return GST_VAAPI_ROTATION_0;
|
|
|
|
case VA_ROTATION_90:
|
|
|
|
return GST_VAAPI_ROTATION_90;
|
|
|
|
case VA_ROTATION_180:
|
|
|
|
return GST_VAAPI_ROTATION_180;
|
|
|
|
case VA_ROTATION_270:
|
|
|
|
return GST_VAAPI_ROTATION_270;
|
|
|
|
}
|
|
|
|
GST_ERROR ("unsupported VA-API rotation value %d", value);
|
|
|
|
return GST_VAAPI_ROTATION_0;
|
2012-08-22 06:18:11 +00:00
|
|
|
}
|
2013-07-29 01:23:50 +00:00
|
|
|
|
2013-07-12 13:33:32 +00:00
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiRateControl (guint value)
|
2013-07-12 13:33:32 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (value) {
|
|
|
|
case GST_VAAPI_RATECONTROL_NONE:
|
|
|
|
return VA_RC_NONE;
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_CQP
|
2014-01-23 16:41:02 +00:00
|
|
|
case GST_VAAPI_RATECONTROL_CQP:
|
|
|
|
return VA_RC_CQP;
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
case GST_VAAPI_RATECONTROL_CBR:
|
|
|
|
return VA_RC_CBR;
|
|
|
|
case GST_VAAPI_RATECONTROL_VCM:
|
|
|
|
return VA_RC_VCM;
|
|
|
|
case GST_VAAPI_RATECONTROL_VBR:
|
|
|
|
return VA_RC_VBR;
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_VBR_CONSTRAINED
|
2014-01-23 16:41:02 +00:00
|
|
|
case GST_VAAPI_RATECONTROL_VBR_CONSTRAINED:
|
|
|
|
return VA_RC_VBR_CONSTRAINED;
|
2016-05-11 09:04:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VA_RC_MB
|
|
|
|
case GST_VAAPI_RATECONTROL_MB:
|
|
|
|
return VA_RC_MB;
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
}
|
|
|
|
GST_ERROR ("unsupported GstVaapiRateControl value %u", value);
|
|
|
|
return VA_RC_NONE;
|
2013-07-12 13:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
to_GstVaapiRateControl (guint value)
|
2013-07-12 13:33:32 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (value) {
|
|
|
|
case VA_RC_NONE:
|
|
|
|
return GST_VAAPI_RATECONTROL_NONE;
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_CQP
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_CQP:
|
|
|
|
return GST_VAAPI_RATECONTROL_CQP;
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_CBR:
|
|
|
|
return GST_VAAPI_RATECONTROL_CBR;
|
|
|
|
case VA_RC_VCM:
|
|
|
|
return GST_VAAPI_RATECONTROL_VCM;
|
|
|
|
case VA_RC_VBR:
|
|
|
|
return GST_VAAPI_RATECONTROL_VBR;
|
2014-01-23 21:44:09 +00:00
|
|
|
#ifdef VA_RC_VBR_CONSTRAINED
|
2014-01-23 16:41:02 +00:00
|
|
|
case VA_RC_VBR_CONSTRAINED:
|
|
|
|
return GST_VAAPI_RATECONTROL_VBR_CONSTRAINED;
|
2016-05-11 09:04:46 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VA_RC_MB
|
|
|
|
case VA_RC_MB:
|
|
|
|
return GST_VAAPI_RATECONTROL_MB;
|
2014-01-23 21:44:09 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
}
|
|
|
|
GST_ERROR ("unsupported VA-API Rate Control value %u", value);
|
|
|
|
return GST_VAAPI_RATECONTROL_NONE;
|
2013-07-12 13:33:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 01:23:50 +00:00
|
|
|
/* VPP: translate GstVaapiDeinterlaceMethod to VA deinterlacing algorithm */
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiDeinterlaceMethod (guint value)
|
2013-07-29 01:23:50 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
switch (value) {
|
2013-07-29 01:23:50 +00:00
|
|
|
case GST_VAAPI_DEINTERLACE_METHOD_NONE:
|
2014-01-23 16:41:02 +00:00
|
|
|
return 0;
|
2013-07-29 01:23:50 +00:00
|
|
|
#if USE_VA_VPP
|
|
|
|
case GST_VAAPI_DEINTERLACE_METHOD_BOB:
|
2014-01-23 16:41:02 +00:00
|
|
|
return VAProcDeinterlacingBob;
|
2013-07-29 01:23:50 +00:00
|
|
|
case GST_VAAPI_DEINTERLACE_METHOD_WEAVE:
|
2014-01-23 16:41:02 +00:00
|
|
|
return VAProcDeinterlacingWeave;
|
2013-07-29 01:23:50 +00:00
|
|
|
case GST_VAAPI_DEINTERLACE_METHOD_MOTION_ADAPTIVE:
|
2014-01-23 16:41:02 +00:00
|
|
|
return VAProcDeinterlacingMotionAdaptive;
|
2013-07-29 01:23:50 +00:00
|
|
|
case GST_VAAPI_DEINTERLACE_METHOD_MOTION_COMPENSATED:
|
2014-01-23 16:41:02 +00:00
|
|
|
return VAProcDeinterlacingMotionCompensated;
|
2013-07-29 01:23:50 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
}
|
|
|
|
GST_ERROR ("unsupported GstVaapiDeinterlaceMethod value %d", value);
|
|
|
|
return 0;
|
2013-07-29 01:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* VPP: translate GstVaapiDeinterlaceFlags into VA deinterlacing flags */
|
|
|
|
guint
|
2014-01-23 16:41:02 +00:00
|
|
|
from_GstVaapiDeinterlaceFlags (guint flags)
|
2013-07-29 01:23:50 +00:00
|
|
|
{
|
2014-01-23 16:41:02 +00:00
|
|
|
guint va_flags = 0;
|
2013-07-29 01:23:50 +00:00
|
|
|
|
|
|
|
#if USE_VA_VPP
|
2014-01-23 16:41:02 +00:00
|
|
|
if (!(flags & GST_VAAPI_DEINTERLACE_FLAG_TFF))
|
|
|
|
va_flags |= VA_DEINTERLACING_BOTTOM_FIELD_FIRST;
|
2013-07-29 01:23:50 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (flags & GST_VAAPI_DEINTERLACE_FLAG_ONEFIELD)
|
|
|
|
va_flags |= VA_DEINTERLACING_ONE_FIELD;
|
2013-11-21 17:44:46 +00:00
|
|
|
|
2014-01-23 16:41:02 +00:00
|
|
|
if (!(flags & GST_VAAPI_DEINTERLACE_FLAG_TOPFIELD))
|
|
|
|
va_flags |= VA_DEINTERLACING_BOTTOM_FIELD;
|
2013-07-29 01:23:50 +00:00
|
|
|
#endif
|
2014-01-23 16:41:02 +00:00
|
|
|
return va_flags;
|
2013-07-29 01:23:50 +00:00
|
|
|
}
|
2014-10-29 15:57:12 +00:00
|
|
|
|
|
|
|
/* VPP: translate GstVaapiScaleMethod into VA scaling flags */
|
|
|
|
guint
|
|
|
|
from_GstVaapiScaleMethod (guint value)
|
|
|
|
{
|
|
|
|
guint va_flags;
|
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case GST_VAAPI_SCALE_METHOD_DEFAULT:
|
|
|
|
va_flags = VA_FILTER_SCALING_DEFAULT;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_SCALE_METHOD_FAST:
|
|
|
|
va_flags = VA_FILTER_SCALING_FAST;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_SCALE_METHOD_HQ:
|
|
|
|
va_flags = VA_FILTER_SCALING_HQ;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
va_flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return va_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VPP: translate VA scaling flags into GstVaapiScale Method */
|
|
|
|
guint
|
|
|
|
to_GstVaapiScaleMethod (guint flags)
|
|
|
|
{
|
|
|
|
GstVaapiScaleMethod method;
|
|
|
|
|
|
|
|
switch (flags) {
|
|
|
|
case VA_FILTER_SCALING_FAST:
|
|
|
|
method = GST_VAAPI_SCALE_METHOD_FAST;
|
|
|
|
break;
|
|
|
|
case VA_FILTER_SCALING_HQ:
|
|
|
|
method = GST_VAAPI_SCALE_METHOD_HQ;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
method = GST_VAAPI_SCALE_METHOD_DEFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return method;
|
|
|
|
}
|