videobuffer: add GLX buffer support.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
This commit is contained in:
Nicolas Dufresne 2011-11-04 19:47:09 -04:00 committed by Gwenole Beauchesne
parent a6717334f9
commit c5b18c27d5
7 changed files with 556 additions and 0 deletions

View file

@ -76,6 +76,7 @@ libgstvaapi_source_priv_h = \
gstvaapidisplay_priv.h \
gstvaapiobject_priv.h \
gstvaapiutils.h \
gstvaapivideobuffer_priv.h \
$(libgst_vaapi_ffmpeg_source_priv_h) \
$(NULL)
@ -104,12 +105,16 @@ libgstvaapi_glx_source_c = \
gstvaapiutils.c \
gstvaapiutils_glx.c \
gstvaapiutils_x11.c \
gstvaapivideobuffer_glx.c \
gstvaapivideoconverter_glx.c \
gstvaapiwindow_glx.c \
$(NULL)
libgstvaapi_glx_source_h = \
gstvaapidisplay_glx.h \
gstvaapitexture.h \
gstvaapivideobuffer_glx.h \
gstvaapivideoconverter_glx.h \
gstvaapiwindow_glx.h \
$(NULL)

View file

@ -26,6 +26,7 @@
#include "config.h"
#include "gstvaapivideobuffer.h"
#include "gstvaapivideobuffer_priv.h"
#include "gstvaapiimagepool.h"
#include "gstvaapisurfacepool.h"
#include "gstvaapiobject_priv.h"
@ -562,3 +563,36 @@ gst_vaapi_video_buffer_set_surface_proxy(
buffer->priv->proxy = g_object_ref(proxy);
}
}
/**
* gst_vaapi_video_buffer_set_display:
* @buffer: a #GstVaapiVideoBuffer
* @display a #GstVaapiDisplay
*
* For subclass only, don't use.
*/
void
gst_vaapi_video_buffer_set_display(
GstVaapiVideoBuffer *buffer,
GstVaapiDisplay *display
)
{
set_display(buffer, display);
}
/**
* gst_vaapi_video_buffer_set_display:
* @buffer: a #GstVaapiVideoBuffer
* @other_buffer: a #GstBuffer
*
* For subclass only, don't use.
*/
void
gst_vaapi_video_buffer_set_buffer(
GstVaapiVideoBuffer *buffer,
GstBuffer *other_buffer
)
{
g_return_if_fail (buffer->priv->buffer == NULL);
buffer->priv->buffer = gst_buffer_ref (other_buffer);
}

View file

