mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
gl: add EGLImage support
* picked from old libgstegl: - GstEGLImageMemory - GstEGLImageAllocator - last_buffer management from removed GstEGLImageBufferPool * add-ons: - GstEGLImageMemory now old a reference on GstGLContext so that it can delete the EGLImage and its gltexture source while having the associated gl context being current. - add EGLImage support for GstVideoGLTextureUploadMeta which mainly call EGLImageTargetTexture2D - GstGLBufferPool now supports GstEGLImageAllocator - glimagesink / glfilters / etc.. now propose GstEGLImageAllocator to upstream https://bugzilla.gnome.org/show_bug.cgi?id=703343
This commit is contained in:
parent
6d10548e7f
commit
0ae3c984aa
17 changed files with 977 additions and 62 deletions
|
@ -169,7 +169,9 @@ static GstStaticPadTemplate gst_glimage_sink_template =
|
|||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_UPLOAD_FORMATS) "; "
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_EGL_IMAGE,
|
||||
"RGBA") "; " GST_VIDEO_CAPS_MAKE (GST_GL_UPLOAD_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
||||
GST_GL_UPLOAD_FORMATS))
|
||||
|
@ -863,6 +865,8 @@ gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|||
GstStructure *gl_context;
|
||||
gchar *platform, *gl_apis;
|
||||
gpointer handle;
|
||||
GstAllocator *allocator = NULL;
|
||||
GstAllocationParams params;
|
||||
|
||||
if (!_ensure_gl_setup (glimage_sink))
|
||||
return FALSE;
|
||||
|
@ -936,6 +940,18 @@ gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|||
g_free (platform);
|
||||
gst_structure_free (gl_context);
|
||||
|
||||
gst_allocation_params_init (¶ms);
|
||||
|
||||
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
|
||||
gst_query_add_allocation_param (query, allocator, ¶ms);
|
||||
gst_object_unref (allocator);
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
allocator = gst_allocator_find (GST_EGL_IMAGE_MEMORY_TYPE);
|
||||
gst_query_add_allocation_param (query, allocator, ¶ms);
|
||||
gst_object_unref (allocator);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
|
|
|
@ -4,16 +4,16 @@ noinst_LTLIBRARIES = libgstgl-egl.la
|
|||
|
||||
libgstgl_egl_la_SOURCES = \
|
||||
gstgldisplay_egl.c \
|
||||
gstglcontext_egl.c
|
||||
gstglcontext_egl.c \
|
||||
gsteglimagememory.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gstglcontext_egl.h
|
||||
|
||||
libgstgl_eglincludedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/gl/egl
|
||||
libgstgl_eglinclude_HEADERS = \
|
||||
gstgldisplay_egl.h
|
||||
|
||||
libgstgl_egl_la_LIBADD = $(top_builddir)/gst-libs/gst/egl/libgstegl-$(GST_API_VERSION).la
|
||||
gstgldisplay_egl.h \
|
||||
gsteglimagememory.h
|
||||
|
||||
libgstgl_egl_la_CFLAGS = \
|
||||
-I$(top_srcdir)/gst-libs \
|
||||
|
|
568
gst-libs/gst/gl/egl/gsteglimagememory.c
Normal file
568
gst-libs/gst/gl/egl/gsteglimagememory.c
Normal file
|
@ -0,0 +1,568 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2012 Collabora Ltd.
|
||||
* @author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* Copyright (C) 2014 Julien Isorce <julien.isorce@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 "gsteglimagememory.h"
|
||||
#include "gstglcontext_egl.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_EGL_IMAGE_MEMORY);
|
||||
#define GST_CAT_DEFAULT GST_CAT_EGL_IMAGE_MEMORY
|
||||
|
||||
typedef void (*GstEGLImageDestroyNotify) (GstGLContextEGL * context,
|
||||
gpointer data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstMemory parent;
|
||||
|
||||
GstGLContextEGL *context;
|
||||
EGLImageKHR image;
|
||||
GstVideoGLTextureType type;
|
||||
GstVideoGLTextureOrientation orientation;
|
||||
|
||||
gpointer user_data;
|
||||
GstEGLImageDestroyNotify user_data_destroy;
|
||||
} GstEGLImageMemory;
|
||||
|
||||
#define GST_EGL_IMAGE_MEMORY(mem) ((GstEGLImageMemory*)(mem))
|
||||
|
||||
gboolean
|
||||
gst_is_egl_image_memory (GstMemory * mem)
|
||||
{
|
||||
g_return_val_if_fail (mem != NULL, FALSE);
|
||||
g_return_val_if_fail (mem->allocator != NULL, FALSE);
|
||||
|
||||
return g_strcmp0 (mem->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0;
|
||||
}
|
||||
|
||||
EGLImageKHR
|
||||
gst_egl_image_memory_get_image (GstMemory * mem)
|
||||
{
|
||||
g_return_val_if_fail (gst_is_egl_image_memory (mem), EGL_NO_IMAGE_KHR);
|
||||
|
||||
if (mem->parent)
|
||||
mem = mem->parent;
|
||||
|
||||
return GST_EGL_IMAGE_MEMORY (mem)->image;
|
||||
}
|
||||
|
||||
EGLDisplay
|
||||
gst_egl_image_memory_get_display (GstMemory * mem)
|
||||
{
|
||||
g_return_val_if_fail (gst_is_egl_image_memory (mem), NULL);
|
||||
|
||||
if (mem->parent)
|
||||
mem = mem->parent;
|
||||
|
||||
return GST_EGL_IMAGE_MEMORY (mem)->context->egl_display;
|
||||
}
|
||||
|
||||
GstVideoGLTextureOrientation
|
||||
gst_egl_image_memory_get_orientation (GstMemory * mem)
|
||||
{
|
||||
g_return_val_if_fail (gst_is_egl_image_memory (mem),
|
||||
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL);
|
||||
|
||||
if (mem->parent)
|
||||
mem = mem->parent;
|
||||
|
||||
return GST_EGL_IMAGE_MEMORY (mem)->orientation;
|
||||
}
|
||||
|
||||
void
|
||||
gst_egl_image_memory_set_orientation (GstMemory * mem,
|
||||
GstVideoGLTextureOrientation orientation)
|
||||
{
|
||||
g_return_if_fail (gst_is_egl_image_memory (mem));
|
||||
|
||||
if (mem->parent)
|
||||
mem = mem->parent;
|
||||
|
||||
GST_EGL_IMAGE_MEMORY (mem)->orientation = orientation;
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
gst_egl_image_allocator_alloc_vfunc (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams * params)
|
||||
{
|
||||
g_warning
|
||||
("Use gst_egl_image_allocator_alloc() to allocate from this allocator");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_egl_image_allocator_free_vfunc (GstAllocator * allocator, GstMemory * mem)
|
||||
{
|
||||
GstEGLImageMemory *emem = (GstEGLImageMemory *) mem;
|
||||
|
||||
g_return_if_fail (gst_is_egl_image_memory (mem));
|
||||
|
||||
/* Shared memory should not destroy all the data */
|
||||
if (!mem->parent) {
|
||||
eglDestroyImageKHR (emem->context->egl_display, emem->image);
|
||||
|
||||
if (emem->user_data_destroy)
|
||||
emem->user_data_destroy (emem->context, emem->user_data);
|
||||
|
||||
gst_object_unref (emem->context);
|
||||
emem->context = NULL;
|
||||
}
|
||||
|
||||
g_slice_free (GstEGLImageMemory, emem);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
gst_egl_image_mem_map (GstMemory * mem, gsize maxsize, GstMapFlags flags)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_egl_image_mem_unmap (GstMemory * mem)
|
||||
{
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
gst_egl_image_mem_share (GstMemory * mem, gssize offset, gssize size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
gst_egl_image_mem_copy (GstMemory * mem, gssize offset, gssize size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_egl_image_mem_is_span (GstMemory * mem1, GstMemory * mem2, gsize * offset)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef GstAllocator GstEGLImageAllocator;
|
||||
typedef GstAllocatorClass GstEGLImageAllocatorClass;
|
||||
|
||||
GType gst_egl_image_allocator_get_type (void);
|
||||
G_DEFINE_TYPE (GstEGLImageAllocator, gst_egl_image_allocator,
|
||||
GST_TYPE_ALLOCATOR);
|
||||
|
||||
#define GST_TYPE_EGL_IMAGE_ALLOCATOR (gst_egl_image_mem_allocator_get_type())
|
||||
#define GST_IS_EGL_IMAGE_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_EGL_IMAGE_ALLOCATOR))
|
||||
|
||||
static void
|
||||
gst_egl_image_allocator_class_init (GstEGLImageAllocatorClass * klass)
|
||||
{
|
||||
GstAllocatorClass *allocator_class = (GstAllocatorClass *) klass;
|
||||
|
||||
allocator_class->alloc = gst_egl_image_allocator_alloc_vfunc;
|
||||
allocator_class->free = gst_egl_image_allocator_free_vfunc;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_egl_image_allocator_init (GstEGLImageAllocator * allocator)
|
||||
{
|
||||
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
||||
|
||||
alloc->mem_type = GST_EGL_IMAGE_MEMORY_TYPE;
|
||||
alloc->mem_map = gst_egl_image_mem_map;
|
||||
alloc->mem_unmap = gst_egl_image_mem_unmap;
|
||||
alloc->mem_share = gst_egl_image_mem_share;
|
||||
alloc->mem_copy = gst_egl_image_mem_copy;
|
||||
alloc->mem_is_span = gst_egl_image_mem_is_span;
|
||||
|
||||
GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
gst_egl_image_allocator_init_instance (gpointer data)
|
||||
{
|
||||
GstAllocator *allocator =
|
||||
g_object_new (gst_egl_image_allocator_get_type (), NULL);;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (GST_CAT_EGL_IMAGE_MEMORY, "eglimagememory", 0,
|
||||
"EGLImage Memory");
|
||||
|
||||
gst_allocator_register (GST_EGL_IMAGE_MEMORY_TYPE,
|
||||
gst_object_ref (allocator));
|
||||
|
||||
return allocator;
|
||||
}
|
||||
|
||||
static GstAllocator *
|
||||
gst_egl_image_allocator_obtain (void)
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
g_once (&once, gst_egl_image_allocator_init_instance, NULL);
|
||||
|
||||
g_return_val_if_fail (once.retval != NULL, NULL);
|
||||
|
||||
return GST_ALLOCATOR (g_object_ref (once.retval));
|
||||
}
|
||||
|
||||
void
|
||||
gst_egl_image_memory_init (void)
|
||||
{
|
||||
gst_egl_image_allocator_obtain ();
|
||||
}
|
||||
|
||||
static void
|
||||
gst_egl_image_memory_del_gl_texture (GstGLContext * context, gpointer tex)
|
||||
{
|
||||
GLuint textures[1] = { GPOINTER_TO_UINT (tex) };
|
||||
|
||||
gst_gl_context_del_texture (context, textures);
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
gst_egl_image_allocator_wrap (GstAllocator * allocator,
|
||||
GstGLContextEGL * context, EGLImageKHR image, GstVideoGLTextureType type,
|
||||
GstMemoryFlags flags, gsize size, gpointer user_data,
|
||||
GstEGLImageDestroyNotify user_data_destroy)
|
||||
{
|
||||
GstEGLImageMemory *mem = NULL;
|
||||
|
||||
g_return_val_if_fail (context != NULL, NULL);
|
||||
g_return_val_if_fail (image != EGL_NO_IMAGE_KHR, NULL);
|
||||
|
||||
if (!allocator) {
|
||||
allocator = gst_egl_image_allocator_obtain ();
|
||||
}
|
||||
|
||||
mem = g_slice_new (GstEGLImageMemory);
|
||||
gst_memory_init (GST_MEMORY_CAST (mem), flags,
|
||||
allocator, NULL, size, 0, 0, size);
|
||||
|
||||
gst_object_unref (allocator);
|
||||
|
||||
mem->context = gst_object_ref (context);
|
||||
mem->image = image;
|
||||
mem->type = type;
|
||||
mem->orientation = GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;
|
||||
|
||||
mem->user_data = user_data;
|
||||
mem->user_data_destroy = user_data_destroy;
|
||||
|
||||
return GST_MEMORY_CAST (mem);
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
gst_egl_image_allocator_alloc (GstAllocator * allocator,
|
||||
GstGLContextEGL * context, GstVideoGLTextureType type, gint width,
|
||||
gint height, gsize size)
|
||||
{
|
||||
/* EGL_NO_CONTEXT */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_eglimage_to_gl_texture_upload_meta (GstVideoGLTextureUploadMeta *
|
||||
meta, guint texture_id[4])
|
||||
{
|
||||
gint i = 0;
|
||||
gint n = 0;
|
||||
|
||||
g_return_val_if_fail (meta != NULL, FALSE);
|
||||
g_return_val_if_fail (texture_id != NULL, FALSE);
|
||||
|
||||
GST_DEBUG ("Uploading for meta with textures %i,%i,%i,%i", texture_id[0],
|
||||
texture_id[1], texture_id[2], texture_id[3]);
|
||||
|
||||
n = gst_buffer_n_memory (meta->buffer);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
GstMemory *mem = gst_buffer_peek_memory (meta->buffer, i);
|
||||
const GstGLFuncs *gl = NULL;
|
||||
|
||||
if (!gst_is_egl_image_memory (mem)) {
|
||||
GST_WARNING ("memory %p does not hold an EGLImage", mem);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gl = GST_GL_CONTEXT (GST_EGL_IMAGE_MEMORY (mem)->context)->gl_vtable;
|
||||
|
||||
if (i == 0)
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
else if (i == 1)
|
||||
gl->ActiveTexture (GL_TEXTURE1);
|
||||
else if (i == 2)
|
||||
gl->ActiveTexture (GL_TEXTURE2);
|
||||
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture_id[i]);
|
||||
gl->EGLImageTargetTexture2D (GL_TEXTURE_2D,
|
||||
gst_egl_image_memory_get_image (mem));
|
||||
}
|
||||
|
||||
if (GST_IS_GL_BUFFER_POOL (meta->buffer->pool))
|
||||
gst_gl_buffer_pool_replace_last_buffer (GST_GL_BUFFER_POOL (meta->
|
||||
buffer->pool), meta->buffer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_egl_image_memory_setup_buffer (GstGLContext * ctx, GstVideoInfo * info,
|
||||
GstBuffer * buffer)
|
||||
{
|
||||
gint i = 0;
|
||||
gint stride[3];
|
||||
gsize offset[3];
|
||||
GstMemory *mem[3] = { NULL, NULL, NULL };
|
||||
guint n_mem = 0;
|
||||
GstMemoryFlags flags = 0;
|
||||
EGLImageKHR image = EGL_NO_IMAGE_KHR;
|
||||
EGLClientBuffer client_buffer_tex[3] = { 0, 0, 0 };
|
||||
GstVideoGLTextureType texture_types[] = { 0, 0, 0, 0 };
|
||||
GstAllocator *allocator = gst_egl_image_allocator_obtain ();
|
||||
GstGLContextEGL *context = GST_GL_CONTEXT_EGL (ctx);
|
||||
|
||||
g_return_val_if_fail (ctx, FALSE);
|
||||
g_return_val_if_fail (info, FALSE);
|
||||
g_return_val_if_fail (buffer, FALSE);
|
||||
|
||||
memset (stride, 0, sizeof (stride));
|
||||
memset (offset, 0, sizeof (offset));
|
||||
|
||||
flags |= GST_MEMORY_FLAG_NOT_MAPPABLE;
|
||||
flags |= GST_MEMORY_FLAG_NO_SHARE;
|
||||
|
||||
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
||||
case GST_VIDEO_FORMAT_RGB:
|
||||
case GST_VIDEO_FORMAT_BGR:
|
||||
case GST_VIDEO_FORMAT_RGB16:
|
||||
case GST_VIDEO_FORMAT_RGBA:
|
||||
case GST_VIDEO_FORMAT_BGRA:
|
||||
case GST_VIDEO_FORMAT_ARGB:
|
||||
case GST_VIDEO_FORMAT_ABGR:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
case GST_VIDEO_FORMAT_xRGB:
|
||||
case GST_VIDEO_FORMAT_xBGR:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
{
|
||||
gsize size = 0;
|
||||
|
||||
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
||||
case GST_VIDEO_FORMAT_RGB:
|
||||
case GST_VIDEO_FORMAT_BGR:
|
||||
case GST_VIDEO_FORMAT_RGB16:
|
||||
{
|
||||
texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGB;
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_RGBA:
|
||||
case GST_VIDEO_FORMAT_BGRA:
|
||||
case GST_VIDEO_FORMAT_ARGB:
|
||||
case GST_VIDEO_FORMAT_ABGR:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
case GST_VIDEO_FORMAT_xRGB:
|
||||
case GST_VIDEO_FORMAT_xBGR:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
{
|
||||
texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
mem[0] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[0], GST_VIDEO_INFO_WIDTH (info),
|
||||
GST_VIDEO_INFO_HEIGHT (info), size);
|
||||
if (mem[0]) {
|
||||
stride[0] = size / GST_VIDEO_INFO_HEIGHT (info);
|
||||
n_mem = 1;
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE);
|
||||
} else {
|
||||
gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, 0, stride,
|
||||
offset, &size, (GLuint *) & client_buffer_tex[0]);
|
||||
|
||||
image = eglCreateImageKHR (context->egl_display,
|
||||
context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[0],
|
||||
NULL);
|
||||
if (eglGetError () != EGL_SUCCESS)
|
||||
goto mem_error;
|
||||
|
||||
mem[0] =
|
||||
gst_egl_image_allocator_wrap (allocator, context,
|
||||
image, texture_types[0], flags, size, client_buffer_tex[0],
|
||||
(GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture);
|
||||
n_mem = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
{
|
||||
gsize size[2];
|
||||
|
||||
texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE;
|
||||
texture_types[1] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA;
|
||||
|
||||
mem[0] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[0], GST_VIDEO_INFO_COMP_WIDTH (info,
|
||||
0), GST_VIDEO_INFO_COMP_HEIGHT (info, 0), size[0]);
|
||||
mem[1] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[1],
|
||||
GST_VIDEO_INFO_COMP_WIDTH (info, 1),
|
||||
GST_VIDEO_INFO_COMP_HEIGHT (info, 1), size[1]);
|
||||
|
||||
if (mem[0] && mem[1]) {
|
||||
stride[0] = size[0] / GST_VIDEO_INFO_HEIGHT (info);
|
||||
offset[1] = size[0];
|
||||
stride[1] = size[1] / GST_VIDEO_INFO_HEIGHT (info);
|
||||
n_mem = 2;
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE);
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[1], GST_MEMORY_FLAG_NO_SHARE);
|
||||
} else {
|
||||
if (mem[0])
|
||||
gst_memory_unref (mem[0]);
|
||||
if (mem[1])
|
||||
gst_memory_unref (mem[1]);
|
||||
mem[0] = mem[1] = NULL;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, 0,
|
||||
stride, offset, size, (GLuint *) & client_buffer_tex[i]);
|
||||
|
||||
image = eglCreateImageKHR (context->egl_display,
|
||||
context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[i],
|
||||
NULL);
|
||||
if (eglGetError () != EGL_SUCCESS)
|
||||
goto mem_error;
|
||||
|
||||
mem[i] =
|
||||
gst_egl_image_allocator_wrap (allocator, context,
|
||||
image, texture_types[i], flags, size[i], client_buffer_tex[i],
|
||||
(GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture);
|
||||
}
|
||||
|
||||
n_mem = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_Y444:
|
||||
case GST_VIDEO_FORMAT_Y42B:
|
||||
case GST_VIDEO_FORMAT_Y41B:
|
||||
{
|
||||
gsize size[3];
|
||||
|
||||
texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE;
|
||||
texture_types[1] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE;
|
||||
texture_types[2] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE;
|
||||
|
||||
mem[0] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[0], GST_VIDEO_INFO_COMP_WIDTH (info,
|
||||
0), GST_VIDEO_INFO_COMP_HEIGHT (info, 0), size[0]);
|
||||
mem[1] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[1], GST_VIDEO_INFO_COMP_WIDTH (info,
|
||||
1), GST_VIDEO_INFO_COMP_HEIGHT (info, 1), size[1]);
|
||||
mem[2] =
|
||||
gst_egl_image_allocator_alloc (allocator, context,
|
||||
texture_types[2], GST_VIDEO_INFO_COMP_WIDTH (info,
|
||||
2), GST_VIDEO_INFO_COMP_HEIGHT (info, 2), size[2]);
|
||||
|
||||
if (mem[0] && mem[1] && mem[2]) {
|
||||
stride[0] = size[0] / GST_VIDEO_INFO_HEIGHT (info);
|
||||
offset[1] = size[0];
|
||||
stride[1] = size[1] / GST_VIDEO_INFO_HEIGHT (info);
|
||||
offset[2] = size[1];
|
||||
stride[2] = size[2] / GST_VIDEO_INFO_HEIGHT (info);
|
||||
n_mem = 3;
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE);
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[1], GST_MEMORY_FLAG_NO_SHARE);
|
||||
GST_MINI_OBJECT_FLAG_SET (mem[2], GST_MEMORY_FLAG_NO_SHARE);
|
||||
} else {
|
||||
if (mem[0])
|
||||
gst_memory_unref (mem[0]);
|
||||
if (mem[1])
|
||||
gst_memory_unref (mem[1]);
|
||||
if (mem[2])
|
||||
gst_memory_unref (mem[2]);
|
||||
mem[0] = mem[1] = mem[2] = NULL;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, i,
|
||||
stride, offset, size, (GLuint *) & client_buffer_tex[i]);
|
||||
|
||||
image = eglCreateImageKHR (context->egl_display,
|
||||
context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[i],
|
||||
NULL);
|
||||
if (eglGetError () != EGL_SUCCESS)
|
||||
goto mem_error;
|
||||
|
||||
mem[i] =
|
||||
gst_egl_image_allocator_wrap (allocator, context,
|
||||
image, texture_types[i], flags, size[i], client_buffer_tex[i],
|
||||
(GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture);
|
||||
}
|
||||
|
||||
n_mem = 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
gst_buffer_add_video_meta_full (buffer, 0, GST_VIDEO_INFO_FORMAT (info),
|
||||
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
|
||||
GST_VIDEO_INFO_N_PLANES (info), offset, stride);
|
||||
|
||||
gst_buffer_add_video_gl_texture_upload_meta (buffer,
|
||||
gst_egl_image_memory_get_orientation (mem[0]), n_mem, texture_types,
|
||||
gst_eglimage_to_gl_texture_upload_meta, NULL, NULL, NULL);
|
||||
|
||||
for (i = 0; i < n_mem; i++)
|
||||
gst_buffer_append_memory (buffer, mem[i]);
|
||||
|
||||
return TRUE;
|
||||
|
||||
mem_error:
|
||||
{
|
||||
GST_ERROR_OBJECT (GST_CAT_DEFAULT, "Failed to create EGLImage");
|
||||
|
||||
for (i = 0; i < n_mem; i++) {
|
||||
if (client_buffer_tex[i])
|
||||
gst_gl_context_del_texture (ctx, (GLuint *) & client_buffer_tex[i]);
|
||||
if (mem[i])
|
||||
gst_memory_unref (mem[i]);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
50
gst-libs/gst/gl/egl/gsteglimagememory.h
Normal file
50
gst-libs/gst/gl/egl/gsteglimagememory.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2012 Collabora Ltd.
|
||||
* @author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* Copyright (C) 2014 Julien Isorce <julien.isorce@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_EGL_IMAGE_MEMORY_H_
|
||||
#define _GST_EGL_IMAGE_MEMORY_H_
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/gstallocator.h>
|
||||
#include <gst/gstmemory.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include <gst/gl/gl.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_EGL_IMAGE_MEMORY_TYPE "EGLImage"
|
||||
|
||||
#define GST_CAPS_FEATURE_MEMORY_EGL_IMAGE "memory:EGLImage"
|
||||
|
||||
void gst_egl_image_memory_init (void);
|
||||
gboolean gst_egl_image_memory_setup_buffer (GstGLContext * context, GstVideoInfo * info, GstBuffer * buffer);
|
||||
gboolean gst_is_egl_image_memory (GstMemory * mem);
|
||||
EGLImageKHR gst_egl_image_memory_get_image (GstMemory * mem);
|
||||
EGLDisplay gst_egl_image_memory_get_display (GstMemory * mem);
|
||||
GstVideoGLTextureOrientation gst_egl_image_memory_get_orientation (GstMemory * mem);
|
||||
void gst_egl_image_memory_set_orientation (GstMemory * mem,
|
||||
GstVideoGLTextureOrientation orientation);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _GST_GL_MEMORY_H_ */
|
|
@ -54,6 +54,11 @@ struct _GstGLContextEGLClass {
|
|||
GType gst_gl_context_egl_get_type (void);
|
||||
GstGLContextEGL * gst_gl_context_egl_new (void);
|
||||
|
||||
/* TODO:
|
||||
* add support for EGL_NO_CONTEXT
|
||||
* add gst_gl_context_egl_new_gl_no_context that only manages the display
|
||||
* add gst_gl_context_egl_is_gl_no_context () */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_GL_EGL_H__ */
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#endif
|
||||
|
||||
#include <gst/gl/egl/gstgldisplay_egl.h>
|
||||
#include <gst/gl/egl/gsteglimagememory.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
|
||||
#define GST_CAT_DEFAULT gst_gl_display_debug
|
||||
|
@ -48,6 +49,8 @@ gst_gl_display_egl_init (GstGLDisplayEGL * display_egl)
|
|||
|
||||
display->type = GST_GL_DISPLAY_TYPE_EGL;
|
||||
display_egl->foreign_display = FALSE;
|
||||
|
||||
gst_egl_image_memory_init ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -55,10 +58,7 @@ gst_gl_display_egl_finalize (GObject * object)
|
|||
{
|
||||
GstGLDisplayEGL *display_egl = GST_GL_DISPLAY_EGL (object);
|
||||
|
||||
if (display_egl->gst_display) {
|
||||
gst_egl_display_unref (display_egl->gst_display);
|
||||
display_egl->gst_display = NULL;
|
||||
} else if (display_egl->display && !display_egl->foreign_display) {
|
||||
if (display_egl->display && !display_egl->foreign_display) {
|
||||
eglTerminate (display_egl->display);
|
||||
display_egl->display = NULL;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ gst_gl_display_egl_new (void)
|
|||
* Returns: (transfer full): a new #GstGLDisplayEGL
|
||||
*/
|
||||
GstGLDisplayEGL *
|
||||
gst_gl_display_egl_new_with_egl_display (EGLDisplay * display)
|
||||
gst_gl_display_egl_new_with_egl_display (EGLDisplay display)
|
||||
{
|
||||
GstGLDisplayEGL *ret;
|
||||
|
||||
|
@ -117,32 +117,6 @@ gst_gl_display_egl_new_with_egl_display (EGLDisplay * display)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_gl_display_egl_new_with_display:
|
||||
* @display: an existing, x11 display
|
||||
*
|
||||
* Creates a new display connection from a X11 Display.
|
||||
*
|
||||
* Returns: (transfer full): a new #GstGLDisplayEGL
|
||||
*/
|
||||
GstGLDisplayEGL *
|
||||
gst_gl_display_egl_new_with_gst_egl_display (GstEGLDisplay * display)
|
||||
{
|
||||
GstGLDisplayEGL *ret;
|
||||
|
||||
g_return_val_if_fail (display != NULL, NULL);
|
||||
|
||||
GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
|
||||
|
||||
ret = g_object_new (GST_TYPE_GL_DISPLAY_EGL, NULL);
|
||||
|
||||
ret->gst_display = gst_egl_display_ref (display);
|
||||
ret->display = gst_egl_display_get (display);
|
||||
ret->foreign_display = TRUE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static guintptr
|
||||
gst_gl_display_egl_get_handle (GstGLDisplay * display)
|
||||
{
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
#define __GST_GL_DISPLAY_EGL_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/gl/gl.h>
|
||||
|
||||
/* FIXME temp until merge */
|
||||
#include <gst/egl/egl.h>
|
||||
#include <gst/gl/gstgldisplay.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -52,8 +49,7 @@ struct _GstGLDisplayEGL
|
|||
GstGLDisplay parent;
|
||||
|
||||
/* <private> */
|
||||
GstEGLDisplay *gst_display;
|
||||
EGLDisplay *display;
|
||||
EGLDisplay display;
|
||||
|
||||
gboolean foreign_display;
|
||||
};
|
||||
|
@ -64,8 +60,7 @@ struct _GstGLDisplayEGLClass
|
|||
};
|
||||
|
||||
GstGLDisplayEGL *gst_gl_display_egl_new (void);
|
||||
GstGLDisplayEGL *gst_gl_display_egl_new_with_egl_display (EGLDisplay *display);
|
||||
GstGLDisplayEGL *gst_gl_display_egl_new_with_gst_egl_display (GstEGLDisplay *display);
|
||||
GstGLDisplayEGL *gst_gl_display_egl_new_with_egl_display (EGLDisplay display);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -39,4 +39,9 @@
|
|||
#include <gst/gl/gstglmixer.h>
|
||||
#include <gst/gl/gstglshadervariables.h>
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
#include <gst/gl/egl/gstgldisplay_egl.h>
|
||||
#include <gst/gl/egl/gsteglimagememory.h>
|
||||
#endif
|
||||
|
||||
#endif /* __GST_GL_H__ */
|
||||
|
|
|
@ -36,7 +36,11 @@
|
|||
#pragma GCC optimize ("gnu89-inline")
|
||||
#endif
|
||||
|
||||
#ifndef EGL_EGLEXT_PROTOTYPES
|
||||
#define EGL_EGLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#if defined (USE_EGL_RPI) && defined(__GNUC__)
|
||||
#pragma GCC reset_options
|
||||
|
@ -47,6 +51,9 @@
|
|||
|
||||
/* OpenGL 2.0 for Embedded Systems */
|
||||
#if GST_GL_HAVE_GLES2
|
||||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
# include <GLES2/gl2.h>
|
||||
# include <GLES2/gl2ext.h>
|
||||
# if !GST_GL_HAVE_OPENGL
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include "gl.h"
|
||||
#include "gstglbufferpool.h"
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
#include <gst/gl/egl/gsteglimagememory.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* SECTION:gstglbufferpool
|
||||
* @short_description: buffer pool for #GstGLMemory objects
|
||||
|
@ -46,13 +50,14 @@ struct _GstGLBufferPoolPrivate
|
|||
GstCaps *caps;
|
||||
gint im_format;
|
||||
GstVideoInfo info;
|
||||
guint padded_width;
|
||||
guint padded_height;
|
||||
gboolean add_videometa;
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
gboolean want_eglimage;
|
||||
GstBuffer *last_buffer;
|
||||
#endif
|
||||
};
|
||||
|
||||
static void gst_gl_buffer_pool_finalize (GObject * object);
|
||||
static void gst_gl_buffer_pool_dispose (GObject * object);
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_GL_BUFFER_POOL);
|
||||
#define GST_CAT_DEFAULT GST_CAT_GL_BUFFER_POOL
|
||||
|
@ -119,6 +124,11 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|||
priv->add_videometa = gst_buffer_pool_config_has_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
priv->want_eglimage = (priv->allocator
|
||||
&& g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0);
|
||||
#endif
|
||||
|
||||
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
||||
|
||||
/* ERRORS */
|
||||
|
@ -166,6 +176,18 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|||
if (!(buf = gst_buffer_new ())) {
|
||||
goto no_buffer;
|
||||
}
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
if (priv->want_eglimage) {
|
||||
/* alloc and append memories, also add video_meta and
|
||||
* texture_upload_meta */
|
||||
if (!gst_egl_image_memory_setup_buffer (glpool->context, info, buf))
|
||||
goto egl_image_mem_create_failed;
|
||||
|
||||
*buffer = buf;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(gl_mem = gst_gl_memory_alloc (glpool->context, priv->info)))
|
||||
goto mem_create_failed;
|
||||
|
@ -192,12 +214,56 @@ no_buffer:
|
|||
GST_WARNING_OBJECT (pool, "can't create image");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
mem_create_failed:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "Could not create GL Memory");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
egl_image_mem_create_failed:
|
||||
{
|
||||
GST_WARNING_OBJECT (pool, "Could not create EGLImage Memory");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static GstFlowReturn
|
||||
gst_gl_buffer_pool_acquire_buffer (GstBufferPool * bpool,
|
||||
GstBuffer ** buffer, GstBufferPoolAcquireParams * params)
|
||||
{
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
GstGLBufferPool *glpool = NULL;
|
||||
#endif
|
||||
|
||||
ret =
|
||||
GST_BUFFER_POOL_CLASS
|
||||
(gst_gl_buffer_pool_parent_class)->acquire_buffer (bpool, buffer, params);
|
||||
if (ret != GST_FLOW_OK || !*buffer)
|
||||
return ret;
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
glpool = GST_GL_BUFFER_POOL (bpool);
|
||||
|
||||
/* XXX: Don't return the memory we just rendered, glEGLImageTargetTexture2DOES()
|
||||
* keeps the EGLImage unmappable until the next one is uploaded
|
||||
*/
|
||||
if (glpool->priv->want_eglimage && *buffer
|
||||
&& *buffer == glpool->priv->last_buffer) {
|
||||
GstBuffer *oldbuf = *buffer;
|
||||
|
||||
ret =
|
||||
GST_BUFFER_POOL_CLASS
|
||||
(gst_gl_buffer_pool_parent_class)->acquire_buffer (bpool,
|
||||
buffer, params);
|
||||
gst_object_replace ((GstObject **) & oldbuf->pool, (GstObject *) glpool);
|
||||
gst_buffer_unref (oldbuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,6 +285,18 @@ gst_gl_buffer_pool_new (GstGLContext * context)
|
|||
return GST_BUFFER_POOL_CAST (pool);
|
||||
}
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
void
|
||||
gst_gl_buffer_pool_replace_last_buffer (GstGLBufferPool * pool,
|
||||
GstBuffer * buffer)
|
||||
{
|
||||
g_return_if_fail (pool != NULL);
|
||||
g_return_if_fail (buffer != NULL);
|
||||
|
||||
gst_buffer_replace (&pool->priv->last_buffer, buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gst_gl_buffer_pool_class_init (GstGLBufferPoolClass * klass)
|
||||
{
|
||||
|
@ -228,30 +306,32 @@ gst_gl_buffer_pool_class_init (GstGLBufferPoolClass * klass)
|
|||
g_type_class_add_private (klass, sizeof (GstGLBufferPoolPrivate));
|
||||
|
||||
gobject_class->finalize = gst_gl_buffer_pool_finalize;
|
||||
gobject_class->dispose = gst_gl_buffer_pool_dispose;
|
||||
|
||||
gstbufferpool_class->get_options = gst_gl_buffer_pool_get_options;
|
||||
gstbufferpool_class->set_config = gst_gl_buffer_pool_set_config;
|
||||
gstbufferpool_class->alloc_buffer = gst_gl_buffer_pool_alloc;
|
||||
gstbufferpool_class->acquire_buffer = gst_gl_buffer_pool_acquire_buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_buffer_pool_init (GstGLBufferPool * pool)
|
||||
{
|
||||
GstGLBufferPoolPrivate *priv = NULL;
|
||||
|
||||
pool->priv = GST_GL_BUFFER_POOL_GET_PRIVATE (pool);
|
||||
}
|
||||
priv = pool->priv;
|
||||
|
||||
static void
|
||||
gst_gl_buffer_pool_dispose (GObject * object)
|
||||
{
|
||||
GstGLBufferPool *pool = GST_GL_BUFFER_POOL_CAST (object);
|
||||
priv->allocator = NULL;
|
||||
priv->caps = NULL;
|
||||
priv->im_format = GST_VIDEO_FORMAT_UNKNOWN;
|
||||
priv->add_videometa = TRUE;
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
priv->want_eglimage = FALSE;
|
||||
priv->last_buffer = FALSE;
|
||||
#endif
|
||||
|
||||
if (pool->context) {
|
||||
gst_object_unref (pool->context);
|
||||
pool->context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gst_gl_buffer_pool_parent_class)->dispose (object);
|
||||
gst_video_info_init (&priv->info);
|
||||
gst_allocation_params_init (&priv->params);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -262,8 +342,18 @@ gst_gl_buffer_pool_finalize (GObject * object)
|
|||
|
||||
GST_LOG_OBJECT (pool, "finalize GL buffer pool %p", pool);
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
gst_buffer_replace (&pool->priv->last_buffer, NULL);
|
||||
#endif
|
||||
|
||||
if (priv->caps)
|
||||
gst_caps_unref (priv->caps);
|
||||
|
||||
G_OBJECT_CLASS (gst_gl_buffer_pool_parent_class)->finalize (object);
|
||||
|
||||
/* only release the context once all our memory have been deleted */
|
||||
if (pool->context) {
|
||||
gst_object_unref (pool->context);
|
||||
pool->context = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,10 @@ struct _GstGLBufferPoolClass
|
|||
};
|
||||
|
||||
GstBufferPool *gst_gl_buffer_pool_new (GstGLContext * context);
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
void gst_gl_buffer_pool_replace_last_buffer (GstGLBufferPool * pool,
|
||||
GstBuffer * buffer);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#endif
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
#include <gst/gl/egl/gstgldisplay_egl.h>
|
||||
#include <gst/gl/egl/gsteglimagememory.h>
|
||||
#endif
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_context);
|
||||
|
@ -89,6 +90,10 @@ gst_gl_display_init (GstGLDisplay * display)
|
|||
GST_TRACE ("init %p", display);
|
||||
|
||||
gst_gl_memory_init ();
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
gst_egl_image_memory_init ();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -30,6 +30,8 @@ G_BEGIN_DECLS
|
|||
/* SUPPORTED */
|
||||
|
||||
//FIXME:
|
||||
#define GL_RGB16 GL_RGB565
|
||||
#define GL_RGB8 GL_RGB
|
||||
#define GL_RGBA8 GL_RGBA
|
||||
#define GL_BGRA GL_RGBA
|
||||
#define GL_BGR GL_RGB
|
||||
|
|
|
@ -34,7 +34,10 @@ static GstStaticPadTemplate gst_gl_filter_src_pad_template =
|
|||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_DOWNLOAD_FORMATS) "; "
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_EGL_IMAGE,
|
||||
"RGBA") "; "
|
||||
GST_VIDEO_CAPS_MAKE (GST_GL_DOWNLOAD_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
||||
"RGBA"))
|
||||
|
@ -44,7 +47,10 @@ static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
|
|||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_UPLOAD_FORMATS) "; "
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_EGL_IMAGE,
|
||||
"RGBA") "; "
|
||||
GST_VIDEO_CAPS_MAKE (GST_GL_UPLOAD_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META,
|
||||
"RGBA"))
|
||||
|
@ -737,6 +743,8 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|||
GstStructure *gl_context;
|
||||
gchar *platform, *gl_apis;
|
||||
gpointer handle;
|
||||
GstAllocator *allocator = NULL;
|
||||
GstAllocationParams params;
|
||||
|
||||
gst_query_parse_allocation (query, &caps, &need_pool);
|
||||
|
||||
|
@ -814,6 +822,18 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
|
|||
g_free (platform);
|
||||
gst_structure_free (gl_context);
|
||||
|
||||
gst_allocation_params_init (¶ms);
|
||||
|
||||
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
|
||||
gst_query_add_allocation_param (query, allocator, ¶ms);
|
||||
gst_object_unref (allocator);
|
||||
|
||||
#if GST_GL_HAVE_PLATFORM_EGL
|
||||
allocator = gst_allocator_find (GST_EGL_IMAGE_MEMORY_TYPE);
|
||||
gst_query_add_allocation_param (query, allocator, ¶ms);
|
||||
gst_object_unref (allocator);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
|
|
|
@ -327,6 +327,8 @@ gst_gl_mixer_propose_allocation (GstGLMixer * mix,
|
|||
GstStructure *gl_context;
|
||||
gchar *platform, *gl_apis;
|
||||
gpointer handle;
|
||||
GstAllocator *allocator = NULL;
|
||||
GstAllocationParams params;
|
||||
|
||||
gst_query_parse_allocation (query, &caps, &need_pool);
|
||||
|
||||
|
@ -402,6 +404,12 @@ gst_gl_mixer_propose_allocation (GstGLMixer * mix,
|
|||
g_free (platform);
|
||||
gst_structure_free (gl_context);
|
||||
|
||||
gst_allocation_params_init (¶ms);
|
||||
|
||||
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
|
||||
gst_query_add_allocation_param (query, allocator, ¶ms);
|
||||
gst_object_unref (allocator);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
|
|
|
@ -147,6 +147,169 @@ gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture)
|
|||
pTexture);
|
||||
}
|
||||
|
||||
typedef struct _GenTextureFull
|
||||
{
|
||||
const GstVideoInfo *info;
|
||||
const gint comp;
|
||||
guint result;
|
||||
} GenTextureFull;
|
||||
|
||||
static void
|
||||
_gen_texture_full (GstGLContext * context, GenTextureFull * data)
|
||||
{
|
||||
const GstGLFuncs *gl = context->gl_vtable;
|
||||
GLint glinternalformat = 0;
|
||||
GLenum glformat = 0;
|
||||
GLenum gltype = 0;
|
||||
|
||||
gl->GenTextures (1, &data->result);
|
||||
gl->BindTexture (GL_TEXTURE_2D, data->result);
|
||||
|
||||
switch (GST_VIDEO_INFO_FORMAT (data->info)) {
|
||||
case GST_VIDEO_FORMAT_RGB:
|
||||
case GST_VIDEO_FORMAT_BGR:
|
||||
{
|
||||
glinternalformat = GL_RGB8;
|
||||
glformat = GL_RGB;
|
||||
gltype = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_RGB16:
|
||||
{
|
||||
glinternalformat = GL_RGB16;
|
||||
glformat = GL_RGB;
|
||||
gltype = GL_UNSIGNED_SHORT_5_6_5;
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_RGBA:
|
||||
case GST_VIDEO_FORMAT_BGRA:
|
||||
case GST_VIDEO_FORMAT_ARGB:
|
||||
case GST_VIDEO_FORMAT_ABGR:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
case GST_VIDEO_FORMAT_xRGB:
|
||||
case GST_VIDEO_FORMAT_xBGR:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
{
|
||||
glinternalformat = GL_RGBA8;
|
||||
glformat = GL_RGBA;
|
||||
gltype = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
{
|
||||
glinternalformat = GL_LUMINANCE;
|
||||
glformat = data->comp == 0 ? GL_LUMINANCE : GL_LUMINANCE_ALPHA;
|
||||
gltype = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_Y444:
|
||||
case GST_VIDEO_FORMAT_Y42B:
|
||||
case GST_VIDEO_FORMAT_Y41B:
|
||||
{
|
||||
glformat = GL_LUMINANCE;
|
||||
gltype = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
GST_WARNING ("unsupported %s",
|
||||
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (data->info)));
|
||||
break;
|
||||
}
|
||||
|
||||
gl->TexImage2D (GL_TEXTURE_2D, 0, glinternalformat,
|
||||
GST_VIDEO_INFO_COMP_WIDTH (data->info, data->comp),
|
||||
GST_VIDEO_INFO_COMP_HEIGHT (data->info, data->comp), 0, glformat, gltype,
|
||||
NULL);
|
||||
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_generate_texture_full (GstGLContext * context, const GstVideoInfo * info,
|
||||
const guint comp, gint stride[], gsize offset[], gsize size[],
|
||||
GLuint * pTexture)
|
||||
{
|
||||
GenTextureFull data = { info, comp, 0 };
|
||||
|
||||
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
||||
case GST_VIDEO_FORMAT_RGB:
|
||||
case GST_VIDEO_FORMAT_BGR:
|
||||
{
|
||||
stride[0] = GST_ROUND_UP_4 (GST_VIDEO_INFO_WIDTH (info) * 3);
|
||||
offset[0] = 0;
|
||||
size[0] = stride[0] * GST_VIDEO_INFO_HEIGHT (info);
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_RGB16:
|
||||
{
|
||||
stride[0] = GST_ROUND_UP_4 (GST_VIDEO_INFO_WIDTH (info) * 2);
|
||||
offset[0] = 0;
|
||||
size[0] = stride[0] * GST_VIDEO_INFO_HEIGHT (info);
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_RGBA:
|
||||
case GST_VIDEO_FORMAT_BGRA:
|
||||
case GST_VIDEO_FORMAT_ARGB:
|
||||
case GST_VIDEO_FORMAT_ABGR:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
case GST_VIDEO_FORMAT_xRGB:
|
||||
case GST_VIDEO_FORMAT_xBGR:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
{
|
||||
stride[0] = GST_ROUND_UP_4 (GST_VIDEO_INFO_WIDTH (info) * 4);
|
||||
offset[0] = 0;
|
||||
size[0] = stride[0] * GST_VIDEO_INFO_HEIGHT (info);
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_NV12:
|
||||
case GST_VIDEO_FORMAT_NV21:
|
||||
{
|
||||
size[comp] = stride[comp] * GST_VIDEO_INFO_COMP_HEIGHT (info, comp);
|
||||
if (comp == 0) {
|
||||
stride[0] = GST_ROUND_UP_4 (GST_VIDEO_INFO_COMP_WIDTH (info, 1));
|
||||
offset[0] = 0;
|
||||
} else {
|
||||
stride[1] = GST_ROUND_UP_4 (GST_VIDEO_INFO_COMP_WIDTH (info, 1) * 2);
|
||||
offset[1] = size[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_Y444:
|
||||
case GST_VIDEO_FORMAT_Y42B:
|
||||
case GST_VIDEO_FORMAT_Y41B:
|
||||
{
|
||||
stride[comp] = GST_ROUND_UP_4 (GST_VIDEO_INFO_COMP_WIDTH (info, comp));;
|
||||
size[comp] = stride[comp] * GST_VIDEO_INFO_COMP_HEIGHT (info, comp);
|
||||
if (comp == 0)
|
||||
offset[0] = 0;
|
||||
else if (comp == 1)
|
||||
offset[1] = size[0];
|
||||
else
|
||||
offset[2] = offset[1] + size[1];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
GST_WARNING ("unsupported %s",
|
||||
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (info)));
|
||||
break;
|
||||
}
|
||||
|
||||
gst_gl_context_thread_add (context,
|
||||
(GstGLContextThreadFunc) _gen_texture_full, &data);
|
||||
|
||||
*pTexture = data.result;
|
||||
}
|
||||
|
||||
typedef struct _GenFBO
|
||||
{
|
||||
GstGLFramebuffer *frame;
|
||||
|
|
|
@ -78,6 +78,9 @@ void gst_gl_context_gen_texture (GstGLContext * context, GLuint * pTexture,
|
|||
GstVideoFormat v_format, GLint width, GLint height);
|
||||
void gst_gl_context_del_texture (GstGLContext * context, GLuint * pTexture);
|
||||
|
||||
void gst_gl_generate_texture_full (GstGLContext * context, const GstVideoInfo * info,
|
||||
const guint comp, gint stride[], gsize offset[], gsize size[], GLuint * pTexture);
|
||||
|
||||
gboolean gst_gl_context_gen_fbo (GstGLContext * context, gint width, gint height,
|
||||
GLuint * fbo, GLuint * depthbuffer);
|
||||
gboolean gst_gl_context_use_fbo (GstGLContext * context, gint texture_fbo_width,
|
||||
|
|
Loading…
Reference in a new issue