Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gl/upload: add GstGLUploadMeta object
That simply deals with the provider aspect of GstVideoGLTextureUploadMeta.
  • Loading branch information
ystreet authored and tp-m committed Dec 9, 2017
1 parent 1f6fcea commit 3234333
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 166 deletions.
2 changes: 1 addition & 1 deletion ext/gl/gstglimagesink.c
Expand Up @@ -703,7 +703,7 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)

if (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);

Expand Down
2 changes: 2 additions & 0 deletions gst-libs/gst/gl/Makefile.am
Expand Up @@ -20,6 +20,7 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
gstglcolorconvert.c \
gstgldownload.c \
gstglupload.c \
gstgluploadmeta.c \
gstglwindow.c \
gstglapi.c \
gstglfeature.c \
Expand All @@ -41,6 +42,7 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \
gstglshader.h \
gstglcolorconvert.h \
gstgldownload.h \
gstgluploadmeta.h \
gstglupload.h \
gstglapi.h \
gstglfeature.h \
Expand Down
1 change: 1 addition & 0 deletions gst-libs/gst/gl/gl.h
Expand Up @@ -32,6 +32,7 @@
#include <gst/gl/gstglshader.h>
#include <gst/gl/gstglcolorconvert.h>
#include <gst/gl/gstglupload.h>
#include <gst/gl/gstgluploadmeta.h>
#include <gst/gl/gstgldownload.h>
#include <gst/gl/gstglmemory.h>
#include <gst/gl/gstglbufferpool.h>
Expand Down
4 changes: 4 additions & 0 deletions gst-libs/gst/gl/gstgl_fwd.h
Expand Up @@ -55,6 +55,10 @@ typedef struct _GstGLUpload GstGLUpload;
typedef struct _GstGLUploadClass GstGLUploadClass;
typedef struct _GstGLUploadPrivate GstGLUploadPrivate;

typedef struct _GstGLUploadMeta GstGLUploadMeta;
typedef struct _GstGLUploadMetaClass GstGLUploadMetaClass;
typedef struct _GstGLUploadMetaPrivate GstGLUploadMetaPrivate;

typedef struct _GstGLColorConvert GstGLColorConvert;
typedef struct _GstGLColorConvertClass GstGLColorConvertClass;
typedef struct _GstGLColorConvertPrivate GstGLColorConvertPrivate;
Expand Down
6 changes: 3 additions & 3 deletions gst-libs/gst/gl/gstglbufferpool.c
Expand Up @@ -135,7 +135,7 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
if (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);
Expand Down Expand Up @@ -175,7 +175,7 @@ gst_gl_buffer_pool_start (GstBufferPool * pool)
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
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);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
if (!gst_gl_memory_setup_buffer (glpool->context, info, buf))
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;

Expand Down
2 changes: 1 addition & 1 deletion gst-libs/gst/gl/gstglbufferpool.h
Expand Up @@ -50,7 +50,7 @@ struct _GstGLBufferPool
GstBufferPool bufferpool;

GstGLContext *context;
GstGLUpload *upload;
GstGLUploadMeta *upload;

GstGLBufferPoolPrivate *priv;
};
Expand Down
17 changes: 1 addition & 16 deletions gst-libs/gst/gl/gstglfilter.c
Expand Up @@ -1185,8 +1185,6 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
{
GstGLFilter *filter;
GstGLFilterClass *filter_class;
GstCaps *in_caps, *out_caps;
GstBufferPool *pool;

filter = GST_GL_FILTER (bt);
filter_class = GST_GL_FILTER_GET_CLASS (bt);
Expand All @@ -1195,21 +1193,8 @@ gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
return GST_FLOW_NOT_NEGOTIATED;

if (!filter->upload) {
in_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));
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);
}
filter->upload = gst_gl_upload_new (filter->context);
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);
Expand Down
143 changes: 0 additions & 143 deletions gst-libs/gst/gl/gstglupload.c
Expand Up @@ -367,57 +367,6 @@ gst_gl_upload_release_buffer (GstGLUpload * upload)
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().
* i.e. consumer of GstVideoGLTextureUploadMeta
Expand Down Expand Up @@ -487,98 +436,6 @@ gst_gl_upload_perform_with_gl_texture_upload_meta (GstGLUpload * upload,
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:
* @upload: a #GstGLUpload
Expand Down
2 changes: 0 additions & 2 deletions gst-libs/gst/gl/gstglupload.h
Expand Up @@ -80,8 +80,6 @@ GstGLUpload * gst_gl_upload_new (GstGLContext * context);
void gst_gl_upload_set_format (GstGLUpload * upload, GstVideoInfo * in_info);
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);
void gst_gl_upload_release_buffer (GstGLUpload * upload);
gboolean gst_gl_upload_perform_with_data (GstGLUpload * upload, GLuint texture_id,
Expand Down

0 comments on commit 3234333

Please sign in to comment.