1 From 8d32de090554cf29fe359f83aa46000ba658a693 Mon Sep 17 00:00:00 2001
2 From: Thibault Saunier <tsaunier@igalia.com>
3 Date: Fri, 27 Sep 2019 11:10:43 -0300
4 Subject: [PATCH] glupload: Add VideoMetas and GLSyncMeta to the raw uploaded
7 This is done by reusing `gst_gl_memory_setup_buffer` avoiding to
10 Without a VideoMeta, mapping those buffers lead to GstBuffer mapping the
11 buffer in system memory even when specifying the GL flags (through the
12 buffer merging mechanism) making the result totally broken.
14 Part-of: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/444
15 Upstream-Status: Backport [8d32de090554cf29fe359f83aa46000ba658a693]
17 Signed-off-by: Zan Dobersek <zdobersek@igalia.com>
19 gst-libs/gst/gl/gstglupload.c | 32 +++++++++++---------------------
20 tests/check/libs/gstglupload.c | 2 ++
21 2 files changed, 13 insertions(+), 21 deletions(-)
23 diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c
24 index bc6db7e0a..67ec4f4e9 100644
25 --- a/gst-libs/gst/gl/gstglupload.c
26 +++ b/gst-libs/gst/gl/gstglupload.c
27 @@ -1293,33 +1293,23 @@ _raw_data_upload_perform (gpointer impl, GstBuffer * buffer,
28 (raw->upload->context));
30 /* FIXME Use a buffer pool to cache the generated textures */
31 - /* FIXME: multiview support with separated left/right frames? */
32 *outbuf = gst_buffer_new ();
33 - for (i = 0; i < n_mem; i++) {
34 - GstGLBaseMemory *tex;
36 - raw->params->parent.wrapped_data = raw->in_frame->frame.data[i];
37 - raw->params->plane = i;
38 - raw->params->tex_format =
39 - gst_gl_format_from_video_info (raw->upload->context, in_info, i);
42 - gst_gl_base_memory_alloc (allocator,
43 - (GstGLAllocationParams *) raw->params);
45 - gst_buffer_unref (*outbuf);
47 - GST_ERROR_OBJECT (raw->upload, "Failed to allocate wrapped texture");
48 - return GST_GL_UPLOAD_ERROR;
50 + raw->params->parent.context = raw->upload->context;
51 + if (gst_gl_memory_setup_buffer ((GstGLMemoryAllocator *) allocator, *outbuf,
52 + raw->params, NULL, raw->in_frame->frame.data, n_mem)) {
54 - _raw_upload_frame_ref (raw->in_frame);
55 - gst_buffer_append_memory (*outbuf, (GstMemory *) tex);
56 + for (i = 0; i < n_mem; i++)
57 + _raw_upload_frame_ref (raw->in_frame);
58 + gst_buffer_add_gl_sync_meta (raw->upload->context, *outbuf);
60 + GST_ERROR_OBJECT (raw->upload, "Failed to allocate wrapped texture");
61 + gst_buffer_unref (*outbuf);
62 + return GST_GL_UPLOAD_ERROR;
64 gst_object_unref (allocator);
66 _raw_upload_frame_unref (raw->in_frame);
69 return GST_GL_UPLOAD_DONE;
72 diff --git a/tests/check/libs/gstglupload.c b/tests/check/libs/gstglupload.c
73 index 74bff2b83..eff2f18ba 100644
74 --- a/tests/check/libs/gstglupload.c
75 +++ b/tests/check/libs/gstglupload.c
76 @@ -281,6 +281,8 @@ GST_START_TEST (test_upload_data)
77 res = gst_gl_upload_perform_with_buffer (upload, inbuf, &outbuf);
78 fail_unless (res == GST_GL_UPLOAD_DONE, "Failed to upload buffer");
79 fail_unless (GST_IS_BUFFER (outbuf));
80 + fail_unless (gst_buffer_get_video_meta (outbuf));
81 + fail_unless (gst_buffer_get_gl_sync_meta (outbuf));
83 res = gst_buffer_map (outbuf, &map_info, GST_MAP_READ | GST_MAP_GL);
84 fail_if (res == FALSE, "Failed to map gl memory");