@ -0,0 +1,170 @@
/*
* gstvaapivideobuffer_glx.c - Gst VA video buffer
*
* Copyright (C) 2011 Intel Corporation
* Copyright (C) 2011 Collabora Ltd.
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
*
* 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.
*
* This library 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
* Lesser General Public License for more details.
*
* 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
*/
/**
* SECTION:gstvaapivideobufferglx
* @short_description: VA video buffer for GStreamer with GLX support
*/
#include "config.h"
#include "gstvaapivideobuffer_glx.h"
#include "gstvaapivideobuffer_priv.h"
#include "gstvaapivideoconverter_glx.h"
#include "gstvaapiobject_priv.h"
#include "gstvaapiimagepool.h"
#include "gstvaapisurfacepool.h"
#define DEBUG 1
#include "gstvaapidebug.h"
G_DEFINE_TYPE (GstVaapiVideoBufferGLX, gst_vaapi_video_buffer_glx,
GST_VAAPI_TYPE_VIDEO_BUFFER);
static void
gst_vaapi_video_buffer_glx_class_init(GstVaapiVideoBufferGLXClass * klass)
{
GstSurfaceBufferClass * const surface_class = GST_SURFACE_BUFFER_CLASS (klass);
surface_class->create_converter = gst_vaapi_video_converter_glx_new;
}
static void
gst_vaapi_video_buffer_glx_init (GstVaapiVideoBufferGLX * buffer)
{
}
static inline gpointer
_gst_vaapi_video_buffer_glx_new (void)
{
return gst_mini_object_new (GST_VAAPI_TYPE_VIDEO_BUFFER_GLX);
}
/**
* gst_vaapi_video_buffer_glx_new:
* @display: a #GstVaapiDisplayGLX
*
* Creates an empty #GstBuffer. The caller is responsible for completing
* the initialization of the buffer with the gst_vaapi_video_buffer_set_*()
* functions.
*
* Return value: the newly allocated #GstBuffer, or %NULL or error
*/
GstBuffer *
gst_vaapi_video_buffer_glx_new(GstVaapiDisplayGLX * display)
{
GstBuffer *buffer;
g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_GLX (display), NULL);
buffer = _gst_vaapi_video_buffer_glx_new ();
if (!buffer)
return NULL;
gst_vaapi_video_buffer_set_display (GST_VAAPI_VIDEO_BUFFER (buffer),
GST_VAAPI_DISPLAY (display));
return buffer;
}
/**
* gst_vaapi_video_buffer_glx_new_from_pool:
* @pool: a #GstVaapiVideoPool
*
* Creates a #GstBuffer with a video object allocated from a @pool.
* Only #GstVaapiSurfacePool and #GstVaapiImagePool pools are supported.
*
* The buffer is destroyed through the last call to gst_buffer_unref()
* and the video objects are pushed back to their respective pools.
*
* Return value: the newly allocated #GstBuffer, or %NULL on error
*/
GstBuffer *
gst_vaapi_video_buffer_glx_new_from_pool (GstVaapiVideoPool * pool)
{
GstVaapiVideoBuffer *buffer;
gboolean is_image_pool, is_surface_pool;
g_return_val_if_fail (GST_VAAPI_IS_VIDEO_POOL (pool), NULL);
is_image_pool = GST_VAAPI_IS_IMAGE_POOL (pool);
is_surface_pool = GST_VAAPI_IS_SURFACE_POOL (pool);
if (!is_image_pool && !is_surface_pool)
return NULL;
buffer = _gst_vaapi_video_buffer_glx_new ();
if (buffer &&
((is_image_pool &&
gst_vaapi_video_buffer_set_image_from_pool (buffer, pool)) ||
(is_surface_pool &&
gst_vaapi_video_buffer_set_surface_from_pool (buffer, pool)))) {
gst_vaapi_video_buffer_set_display (buffer,
gst_vaapi_video_pool_get_display (pool));
return GST_BUFFER (buffer);
}
gst_mini_object_unref (GST_MINI_OBJECT(buffer));
return NULL;
}
/**
* gst_vaapi_video_buffer_glx_new_from_buffer:
* @buffer: a #GstBuffer
*
* Creates a #GstBuffer with video objects bound to @buffer video
* objects, if any.
*
* Return value: the newly allocated #GstBuffer, or %NULL on error
*/
GstBuffer *
gst_vaapi_video_buffer_glx_new_from_buffer (GstBuffer * buffer)
{
GstVaapiVideoBuffer *inbuf, *outbuf;
GstVaapiImage *image;
GstVaapiSurface *surface;
GstVaapiSurfaceProxy *proxy;
if (!GST_VAAPI_IS_VIDEO_BUFFER_GLX (buffer)) {
if (!buffer->parent || !GST_VAAPI_IS_VIDEO_BUFFER_GLX (buffer->parent))
return NULL;
buffer = buffer->parent;
}
inbuf = GST_VAAPI_VIDEO_BUFFER (buffer);
outbuf = _gst_vaapi_video_buffer_glx_new ();
if (!outbuf)
return NULL;
image = gst_vaapi_video_buffer_get_image (inbuf);
surface = gst_vaapi_video_buffer_get_surface (inbuf);
proxy =
gst_vaapi_video_buffer_get_surface_proxy (inbuf);
if (image)
gst_vaapi_video_buffer_set_image (outbuf, image);
if (surface)
gst_vaapi_video_buffer_set_surface (outbuf, surface);
if (proxy)
gst_vaapi_video_buffer_set_surface_proxy (outbuf, proxy);
gst_vaapi_video_buffer_set_buffer (outbuf, buffer);
return GST_BUFFER (outbuf);
}

View file

