2011-11-04 23:47:09 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2011-11-04 23:47:09 +00:00
|
|
|
#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,
|
2012-09-07 14:14:11 +00:00
|
|
|
gst_vaapi_video_converter_glx_iface_init))
|
2011-11-04 23:47:09 +00:00
|
|
|
|
|
|
|
struct _GstVaapiVideoConverterGLXPrivate {
|
|
|
|
GstVaapiTexture *texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_video_converter_glx_dispose(GObject *object)
|
|
|
|
{
|
|
|
|
GstVaapiVideoConverterGLXPrivate *priv =
|
|
|
|
GST_VAAPI_VIDEO_CONVERTER_GLX (object)->priv;
|
|
|
|
|
2012-06-30 20:34:15 +00:00
|
|
|
g_clear_object(&priv->texture);
|
2011-11-04 23:47:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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:
|
2012-04-02 10:52:54 +00:00
|
|
|
* @surface: the #GstSurfaceBuffer
|
|
|
|
* @type: type of the target buffer (must be "opengl")
|
|
|
|
* @dest: target of the conversion (must be GL texture id)
|
2011-11-04 23:47:09 +00:00
|
|
|
*
|
2012-04-02 10:52:54 +00:00
|
|
|
* Creates an empty #GstBuffer. The caller is responsible for
|
|
|
|
* completing the initialization of the buffer with the
|
|
|
|
* gst_vaapi_video_converter_glx_set_*() functions.
|
2011-11-04 23:47:09 +00:00
|
|
|
*
|
2012-04-02 10:52:54 +00:00
|
|
|
* Return value: the newly allocated #GstBuffer, or %NULL on error
|
2011-11-04 23:47:09 +00:00
|
|
|
*/
|
|
|
|
GstSurfaceConverter *
|
|
|
|
gst_vaapi_video_converter_glx_new(GstSurfaceBuffer *surface, const gchar *type,
|
|
|
|
GValue *dest)
|
|
|
|
{
|
2013-01-05 16:37:13 +00:00
|
|
|
GstVaapiVideoMeta * const meta =
|
|
|
|
gst_vaapi_video_buffer_get_meta(GST_VAAPI_VIDEO_BUFFER(surface));
|
2011-11-04 23:47:09 +00:00
|
|
|
GstVaapiTexture *texture;
|
2013-01-05 16:37:13 +00:00
|
|
|
GstVaapiVideoConverterGLX *converter;
|
2011-11-04 23:47:09 +00:00
|
|
|
|
|
|
|
/* We only support Open GL texture conversion */
|
2013-01-05 16:37:13 +00:00
|
|
|
if (strcmp(type, "opengl") || !G_VALUE_HOLDS_UINT(dest))
|
2011-11-04 23:47:09 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* FIXME Should we assume target and format ? */
|
2013-01-05 16:37:13 +00:00
|
|
|
texture = gst_vaapi_texture_new_with_texture(
|
|
|
|
gst_vaapi_video_meta_get_display(meta),
|
|
|
|
g_value_get_uint(dest), GL_TEXTURE_2D, GL_BGRA);
|
|
|
|
if (!texture)
|
|
|
|
return NULL;
|
2011-11-04 23:47:09 +00:00
|
|
|
|
2013-01-05 16:37:13 +00:00
|
|
|
converter = g_object_new(GST_VAAPI_TYPE_VIDEO_CONVERTER, NULL);
|
|
|
|
converter->priv->texture = texture;
|
|
|
|
return GST_SURFACE_CONVERTER(converter);
|
2011-11-04 23:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_video_converter_glx_upload (GstSurfaceConverter *converter,
|
|
|
|
GstSurfaceBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstVaapiVideoConverterGLXPrivate *priv =
|
|
|
|
GST_VAAPI_VIDEO_CONVERTER_GLX (converter)->priv;
|
2013-01-05 16:37:13 +00:00
|
|
|
GstVaapiVideoMeta * const meta =
|
|
|
|
gst_vaapi_video_buffer_get_meta (GST_VAAPI_VIDEO_BUFFER (buffer));
|
|
|
|
GstVaapiSurface *surface = gst_vaapi_video_meta_get_surface (meta);
|
2011-11-04 23:47:09 +00:00
|
|
|
GstVaapiDisplay *new_dpy, *old_dpy;
|
2011-11-25 20:00:25 +00:00
|
|
|
GstVideoOverlayComposition * const composition =
|
|
|
|
gst_video_buffer_get_overlay_composition (GST_BUFFER (buffer));
|
2011-11-04 23:47:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-12-14 13:40:37 +00:00
|
|
|
if (!gst_vaapi_surface_set_subpictures_from_composition (surface,
|
|
|
|
composition, TRUE))
|
2011-11-25 20:00:25 +00:00
|
|
|
GST_WARNING ("could not update subtitles");
|
|
|
|
|
2011-11-04 23:47:09 +00:00
|
|
|
return gst_vaapi_texture_put_surface (priv->texture, surface,
|
2013-01-05 16:37:13 +00:00
|
|
|
gst_vaapi_video_meta_get_render_flags (meta));
|
2011-11-04 23:47:09 +00:00
|
|
|
}
|