2013-07-15 11:41:00 +00:00
|
|
|
/*
|
|
|
|
* gstvaapivideometa_texture.c - GStreamer/VA video meta (GLTextureUpload)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2013-07-15 11:41:00 +00:00
|
|
|
* Copyright (C) 2013 Igalia
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
|
2013-07-15 11:41:00 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2015-04-03 14:08:30 +00:00
|
|
|
#include "gstcompat.h"
|
2015-02-20 14:29:17 +00:00
|
|
|
#include "gst/vaapi/ogl_compat.h"
|
2013-07-15 11:41:00 +00:00
|
|
|
#include "gstvaapivideometa.h"
|
2015-02-20 14:29:17 +00:00
|
|
|
#include "gstvaapivideometa_texture.h"
|
2013-07-15 11:41:00 +00:00
|
|
|
#include "gstvaapipluginutil.h"
|
|
|
|
|
2022-12-10 13:11:08 +00:00
|
|
|
#if GST_VAAPI_USE_GLX
|
2014-10-23 15:44:23 +00:00
|
|
|
#include <gst/vaapi/gstvaapitexture_glx.h>
|
|
|
|
#endif
|
|
|
|
|
2014-12-09 10:46:58 +00:00
|
|
|
#define DEFAULT_FORMAT GST_VIDEO_FORMAT_RGBA
|
|
|
|
|
2022-12-10 13:11:08 +00:00
|
|
|
#if (GST_VAAPI_USE_GLX || GST_VAAPI_USE_EGL)
|
2014-08-21 08:45:31 +00:00
|
|
|
struct _GstVaapiVideoMetaTexture
|
|
|
|
{
|
|
|
|
GstVaapiTexture *texture;
|
2016-03-28 11:13:56 +00:00
|
|
|
GstVideoGLTextureType texture_type[4];
|
2014-12-09 10:46:58 +00:00
|
|
|
guint gl_format;
|
|
|
|
guint width;
|
|
|
|
guint height;
|
2013-12-11 13:04:27 +00:00
|
|
|
};
|
|
|
|
|
2015-02-20 14:13:03 +00:00
|
|
|
static guint
|
|
|
|
get_texture_orientation_flags (GstVideoGLTextureOrientation orientation)
|
|
|
|
{
|
|
|
|
guint flags;
|
|
|
|
|
|
|
|
switch (orientation) {
|
|
|
|
case GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_FLIP:
|
|
|
|
flags = GST_VAAPI_TEXTURE_ORIENTATION_FLAG_Y_INVERTED;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_NORMAL:
|
|
|
|
flags = GST_VAAPI_TEXTURE_ORIENTATION_FLAG_X_INVERTED;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_GL_TEXTURE_ORIENTATION_X_FLIP_Y_FLIP:
|
|
|
|
flags = GST_VAAPI_TEXTURE_ORIENTATION_FLAG_X_INVERTED |
|
|
|
|
GST_VAAPI_TEXTURE_ORIENTATION_FLAG_Y_INVERTED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-12-09 10:46:58 +00:00
|
|
|
static gboolean
|
|
|
|
meta_texture_ensure_format (GstVaapiVideoMetaTexture * meta,
|
|
|
|
GstVideoFormat format)
|
|
|
|
{
|
2016-03-28 11:13:56 +00:00
|
|
|
memset (meta->texture_type, 0, sizeof (meta->texture_type));
|
|
|
|
|
2014-12-09 10:46:58 +00:00
|
|
|
switch (format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
meta->gl_format = GL_RGBA;
|
2016-03-28 11:13:56 +00:00
|
|
|
meta->texture_type[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
|
2014-12-09 10:46:58 +00:00
|
|
|
break;
|
2015-02-09 20:09:07 +00:00
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
meta->gl_format = GL_BGRA_EXT;
|
|
|
|
/* FIXME: add GST_VIDEO_GL_TEXTURE_TYPE_BGRA extension */
|
2016-03-28 11:13:56 +00:00
|
|
|
meta->texture_type[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
|
2015-02-09 20:09:07 +00:00
|
|
|
break;
|
2014-12-09 10:46:58 +00:00
|
|
|
default:
|
|
|
|
goto error_unsupported_format;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_unsupported_format:
|
|
|
|
GST_ERROR ("unsupported texture format %s",
|
|
|
|
gst_video_format_to_string (format));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
static gboolean
|
|
|
|
meta_texture_ensure_info_from_buffer (GstVaapiVideoMetaTexture * meta,
|
2014-12-09 10:46:58 +00:00
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoMeta *vmeta;
|
2015-02-09 20:09:07 +00:00
|
|
|
GstVideoFormat format;
|
2014-12-09 10:46:58 +00:00
|
|
|
|
|
|
|
if (!buffer || !(vmeta = gst_buffer_get_video_meta (buffer))) {
|
2015-02-09 20:09:07 +00:00
|
|
|
format = DEFAULT_FORMAT;
|
2014-12-09 10:46:58 +00:00
|
|
|
meta->width = 0;
|
|
|
|
meta->height = 0;
|
|
|
|
} else {
|
2015-02-09 20:09:07 +00:00
|
|
|
const GstVideoFormatInfo *const fmt_info =
|
|
|
|
gst_video_format_get_info (vmeta->format);
|
|
|
|
format = (fmt_info && GST_VIDEO_FORMAT_INFO_IS_RGB (fmt_info)) ?
|
|
|
|
vmeta->format : DEFAULT_FORMAT;
|
2014-12-09 10:46:58 +00:00
|
|
|
meta->width = vmeta->width;
|
|
|
|
meta->height = vmeta->height;
|
|
|
|
}
|
2015-02-09 20:09:07 +00:00
|
|
|
return meta_texture_ensure_format (meta, format);
|
2014-12-09 10:46:58 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 11:41:00 +00:00
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
meta_texture_free (GstVaapiVideoMetaTexture * meta)
|
2013-07-15 11:41:00 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
if (G_UNLIKELY (!meta))
|
|
|
|
return;
|
2013-07-15 11:41:00 +00:00
|
|
|
|
2020-04-18 11:32:24 +00:00
|
|
|
gst_mini_object_replace ((GstMiniObject **) & meta->texture, NULL);
|
2023-01-24 19:16:47 +00:00
|
|
|
g_free (meta);
|
2013-12-11 13:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiVideoMetaTexture *
|
2014-08-21 08:45:31 +00:00
|
|
|
meta_texture_new (void)
|
2013-12-11 13:04:27 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoMetaTexture *meta;
|
2013-12-11 13:04:27 +00:00
|
|
|
|
2023-01-24 19:16:47 +00:00
|
|
|
meta = g_new (GstVaapiVideoMetaTexture, 1);
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!meta)
|
|
|
|
return NULL;
|
2013-12-11 13:04:27 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
meta->texture = NULL;
|
2015-02-09 20:09:07 +00:00
|
|
|
if (!meta_texture_ensure_info_from_buffer (meta, NULL))
|
|
|
|
goto error;
|
2014-08-21 08:45:31 +00:00
|
|
|
return meta;
|
2015-02-09 20:09:07 +00:00
|
|
|
|
2016-10-20 16:12:04 +00:00
|
|
|
/* ERRORS */
|
2015-02-09 20:09:07 +00:00
|
|
|
error:
|
2016-10-20 16:12:04 +00:00
|
|
|
{
|
|
|
|
meta_texture_free (meta);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-15 11:41:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 17:01:29 +00:00
|
|
|
static GstVaapiVideoMetaTexture *
|
2014-08-21 08:45:31 +00:00
|
|
|
meta_texture_copy (GstVaapiVideoMetaTexture * meta)
|
2013-12-12 17:01:29 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoMetaTexture *copy;
|
2013-12-12 17:01:29 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
copy = meta_texture_new ();
|
|
|
|
if (!copy)
|
|
|
|
return NULL;
|
2013-12-12 17:01:29 +00:00
|
|
|
|
2016-03-28 11:13:56 +00:00
|
|
|
memcpy (copy->texture_type, meta->texture_type, sizeof (meta->texture_type));
|
2014-12-09 10:46:58 +00:00
|
|
|
copy->gl_format = meta->gl_format;
|
|
|
|
copy->width = meta->width;
|
|
|
|
copy->height = meta->height;
|
2020-04-18 11:32:24 +00:00
|
|
|
|
|
|
|
gst_mini_object_replace ((GstMiniObject **) & copy->texture,
|
|
|
|
(GstMiniObject *) meta->texture);
|
2014-08-21 08:45:31 +00:00
|
|
|
return copy;
|
2013-12-12 17:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 11:41:00 +00:00
|
|
|
static gboolean
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_texture_upload (GstVideoGLTextureUploadMeta * meta,
|
|
|
|
guint texture_id[4])
|
2013-07-15 11:41:00 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoMeta *const vmeta =
|
|
|
|
gst_buffer_get_vaapi_video_meta (meta->buffer);
|
|
|
|
GstVaapiVideoMetaTexture *const meta_texture = meta->user_data;
|
2014-10-23 09:56:31 +00:00
|
|
|
GstVaapiSurfaceProxy *const proxy =
|
|
|
|
gst_vaapi_video_meta_get_surface_proxy (vmeta);
|
|
|
|
GstVaapiSurface *const surface = gst_vaapi_surface_proxy_get_surface (proxy);
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const dpy = gst_vaapi_surface_get_display (surface);
|
2016-09-22 07:34:38 +00:00
|
|
|
GstVaapiTexture *texture = NULL;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2014-12-03 10:39:24 +00:00
|
|
|
if (!gst_vaapi_display_has_opengl (dpy))
|
2014-08-21 08:45:31 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2016-09-22 07:34:38 +00:00
|
|
|
if (meta_texture->texture
|
2014-08-21 08:45:31 +00:00
|
|
|
/* Check whether VA display changed */
|
2020-04-18 11:32:24 +00:00
|
|
|
&& GST_VAAPI_TEXTURE_DISPLAY (meta_texture->texture) == dpy
|
2014-08-21 08:45:31 +00:00
|
|
|
/* Check whether texture id changed */
|
2016-09-22 07:34:38 +00:00
|
|
|
&& (gst_vaapi_texture_get_id (meta_texture->texture) == texture_id[0])) {
|
|
|
|
texture = meta_texture->texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!texture) {
|
2014-08-21 08:45:31 +00:00
|
|
|
/* FIXME: should we assume target? */
|
2016-09-22 07:34:38 +00:00
|
|
|
texture =
|
2015-02-20 14:29:17 +00:00
|
|
|
gst_vaapi_texture_new_wrapped (dpy, texture_id[0],
|
|
|
|
GL_TEXTURE_2D, meta_texture->gl_format, meta_texture->width,
|
|
|
|
meta_texture->height);
|
2016-09-22 07:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (meta_texture->texture != texture) {
|
2020-04-18 11:32:24 +00:00
|
|
|
gst_mini_object_replace ((GstMiniObject **) & meta_texture->texture,
|
|
|
|
(GstMiniObject *) texture);
|
2014-08-21 08:45:31 +00:00
|
|
|
}
|
2015-02-20 14:13:03 +00:00
|
|
|
|
2016-09-22 07:34:38 +00:00
|
|
|
if (!texture)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-20 14:13:03 +00:00
|
|
|
gst_vaapi_texture_set_orientation_flags (meta_texture->texture,
|
|
|
|
get_texture_orientation_flags (meta->texture_orientation));
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
return gst_vaapi_texture_put_surface (meta_texture->texture, surface,
|
2014-10-23 09:56:31 +00:00
|
|
|
gst_vaapi_surface_proxy_get_crop_rect (proxy),
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_meta_get_render_flags (vmeta));
|
2013-07-15 11:41:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 07:55:42 +00:00
|
|
|
GstMeta *
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_buffer_add_texture_upload_meta (GstBuffer * buffer)
|
2013-07-15 11:41:00 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoMetaTexture *meta_texture;
|
2013-12-11 13:04:27 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!buffer)
|
2013-12-11 13:04:27 +00:00
|
|
|
return FALSE;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
|
|
|
meta_texture = meta_texture_new ();
|
|
|
|
if (!meta_texture)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
if (!meta_texture_ensure_info_from_buffer (meta_texture, buffer))
|
|
|
|
goto error;
|
|
|
|
|
2020-05-17 07:55:42 +00:00
|
|
|
return (GstMeta *) gst_buffer_add_video_gl_texture_upload_meta (buffer,
|
|
|
|
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, 1,
|
|
|
|
meta_texture->texture_type, gst_vaapi_texture_upload, meta_texture,
|
|
|
|
(GBoxedCopyFunc) meta_texture_copy, (GBoxedFreeFunc) meta_texture_free);
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2016-10-20 16:12:04 +00:00
|
|
|
/* ERRORS */
|
2014-08-21 08:45:31 +00:00
|
|
|
error:
|
2016-10-20 16:12:04 +00:00
|
|
|
{
|
|
|
|
meta_texture_free (meta_texture);
|
2020-05-17 07:55:42 +00:00
|
|
|
return NULL;
|
2016-10-20 16:12:04 +00:00
|
|
|
}
|
2013-07-15 11:41:00 +00:00
|
|
|
}
|
2013-11-20 17:20:07 +00:00
|
|
|
|
|
|
|
gboolean
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_buffer_ensure_texture_upload_meta (GstBuffer * buffer)
|
2013-11-20 17:20:07 +00:00
|
|
|
{
|
2014-12-09 10:46:58 +00:00
|
|
|
GstVideoGLTextureUploadMeta *const meta =
|
|
|
|
gst_buffer_get_video_gl_texture_upload_meta (buffer);
|
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
return meta ?
|
|
|
|
meta_texture_ensure_info_from_buffer (meta->user_data, buffer) :
|
2020-05-17 07:55:42 +00:00
|
|
|
(gst_buffer_add_texture_upload_meta (buffer) != NULL);
|
2013-11-20 17:20:07 +00:00
|
|
|
}
|
2013-07-15 11:41:00 +00:00
|
|
|
#endif
|