2 * gstvaapivideoconverter_glx.c - Gst VA video converter
4 * Copyright (C) 2011 Intel Corporation
5 * Copyright (C) 2011 Collabora Ltd.
6 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA
26 #include "gstvaapivideoconverter_glx.h"
27 #include "gstvaapivideobuffer.h"
28 #include "gstvaapitexture.h"
30 static void gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface *iface);
32 G_DEFINE_TYPE_WITH_CODE (GstVaapiVideoConverterGLX, gst_vaapi_video_converter_glx,
34 G_IMPLEMENT_INTERFACE (GST_TYPE_SURFACE_CONVERTER,
35 gst_vaapi_video_converter_glx_iface_init));
37 struct _GstVaapiVideoConverterGLXPrivate {
38 GstVaapiTexture *texture;
42 gst_vaapi_video_converter_glx_dispose(GObject *object)
44 GstVaapiVideoConverterGLXPrivate *priv =
45 GST_VAAPI_VIDEO_CONVERTER_GLX (object)->priv;
47 g_clear_object(&priv->texture);
49 G_OBJECT_CLASS (gst_vaapi_video_converter_glx_parent_class)->dispose (object);
53 gst_vaapi_video_converter_glx_class_init(GstVaapiVideoConverterGLXClass *klass)
55 GObjectClass *object_class = G_OBJECT_CLASS (klass);
57 g_type_class_add_private (klass, sizeof (GstVaapiVideoConverterGLXPrivate));
58 object_class->dispose = gst_vaapi_video_converter_glx_dispose;
62 gst_vaapi_video_converter_glx_init(GstVaapiVideoConverterGLX *buffer)
64 buffer->priv = G_TYPE_INSTANCE_GET_PRIVATE(buffer,
65 GST_VAAPI_TYPE_VIDEO_CONVERTER,
66 GstVaapiVideoConverterGLXPrivate);
70 gst_vaapi_video_converter_glx_iface_init (GstSurfaceConverterInterface *iface) {
71 iface->upload = gst_vaapi_video_converter_glx_upload;
75 * gst_vaapi_video_converter_glx_new:
76 * @surface: the #GstSurfaceBuffer
77 * @type: type of the target buffer (must be "opengl")
78 * @dest: target of the conversion (must be GL texture id)
80 * Creates an empty #GstBuffer. The caller is responsible for
81 * completing the initialization of the buffer with the
82 * gst_vaapi_video_converter_glx_set_*() functions.
84 * Return value: the newly allocated #GstBuffer, or %NULL on error
87 gst_vaapi_video_converter_glx_new(GstSurfaceBuffer *surface, const gchar *type,
90 GstVaapiVideoBuffer *buffer = GST_VAAPI_VIDEO_BUFFER (surface);
91 GstVaapiDisplay *display = gst_vaapi_video_buffer_get_display (buffer);
92 GstVaapiTexture *texture;
93 GstVaapiVideoConverterGLX *converter = NULL;
95 /* We only support Open GL texture conversion */
96 if (strcmp(type, "opengl") || !G_VALUE_HOLDS_UINT (dest))
99 /* FIXME Should we assume target and format ? */
100 texture = gst_vaapi_texture_new_with_texture (display,
101 g_value_get_uint (dest),
106 converter = g_object_new (GST_VAAPI_TYPE_VIDEO_CONVERTER, NULL);
107 converter->priv->texture = texture;
110 return GST_SURFACE_CONVERTER (converter);
114 gst_vaapi_video_converter_glx_upload (GstSurfaceConverter *converter,
115 GstSurfaceBuffer *buffer)
117 GstVaapiVideoConverterGLXPrivate *priv =
118 GST_VAAPI_VIDEO_CONVERTER_GLX (converter)->priv;
119 GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER (buffer);
120 GstVaapiSurface *surface = gst_vaapi_video_buffer_get_surface (vbuffer);
121 GstVaapiDisplay *new_dpy, *old_dpy;
122 GstVideoOverlayComposition * const composition =
123 gst_video_buffer_get_overlay_composition (GST_BUFFER (buffer));
125 new_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface));
126 old_dpy = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (priv->texture));
128 if (old_dpy != new_dpy) {
129 guint texture = gst_vaapi_texture_get_id (priv->texture);
130 g_object_unref (priv->texture);
131 priv->texture = gst_vaapi_texture_new_with_texture (new_dpy,
137 if (!gst_vaapi_surface_set_subpictures_from_composition (surface,
139 GST_WARNING ("could not update subtitles");
141 return gst_vaapi_texture_put_surface (priv->texture, surface,
142 gst_vaapi_video_buffer_get_render_flags (vbuffer));