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
|
|
|
*
|
2011-06-14 11:52:56 +00:00
|
|
|
* gstreamer-vaapi (C) 2010-2011 Splitted-Desktop Systems
|
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
|
|
|
*/
|
|
|
|
|
2010-03-21 08:38:17 +00:00
|
|
|
#include "config.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"
|
2010-01-25 16:15:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-03-30 12:55:27 +00:00
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
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
|
|
|
|
vaapi_check_status(VAStatus status, const char *msg)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
|
|
|
if (status != VA_STATUS_SUCCESS) {
|
2010-03-30 12:55:27 +00:00
|
|
|
GST_DEBUG("%s: %s", msg, vaErrorStr(status));
|
|
|
|
return FALSE;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
2010-03-30 12:55:27 +00:00
|
|
|
return TRUE;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string representation of a FOURCC */
|
|
|
|
const char *string_of_FOURCC(guint32 fourcc)
|
|
|
|
{
|
|
|
|
static int buf;
|
|
|
|
static char str[2][5]; // XXX: 2 buffers should be enough for most purposes
|
|
|
|
|
|
|
|
buf ^= 1;
|
|
|
|
str[buf][0] = fourcc;
|
|
|
|
str[buf][1] = fourcc >> 8;
|
|
|
|
str[buf][2] = fourcc >> 16;
|
|
|
|
str[buf][3] = fourcc >> 24;
|
|
|
|
str[buf][4] = '\0';
|
|
|
|
return str[buf];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string representation of a VAProfile */
|
|
|
|
const char *string_of_VAProfile(VAProfile profile)
|
|
|
|
{
|
|
|
|
switch (profile) {
|
|
|
|
#define PROFILE(profile) \
|
|
|
|
case VAProfile##profile: return "VAProfile" #profile
|
|
|
|
PROFILE(MPEG2Simple);
|
|
|
|
PROFILE(MPEG2Main);
|
|
|
|
PROFILE(MPEG4Simple);
|
|
|
|
PROFILE(MPEG4AdvancedSimple);
|
|
|
|
PROFILE(MPEG4Main);
|
2012-01-06 16:51:59 +00:00
|
|
|
#if VA_CHECK_VERSION(0,32,0)
|
|
|
|
PROFILE(JPEGBaseline);
|
|
|
|
PROFILE(H263Baseline);
|
|
|
|
PROFILE(H264ConstrainedBaseline);
|
|
|
|
#endif
|
2010-01-25 16:15:01 +00:00
|
|
|
PROFILE(H264Baseline);
|
|
|
|
PROFILE(H264Main);
|
|
|
|
PROFILE(H264High);
|
|
|
|
PROFILE(VC1Simple);
|
|
|
|
PROFILE(VC1Main);
|
|
|
|
PROFILE(VC1Advanced);
|
|
|
|
#undef PROFILE
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string representation of a VAEntrypoint */
|
|
|
|
const char *string_of_VAEntrypoint(VAEntrypoint entrypoint)
|
|
|
|
{
|
|
|
|
switch (entrypoint) {
|
|
|
|
#define ENTRYPOINT(entrypoint) \
|
|
|
|
case VAEntrypoint##entrypoint: return "VAEntrypoint" #entrypoint
|
|
|
|
ENTRYPOINT(VLD);
|
|
|
|
ENTRYPOINT(IZZ);
|
|
|
|
ENTRYPOINT(IDCT);
|
|
|
|
ENTRYPOINT(MoComp);
|
|
|
|
ENTRYPOINT(Deblocking);
|
|
|
|
#undef ENTRYPOINT
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
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
|
|
|
|
from_GstVaapiSurfaceRenderFlags(guint flags)
|
2010-03-21 08:38:17 +00:00
|
|
|
{
|
2010-03-24 16:17:49 +00:00
|
|
|
guint va_fields = 0, va_csc = 0;
|
2010-03-21 08:38:17 +00:00
|
|
|
|
|
|
|
if (flags & GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD)
|
2010-03-24 16:17:49 +00:00
|
|
|
va_fields |= VA_TOP_FIELD;
|
2010-03-21 08:38:17 +00:00
|
|
|
if (flags & GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD)
|
2010-03-24 16:17:49 +00:00
|
|
|
va_fields |= VA_BOTTOM_FIELD;
|
|
|
|
if ((va_fields ^ (VA_TOP_FIELD|VA_BOTTOM_FIELD)) == 0)
|
|
|
|
va_fields = VA_FRAME_PICTURE;
|
2010-03-21 08:38:17 +00:00
|
|
|
|
2010-03-24 16:17:49 +00:00
|
|
|
#ifdef VA_SRC_BT601
|
|
|
|
if (flags & GST_VAAPI_COLOR_STANDARD_ITUR_BT_601)
|
|
|
|
va_csc = VA_SRC_BT601;
|
|
|
|
#endif
|
|
|
|
#ifdef VA_SRC_BT709
|
2010-03-21 08:38:17 +00:00
|
|
|
if (flags & GST_VAAPI_COLOR_STANDARD_ITUR_BT_709)
|
2010-03-24 16:17:49 +00:00
|
|
|
va_csc = VA_SRC_BT709;
|
|
|
|
#endif
|
2010-03-21 08:38:17 +00:00
|
|
|
|
2010-03-24 16:17:49 +00:00
|
|
|
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
|
|
|
|
to_GstVaapiSurfaceStatus(guint va_flags)
|
2010-03-30 08:11:50 +00:00
|
|
|
{
|
|
|
|
guint flags;
|
|
|
|
const guint va_flags_mask = (VASurfaceReady|
|
|
|
|
VASurfaceRendering|
|
|
|
|
VASurfaceDisplaying);
|
|
|
|
|
|
|
|
/* Check for core status */
|
|
|
|
switch (va_flags & va_flags_mask) {
|
|
|
|
case VASurfaceReady:
|
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_IDLE;
|
|
|
|
break;
|
|
|
|
case VASurfaceRendering:
|
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_RENDERING;
|
|
|
|
break;
|
|
|
|
case VASurfaceDisplaying:
|
|
|
|
flags = GST_VAAPI_SURFACE_STATUS_DISPLAYING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for encoder status */
|
2010-03-30 13:05:31 +00:00
|
|
|
#if VA_CHECK_VERSION(0,30,0)
|
2010-03-30 08:11:50 +00:00
|
|
|
if (va_flags & VASurfaceSkipped)
|
|
|
|
flags |= GST_VAAPI_SURFACE_STATUS_SKIPPED;
|
2010-03-30 13:05:31 +00:00
|
|
|
#endif
|
2010-03-30 08:11:50 +00:00
|
|
|
return flags;
|
|
|
|
}
|