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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gst/vaapi/sysdeps.h"
|
2014-10-23 15:44:23 +00:00
|
|
|
#include <GL/gl.h>
|
2013-07-15 11:41:00 +00:00
|
|
|
#include "gstvaapivideometa.h"
|
|
|
|
#include "gstvaapipluginutil.h"
|
|
|
|
|
2014-10-23 15:44:23 +00:00
|
|
|
#if USE_GLX
|
|
|
|
#include <gst/vaapi/gstvaapitexture_glx.h>
|
|
|
|
#endif
|
|
|
|
|
2013-07-15 11:41:00 +00:00
|
|
|
#if GST_CHECK_VERSION(1,1,0) && USE_GLX
|
2015-01-19 09:30:12 +00:00
|
|
|
|
|
|
|
#include "gstvaapivideometa_texture.h"
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
struct _GstVaapiVideoMetaTexture
|
|
|
|
{
|
|
|
|
GstVaapiTexture *texture;
|
2013-12-11 13:04:27 +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
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_texture_replace (&meta->texture, NULL);
|
|
|
|
g_slice_free (GstVaapiVideoMetaTexture, 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
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
meta = g_slice_new (GstVaapiVideoMetaTexture);
|
|
|
|
if (!meta)
|
|
|
|
return NULL;
|
2013-12-11 13:04:27 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
meta->texture = NULL;
|
|
|
|
return meta;
|
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
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_texture_replace (©->texture, meta->texture);
|
|
|
|
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);
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiDisplay *const dpy = GST_VAAPI_OBJECT_DISPLAY (surface);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!meta_texture->texture ||
|
|
|
|
/* Check whether VA display changed */
|
|
|
|
GST_VAAPI_OBJECT_DISPLAY (meta_texture->texture) != dpy ||
|
|
|
|
/* Check whether texture id changed */
|
|
|
|
gst_vaapi_texture_get_id (meta_texture->texture) != texture_id[0]) {
|
|
|
|
/* FIXME: should we assume target? */
|
|
|
|
GstVaapiTexture *const texture =
|
2014-10-23 15:44:23 +00:00
|
|
|
gst_vaapi_texture_glx_new_wrapped (dpy, texture_id[0],
|
2014-08-21 08:45:31 +00:00
|
|
|
GL_TEXTURE_2D, GL_RGBA);
|
|
|
|
gst_vaapi_texture_replace (&meta_texture->texture, texture);
|
|
|
|
if (!texture)
|
|
|
|
return FALSE;
|
|
|
|
gst_vaapi_texture_unref (texture);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
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
|
|
|
GstVideoGLTextureUploadMeta *meta = NULL;
|
|
|
|
GstVideoGLTextureType tex_type[] = { GST_VIDEO_GL_TEXTURE_TYPE_RGBA };
|
|
|
|
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;
|
|
|
|
|
|
|
|
meta = gst_buffer_add_video_gl_texture_upload_meta (buffer,
|
|
|
|
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL,
|
|
|
|
1, tex_type, gst_vaapi_texture_upload,
|
|
|
|
meta_texture, (GBoxedCopyFunc) meta_texture_copy,
|
|
|
|
(GBoxedFreeFunc) meta_texture_free);
|
|
|
|
if (!meta)
|
|
|
|
goto error;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
meta_texture_free (meta_texture);
|
|
|
|
return FALSE;
|
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-08-21 08:45:31 +00:00
|
|
|
return gst_buffer_get_video_gl_texture_upload_meta (buffer) ||
|
|
|
|
gst_buffer_add_texture_upload_meta (buffer);
|
2013-11-20 17:20:07 +00:00
|
|
|
}
|
2013-07-15 11:41:00 +00:00
|
|
|
#endif
|