summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia
diff options
context:
space:
mode:
authorYuqing Zhu <carol.zhu@nxp.com>2016-10-13 09:59:50 +0800
committerOtavio Salvador <otavio@ossystems.com.br>2016-10-27 10:36:28 -0200
commitcdcc02c5857ebf0c044dbb2ec2f1a46f047c5b8f (patch)
tree812500d34506a01a96622ca6835e90ed96adfcf6 /recipes-multimedia
parent5bf09940cd9a3cbf7888c5c610e35d53b237387d (diff)
downloadmeta-freescale-cdcc02c5857ebf0c044dbb2ec2f1a46f047c5b8f.tar.gz
gstreamer1.0-plugins-bad: Add directviv to glimagesink to improve playback performance
1.Add a physical buffer uploader in glupload plugin and using viv direct texture to bind physical continious buffer with texture to avoid memory copy from videobuffer to texture to gain good performance. 2.Reduce glimagesink load latency by override glimagesink ALLOCATION query to avoid memory copy. Signed-off-by: Yuqing Zhu <carol.zhu@nxp.com> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Diffstat (limited to 'recipes-multimedia')
-rw-r--r--recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0002-Add-directviv-to-glimagesink-to-improve-playback-per.patch438
-rw-r--r--recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad_%.bbappend1
2 files changed, 439 insertions, 0 deletions
diff --git a/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0002-Add-directviv-to-glimagesink-to-improve-playback-per.patch b/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0002-Add-directviv-to-glimagesink-to-improve-playback-per.patch
new file mode 100644
index 00000000..43d89060
--- /dev/null
+++ b/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0002-Add-directviv-to-glimagesink-to-improve-playback-per.patch
@@ -0,0 +1,438 @@
1From 94e6bb069cb5207761f2e4234137f2a748f984db Mon Sep 17 00:00:00 2001
2From: Haihua Hu <b55597@freescale.com>
3Date: Tue, 13 Oct 2015 09:33:54 +0800
4Subject: [PATCH 13/18] Add directviv to glimagesink to improve playback
5 performance
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
101.Add a physical buffer uploader in glupload plugin and using viv direct
11 texture to bind physical continious buffer with texture to avoid memory
12 copy from videobuffer to texture to gain good performance.
132.Reduce glimagesink load latency by override glimagesink ALLOCATION query to
14 avoid memory copy.
15
16Upstream-Status: Inappropriate [i.MX specific]
17
18Signed-off-by: Haihua Hu <b55597@freescale.com>
19Signed-off-by: Lyon Wang <lyon.wang@freescale.com>
20---
21 ext/gl/gstglimagesink.c | 5 ++
22 gst-libs/gst/gl/Makefile.am | 2 +
23 gst-libs/gst/gl/gstglupload.c | 141 ++++++++++++++++++++++++++++++-
24 gst-libs/gst/gl/gstglvivdirecttexture.c | 143 ++++++++++++++++++++++++++++++++
25 gst-libs/gst/gl/gstglvivdirecttexture.h | 35 ++++++++
26 5 files changed, 323 insertions(+), 3 deletions(-)
27 create mode 100644 gst-libs/gst/gl/gstglvivdirecttexture.c
28 create mode 100644 gst-libs/gst/gl/gstglvivdirecttexture.h
29
30diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c
31index 3b5e3b5..532ea6a 100644
32--- a/ext/gl/gstglimagesink.c
33+++ b/ext/gl/gstglimagesink.c
34@@ -911,6 +911,11 @@ gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query)
35 res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
36 break;
37 }
38+ case GST_QUERY_ALLOCATION:
39+ {
40+ gst_glimage_sink_propose_allocation(bsink, query);
41+ break;
42+ }
43 default:
44 res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
45 break;
46diff --git a/gst-libs/gst/gl/Makefile.am b/gst-libs/gst/gl/Makefile.am
47index 4bd6511..c396603 100644
48--- a/gst-libs/gst/gl/Makefile.am
49+++ b/gst-libs/gst/gl/Makefile.am
50@@ -33,6 +33,7 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
51 gstglviewconvert.c \
52 gstgloverlaycompositor.c \
53 gstglquery.c \
54+ gstglvivdirecttexture.c \
55 gstglcontrolbindingproxy.c
56
57 libgstgl_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/gl
58@@ -66,6 +67,7 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \
59 gstglcontrolbindingproxy.h \
60 gstgl_fwd.h \
61 gstgl_enums.h \
62+ gstglvivdirecttexture.h \
63 gl.h
64
65 noinst_HEADERS = \
66diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c
67index 32e6150..99cc68a 100644
68--- a/gst-libs/gst/gl/gstglupload.c
69+++ b/gst-libs/gst/gl/gstglupload.c
70@@ -23,6 +23,7 @@
71 #endif
72
73 #include <stdio.h>
74+#include <gst/gl/gstglvivdirecttexture.h>
75
76 #include "gl.h"
77 #include "gstglupload.h"
78@@ -51,7 +52,7 @@
79 #define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
80 #define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
81
82-GST_DEBUG_CATEGORY_STATIC (gst_gl_upload_debug);
83+GST_DEBUG_CATEGORY (gst_gl_upload_debug);
84 #define GST_CAT_DEFAULT gst_gl_upload_debug
85
86 #define DEBUG_INIT \
87@@ -1169,6 +1170,140 @@ static const UploadMethod _upload_meta_upload = {
88 &_upload_meta_upload_free
89 };
90
91+struct PhyBufferUpload
92+{
93+ GstGLUpload *upload;
94+ GstGLVideoAllocationParams *params;
95+};
96+
97+static gpointer
98+_physical_buffer_upload_new(GstGLUpload *upload)
99+{
100+ struct PhyBufferUpload *phybuffer = g_new0 (struct PhyBufferUpload, 1);
101+
102+ phybuffer->upload = upload;
103+
104+ return phybuffer;
105+}
106+
107+static GstCaps *
108+_physical_buffer_upload_transform_caps(GstGLContext *context,
109+ GstPadDirection direction, GstCaps *caps)
110+{
111+ GstCapsFeatures *passthrough =
112+ gst_caps_features_from_string
113+ (GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
114+ GstCaps *ret;
115+
116+ if (direction == GST_PAD_SINK) {
117+ GstCaps *tmp;
118+
119+ ret =
120+ _set_caps_features_with_passthrough (caps,
121+ GST_CAPS_FEATURE_MEMORY_GL_MEMORY, passthrough);
122+
123+ gst_caps_set_simple (ret, "format", G_TYPE_STRING, "RGBA", NULL);
124+ tmp = _caps_intersect_texture_target (ret, 1 << GST_GL_TEXTURE_TARGET_2D);
125+ gst_caps_unref (ret);
126+ ret = tmp;
127+ } else {
128+ ret = gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
129+ (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,GST_GL_DIRECTVIV_FORMAT));
130+ }
131+
132+ gst_caps_features_free (passthrough);
133+ return ret;
134+}
135+
136+static gboolean
137+_physical_buffer_upload_accept(gpointer impl, GstBuffer *buffer,
138+ GstCaps *in_caps, GstCaps *out_caps)
139+{
140+ struct PhyBufferUpload *upload = impl;
141+ GstCapsFeatures *features;
142+
143+ features = gst_caps_get_features (out_caps, 0);
144+ if (!gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY))
145+ return FALSE;
146+
147+ if (upload->params)
148+ gst_gl_allocation_params_free ((GstGLAllocationParams *) upload->params);
149+ if (!(upload->params =
150+ gst_gl_video_allocation_params_new (upload->upload->context, NULL,
151+ &upload->upload->priv->in_info, -1, NULL,
152+ GST_GL_TEXTURE_TARGET_2D)))
153+ return FALSE;
154+
155+ return gst_is_physical_buffer(buffer);
156+}
157+
158+static void
159+_physical_buffer_upload_propose_allocation(gpointer impl, GstQuery *decide_query,
160+ GstQuery *query)
161+{
162+ gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
163+}
164+
165+static GstGLUploadReturn
166+_physical_buffer_upload_perform(gpointer impl, GstBuffer *buffer, GstBuffer **outbuf)
167+{
168+ struct PhyBufferUpload *phyBuffer = impl;
169+ GstGLMemoryAllocator *allocator;
170+ GstVideoInfo *info;
171+ gint n_mem;
172+
173+ info = &phyBuffer->upload->priv->out_info;
174+ n_mem = GST_VIDEO_INFO_N_PLANES (info);
175+ GST_LOG_OBJECT (phyBuffer->upload, "Attempting viv direct upload");
176+
177+ allocator =
178+ GST_GL_MEMORY_ALLOCATOR (gst_allocator_find
179+ (GST_GL_MEMORY_PBO_ALLOCATOR_NAME));
180+
181+ /* FIXME: buffer pool */
182+ *outbuf = gst_buffer_new ();
183+ gst_gl_memory_setup_buffer (allocator, *outbuf, phyBuffer->params);
184+ gst_object_unref (allocator);
185+
186+ GstGLMemory *out_gl_mem =
187+ (GstGLMemory *) gst_buffer_peek_memory (*outbuf, 0);
188+
189+ gst_gl_viv_direct_bind_gstbuffer(phyBuffer->upload->context, out_gl_mem->tex_id,
190+ &phyBuffer->upload->priv->in_info, buffer);
191+
192+ gst_buffer_add_video_meta_full (*outbuf, 0,
193+ GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
194+ GST_VIDEO_INFO_HEIGHT (info), n_mem, info->offset, info->stride);
195+
196+ return GST_GL_UPLOAD_DONE;
197+}
198+
199+static void
200+_physical_buffer_upload_free(gpointer impl)
201+{
202+ struct PhyBufferUpload *phyBuffer = impl;
203+
204+ if (phyBuffer->params)
205+ gst_gl_allocation_params_free ((GstGLAllocationParams *) phyBuffer->params);
206+
207+ g_free(phyBuffer);
208+}
209+
210+static GstStaticCaps _physical_buffer_upload_caps =
211+GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_DIRECTVIV_FORMAT));
212+
213+static const UploadMethod _physical_buffer_upload = {
214+ "Physical buffer",
215+ 0,
216+ &_physical_buffer_upload_caps,
217+ &_physical_buffer_upload_new,
218+ &_physical_buffer_upload_transform_caps,
219+ &_physical_buffer_upload_accept,
220+ &_physical_buffer_upload_propose_allocation,
221+ &_physical_buffer_upload_perform,
222+ &_physical_buffer_upload_free
223+};
224+
225 struct RawUploadFrame
226 {
227 gint ref_count;
228@@ -1391,7 +1526,7 @@ static const UploadMethod *upload_methods[] = { &_gl_memory_upload,
229 #if GST_GL_HAVE_DMABUF
230 &_dma_buf_upload,
231 #endif
232- &_upload_meta_upload, &_raw_data_upload
233+ &_upload_meta_upload, &_physical_buffer_upload, &_raw_data_upload
234 };
235
236 static GMutex upload_global_lock;
237@@ -1514,7 +1649,7 @@ gst_gl_upload_transform_caps (GstGLContext * context, GstPadDirection direction,
238 }
239
240 if (filter) {
241- result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
242+ result = gst_caps_intersect_full (tmp, filter, GST_CAPS_INTERSECT_FIRST);
243 gst_caps_unref (tmp);
244 } else {
245 result = tmp;
246diff --git a/gst-libs/gst/gl/gstglvivdirecttexture.c b/gst-libs/gst/gl/gstglvivdirecttexture.c
247new file mode 100644
248index 0000000..c19b617
249--- /dev/null
250+++ b/gst-libs/gst/gl/gstglvivdirecttexture.c
251@@ -0,0 +1,143 @@
252+/*
253+ * GStreamer
254+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
255+ *
256+ * This library is free software; you can redistribute it and/or
257+ * modify it under the terms of the GNU Library General Public
258+ * License as published by the Free Software Foundation; either
259+ * version 2 of the License, or (at your option) any later version.
260+ *
261+ * This library is distributed in the hope that it will be useful,
262+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
263+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
264+ * Library General Public License for more details.
265+ *
266+ * You should have received a copy of the GNU Library General Public
267+ * License along with this library; if not, write to the
268+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
269+ * Boston, MA 02110-1301, USA.
270+ */
271+
272+#ifdef HAVE_CONFIG_H
273+#include "config.h"
274+#endif
275+
276+#include "gl.h"
277+
278+GST_DEBUG_CATEGORY_EXTERN (gst_gl_upload_debug);
279+#define GST_CAT_DEFAULT gst_gl_upload_debug
280+
281+typedef struct {
282+ guint tex_id;
283+ guint w;
284+ guint h;
285+ guint fmt;
286+ void *vaddr;
287+ guint paddr;
288+ gboolean ret;
289+} GstVivDirectTexture;
290+
291+gboolean
292+gst_is_physical_buffer (GstBuffer *buffer)
293+{
294+
295+ GstMemory *mem;
296+
297+ mem = gst_buffer_peek_memory (buffer, 0);
298+ if (!mem->allocator)
299+ return FALSE;
300+
301+ return g_type_check_instance_is_a (mem->allocator, g_type_from_name("GstAllocatorPhyMem"));
302+}
303+
304+static void
305+_do_viv_direct_tex_bind_mem (GstGLContext * context, GstVivDirectTexture * viv_tex)
306+{
307+ GST_DEBUG ("viv direct upload, tex_id %d, fmt: %d, res: (%dx%d)", viv_tex->tex_id, viv_tex->fmt, viv_tex->w, viv_tex->h);
308+ GST_DEBUG ("Physical memory buffer, vaddr: %p, paddr: %p", viv_tex->vaddr, viv_tex->paddr);
309+
310+ glBindTexture (GL_TEXTURE_2D, viv_tex->tex_id);
311+ glTexDirectVIVMap (GL_TEXTURE_2D, viv_tex->w, viv_tex->h, viv_tex->fmt, &viv_tex->vaddr, &viv_tex->paddr);
312+ glTexDirectInvalidateVIV (GL_TEXTURE_2D);
313+ viv_tex->ret = TRUE;
314+
315+ return;
316+}
317+
318+gboolean
319+gst_gl_viv_direct_bind_gstbuffer (GstGLContext * context, guint tex_id, GstVideoInfo * info, GstBuffer * buffer)
320+{
321+ typedef struct {
322+ guint8 *vaddr;
323+ guint8 *paddr;
324+ guint8 *caddr;
325+ gsize size;
326+ gpointer *user_data;
327+ } PhyMemBlock;
328+ //Note: structure PhyMemBlock is copied from gst1.0-fsl-plugin/libs/allocator/gstallocatorphymem.h
329+
330+ typedef struct {
331+ GstMemory mem;
332+ guint8 *vaddr;
333+ guint8 *paddr;
334+ PhyMemBlock block;
335+ } GstMemoryPhy;
336+ //Note: structure GstMemoryPhy is copied from gst1.0-fsl-plugin/libs/allocator/gstallocatorphymem.c
337+
338+ GstMemory *mem = gst_buffer_peek_memory (buffer, 0);
339+ GstMemoryPhy *memphy = (GstMemoryPhy*) mem;
340+ PhyMemBlock *memblk = &memphy->block;
341+
342+ GstVideoFormat fmt = GST_VIDEO_INFO_FORMAT (info);
343+ gint width, height;
344+ GstVideoMeta *vmeta = gst_buffer_get_video_meta (buffer);
345+ if (vmeta && (fmt == GST_VIDEO_FORMAT_I420 || fmt == GST_VIDEO_FORMAT_NV12)) {
346+ width = vmeta->stride[0];
347+ height = vmeta->offset[1] / width;
348+ }
349+ else {
350+ width = GST_VIDEO_INFO_WIDTH (info);
351+ height = GST_VIDEO_INFO_HEIGHT (info);
352+ }
353+
354+ guint viv_fmt;
355+ switch (fmt) {
356+ case GST_VIDEO_FORMAT_I420:
357+ viv_fmt = GL_VIV_I420;
358+ break;
359+ case GST_VIDEO_FORMAT_YV12:
360+ viv_fmt = GL_VIV_YV12;
361+ break;
362+ case GST_VIDEO_FORMAT_NV12:
363+ viv_fmt = GL_VIV_NV12;
364+ break;
365+ case GST_VIDEO_FORMAT_NV21:
366+ viv_fmt = GL_VIV_NV21;
367+ break;
368+ case GST_VIDEO_FORMAT_YUY2:
369+ viv_fmt = GL_VIV_YUY2;
370+ break;
371+ case GST_VIDEO_FORMAT_UYVY:
372+ viv_fmt = GL_VIV_UYVY;
373+ break;
374+ case GST_VIDEO_FORMAT_RGBA:
375+ viv_fmt = GL_RGBA;
376+ break;
377+ case GST_VIDEO_FORMAT_BGRA:
378+ viv_fmt = GL_BGRA_EXT;
379+ break;
380+ case GST_VIDEO_FORMAT_RGB16:
381+ viv_fmt = GL_RGB565_OES;
382+ break;
383+ default:
384+ GST_ERROR ("Not supported format %d for viv direct texture upload.", fmt);
385+ viv_fmt = GL_NONE;
386+ return FALSE;
387+ }
388+
389+ GstVivDirectTexture viv_tex = {tex_id, width, height, viv_fmt, memblk->vaddr, memblk->paddr, FALSE};
390+ gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _do_viv_direct_tex_bind_mem, &viv_tex);
391+
392+ return viv_tex.ret;
393+}
394+
395diff --git a/gst-libs/gst/gl/gstglvivdirecttexture.h b/gst-libs/gst/gl/gstglvivdirecttexture.h
396new file mode 100644
397index 0000000..fa88e1a
398--- /dev/null
399+++ b/gst-libs/gst/gl/gstglvivdirecttexture.h
400@@ -0,0 +1,35 @@
401+/*
402+ * GStreamer
403+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
404+ *
405+ * This library is free software; you can redistribute it and/or
406+ * modify it under the terms of the GNU Library General Public
407+ * License as published by the Free Software Foundation; either
408+ * version 2 of the License, or (at your option) any later version.
409+ *
410+ * This library is distributed in the hope that it will be useful,
411+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
412+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
413+ * Library General Public License for more details.
414+ *
415+ * You should have received a copy of the GNU Library General Public
416+ * License along with this library; if not, write to the
417+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
418+ * Boston, MA 02110-1301, USA.
419+ */
420+
421+#ifndef __GST_GL_VIVDIRECT_H__
422+#define __GST_GL_VIVDIRECT_H__
423+
424+#include <gst/video/video.h>
425+#include <gst/gl/gstgl_fwd.h>
426+
427+#define GST_GL_DIRECTVIV_FORMAT "{RGBA, I420, YV12, NV12, NV21, YUY2, UYVY, BGRA, RGB16}"
428+G_BEGIN_DECLS
429+
430+gboolean gst_is_physical_buffer (GstBuffer *buffer);
431+gboolean gst_gl_viv_direct_bind_gstbuffer (GstGLContext * context, guint tex_id, GstVideoInfo * info, GstBuffer * buffer);
432+
433+G_END_DECLS
434+
435+#endif /* __GST_GL_VIVDIRECT_H__ */
436--
4371.9.1
438
diff --git a/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad_%.bbappend b/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad_%.bbappend
index 98e8d144..16d0ce84 100644
--- a/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad_%.bbappend
+++ b/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad_%.bbappend
@@ -11,6 +11,7 @@ PACKAGECONFIG_GL_mx6sl = "${@bb.utils.contains('DISTRO_FEATURES', 'opengl', \
11 'opengl', '', d), '', d)}" 11 'opengl', '', d), '', d)}"
12 12
13SRC_URI_append = " file://0001-glplugin-Change-wayland-default-res-to-1024x768.patch \ 13SRC_URI_append = " file://0001-glplugin-Change-wayland-default-res-to-1024x768.patch \
14 file://0002-Add-directviv-to-glimagesink-to-improve-playback-per.patch \
14" 15"
15 16
16 17