2010-01-25 16:15:01 +00:00
|
|
|
/*
|
|
|
|
* gstvaapidisplay.c - VA display abstraction
|
|
|
|
*
|
|
|
|
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
#include "gstvaapidisplay.h"
|
|
|
|
#include <va/va_backend.h>
|
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG_CATEGORY(gst_debug_vaapi);
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
G_DEFINE_TYPE(GstVaapiDisplay, gst_vaapi_display, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
#define GST_VAAPI_DISPLAY_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
|
|
|
GST_VAAPI_TYPE_DISPLAY, \
|
|
|
|
GstVaapiDisplayPrivate))
|
|
|
|
|
|
|
|
struct _GstVaapiDisplayPrivate {
|
2010-03-17 07:59:31 +00:00
|
|
|
GStaticMutex mutex;
|
2010-01-25 16:15:01 +00:00
|
|
|
VADisplay display;
|
2010-03-11 15:01:00 +00:00
|
|
|
gboolean create_display;
|
2010-01-25 16:15:01 +00:00
|
|
|
VAProfile *profiles;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint num_profiles;
|
2010-01-25 16:15:01 +00:00
|
|
|
VAImageFormat *image_formats;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint num_image_formats;
|
2010-01-25 16:15:01 +00:00
|
|
|
VAImageFormat *subpicture_formats;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint *subpicture_flags;
|
|
|
|
guint num_subpicture_formats;
|
2010-01-25 16:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_DISPLAY
|
|
|
|
};
|
|
|
|
|
2010-03-11 12:11:36 +00:00
|
|
|
static void
|
2010-03-16 08:43:16 +00:00
|
|
|
append_format(
|
|
|
|
VAImageFormat **pva_formats,
|
2010-03-18 08:02:25 +00:00
|
|
|
guint *pnum_va_formats,
|
2010-03-16 08:43:16 +00:00
|
|
|
GstVaapiImageFormat format
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const VAImageFormat *va_format;
|
|
|
|
VAImageFormat *new_va_formats;
|
|
|
|
|
|
|
|
va_format = gst_vaapi_image_format_get_va_format(format);
|
|
|
|
if (!va_format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new_va_formats = realloc(
|
|
|
|
*pva_formats,
|
|
|
|
sizeof(new_va_formats[0]) * (1 + *pnum_va_formats)
|
|
|
|
);
|
|
|
|
if (!new_va_formats)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new_va_formats[(*pnum_va_formats)++] = *va_format;
|
|
|
|
*pva_formats = new_va_formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-18 08:02:25 +00:00
|
|
|
filter_formats(VAImageFormat **pva_formats, guint *pnum_va_formats)
|
2010-03-11 12:11:36 +00:00
|
|
|
{
|
2010-03-18 08:02:25 +00:00
|
|
|
guint i = 0;
|
2010-03-16 08:43:16 +00:00
|
|
|
gboolean has_YV12 = FALSE;
|
|
|
|
gboolean has_I420 = FALSE;
|
2010-03-11 12:11:36 +00:00
|
|
|
|
|
|
|
while (i < *pnum_va_formats) {
|
2010-03-16 08:43:16 +00:00
|
|
|
VAImageFormat * const va_format = &(*pva_formats)[i];
|
2010-03-11 12:11:36 +00:00
|
|
|
const GstVaapiImageFormat format = gst_vaapi_image_format(va_format);
|
2010-03-16 08:43:16 +00:00
|
|
|
if (format) {
|
2010-03-11 12:11:36 +00:00
|
|
|
++i;
|
2010-03-16 08:43:16 +00:00
|
|
|
switch (format) {
|
|
|
|
case GST_VAAPI_IMAGE_YV12:
|
|
|
|
has_YV12 = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_IMAGE_I420:
|
|
|
|
has_I420 = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-11 12:11:36 +00:00
|
|
|
else {
|
|
|
|
/* Remove any format that is not supported by libgstvaapi */
|
|
|
|
GST_DEBUG("unsupported format %c%c%c%c",
|
|
|
|
va_format->fourcc & 0xff,
|
|
|
|
(va_format->fourcc >> 8) & 0xff,
|
|
|
|
(va_format->fourcc >> 16) & 0xff,
|
|
|
|
(va_format->fourcc >> 24) & 0xff);
|
2010-03-16 08:43:16 +00:00
|
|
|
*va_format = (*pva_formats)[--(*pnum_va_formats)];
|
2010-03-11 12:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-16 08:43:16 +00:00
|
|
|
|
|
|
|
/* Append I420 (resp. YV12) format if YV12 (resp. I420) is not
|
|
|
|
supported by the underlying driver */
|
|
|
|
if (has_YV12 && !has_I420)
|
|
|
|
append_format(pva_formats, pnum_va_formats, GST_VAAPI_IMAGE_I420);
|
|
|
|
else if (has_I420 && !has_YV12)
|
|
|
|
append_format(pva_formats, pnum_va_formats, GST_VAAPI_IMAGE_YV12);
|
2010-03-11 12:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort image formats. Prefer YUV formats first */
|
|
|
|
static int
|
|
|
|
compare_yuv_formats(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const GstVaapiImageFormat fmt1 = gst_vaapi_image_format((VAImageFormat *)a);
|
|
|
|
const GstVaapiImageFormat fmt2 = gst_vaapi_image_format((VAImageFormat *)b);
|
|
|
|
|
|
|
|
g_assert(fmt1 && fmt2);
|
|
|
|
|
|
|
|
const gboolean is_fmt1_yuv = gst_vaapi_image_format_is_yuv(fmt1);
|
|
|
|
const gboolean is_fmt2_yuv = gst_vaapi_image_format_is_yuv(fmt2);
|
|
|
|
|
|
|
|
if (is_fmt1_yuv != is_fmt2_yuv)
|
|
|
|
return is_fmt1_yuv ? -1 : 1;
|
|
|
|
|
|
|
|
return ((int)gst_vaapi_image_format_get_score(fmt1) -
|
|
|
|
(int)gst_vaapi_image_format_get_score(fmt2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort subpicture formats. Prefer RGB formats first */
|
|
|
|
static int
|
|
|
|
compare_rgb_formats(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const GstVaapiImageFormat fmt1 = gst_vaapi_image_format((VAImageFormat *)a);
|
|
|
|
const GstVaapiImageFormat fmt2 = gst_vaapi_image_format((VAImageFormat *)b);
|
|
|
|
|
|
|
|
g_assert(fmt1 && fmt2);
|
|
|
|
|
|
|
|
const gboolean is_fmt1_rgb = gst_vaapi_image_format_is_rgb(fmt1);
|
|
|
|
const gboolean is_fmt2_rgb = gst_vaapi_image_format_is_rgb(fmt2);
|
|
|
|
|
|
|
|
if (is_fmt1_rgb != is_fmt2_rgb)
|
|
|
|
return is_fmt1_rgb ? -1 : 1;
|
|
|
|
|
|
|
|
return ((int)gst_vaapi_image_format_get_score(fmt1) -
|
|
|
|
(int)gst_vaapi_image_format_get_score(fmt2));
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_destroy(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayPrivate * const priv = display->priv;
|
|
|
|
|
|
|
|
if (priv->profiles) {
|
|
|
|
g_free(priv->profiles);
|
|
|
|
priv->profiles = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->image_formats) {
|
|
|
|
g_free(priv->image_formats);
|
|
|
|
priv->image_formats = NULL;
|
|
|
|
priv->num_image_formats = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->subpicture_formats) {
|
|
|
|
g_free(priv->subpicture_formats);
|
|
|
|
priv->subpicture_formats = NULL;
|
|
|
|
priv->num_subpicture_formats = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->subpicture_flags) {
|
|
|
|
g_free(priv->subpicture_flags);
|
|
|
|
priv->subpicture_flags = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->display) {
|
|
|
|
vaTerminate(priv->display);
|
|
|
|
priv->display = NULL;
|
|
|
|
}
|
2010-03-11 15:01:00 +00:00
|
|
|
|
|
|
|
if (priv->create_display) {
|
|
|
|
GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
|
|
|
|
if (klass->close_display)
|
|
|
|
klass->close_display(display);
|
|
|
|
}
|
2010-03-10 12:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vaapi_display_create(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayPrivate * const priv = display->priv;
|
|
|
|
VAStatus status;
|
|
|
|
int major_version, minor_version;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint i;
|
2010-03-10 12:25:19 +00:00
|
|
|
|
2010-03-11 15:01:00 +00:00
|
|
|
if (!priv->display && priv->create_display) {
|
|
|
|
GstVaapiDisplayClass *klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
|
|
|
|
if (klass->open_display && !klass->open_display(display))
|
|
|
|
return FALSE;
|
|
|
|
if (klass->get_display)
|
|
|
|
priv->display = klass->get_display(display);
|
|
|
|
}
|
|
|
|
if (!priv->display)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
status = vaInitialize(priv->display, &major_version, &minor_version);
|
|
|
|
if (!vaapi_check_status(status, "vaInitialize()"))
|
|
|
|
return FALSE;
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG("VA-API version %d.%d", major_version, minor_version);
|
2010-03-10 12:25:19 +00:00
|
|
|
|
|
|
|
/* VA profiles */
|
|
|
|
priv->num_profiles = vaMaxNumProfiles(priv->display);
|
|
|
|
priv->profiles = g_new(VAProfile, priv->num_profiles);
|
|
|
|
if (!priv->profiles)
|
|
|
|
return FALSE;
|
|
|
|
status = vaQueryConfigProfiles(priv->display,
|
|
|
|
priv->profiles,
|
|
|
|
&priv->num_profiles);
|
|
|
|
if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG("%d profiles", priv->num_profiles);
|
2010-03-10 12:25:19 +00:00
|
|
|
for (i = 0; i < priv->num_profiles; i++)
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG(" %s", string_of_VAProfile(priv->profiles[i]));
|
2010-03-10 12:25:19 +00:00
|
|
|
|
|
|
|
/* VA image formats */
|
|
|
|
priv->num_image_formats = vaMaxNumImageFormats(priv->display);
|
|
|
|
priv->image_formats = g_new(VAImageFormat, priv->num_image_formats);
|
|
|
|
if (!priv->image_formats)
|
|
|
|
return FALSE;
|
2010-03-11 12:11:36 +00:00
|
|
|
status = vaQueryImageFormats(
|
|
|
|
priv->display,
|
|
|
|
priv->image_formats,
|
|
|
|
&priv->num_image_formats
|
|
|
|
);
|
2010-03-10 12:25:19 +00:00
|
|
|
if (!vaapi_check_status(status, "vaQueryImageFormats()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG("%d image formats", priv->num_image_formats);
|
2010-03-10 12:25:19 +00:00
|
|
|
for (i = 0; i < priv->num_image_formats; i++)
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG(" %s", string_of_FOURCC(priv->image_formats[i].fourcc));
|
2010-03-10 12:25:19 +00:00
|
|
|
|
2010-03-16 08:43:16 +00:00
|
|
|
filter_formats(&priv->image_formats, &priv->num_image_formats);
|
2010-03-11 12:11:36 +00:00
|
|
|
qsort(
|
|
|
|
priv->image_formats,
|
|
|
|
priv->num_image_formats,
|
|
|
|
sizeof(priv->image_formats[0]),
|
|
|
|
compare_yuv_formats
|
|
|
|
);
|
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
/* VA subpicture formats */
|
|
|
|
priv->num_subpicture_formats = vaMaxNumSubpictureFormats(priv->display);
|
|
|
|
priv->subpicture_formats = g_new(VAImageFormat, priv->num_subpicture_formats);
|
|
|
|
if (!priv->subpicture_formats)
|
|
|
|
return FALSE;
|
2010-03-18 08:02:25 +00:00
|
|
|
priv->subpicture_flags = g_new(guint, priv->num_subpicture_formats);
|
2010-03-10 12:25:19 +00:00
|
|
|
if (!priv->subpicture_flags)
|
|
|
|
return FALSE;
|
2010-03-11 12:11:36 +00:00
|
|
|
status = vaQuerySubpictureFormats(
|
|
|
|
priv->display,
|
|
|
|
priv->subpicture_formats,
|
|
|
|
priv->subpicture_flags,
|
|
|
|
&priv->num_subpicture_formats
|
|
|
|
);
|
2010-03-10 12:25:19 +00:00
|
|
|
if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-16 08:43:16 +00:00
|
|
|
filter_formats(&priv->subpicture_formats, &priv->num_subpicture_formats);
|
2010-03-11 12:11:36 +00:00
|
|
|
qsort(
|
|
|
|
priv->subpicture_formats,
|
|
|
|
priv->num_subpicture_formats,
|
|
|
|
sizeof(priv->subpicture_formats[0]),
|
|
|
|
compare_rgb_formats
|
|
|
|
);
|
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG("%d subpicture formats", priv->num_subpicture_formats);
|
2010-03-10 12:25:19 +00:00
|
|
|
for (i = 0; i < priv->num_subpicture_formats; i++)
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG(" %s", string_of_FOURCC(priv->subpicture_formats[i].fourcc));
|
2010-03-10 12:25:19 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-17 07:59:31 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_lock_default(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
g_static_mutex_lock(&display->priv->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_display_unlock_default(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
g_static_mutex_unlock(&display->priv->mutex);
|
|
|
|
}
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_finalize(GObject *object)
|
|
|
|
{
|
2010-03-09 12:00:32 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
gst_vaapi_display_destroy(display);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-11 15:01:00 +00:00
|
|
|
gst_vaapi_display_set_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
2010-03-15 13:32:37 +00:00
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2010-03-09 12:00:32 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
2010-03-11 15:01:00 +00:00
|
|
|
display->priv->display = g_value_get_pointer(value);
|
2010-01-25 16:15:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-11 15:01:00 +00:00
|
|
|
gst_vaapi_display_get_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2010-03-09 12:00:32 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_pointer(value, gst_vaapi_display_get_display(display));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 15:01:00 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_constructed(GObject *object)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_DISPLAY(object);
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
|
|
|
|
display->priv->create_display = display->priv->display == NULL;
|
|
|
|
gst_vaapi_display_create(display);
|
|
|
|
|
|
|
|
parent_class = G_OBJECT_CLASS(gst_vaapi_display_parent_class);
|
|
|
|
if (parent_class->constructed)
|
|
|
|
parent_class->constructed(object);
|
|
|
|
}
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
2010-03-17 07:59:31 +00:00
|
|
|
GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2010-03-10 13:13:51 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT(gst_debug_vaapi, "vaapi", 0, "VA-API helper");
|
|
|
|
|
2010-01-25 16:15:01 +00:00
|
|
|
g_type_class_add_private(klass, sizeof(GstVaapiDisplayPrivate));
|
|
|
|
|
2010-03-17 07:59:31 +00:00
|
|
|
object_class->finalize = gst_vaapi_display_finalize;
|
|
|
|
object_class->set_property = gst_vaapi_display_set_property;
|
|
|
|
object_class->get_property = gst_vaapi_display_get_property;
|
|
|
|
object_class->constructed = gst_vaapi_display_constructed;
|
|
|
|
|
|
|
|
dpy_class->lock_display = gst_vaapi_display_lock_default;
|
|
|
|
dpy_class->unlock_display = gst_vaapi_display_unlock_default;
|
2010-01-25 16:15:01 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_pointer("display",
|
|
|
|
"VA display",
|
|
|
|
"VA display",
|
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_display_init(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE(display);
|
|
|
|
|
|
|
|
display->priv = priv;
|
|
|
|
priv->display = NULL;
|
2010-03-11 15:01:00 +00:00
|
|
|
priv->create_display = TRUE;
|
2010-01-25 16:15:01 +00:00
|
|
|
priv->profiles = 0;
|
|
|
|
priv->num_profiles = 0;
|
|
|
|
priv->image_formats = NULL;
|
|
|
|
priv->num_image_formats = 0;
|
|
|
|
priv->subpicture_formats = NULL;
|
|
|
|
priv->subpicture_flags = NULL;
|
|
|
|
priv->num_subpicture_formats = 0;
|
2010-03-17 07:59:31 +00:00
|
|
|
|
|
|
|
g_static_mutex_init(&priv->mutex);
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
GstVaapiDisplay *
|
|
|
|
gst_vaapi_display_new_with_display(VADisplay va_display)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2010-03-10 12:25:19 +00:00
|
|
|
return g_object_new(GST_VAAPI_TYPE_DISPLAY,
|
|
|
|
"display", va_display,
|
|
|
|
NULL);
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 07:59:31 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_display_lock(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
|
|
|
|
|
|
|
|
klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
|
|
|
|
if (klass->lock_display)
|
|
|
|
klass->lock_display(display);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_vaapi_display_unlock(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayClass *klass;
|
|
|
|
|
|
|
|
g_return_if_fail(GST_VAAPI_IS_DISPLAY(display));
|
|
|
|
|
|
|
|
klass = GST_VAAPI_DISPLAY_GET_CLASS(display);
|
|
|
|
if (klass->unlock_display)
|
|
|
|
klass->unlock_display(display);
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
VADisplay
|
|
|
|
gst_vaapi_display_get_display(GstVaapiDisplay *display)
|
2010-01-25 16:15:01 +00:00
|
|
|
{
|
2010-03-10 12:25:19 +00:00
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
2010-01-25 16:15:01 +00:00
|
|
|
|
2010-03-10 12:25:19 +00:00
|
|
|
return display->priv->display;
|
2010-01-25 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 17:41:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_display_has_profile(GstVaapiDisplay *display, VAProfile profile)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < display->priv->num_profiles; i++)
|
|
|
|
if (display->priv->profiles[i] == profile)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gst_vaapi_display_has_format(
|
2010-03-10 10:43:31 +00:00
|
|
|
GstVaapiDisplay *display,
|
|
|
|
GstVaapiImageFormat format,
|
2010-03-04 17:41:34 +00:00
|
|
|
const VAImageFormat *va_formats,
|
2010-03-18 08:02:25 +00:00
|
|
|
guint num_va_formats
|
2010-03-04 17:41:34 +00:00
|
|
|
)
|
|
|
|
{
|
2010-03-18 08:02:25 +00:00
|
|
|
guint i;
|
2010-03-04 17:41:34 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(format != 0, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < num_va_formats; i++)
|
|
|
|
if (gst_vaapi_image_format(&va_formats[i]) == format)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-10 10:43:31 +00:00
|
|
|
static GstCaps *
|
|
|
|
_gst_vaapi_display_get_caps(
|
|
|
|
GstVaapiDisplay *display,
|
|
|
|
const VAImageFormat *va_formats,
|
2010-03-18 08:02:25 +00:00
|
|
|
guint num_va_formats
|
2010-03-10 10:43:31 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
GstCaps *out_caps;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint i;
|
2010-03-10 10:43:31 +00:00
|
|
|
|
|
|
|
out_caps = gst_caps_new_empty();
|
|
|
|
if (!out_caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < num_va_formats; i++) {
|
|
|
|
GstVaapiImageFormat format = gst_vaapi_image_format(&va_formats[i]);
|
|
|
|
if (format) {
|
|
|
|
GstCaps * const caps = gst_vaapi_image_format_get_caps(format);
|
|
|
|
if (caps)
|
|
|
|
gst_caps_append(out_caps, caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_display_get_image_caps(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
|
|
|
|
|
|
|
return _gst_vaapi_display_get_caps(display,
|
|
|
|
display->priv->image_formats,
|
|
|
|
display->priv->num_image_formats);
|
|
|
|
}
|
|
|
|
|
2010-03-04 17:41:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_display_has_image_format(
|
|
|
|
GstVaapiDisplay *display,
|
|
|
|
GstVaapiImageFormat format
|
|
|
|
)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
|
|
|
|
|
|
|
|
return _gst_vaapi_display_has_format(display, format,
|
|
|
|
display->priv->image_formats,
|
|
|
|
display->priv->num_image_formats);
|
|
|
|
}
|
|
|
|
|
2010-03-10 10:43:31 +00:00
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_display_get_subpicture_caps(GstVaapiDisplay *display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
|
|
|
|
|
|
|
return _gst_vaapi_display_get_caps(display,
|
|
|
|
display->priv->subpicture_formats,
|
|
|
|
display->priv->num_subpicture_formats);
|
|
|
|
}
|
|
|
|
|
2010-03-04 17:41:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_display_has_subpicture_format(
|
|
|
|
GstVaapiDisplay *display,
|
|
|
|
GstVaapiImageFormat format
|
|
|
|
)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
|
|
|
|
|
|
|
|
return _gst_vaapi_display_has_format(display, format,
|
|
|
|
display->priv->subpicture_formats,
|
|
|
|
display->priv->num_subpicture_formats);
|
|
|
|
}
|