@ -0,0 +1,88 @@
/*
* gstvaapivideobuffer_glx.h - Gstreamer/VA video buffer
*
* Copyright (C) 2011 Intel Corporation
* Copyright (C) 2011 Collabora Ltd.
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
*
* 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.
*
* This library 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
* Lesser General Public License for more details.
*
* 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
*/
#ifndef GST_VAAPI_VIDEO_BUFFER_GLX_H
#define GST_VAAPI_VIDEO_BUFFER_GLX_H
#include <gst/vaapi/gstvaapidisplay_glx.h>
#include <gst/vaapi/gstvaapivideobuffer.h>
#include <gst/vaapi/gstvaapivideopool.h>
#include <gst/video/gstsurfacebuffer.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_BUFFER_GLX \
(gst_vaapi_video_buffer_glx_get_type())
#define GST_VAAPI_VIDEO_BUFFER_GLX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER_GLX, \
GstVaapiVideoBufferGLX))
#define GST_VAAPI_VIDEO_BUFFER_GLX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_VIDEO_BUFFER_GLX, \
GstVaapiVideoBufferGLXClass))
#define GST_VAAPI_IS_VIDEO_BUFFER_GLX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_GLX))
#define GST_VAAPI_IS_VIDEO_BUFFER_GLX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER_GLX))
#define GST_VAAPI_VIDEO_BUFFER_GLX_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_VIDEO_BUFFER_GLX, \
GstVaapiVideoBufferGLXClass))
typedef struct _GstVaapiVideoBufferGLX GstVaapiVideoBufferGLX;
typedef struct _GstVaapiVideoBufferGLXClass GstVaapiVideoBufferGLXClass;
/**
* GstVaapiVideoBufferGLX:
*
* A #GstBuffer holding video objects (#GstVaapiSurface and #GstVaapiImage).
*/
struct _GstVaapiVideoBufferGLX {
/*< private >*/
GstVaapiVideoBuffer parent_instance;
};
/**
* GstVaapiVideoBufferGLXClass:
*
* A #GstBuffer holding video objects
*/
struct _GstVaapiVideoBufferGLXClass {
/*< private >*/
GstVaapiVideoBufferClass parent_class;
};
GType gst_vaapi_video_buffer_glx_get_type (void);
GstBuffer *gst_vaapi_video_buffer_glx_new (GstVaapiDisplayGLX * display);
GstBuffer *gst_vaapi_video_buffer_glx_new_from_pool (GstVaapiVideoPool * pool);
GstBuffer *gst_vaapi_video_buffer_glx_new_from_buffer (GstBuffer * buffer);
G_END_DECLS
#endif /* GST_VAAPI_VIDEO_BUFFER_GLX_H */

View file

@ -0,0 +1,45 @@
/*
* gstvaapivideobuffer_priv.h - Gstreamer/VA video buffer (private interface)
*
* Copyright (C) 2011 Intel Corporation
* Copyright (C) 2011 Collabora Ltd.
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
*
* 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.
*
* This library 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
* Lesser General Public License for more details.
*
* 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
*/
#ifndef GST_VAAPI_VIDEO_BUFFER_PRIV_H
#define GST_VAAPI_VIDEO_BUFFER_PRIV_H
#include <gst/vaapi/gstvaapivideobuffer.h>
G_BEGIN_DECLS
void
gst_vaapi_video_buffer_set_display(
GstVaapiVideoBuffer *buffer,
GstVaapiDisplay *display
);
void
gst_vaapi_video_buffer_set_buffer(
GstVaapiVideoBuffer *buffer,
GstBuffer *other_buffer
);
G_END_DECLS
#endif /* GST_VAAPI_VIDEO_BUFFER_PRIV_H */

View file

