Commit 693277e2 authored by gb's avatar gb

Add initial VA display abstraction.

parent 30a27764
......@@ -93,6 +93,7 @@ AC_SUBST(plugindir)
dnl Check for VA-API
PKG_CHECK_MODULES(LIBVA, [libva])
PKG_CHECK_MODULES(X11, [x11])
PKG_CHECK_MODULES(LIBVA_X11, [libva-x11])
dnl Check for SDS extensions to VA-API
......
lib_LTLIBRARIES = libgstvaapi-@GST_MAJORMINOR@.la
libgstvaapi_@GST_MAJORMINOR@_la_SOURCES = \
libgstvaapi_@GST_MAJORMINOR@_la_SOURCES = \
gstvaapidisplay.c \
vaapi_utils.c \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@include_HEADERS = \
gstvaapidisplay.h \
vaapi_debug.h \
vaapi_utils.h \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/vaapi
libgstvaapi_@GST_MAJORMINOR@include_HEADERS = \
libgstvaapi_@GST_MAJORMINOR@_la_CFLAGS = \
$(GST_BASE_CFLAGS) \
$(GST_CFLAGS) \
$(LIBVA_CFLAGS) \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@_la_LIBADD = \
$(GST_BASE_LIBS) \
$(GST_LIBS) \
$(LIBVA_LIBS) \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@_la_SOURCES += \
gstvaapidisplay_x11.c \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@include_HEADERS += \
gstvaapidisplay_x11.h \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@_la_CFLAGS += \
$(LIBVA_X11_CFLAGS) \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@_la_LIBADD += \
$(LIBVA_X11_LIBS) \
$(NULL)
# Extra clean files so that maintainer-clean removes *everything*
......
/*
* 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"
#include "vaapi_utils.h"
#include "gstvaapidisplay.h"
#include <va/va_backend.h>
#define DEBUG 1
#include "vaapi_debug.h"
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 {
VADisplay display;
VAProfile *profiles;
unsigned int num_profiles;
VAImageFormat *image_formats;
unsigned int num_image_formats;
VAImageFormat *subpicture_formats;
unsigned int *subpicture_flags;
unsigned int num_subpicture_formats;
};
enum {
PROP_0,
PROP_DISPLAY
};
static void
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display);
static void
gst_vaapi_display_finalize(GObject *object)
{
GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
GstVaapiDisplayPrivate *priv = display->priv;
gst_vaapi_display_set_display(display, NULL);
G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
}
static void
gst_vaapi_display_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
GstVaapiDisplayPrivate *priv = display->priv;
switch (prop_id) {
case PROP_DISPLAY:
gst_vaapi_display_set_display(display, g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
gst_vaapi_display_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
GstVaapiDisplayPrivate *priv = display->priv;
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;
}
}
static void
gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(GstVaapiDisplayPrivate));
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;
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;
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;
}
VADisplay
gst_vaapi_display_get_display(GstVaapiDisplay *display)
{
GstVaapiDisplayPrivate *priv = display->priv;
return priv->display;
}
static void
gst_vaapi_display_destroy_resources(GstVaapiDisplay *display)
{
GstVaapiDisplayPrivate *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;
}
if (priv->subpicture_formats) {
g_free(priv->subpicture_formats);
priv->subpicture_formats = NULL;
}
if (priv->subpicture_flags) {
g_free(priv->subpicture_flags);
priv->subpicture_flags = NULL;
}
}
static gboolean
gst_vaapi_display_create_resources(GstVaapiDisplay *display)
{
GstVaapiDisplayPrivate *priv = display->priv;
VAStatus status;
unsigned int i;
/* 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;
D(bug("%d profiles\n", priv->num_profiles));
for (i = 0; i < priv->num_profiles; i++)
D(bug(" %s\n", string_of_VAProfile(priv->profiles[i])));
/* 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;
status = vaQueryImageFormats(priv->display,
priv->image_formats,
&priv->num_image_formats);
if (!vaapi_check_status(status, "vaQueryImageFormats()"))
return FALSE;
D(bug("%d image formats\n", priv->num_image_formats));
for (i = 0; i < priv->num_image_formats; i++)
D(bug(" %s\n", string_of_FOURCC(priv->image_formats[i].fourcc)));
/* 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;
priv->subpicture_flags = g_new(unsigned int, priv->num_subpicture_formats);
if (!priv->subpicture_flags)
return FALSE;
status = vaQuerySubpictureFormats(priv->display,
priv->subpicture_formats,
priv->subpicture_flags,
&priv->num_image_formats);
if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
return FALSE;
D(bug("%d subpicture formats\n", priv->num_subpicture_formats));
for (i = 0; i < priv->num_subpicture_formats; i++)
D(bug(" %s\n", string_of_FOURCC(priv->subpicture_formats[i].fourcc)));
return TRUE;
}
void
gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display)
{
GstVaapiDisplayPrivate *priv = display->priv;
VAStatus status;
int major_version, minor_version;
if (priv->display) {
gst_vaapi_display_destroy_resources(display);
/* XXX: make sure this VADisplay is really the last occurrence */
status = vaTerminate(priv->display);
if (!vaapi_check_status(status, "vaTerminate()"))
return;
priv->display = NULL;
}
if (va_display) {
status = vaInitialize(va_display, &major_version, &minor_version);
if (!vaapi_check_status(status, "vaInitialize()"))
return;
priv->display = va_display;
D(bug("VA-API version %d.%d\n", major_version, minor_version));
if (!gst_vaapi_display_create_resources(display)) {
gst_vaapi_display_destroy_resources(display);
return;
}
}
}
/*
* gstvaapidisplay.h - 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
*/
#ifndef GST_VAAPI_DISPLAY_H
#define GST_VAAPI_DISPLAY_H
#include <va/va.h>
#include <gst/gst.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_DISPLAY \
(gst_vaapi_display_get_type())
#define GST_VAAPI_DISPLAY(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DISPLAY, \
GstVaapiDisplay))
#define GST_VAAPI_DISPLAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DISPLAY, \
GstVaapiDisplayClass))
#define GST_VAAPI_IS_DISPLAY(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DISPLAY))
#define GST_VAAPI_IS_DISPLAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DISPLAY))
#define GST_VAAPI_DISPLAY_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DISPLAY, \
GstVaapiDisplay))
typedef struct _GstVaapiDisplay GstVaapiDisplay;
typedef struct _GstVaapiDisplayPrivate GstVaapiDisplayPrivate;
typedef struct _GstVaapiDisplayClass GstVaapiDisplayClass;
struct _GstVaapiDisplay {
/*< private >*/
GObject parent_instance;
GstVaapiDisplayPrivate *priv;
};
struct _GstVaapiDisplayClass {
/*< private >*/
GObjectClass parent_class;
};
GType
gst_vaapi_display_get_type(void);
VADisplay
gst_vaapi_display_get_display(GstVaapiDisplay *display);
G_END_DECLS
#endif /* GST_VAAPI_DISPLAY_H */
/*
* gstvaapidisplay_x11.c - VA/X11 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"
#include "vaapi_utils.h"
#include "gstvaapidisplay_x11.h"
#define DEBUG 1
#include "vaapi_debug.h"
G_DEFINE_TYPE(GstVaapiDisplayX11,
gst_vaapi_display_x11,
GST_VAAPI_TYPE_DISPLAY);
#define GST_VAAPI_DISPLAY_X11_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_DISPLAY_X11, \
GstVaapiDisplayX11Private))
struct _GstVaapiDisplayX11Private {
Display *display;
};
enum {
PROP_0,
PROP_X11_DISPLAY
};
static void
gst_vaapi_display_x11_set_display(GstVaapiDisplayX11 *display,
Display *x11_display);
static void
gst_vaapi_display_x11_finalize(GObject *object)
{
GstVaapiDisplayX11 *display = GST_VAAPI_DISPLAY_X11(object);
GstVaapiDisplayX11Private *priv = display->priv;
G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
}
static void
gst_vaapi_display_x11_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GstVaapiDisplayX11 *display = GST_VAAPI_DISPLAY_X11(object);
GstVaapiDisplayX11Private *priv = display->priv;
switch (prop_id) {
case PROP_X11_DISPLAY:
gst_vaapi_display_x11_set_display(display, g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
gst_vaapi_display_x11_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GstVaapiDisplayX11 *display = GST_VAAPI_DISPLAY_X11(object);
GstVaapiDisplayX11Private *priv = display->priv;
switch (prop_id) {
case PROP_X11_DISPLAY:
g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
object_class->finalize = gst_vaapi_display_x11_finalize;
object_class->set_property = gst_vaapi_display_x11_set_property;
object_class->get_property = gst_vaapi_display_x11_get_property;
g_object_class_install_property
(object_class,
PROP_X11_DISPLAY,
g_param_spec_pointer("x11-display",
"X11 display",
"X11 display",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
}
static void
gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
{
GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
display->priv = priv;
priv->display = NULL;
}
Display *
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
{
GstVaapiDisplayX11Private *priv = display->priv;
return priv->display;
}
void
gst_vaapi_display_x11_set_display(GstVaapiDisplayX11 *display,
Display *x11_display)
{
GstVaapiDisplayX11Private *priv = display->priv;
if (x11_display) {
VADisplay va_display = vaGetDisplay(x11_display);
if (va_display)
g_object_set(GST_VAAPI_DISPLAY(display),
"display", va_display,
NULL);
}
priv->display = x11_display;
}
GstVaapiDisplay *
gst_vaapi_display_x11_new(Display *x11_display)
{
return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
"x11-display", x11_display,
NULL);
}
/*
* gstvaapidisplay_x11.h - VA/X11 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
*/
#ifndef GST_VAAPI_DISPLAY_X11_H
#define GST_VAAPI_DISPLAY_X11_H
#include "gstvaapidisplay.h"
#include <va/va_x11.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_DISPLAY_X11 \
(gst_vaapi_display_x11_get_type())
#define GST_VAAPI_DISPLAY_X11(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DISPLAY_X11, \
GstVaapiDisplayX11))
#define GST_VAAPI_DISPLAY_X11_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DISPLAY_X11, \
GstVaapiDisplayX11Class))
#define GST_VAAPI_IS_DISPLAY_X11(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DISPLAY_X11))
#define GST_VAAPI_IS_DISPLAY_X11_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DISPLAY_X11))
#define GST_VAAPI_DISPLAY_X11_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DISPLAY_X11, \
GstVaapiDisplayX11))
typedef struct _GstVaapiDisplayX11 GstVaapiDisplayX11;
typedef struct _GstVaapiDisplayX11Private GstVaapiDisplayX11Private;
typedef struct _GstVaapiDisplayX11Class GstVaapiDisplayX11Class;
struct _GstVaapiDisplayX11 {
/*< private >*/
GstVaapiDisplay parent_instance;
GstVaapiDisplayX11Private *priv;
};
struct _GstVaapiDisplayX11Class {
/*< private >*/
GstVaapiDisplayClass parent_class;
};
GType
gst_vaapi_display_x11_get_type(void);
GstVaapiDisplay *
gst_vaapi_display_x11_new(Display *x11_display);
Display *
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display);
G_END_DECLS
#endif /* GST_VAAPI_DISPLAY_X11_H */
/*
* vaapi_debug.h - VA-API debugging utilities
*
* 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
*/
#ifndef VAAPI_DEBUG_H
#define VAAPI_DEBUG_H
#include "vaapi_utils.h"
#if DEBUG
# define D(x) x
#else
# define D(x)
#endif
#define bug vaapi_dprintf
#endif /* VAAPI_DEBUG_H */
/*
* vaapi_utils.c - VA-API utilities
*
* 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 "vaapi_utils.h"
#include <stdio.h>
#include <stdarg.h>
/* Debug output */
void vaapi_dprintf(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stdout, "[GstVaapi] ");
vfprintf(stdout, format, args);
va_end(args);
}
/* Check VA status for success or print out an error */
int vaapi_check_status(VAStatus status, const char *msg)
{
if (status != VA_STATUS_SUCCESS) {
vaapi_dprintf("%s: %s\n", msg, vaErrorStr(status));
return 0;
}
return 1;
}
/* 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);