mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
gl/upload: add GstGLUploadMeta object
That simply deals with the provider aspect of GstVideoGLTextureUploadMeta.
This commit is contained in:
parent
1f6fceafa4
commit
32343333aa
11 changed files with 468 additions and 166 deletions
|
@ -703,7 +703,7 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
||||||
|
|
||||||
if (glimage_sink->upload)
|
if (glimage_sink->upload)
|
||||||
gst_object_unref (glimage_sink->upload);
|
gst_object_unref (glimage_sink->upload);
|
||||||
glimage_sink->upload = gst_object_ref (GST_GL_BUFFER_POOL (newpool)->upload);
|
glimage_sink->upload = gst_gl_upload_new (glimage_sink->context);
|
||||||
|
|
||||||
gst_gl_upload_set_format (glimage_sink->upload, &vinfo);
|
gst_gl_upload_set_format (glimage_sink->upload, &vinfo);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
|
||||||
gstglcolorconvert.c \
|
gstglcolorconvert.c \
|
||||||
gstgldownload.c \
|
gstgldownload.c \
|
||||||
gstglupload.c \
|
gstglupload.c \
|
||||||
|
gstgluploadmeta.c \
|
||||||
gstglwindow.c \
|
gstglwindow.c \
|
||||||
gstglapi.c \
|
gstglapi.c \
|
||||||
gstglfeature.c \
|
gstglfeature.c \
|
||||||
|
@ -41,6 +42,7 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \
|
||||||
gstglshader.h \
|
gstglshader.h \
|
||||||
gstglcolorconvert.h \
|
gstglcolorconvert.h \
|
||||||
gstgldownload.h \
|
gstgldownload.h \
|
||||||
|
gstgluploadmeta.h \
|
||||||
gstglupload.h \
|
gstglupload.h \
|
||||||
gstglapi.h \
|
gstglapi.h \
|
||||||
gstglfeature.h \
|
gstglfeature.h \
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <gst/gl/gstglshader.h>
|
#include <gst/gl/gstglshader.h>
|
||||||
#include <gst/gl/gstglcolorconvert.h>
|
#include <gst/gl/gstglcolorconvert.h>
|
||||||
#include <gst/gl/gstglupload.h>
|
#include <gst/gl/gstglupload.h>
|
||||||
|
#include <gst/gl/gstgluploadmeta.h>
|
||||||
#include <gst/gl/gstgldownload.h>
|
#include <gst/gl/gstgldownload.h>
|
||||||
#include <gst/gl/gstglmemory.h>
|
#include <gst/gl/gstglmemory.h>
|
||||||
#include <gst/gl/gstglbufferpool.h>
|
#include <gst/gl/gstglbufferpool.h>
|
||||||
|
|
|
@ -55,6 +55,10 @@ typedef struct _GstGLUpload GstGLUpload;
|
||||||
typedef struct _GstGLUploadClass GstGLUploadClass;
|
typedef struct _GstGLUploadClass GstGLUploadClass;
|
||||||
typedef struct _GstGLUploadPrivate GstGLUploadPrivate;
|
typedef struct _GstGLUploadPrivate GstGLUploadPrivate;
|
||||||
|
|
||||||
|
typedef struct _GstGLUploadMeta GstGLUploadMeta;
|
||||||
|
typedef struct _GstGLUploadMetaClass GstGLUploadMetaClass;
|
||||||
|
typedef struct _GstGLUploadMetaPrivate GstGLUploadMetaPrivate;
|
||||||
|
|
||||||
typedef struct _GstGLColorConvert GstGLColorConvert;
|
typedef struct _GstGLColorConvert GstGLColorConvert;
|
||||||
typedef struct _GstGLColorConvertClass GstGLColorConvertClass;
|
typedef struct _GstGLColorConvertClass GstGLColorConvertClass;
|
||||||
typedef struct _GstGLColorConvertPrivate GstGLColorConvertPrivate;
|
typedef struct _GstGLColorConvertPrivate GstGLColorConvertPrivate;
|
||||||
|
|
|
@ -135,7 +135,7 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
if (glpool->upload)
|
if (glpool->upload)
|
||||||
gst_object_unref (glpool->upload);
|
gst_object_unref (glpool->upload);
|
||||||
|
|
||||||
glpool->upload = gst_gl_upload_new (glpool->context);
|
glpool->upload = gst_gl_upload_meta_new (glpool->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
||||||
|
@ -175,7 +175,7 @@ gst_gl_buffer_pool_start (GstBufferPool * pool)
|
||||||
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
||||||
GstGLBufferPoolPrivate *priv = glpool->priv;
|
GstGLBufferPoolPrivate *priv = glpool->priv;
|
||||||
|
|
||||||
gst_gl_upload_set_format (glpool->upload, &priv->info);
|
gst_gl_upload_meta_set_format (glpool->upload, &priv->info);
|
||||||
|
|
||||||
return GST_BUFFER_POOL_CLASS (parent_class)->start (pool);
|
return GST_BUFFER_POOL_CLASS (parent_class)->start (pool);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
||||||
if (!gst_gl_memory_setup_buffer (glpool->context, info, buf))
|
if (!gst_gl_memory_setup_buffer (glpool->context, info, buf))
|
||||||
goto mem_create_failed;
|
goto mem_create_failed;
|
||||||
|
|
||||||
gst_gl_upload_add_video_gl_texture_upload_meta (glpool->upload, buf);
|
gst_gl_upload_meta_add_to_buffer (glpool->upload, buf);
|
||||||
|
|
||||||
*buffer = buf;
|
*buffer = buf;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ struct _GstGLBufferPool
|
||||||
GstBufferPool bufferpool;
|
GstBufferPool bufferpool;
|
||||||
|
|
||||||
GstGLContext *context;
|
GstGLContext *context;
|
||||||
GstGLUpload *upload;
|
GstGLUploadMeta *upload;
|
||||||
|
|
||||||
GstGLBufferPoolPrivate *priv;
|
GstGLBufferPoolPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1185,8 +1185,6 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
|
||||||
{
|
{
|
||||||
GstGLFilter *filter;
|
GstGLFilter *filter;
|
||||||
GstGLFilterClass *filter_class;
|
GstGLFilterClass *filter_class;
|
||||||
GstCaps *in_caps, *out_caps;
|
|
||||||
GstBufferPool *pool;
|
|
||||||
|
|
||||||
filter = GST_GL_FILTER (bt);
|
filter = GST_GL_FILTER (bt);
|
||||||
filter_class = GST_GL_FILTER_GET_CLASS (bt);
|
filter_class = GST_GL_FILTER_GET_CLASS (bt);
|
||||||
|
@ -1195,21 +1193,8 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
|
||||||
if (!filter->upload) {
|
if (!filter->upload) {
|
||||||
in_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));
|
filter->upload = gst_gl_upload_new (filter->context);
|
||||||
out_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
|
|
||||||
pool = gst_base_transform_get_buffer_pool (bt);
|
|
||||||
|
|
||||||
if (GST_IS_GL_BUFFER_POOL (pool)
|
|
||||||
&& gst_caps_is_equal_fixed (in_caps, out_caps)) {
|
|
||||||
filter->upload = gst_object_ref (GST_GL_BUFFER_POOL (pool)->upload);
|
|
||||||
} else {
|
|
||||||
filter->upload = gst_gl_upload_new (filter->context);
|
|
||||||
}
|
|
||||||
gst_gl_upload_set_format (filter->upload, &filter->in_info);
|
gst_gl_upload_set_format (filter->upload, &filter->in_info);
|
||||||
|
|
||||||
gst_caps_unref (in_caps);
|
|
||||||
gst_caps_unref (out_caps);
|
|
||||||
gst_object_unref (pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (filter_class->filter || filter_class->filter_texture);
|
g_assert (filter_class->filter || filter_class->filter_texture);
|
||||||
|
|
|
@ -367,57 +367,6 @@ gst_gl_upload_release_buffer (GstGLUpload * upload)
|
||||||
gst_video_frame_unmap (&upload->priv->frame);
|
gst_video_frame_unmap (&upload->priv->frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Uploads as a result of a call to gst_video_gl_texture_upload_meta_upload().
|
|
||||||
* i.e. provider of GstVideoGLTextureUploadMeta
|
|
||||||
*/
|
|
||||||
static gboolean
|
|
||||||
_do_upload_for_meta (GstGLUpload * upload, GstVideoGLTextureUploadMeta * meta)
|
|
||||||
{
|
|
||||||
GstVideoInfo in_info;
|
|
||||||
GstVideoFrame frame;
|
|
||||||
GstMemory *mem;
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
g_return_val_if_fail (upload != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (meta != NULL, FALSE);
|
|
||||||
|
|
||||||
/* GstGLMemory */
|
|
||||||
mem = gst_buffer_peek_memory (upload->priv->buffer, 0);
|
|
||||||
|
|
||||||
if (gst_is_gl_memory (mem)) {
|
|
||||||
GstGLMemory *gl_mem = (GstGLMemory *) mem;
|
|
||||||
|
|
||||||
upload->in_tex[0] = gl_mem;
|
|
||||||
ret = _upload_memory (upload);
|
|
||||||
upload->in_tex[0] = NULL;
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gst_video_frame_map (&frame, &in_info, upload->priv->buffer,
|
|
||||||
GST_MAP_READ)) {
|
|
||||||
GST_ERROR ("failed to map video frame");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update the video info from the one updated by frame_map using video meta */
|
|
||||||
gst_gl_upload_set_format (upload, &upload->priv->frame.info);
|
|
||||||
|
|
||||||
if (!upload->priv->tex_id)
|
|
||||||
gst_gl_context_gen_texture (upload->context, &upload->priv->tex_id,
|
|
||||||
GST_VIDEO_FORMAT_RGBA, GST_VIDEO_INFO_WIDTH (&upload->in_info),
|
|
||||||
GST_VIDEO_INFO_HEIGHT (&upload->in_info));
|
|
||||||
|
|
||||||
ret = _gst_gl_upload_perform_with_data_unlocked (upload,
|
|
||||||
upload->out_tex->tex_id, frame.data);
|
|
||||||
|
|
||||||
gst_video_frame_unmap (&frame);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uploads using gst_video_gl_texture_upload_meta_upload().
|
* Uploads using gst_video_gl_texture_upload_meta_upload().
|
||||||
* i.e. consumer of GstVideoGLTextureUploadMeta
|
* i.e. consumer of GstVideoGLTextureUploadMeta
|
||||||
|
@ -487,98 +436,6 @@ gst_gl_upload_perform_with_gl_texture_upload_meta (GstGLUpload * upload,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
_gst_gl_upload_perform_for_gl_texture_upload_meta (GstVideoGLTextureUploadMeta *
|
|
||||||
meta, guint texture_id[4])
|
|
||||||
{
|
|
||||||
GstGLUpload *upload;
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
g_return_val_if_fail (meta != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (texture_id != NULL, FALSE);
|
|
||||||
|
|
||||||
upload = meta->user_data;
|
|
||||||
|
|
||||||
g_mutex_lock (&upload->lock);
|
|
||||||
|
|
||||||
if (!upload->initted) {
|
|
||||||
GstVideoInfo in_info;
|
|
||||||
GstVideoMeta *v_meta = gst_buffer_get_video_meta (upload->priv->buffer);
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
if (v_meta == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gst_video_info_init (&in_info);
|
|
||||||
in_info.finfo = gst_video_format_get_info (v_meta->format);
|
|
||||||
in_info.width = v_meta->width;
|
|
||||||
in_info.height = v_meta->height;
|
|
||||||
|
|
||||||
for (i = 0; i < in_info.finfo->n_planes; i++) {
|
|
||||||
in_info.offset[i] = v_meta->offset[i];
|
|
||||||
in_info.stride[i] = v_meta->stride[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
_gst_gl_upload_set_format_unlocked (upload, &in_info);
|
|
||||||
|
|
||||||
upload->out_tex = gst_gl_memory_wrapped_texture (upload->context,
|
|
||||||
texture_id[0], GST_VIDEO_GL_TEXTURE_TYPE_RGBA,
|
|
||||||
GST_VIDEO_INFO_WIDTH (&upload->in_info),
|
|
||||||
GST_VIDEO_INFO_HEIGHT (&upload->in_info), NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: kinda breaks the abstraction */
|
|
||||||
if (upload->out_tex->tex_id != texture_id[0]) {
|
|
||||||
upload->out_tex->tex_id = texture_id[0];
|
|
||||||
GST_GL_MEMORY_FLAG_SET (upload->out_tex, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_LOG ("Uploading for meta with textures %i,%i,%i,%i", texture_id[0],
|
|
||||||
texture_id[1], texture_id[2], texture_id[3]);
|
|
||||||
|
|
||||||
ret = _do_upload_for_meta (upload, meta);
|
|
||||||
|
|
||||||
g_mutex_unlock (&upload->lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_gl_upload_add_video_gl_texture_upload_meta:
|
|
||||||
* @upload: a #GstGLUpload
|
|
||||||
* @buffer: a #GstBuffer
|
|
||||||
*
|
|
||||||
* Adds a #GstVideoGLTextureUploadMeta on @buffer using @upload
|
|
||||||
*
|
|
||||||
* Returns: whether it was successful
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
gst_gl_upload_add_video_gl_texture_upload_meta (GstGLUpload * upload,
|
|
||||||
GstBuffer * buffer)
|
|
||||||
{
|
|
||||||
GstVideoGLTextureType texture_types[GST_VIDEO_MAX_PLANES];
|
|
||||||
GstVideoMeta *v_meta;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (upload != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (buffer != NULL, FALSE);
|
|
||||||
v_meta = gst_buffer_get_video_meta (buffer);
|
|
||||||
g_return_val_if_fail (v_meta != NULL, FALSE);
|
|
||||||
|
|
||||||
upload->priv->buffer = buffer;
|
|
||||||
|
|
||||||
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
|
||||||
texture_types[i] = gst_gl_texture_type_from_format (upload->context, v_meta->format, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_buffer_add_video_gl_texture_upload_meta (buffer,
|
|
||||||
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, 1, texture_types,
|
|
||||||
_gst_gl_upload_perform_for_gl_texture_upload_meta,
|
|
||||||
gst_object_ref (upload), gst_object_ref, gst_object_unref);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_gl_upload_perform_with_data:
|
* gst_gl_upload_perform_with_data:
|
||||||
* @upload: a #GstGLUpload
|
* @upload: a #GstGLUpload
|
||||||
|
|
|
@ -80,8 +80,6 @@ GstGLUpload * gst_gl_upload_new (GstGLContext * context);
|
||||||
void gst_gl_upload_set_format (GstGLUpload * upload, GstVideoInfo * in_info);
|
void gst_gl_upload_set_format (GstGLUpload * upload, GstVideoInfo * in_info);
|
||||||
GstVideoInfo * gst_gl_upload_get_format (GstGLUpload * upload);
|
GstVideoInfo * gst_gl_upload_get_format (GstGLUpload * upload);
|
||||||
|
|
||||||
gboolean gst_gl_upload_add_video_gl_texture_upload_meta (GstGLUpload * upload, GstBuffer * buffer);
|
|
||||||
|
|
||||||
gboolean gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer, guint * tex_id);
|
gboolean gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer, guint * tex_id);
|
||||||
void gst_gl_upload_release_buffer (GstGLUpload * upload);
|
void gst_gl_upload_release_buffer (GstGLUpload * upload);
|
||||||
gboolean gst_gl_upload_perform_with_data (GstGLUpload * upload, GLuint texture_id,
|
gboolean gst_gl_upload_perform_with_data (GstGLUpload * upload, GLuint texture_id,
|
||||||
|
|
376
gst-libs/gst/gl/gstgluploadmeta.c
Normal file
376
gst-libs/gst/gl/gstgluploadmeta.c
Normal file
|
@ -0,0 +1,376 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2012-2014 Matthew Waters <ystree00@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "gl.h"
|
||||||
|
#include "gstgluploadmeta.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:gstgluploadmeta
|
||||||
|
* @short_description: an object that provides #GstVideoGLTextureUploadMeta
|
||||||
|
* @see_also: #GstGLUpload, #GstGLMemory
|
||||||
|
*
|
||||||
|
* #GstGLUploadMeta is an object that uploads data from system memory into GL textures.
|
||||||
|
*
|
||||||
|
* A #GstGLUpload can be created with gst_gl_upload_new()
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define USING_OPENGL(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL)
|
||||||
|
#define USING_OPENGL3(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL3)
|
||||||
|
#define USING_GLES(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES)
|
||||||
|
#define USING_GLES2(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2)
|
||||||
|
#define USING_GLES3(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES3)
|
||||||
|
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
|
||||||
|
struct _GstGLUploadMetaPrivate
|
||||||
|
{
|
||||||
|
GstBuffer *buffer;
|
||||||
|
gboolean initted;
|
||||||
|
|
||||||
|
GstGLMemory *in_tex[GST_VIDEO_MAX_PLANES];
|
||||||
|
GstGLMemory *out_tex[GST_VIDEO_MAX_PLANES];
|
||||||
|
};
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_upload_meta_debug);
|
||||||
|
#define GST_CAT_DEFAULT gst_gl_upload_meta_debug
|
||||||
|
|
||||||
|
#define DEBUG_INIT \
|
||||||
|
GST_DEBUG_CATEGORY_INIT (gst_gl_upload_meta_debug, "gluploadmeta", 0, "uploadmeta");
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GstGLUploadMeta, gst_gl_upload_meta, GST_TYPE_OBJECT, DEBUG_INIT);
|
||||||
|
static void gst_gl_upload_meta_finalize (GObject * object);
|
||||||
|
static void gst_gl_upload_meta_reset (GstGLUploadMeta * upload);
|
||||||
|
|
||||||
|
#define GST_GL_UPLOAD_META_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
|
||||||
|
GST_TYPE_GL_UPLOAD_META, GstGLUploadMetaPrivate))
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_upload_meta_class_init (GstGLUploadMetaClass * klass)
|
||||||
|
{
|
||||||
|
g_type_class_add_private (klass, sizeof (GstGLUploadMetaPrivate));
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_upload_meta_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_upload_meta_init (GstGLUploadMeta * upload)
|
||||||
|
{
|
||||||
|
upload->priv = GST_GL_UPLOAD_META_GET_PRIVATE (upload);
|
||||||
|
|
||||||
|
upload->context = NULL;
|
||||||
|
|
||||||
|
gst_video_info_set_format (&upload->info, GST_VIDEO_FORMAT_ENCODED, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_gl_upload_meta_new:
|
||||||
|
* @context: a #GstGLContext
|
||||||
|
*
|
||||||
|
* Returns: a new #GstGLUploadMeta object
|
||||||
|
*/
|
||||||
|
GstGLUploadMeta *
|
||||||
|
gst_gl_upload_meta_new (GstGLContext * context)
|
||||||
|
{
|
||||||
|
GstGLUploadMeta *upload;
|
||||||
|
|
||||||
|
upload = g_object_new (GST_TYPE_GL_UPLOAD_META, NULL);
|
||||||
|
|
||||||
|
upload->context = gst_object_ref (context);
|
||||||
|
|
||||||
|
return upload;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_upload_meta_finalize (GObject * object)
|
||||||
|
{
|
||||||
|
GstGLUploadMeta *upload;
|
||||||
|
|
||||||
|
upload = GST_GL_UPLOAD_META (object);
|
||||||
|
|
||||||
|
gst_gl_upload_meta_reset (upload);
|
||||||
|
|
||||||
|
if (upload->context) {
|
||||||
|
gst_object_unref (upload->context);
|
||||||
|
upload->context = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gst_gl_upload_meta_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_gl_upload_meta_reset (GstGLUploadMeta * upload)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
||||||
|
if (upload->priv->out_tex[i]) {
|
||||||
|
gst_memory_unref ((GstMemory *) upload->priv->out_tex[i]);
|
||||||
|
upload->priv->out_tex[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
||||||
|
if (upload->priv->in_tex[i]) {
|
||||||
|
gst_memory_unref ((GstMemory *) upload->priv->in_tex[i]);
|
||||||
|
upload->priv->in_tex[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_gst_gl_upload_meta_set_format_unlocked (GstGLUploadMeta * upload,
|
||||||
|
GstVideoInfo *info)
|
||||||
|
{
|
||||||
|
g_return_if_fail (upload != NULL);
|
||||||
|
g_return_if_fail (GST_VIDEO_INFO_FORMAT (info) !=
|
||||||
|
GST_VIDEO_FORMAT_UNKNOWN);
|
||||||
|
g_return_if_fail (GST_VIDEO_INFO_FORMAT (info) !=
|
||||||
|
GST_VIDEO_FORMAT_ENCODED);
|
||||||
|
|
||||||
|
if (gst_video_info_is_equal (&upload->info, info))
|
||||||
|
return;
|
||||||
|
|
||||||
|
gst_gl_upload_meta_reset (upload);
|
||||||
|
upload->info = *info;
|
||||||
|
upload->priv->initted = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_gl_upload_meta_set_format:
|
||||||
|
* @upload: a #GstGLUpload
|
||||||
|
* @info: input #GstVideoInfo
|
||||||
|
*
|
||||||
|
* Initializes @upload with the information required for upload.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_gl_upload_meta_set_format (GstGLUploadMeta * upload, GstVideoInfo * info)
|
||||||
|
{
|
||||||
|
GST_OBJECT_LOCK (upload);
|
||||||
|
_gst_gl_upload_meta_set_format_unlocked (upload, info);
|
||||||
|
GST_OBJECT_UNLOCK (upload);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_gl_upload_meta_get_format:
|
||||||
|
* @upload: a #GstGLUpload
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): The #GstVideoInfo set by
|
||||||
|
* gst_gl_upload_meta_set_format()
|
||||||
|
*/
|
||||||
|
GstVideoInfo *
|
||||||
|
gst_gl_upload_meta_get_format (GstGLUploadMeta * upload)
|
||||||
|
{
|
||||||
|
GstVideoInfo *ret;
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (upload);
|
||||||
|
ret = &upload->info;
|
||||||
|
GST_OBJECT_LOCK (upload);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_perform_with_gl_memory (GstGLUploadMeta * upload, GstVideoGLTextureUploadMeta *
|
||||||
|
meta, guint texture_id[4])
|
||||||
|
{
|
||||||
|
gboolean res = TRUE;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++) {
|
||||||
|
GstGLMemory *in_mem = upload->priv->in_tex[i];
|
||||||
|
|
||||||
|
if (GST_GL_MEMORY_FLAG_IS_SET (in_mem, GST_GL_MEMORY_FLAG_NEED_UPLOAD)) {
|
||||||
|
GstMapInfo map_info;
|
||||||
|
guint tex_id;
|
||||||
|
|
||||||
|
tex_id = in_mem->tex_id;
|
||||||
|
in_mem->tex_id = texture_id[i];
|
||||||
|
|
||||||
|
if (!gst_memory_map ((GstMemory *) in_mem, &map_info, GST_MAP_READ | GST_MAP_GL)) {
|
||||||
|
GST_WARNING_OBJECT (upload, "Failed to map GL memory");
|
||||||
|
res = FALSE;
|
||||||
|
}
|
||||||
|
gst_memory_unmap ((GstMemory *) in_mem, &map_info);
|
||||||
|
|
||||||
|
in_mem->tex_id = tex_id;
|
||||||
|
GST_GL_MEMORY_FLAG_SET (in_mem, GST_GL_MEMORY_FLAG_NEED_UPLOAD);
|
||||||
|
} else {
|
||||||
|
GstGLMemory *out_mem;
|
||||||
|
|
||||||
|
if (!upload->priv->out_tex[i])
|
||||||
|
upload->priv->out_tex[i] = gst_gl_memory_wrapped_texture (upload->context,
|
||||||
|
texture_id[i], meta->texture_type[i],
|
||||||
|
GST_VIDEO_INFO_WIDTH (&upload->info),
|
||||||
|
GST_VIDEO_INFO_HEIGHT (&upload->info), NULL, NULL);
|
||||||
|
|
||||||
|
out_mem = upload->priv->out_tex[i];
|
||||||
|
|
||||||
|
if (out_mem->tex_id != texture_id[i]) {
|
||||||
|
out_mem->tex_id = texture_id[i];
|
||||||
|
GST_GL_MEMORY_FLAG_SET (out_mem, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(res = gst_gl_memory_copy_into_texture (in_mem, out_mem->tex_id,
|
||||||
|
out_mem->tex_type, out_mem->width, out_mem->height, out_mem->stride,
|
||||||
|
FALSE)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_perform_with_data_unlocked (GstGLUploadMeta * upload,
|
||||||
|
GstVideoGLTextureUploadMeta * meta,
|
||||||
|
gpointer data[GST_VIDEO_MAX_PLANES], guint texture_id[4])
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++) {
|
||||||
|
if (!upload->priv->in_tex[i])
|
||||||
|
upload->priv->in_tex[i] = gst_gl_memory_wrapped (upload->context,
|
||||||
|
meta->texture_type[i], GST_VIDEO_INFO_WIDTH (&upload->info),
|
||||||
|
GST_VIDEO_INFO_HEIGHT (&upload->info),
|
||||||
|
GST_VIDEO_INFO_PLANE_STRIDE (&upload->info, i), data[i], NULL, NULL);
|
||||||
|
|
||||||
|
upload->priv->in_tex[i]->data = data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return _perform_with_gl_memory (upload, meta, texture_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_perform_for_gl_texture_upload_meta (GstVideoGLTextureUploadMeta *
|
||||||
|
meta, guint texture_id[4])
|
||||||
|
{
|
||||||
|
GstGLUploadMeta *upload;
|
||||||
|
GstVideoFrame frame;
|
||||||
|
// GstMemory *mem;
|
||||||
|
gboolean ret;
|
||||||
|
// guint i, n;
|
||||||
|
|
||||||
|
g_return_val_if_fail (meta != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (texture_id != NULL, FALSE);
|
||||||
|
|
||||||
|
upload = meta->user_data;
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (upload);
|
||||||
|
|
||||||
|
if (!upload->priv->initted) {
|
||||||
|
GstVideoInfo info;
|
||||||
|
GstVideoMeta *v_meta = gst_buffer_get_video_meta (upload->priv->buffer);
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
if (!(ret = v_meta != NULL))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
gst_video_info_init (&info);
|
||||||
|
info.finfo = gst_video_format_get_info (v_meta->format);
|
||||||
|
info.width = v_meta->width;
|
||||||
|
info.height = v_meta->height;
|
||||||
|
|
||||||
|
for (i = 0; i < info.finfo->n_planes; i++) {
|
||||||
|
info.offset[i] = v_meta->offset[i];
|
||||||
|
info.stride[i] = v_meta->stride[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
_gst_gl_upload_meta_set_format_unlocked (upload, &info);
|
||||||
|
upload->priv->initted = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_LOG ("Uploading for meta with textures %i,%i,%i,%i", texture_id[0],
|
||||||
|
texture_id[1], texture_id[2], texture_id[3]);
|
||||||
|
#if 0
|
||||||
|
/* GstGLMemory */
|
||||||
|
n = gst_buffer_n_memory (upload->priv->buffer);
|
||||||
|
mem = gst_buffer_peek_memory (upload->priv->buffer, 0);
|
||||||
|
|
||||||
|
if (gst_is_gl_memory (mem) && n == GST_VIDEO_INFO_N_PLANES (&upload->info)) {
|
||||||
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++)
|
||||||
|
upload->priv->in_tex[i] = (GstGLMemory *) gst_buffer_peek_memory (upload->priv->buffer, i);
|
||||||
|
|
||||||
|
ret = _perform_with_gl_memory (upload, meta, texture_id);
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++)
|
||||||
|
upload->priv->in_tex[i] = NULL;
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!(ret = gst_video_frame_map (&frame, &upload->info, upload->priv->buffer,
|
||||||
|
GST_MAP_READ))) {
|
||||||
|
GST_ERROR ("failed to map video frame");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update the video info from the one updated by frame_map using video meta */
|
||||||
|
_gst_gl_upload_meta_set_format_unlocked (upload, &frame.info);
|
||||||
|
|
||||||
|
ret = _perform_with_data_unlocked (upload, meta, frame.data, texture_id);
|
||||||
|
|
||||||
|
gst_video_frame_unmap (&frame);
|
||||||
|
|
||||||
|
out:
|
||||||
|
GST_OBJECT_UNLOCK (upload);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_gl_upload_meta_add_to_buffer:
|
||||||
|
* @upload: a #GstGLUploadMeta
|
||||||
|
* @buffer: a #GstBuffer
|
||||||
|
*
|
||||||
|
* Adds a #GstVideoGLTextureUploadMeta on @buffer using @upload
|
||||||
|
*
|
||||||
|
* Returns: whether it was successful
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_gl_upload_meta_add_to_buffer (GstGLUploadMeta * upload, GstBuffer * buffer)
|
||||||
|
{
|
||||||
|
GstVideoGLTextureType texture_types[GST_VIDEO_MAX_PLANES];
|
||||||
|
GstVideoMeta *v_meta;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (upload != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
||||||
|
v_meta = gst_buffer_get_video_meta (buffer);
|
||||||
|
g_return_val_if_fail (v_meta != NULL, FALSE);
|
||||||
|
|
||||||
|
upload->priv->buffer = buffer;
|
||||||
|
|
||||||
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
||||||
|
texture_types[i] = gst_gl_texture_type_from_format (upload->context, v_meta->format, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_buffer_add_video_gl_texture_upload_meta (buffer,
|
||||||
|
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, 1, texture_types,
|
||||||
|
_perform_for_gl_texture_upload_meta, gst_object_ref (upload),
|
||||||
|
gst_object_ref, gst_object_unref);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
79
gst-libs/gst/gl/gstgluploadmeta.h
Normal file
79
gst-libs/gst/gl/gstgluploadmeta.h
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* GStreamer
|
||||||
|
* Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GST_GL_UPLOAD_META_H__
|
||||||
|
#define __GST_GL_UPLOAD_META_H__
|
||||||
|
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/gstmemory.h>
|
||||||
|
|
||||||
|
#include <gst/gl/gstgl_fwd.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
GType gst_gl_upload_meta_get_type (void);
|
||||||
|
#define GST_TYPE_GL_UPLOAD_META (gst_gl_upload_meta_get_type())
|
||||||
|
#define GST_GL_UPLOAD_META(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_UPLOAD_META,GstGLUploadMeta))
|
||||||
|
#define GST_GL_UPLOAD_META_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_UPLOAD_META,GstGLUploadMetaClass))
|
||||||
|
#define GST_IS_GL_UPLOAD_META(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_UPLOAD_META))
|
||||||
|
#define GST_IS_GL_UPLOAD_META_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_UPLOAD_META))
|
||||||
|
#define GST_GL_UPLOAD_META_CAST(obj) ((GstGLUploadMeta*)(obj))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstGLUploadMeta
|
||||||
|
*
|
||||||
|
* Opaque #GstGLUploadMeta object
|
||||||
|
*/
|
||||||
|
struct _GstGLUploadMeta
|
||||||
|
{
|
||||||
|
/* <private> */
|
||||||
|
GstObject parent;
|
||||||
|
|
||||||
|
GstGLContext *context;
|
||||||
|
|
||||||
|
/* input data */
|
||||||
|
GstVideoInfo info;
|
||||||
|
|
||||||
|
/* <private> */
|
||||||
|
GstGLUploadMetaPrivate *priv;
|
||||||
|
|
||||||
|
gpointer _reserved[GST_PADDING];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstGLUploadMetaClass:
|
||||||
|
*
|
||||||
|
* The #GstGLUploadMetaClass struct only contains private data
|
||||||
|
*/
|
||||||
|
struct _GstGLUploadMetaClass
|
||||||
|
{
|
||||||
|
GstObjectClass object_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GstGLUploadMeta * gst_gl_upload_meta_new (GstGLContext * context);
|
||||||
|
|
||||||
|
void gst_gl_upload_meta_set_format (GstGLUploadMeta * upload, GstVideoInfo * info);
|
||||||
|
GstVideoInfo * gst_gl_upload_meta_get_format (GstGLUploadMeta * upload);
|
||||||
|
|
||||||
|
gboolean gst_gl_upload_meta_add_to_buffer (GstGLUploadMeta * upload, GstBuffer * buffer);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GST_GL_UPLOAD_META_H__ */
|
Loading…
Reference in a new issue