@ -0,0 +1,139 @@
/*
* gstvaapivideoconverter_glx.c - Gst VA video converter
*
* Copyright (C) 2011 Intel Corporation
* Copyright (C) 2011 Collabora Ltd.
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
*
* 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.
*
* This library 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
* Lesser General Public License for more details.
*
* 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
*/
#include "config.h"
#include <string.h>
#include "gstvaapivideoconverter_glx.h"
#include "gstvaapivideobuffer.h"
#include "gstvaapitexture.h"
static void gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GstVaapiVideoConverterGLX, gst_vaapi_video_converter_glx,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GST_TYPE_SURFACE_CONVERTER,
gst_vaapi_video_converter_glx_iface_init));
struct _GstVaapiVideoConverterGLXPrivate {
GstVaapiTexture *texture;
};
static void
gst_vaapi_video_converter_glx_dispose(GObject *object)
{
GstVaapiVideoConverterGLXPrivate *priv =
GST_VAAPI_VIDEO_CONVERTER_GLX (object)->priv;
if (priv->texture)
g_object_unref (priv->texture);
priv->texture = NULL;
G_OBJECT_CLASS (gst_vaapi_video_converter_glx_parent_class)->dispose (object);
}
static void
gst_vaapi_video_converter_glx_class_init(GstVaapiVideoConverterGLXClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
g_type_class_add_private (klass, sizeof (GstVaapiVideoConverterGLXPrivate));
object_class->dispose = gst_vaapi_video_converter_glx_dispose;
}
static void
gst_vaapi_video_converter_glx_init(GstVaapiVideoConverterGLX *buffer)
{
buffer->priv = G_TYPE_INSTANCE_GET_PRIVATE(buffer,
GST_VAAPI_TYPE_VIDEO_CONVERTER,
GstVaapiVideoConverterGLXPrivate);
}
static void
gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface *iface) {
iface->upload = gst_vaapi_video_converter_glx_upload;
}
/**
* gst_vaapi_video_converter_glx_new:
* @
*
* Creates an empty #GstBuffer. The caller is responsible for completing
* the initialization of the buffer with the gst_vaapi_video_converter_glx_set_*()
* functions.
*
* Return value: the newly allocated #GstBuffer, or %NULL or error
*/
GstSurfaceConverter *
gst_vaapi_video_converter_glx_new(GstSurfaceBuffer *surface, const gchar *type,
GValue *dest)
{
GstVaapiVideoBuffer *buffer = GST_VAAPI_VIDEO_BUFFER (surface);
GstVaapiDisplay *display = gst_vaapi_video_buffer_get_display (buffer);
GstVaapiTexture *texture;
GstVaapiVideoConverterGLX *converter = NULL;
/* We only support Open GL texture conversion */
if (strcmp(type, "opengl") || !G_VALUE_HOLDS_UINT (dest))
return NULL;
/* FIXME Should we assume target and format ? */
texture = gst_vaapi_texture_new_with_texture (display,
g_value_get_uint (dest),
GL_TEXTURE_2D,
GL_BGRA);
if (texture) {
converter = g_object_new (GST_VAAPI_TYPE_VIDEO_CONVERTER, NULL);
converter->priv->texture = texture;
}
return GST_SURFACE_CONVERTER (converter);
}
gboolean
gst_vaapi_video_converter_glx_upload (GstSurfaceConverter *converter,
GstSurfaceBuffer *buffer)
{
GstVaapiVideoConverterGLXPrivate *priv =
GST_VAAPI_VIDEO_CONVERTER_GLX (converter)->priv;
GstVaapiSurface *surface = gst_vaapi_video_buffer_get_surface (
GST_VAAPI_VIDEO_BUFFER (buffer));
GstVaapiDisplay *new_dpy, *old_dpy;
new_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface));
old_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (priv->texture));
if (old_dpy != new_dpy) {
guint texture = gst_vaapi_texture_get_id (priv->texture);
g_object_unref (priv->texture);
priv->texture = gst_vaapi_texture_new_with_texture (new_dpy,
texture,
GL_TEXTURE_2D,
GL_BGRA);
}
return gst_vaapi_texture_put_surface (priv->texture, surface,
GST_VAAPI_PICTURE_STRUCTURE_FRAME);
}

View file

@ -0,0 +1,75 @@
/*
* gstvaapivideoconverter_glx.h - Gstreamer/VA video converter
*
* Copyright (C) 2011 Intel Corporation
* Copyright (C) 2011 Collabora Ltd.
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
*
* 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.
*
* This library 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
* Lesser General Public License for more details.
*
* 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
*/
#ifndef GST_VAAPI_VIDEO_CONVERTER_GLX_H
#define GST_VAAPI_VIDEO_CONVERTER_GLX_H
#include <gst/video/gstsurfaceconverter.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_VIDEO_CONVERTER (gst_vaapi_video_converter_glx_get_type ())
#define GST_VAAPI_VIDEO_CONVERTER_GLX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER, GstVaapiVideoConverterGLX))
#define GST_VAAPI_VIDEO_CONVERTER_GLX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER, GstVaapiVideoConverterGLXClass))
#define GST_VAAPI_IS_VIDEO_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER))
#define GST_VAAPI_IS_VIDEO_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER))
#define GST_VAAPI_VIDEO_CONVERTER_GLX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER, GstVaapiVideoConverterGLXClass))
typedef struct _GstVaapiVideoConverterGLX GstVaapiVideoConverterGLX;
typedef struct _GstVaapiVideoConverterGLXPrivate GstVaapiVideoConverterGLXPrivate;
typedef struct _GstVaapiVideoConverterGLXClass GstVaapiVideoConverterGLXClass;
/**
* GstVaapiVideoConverterGLX:
*
* Converter to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterGLX {
/*< private >*/
GObject parent_instance;
GstVaapiVideoConverterGLXPrivate *priv;
};
/**
* GstVaapiVideoConverterGLXClass:
*
* Converter to transform VA buffers into GL textures.
*/
struct _GstVaapiVideoConverterGLXClass {
/*< private >*/
GObjectClass parent_class;
};
GType gst_vaapi_video_converter_glx_get_type (void);
GstSurfaceConverter *gst_vaapi_video_converter_glx_new (GstSurfaceBuffer *buffer,
const gchar *type,
GValue *dest);
gboolean gst_vaapi_video_converter_glx_upload (GstSurfaceConverter *self,
GstSurfaceBuffer *buffer);
G_END_DECLS
#endif /* GST_VAAPI_VIDEO_CONVERTER_GLX_H */