diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index f007b0f2f4..68bb260852 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -170,14 +170,12 @@ libgstvaapi_glx_source_c = \ gstvaapiutils.c \ gstvaapiutils_glx.c \ gstvaapiutils_x11.c \ - gstvaapivideoconverter_glx.c \ gstvaapiwindow_glx.c \ $(NULL) libgstvaapi_glx_source_h = \ gstvaapidisplay_glx.h \ gstvaapitexture.h \ - gstvaapivideoconverter_glx.h \ gstvaapiwindow_glx.h \ $(NULL) diff --git a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c b/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c deleted file mode 100644 index afb6e6ed8a..0000000000 --- a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * gstvaapivideoconverter_glx.c - Gst VA video converter - * - * Copyright (C) 2011-2013 Intel Corporation - * Copyright (C) 2011 Collabora Ltd. - * Author: Nicolas Dufresne - * - * 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 "sysdeps.h" -#include -#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; - - g_clear_object(&priv->texture); - - 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: - * @surface: the #GstSurfaceBuffer - * @type: type of the target buffer (must be "opengl") - * @dest: target of the conversion (must be GL texture id) - * - * 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 on error - */ -GstSurfaceConverter * -gst_vaapi_video_converter_glx_new(GstSurfaceBuffer *surface, const gchar *type, - GValue *dest) -{ - GstVaapiVideoMeta * const meta = - gst_vaapi_video_buffer_get_meta(GST_VAAPI_VIDEO_BUFFER(surface)); - GstVaapiTexture *texture; - GstVaapiVideoConverterGLX *converter; - - /* 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( - gst_vaapi_video_meta_get_display(meta), - g_value_get_uint(dest), GL_TEXTURE_2D, GL_BGRA); - if (!texture) - return NULL; - - 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; - GstVaapiVideoMeta * const meta = - gst_vaapi_video_buffer_get_meta (GST_VAAPI_VIDEO_BUFFER (buffer)); - GstVaapiSurface *surface = gst_vaapi_video_meta_get_surface (meta); - GstVaapiDisplay *new_dpy, *old_dpy; - GstVideoOverlayComposition * const composition = - gst_video_buffer_get_overlay_composition (GST_BUFFER (buffer)); - - 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); - } - - if (!gst_vaapi_surface_set_subpictures_from_composition (surface, - composition, TRUE)) - GST_WARNING ("could not update subtitles"); - - return gst_vaapi_texture_put_surface (priv->texture, surface, - gst_vaapi_video_meta_get_render_flags (meta)); -} diff --git a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.h b/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.h deleted file mode 100644 index 67d0f2e7e0..0000000000 --- a/gst-libs/gst/vaapi/gstvaapivideoconverter_glx.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * gstvaapivideoconverter_glx.h - Gstreamer/VA video converter - * - * Copyright (C) 2011-2012 Intel Corporation - * Copyright (C) 2011 Collabora Ltd. - * Author: Nicolas Dufresne - * - * 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 - -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) G_GNUC_CONST; - -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 */ diff --git a/gst/vaapi/Makefile.am b/gst/vaapi/Makefile.am index e1462bf124..67b95fbebe 100644 --- a/gst/vaapi/Makefile.am +++ b/gst/vaapi/Makefile.am @@ -29,7 +29,7 @@ libgstvaapi_LIBS += \ $(top_builddir)/gst-libs/gst/vaapi/libgstvaapi-wayland-$(GST_API_VERSION).la endif -libgstvaapi_la_SOURCES = \ +libgstvaapi_source_c = \ gstvaapi.c \ gstvaapidecode.c \ gstvaapidownload.c \ @@ -41,7 +41,7 @@ libgstvaapi_la_SOURCES = \ gstvaapiuploader.c \ $(NULL) -noinst_HEADERS = \ +libgstvaapi_source_h = \ gstvaapidecode.h \ gstvaapidownload.h \ gstvaapipluginbuffer.h \ @@ -52,6 +52,14 @@ noinst_HEADERS = \ gstvaapiuploader.h \ $(NULL) +if USE_GLX +libgstvaapi_source_c += gstvaapivideoconverter_glx.c +libgstvaapi_source_h += gstvaapivideoconverter_glx.h +endif + +libgstvaapi_la_SOURCES = $(libgstvaapi_source_c) +noinst_HEADERS = $(libgstvaapi_source_h) + libgstvaapi_la_CFLAGS = \ $(libgstvaapi_CFLAGS) \ $(GST_CFLAGS) \ diff --git a/gst/vaapi/gstvaapipluginbuffer.c b/gst/vaapi/gstvaapipluginbuffer.c index 37171edf1d..766978f364 100644 --- a/gst/vaapi/gstvaapipluginbuffer.c +++ b/gst/vaapi/gstvaapipluginbuffer.c @@ -23,7 +23,7 @@ #include #include #if USE_GLX -# include +# include "gstvaapivideoconverter_glx.h" #endif #include "gstvaapipluginbuffer.h" diff --git a/gst/vaapi/gstvaapivideoconverter_glx.c b/gst/vaapi/gstvaapivideoconverter_glx.c new file mode 100644 index 0000000000..842225695c --- /dev/null +++ b/gst/vaapi/gstvaapivideoconverter_glx.c @@ -0,0 +1,154 @@ +/* + * gstvaapivideoconverter_glx.c - Gst VA video converter + * + * Copyright (C) 2011-2013 Intel Corporation + * Copyright (C) 2011 Collabora Ltd. + * Author: Nicolas Dufresne + * + * 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 "gst/vaapi/sysdeps.h" +#include +#include +#include "gstvaapivideoconverter_glx.h" + +typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *, + GstSurfaceBuffer *); + +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)) + +#define GST_VAAPI_VIDEO_CONVERTER_GLX_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \ + GstVaapiVideoConverterGLXPrivate)) + +struct _GstVaapiVideoConverterGLXPrivate { + GstVaapiTexture *texture; +}; + +static gboolean +gst_vaapi_video_converter_glx_upload(GstSurfaceConverter *self, + GstBuffer *buffer); + +static void +gst_vaapi_video_converter_glx_dispose(GObject *object) +{ + GstVaapiVideoConverterGLXPrivate * const priv = + GST_VAAPI_VIDEO_CONVERTER_GLX(object)->priv; + + g_clear_object(&priv->texture); + + G_OBJECT_CLASS(gst_vaapi_video_converter_glx_parent_class)->dispose(object); +} + +static void +gst_vaapi_video_converter_glx_class_init(GstVaapiVideoConverterGLXClass *klass) +{ + GObjectClass * const 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 = GST_VAAPI_VIDEO_CONVERTER_GLX_GET_PRIVATE(buffer); +} + +static void +gst_vaapi_video_converter_glx_iface_init(GstSurfaceConverterInterface *iface) +{ + iface->upload = (GstSurfaceUploadFunction) + gst_vaapi_video_converter_glx_upload; +} + +/** + * gst_vaapi_video_converter_glx_new: + * @surface: the #GstSurfaceBuffer + * @type: type of the target buffer (must be "opengl") + * @dest: target of the conversion (must be GL texture id) + * + * 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 on error + */ +GstSurfaceConverter * +gst_vaapi_video_converter_glx_new(GstBuffer *buffer, const gchar *type, + GValue *dest) +{ + GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer); + GstVaapiTexture *texture; + GstVaapiVideoConverterGLX *converter; + + /* We only support Open GL texture conversion */ + if (strcmp(type, "opengl") != 0 || !G_VALUE_HOLDS_UINT(dest)) + return NULL; + + /* FIXME Should we assume target and format ? */ + 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; + + converter = g_object_new(GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, NULL); + converter->priv->texture = texture; + return GST_SURFACE_CONVERTER(converter); +} + +gboolean +gst_vaapi_video_converter_glx_upload(GstSurfaceConverter *self, + GstBuffer *buffer) +{ + GstVaapiVideoConverterGLXPrivate * const priv = + GST_VAAPI_VIDEO_CONVERTER_GLX(self)->priv; + GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer); + GstVaapiSurface * const surface = gst_vaapi_video_meta_get_surface(meta); + GstVaapiDisplay *new_dpy, *old_dpy; + GstVideoOverlayComposition * const composition = + gst_video_buffer_get_overlay_composition(buffer); + + 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) { + const guint texture = gst_vaapi_texture_get_id(priv->texture); + + g_clear_object(&priv->texture); + priv->texture = gst_vaapi_texture_new_with_texture(new_dpy, + texture, GL_TEXTURE_2D, GL_BGRA); + } + + if (!gst_vaapi_surface_set_subpictures_from_composition(surface, + composition, TRUE)) + GST_WARNING("could not update subtitles"); + + return gst_vaapi_texture_put_surface(priv->texture, surface, + gst_vaapi_video_meta_get_render_flags(meta)); +} diff --git a/gst/vaapi/gstvaapivideoconverter_glx.h b/gst/vaapi/gstvaapivideoconverter_glx.h new file mode 100644 index 0000000000..70e2edf1ae --- /dev/null +++ b/gst/vaapi/gstvaapivideoconverter_glx.h @@ -0,0 +1,90 @@ +/* + * gstvaapivideoconverter_glx.h - Gstreamer/VA video converter + * + * Copyright (C) 2011-2012 Intel Corporation + * Copyright (C) 2011 Collabora Ltd. + * Author: Nicolas Dufresne + * + * 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 + +G_BEGIN_DECLS + +#define GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX \ + (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_GLX, \ + GstVaapiVideoConverterGLX)) + +#define GST_VAAPI_VIDEO_CONVERTER_GLX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \ + GstVaapiVideoConverterGLXClass)) + +#define GST_VAAPI_IS_VIDEO_CONVERTER_GLX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX)) + +#define GST_VAAPI_IS_VIDEO_CONVERTER_GLX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX)) + +#define GST_VAAPI_VIDEO_CONVERTER_GLX_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + GST_VAAPI_TYPE_VIDEO_CONVERTER_GLX, \ + 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 class to transform VA buffers into GL textures. + */ +struct _GstVaapiVideoConverterGLXClass { + /*< private >*/ + GObjectClass parent_class; +}; + +GType +gst_vaapi_video_converter_glx_get_type(void) G_GNUC_CONST; + +GstSurfaceConverter * +gst_vaapi_video_converter_glx_new(GstBuffer *buffer, const gchar *type, + GValue *dest); + +G_END_DECLS + +#endif /* GST_VAAPI_VIDEO_CONVERTER_GLX_H */