glmemory: base classify and add the pbo memory on top

The base class is useful for having multiple backing memory types other
than the default.  e.g. IOSurface, EGLImage, dmabuf?

The PBO transfer logic is now inside GstGLMemoryPBO which uses GstGLBuffer
to manage the PBO memory.

This also moves the format utility functions into their own file.
This commit is contained in:
Matthew Waters 2015-12-14 13:43:59 +11:00
parent 6cf8da132b
commit 2b7495bbc1
20 changed files with 2035 additions and 1347 deletions

View file

@ -27,6 +27,7 @@ gst_insert_bin_get_type
gst_gl_buffer_allocator_get_type
gst_gl_memory_allocator_get_type
gst_gl_base_filter_get_type
gst_gl_buffer_pool_get_type
gst_gl_color_convert_get_type

View file

@ -176,7 +176,8 @@ gst_gl_download_element_prepare_output_buffer (GstBaseTransform * bt,
if (gst_is_gl_memory (mem)) {
if (!features || gst_caps_features_contains (features,
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY)) {
gst_gl_memory_download_transfer ((GstGLMemory *) mem);
if (gst_is_gl_memory_pbo (mem))
gst_gl_memory_pbo_download_transfer ((GstGLMemoryPBO *) mem);
}
}
}

View file

@ -696,7 +696,7 @@ gst_gl_overlay_load_jpeg (GstGLOverlay * overlay, FILE * fp)
gst_video_info_align (&v_info, &v_align);
overlay->image_memory = (GstGLMemory *)
gst_gl_memory_alloc (GST_GL_BASE_FILTER (overlay)->context,
gst_gl_memory_pbo_alloc (GST_GL_BASE_FILTER (overlay)->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &v_info, 0, &v_align);
if (!gst_memory_map ((GstMemory *) overlay->image_memory, &map_info,
@ -801,7 +801,7 @@ gst_gl_overlay_load_png (GstGLOverlay * overlay, FILE * fp)
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, width, height);
overlay->image_memory = (GstGLMemory *)
gst_gl_memory_alloc (GST_GL_BASE_FILTER (overlay)->context,
gst_gl_memory_pbo_alloc (GST_GL_BASE_FILTER (overlay)->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &v_info, 0, NULL);
if (!gst_memory_map ((GstMemory *) overlay->image_memory, &map_info,

View file

@ -111,7 +111,7 @@ GstQSGTexture::bind ()
mem = gst_buffer_peek_memory (this->buffer_, 0);
g_assert (gst_is_gl_memory (mem));
context = ((GstGLBaseBuffer *)mem)->context;
context = ((GstGLBaseMemory *)mem)->context;
sync_meta = gst_buffer_get_gl_sync_meta (this->sync_buffer_);
if (!sync_meta)

View file

@ -16,8 +16,10 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
gstglbasememory.c \
gstglbuffer.c \
gstglmemory.c \
gstglmemorypbo.c \
gstglbufferpool.c \
gstglfilter.c \
gstglformat.c \
gstglbasefilter.c \
gstglshader.c \
gstglshaderstrings.c \
@ -46,8 +48,10 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \
gstglbasememory.h \
gstglbuffer.h \
gstglmemory.h \
gstglmemorypbo.h \
gstglbufferpool.h \
gstglfilter.h \
gstglformat.h \
gstglbasefilter.h \
gstglshader.h \
gstglshaderstrings.h \

View file

@ -33,6 +33,7 @@
#include <gst/gl/gstglcontext.h>
#include <gst/gl/gstgldebug.h>
#include <gst/gl/gstglfeature.h>
#include <gst/gl/gstglformat.h>
#include <gst/gl/gstglutils.h>
#include <gst/gl/gstglwindow.h>
#include <gst/gl/gstglslstage.h>
@ -44,6 +45,7 @@
#include <gst/gl/gstglbasememory.h>
#include <gst/gl/gstglbuffer.h>
#include <gst/gl/gstglmemory.h>
#include <gst/gl/gstglmemorypbo.h>
#include <gst/gl/gstglbufferpool.h>
#include <gst/gl/gstglframebuffer.h>
#include <gst/gl/gstglbasefilter.h>

View file

@ -52,8 +52,12 @@ typedef struct _GstGLBufferAllocator GstGLBufferAllocator;
typedef struct _GstGLBufferAllocatorClass GstGLBufferAllocatorClass;
typedef struct _GstGLMemory GstGLMemory;
typedef struct _GstGLAllocator GstGLAllocator;
typedef struct _GstGLAllocatorClass GstGLAllocatorClass;
typedef struct _GstGLMemoryAllocator GstGLMemoryAllocator;
typedef struct _GstGLMemoryAllocatorClass GstGLMemoryAllocatorClass;
typedef struct _GstGLMemoryPBO GstGLMemoryPBO;
typedef struct _GstGLMemoryPBOAllocator GstGLMemoryPBOAllocator;
typedef struct _GstGLMemoryPBOAllocatorClass GstGLMemoryPBOAllocatorClass;
typedef struct _GstGLSLStage GstGLSLStage;
typedef struct _GstGLSLStagePrivate GstGLSLStagePrivate;

View file

@ -120,10 +120,7 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
if (priv->allocator)
gst_object_unref (priv->allocator);
if (!allocator) {
gst_gl_memory_init ();
priv->allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
} else {
if (allocator) {
priv->allocator = gst_object_ref (allocator);
}
@ -142,12 +139,14 @@ gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
GST_BUFFER_POOL_OPTION_GL_SYNC_META);
#if GST_GL_HAVE_PLATFORM_EGL
g_assert (priv->allocator != NULL);
if (priv->allocator) {
priv->want_eglimage =
(g_strcmp0 (priv->allocator->mem_type, GST_EGL_IMAGE_MEMORY_TYPE) == 0);
#else
priv->want_eglimage = FALSE;
} else
#endif
{
priv->want_eglimage = FALSE;
}
max_align = alloc_params.align;
@ -299,7 +298,7 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
}
#endif
if (!gst_gl_memory_setup_buffer (glpool->context, priv->tex_target,
if (!gst_gl_memory_pbo_setup_buffer (glpool->context, priv->tex_target,
&priv->params, info, valign, buf))
goto mem_create_failed;

View file

@ -2013,7 +2013,7 @@ _do_convert_one_view (GstGLContext * context, GstGLColorConvert * convert,
if (!convert->priv->out_tex[j])
convert->priv->out_tex[j] =
(GstGLMemory *) gst_gl_memory_alloc (context,
(GstGLMemory *) gst_gl_memory_pbo_alloc (context,
convert->priv->to_texture_target, NULL, &temp_info, 0, NULL);
} else {
convert->priv->out_tex[j] = out_tex;
@ -2069,10 +2069,9 @@ out:
res = FALSE;
continue;
}
gst_gl_memory_copy_into_texture (convert->priv->out_tex[j],
gst_gl_memory_copy_into (convert->priv->out_tex[j],
out_tex->tex_id, convert->priv->to_texture_target, out_tex->tex_type,
mem_width, mem_height, GST_VIDEO_INFO_PLANE_STRIDE (&out_tex->info,
out_tex->plane), FALSE);
mem_width, mem_height);
gst_memory_unmap ((GstMemory *) convert->priv->out_tex[j], &from_info);
gst_memory_unmap ((GstMemory *) out_tex, &to_info);
} else {
@ -2120,7 +2119,7 @@ _do_convert (GstGLContext * context, GstGLColorConvert * convert)
gst_gl_sync_meta_wait (sync_meta, convert->context);
convert->outbuf = gst_buffer_new ();
if (!gst_gl_memory_setup_buffer (convert->context,
if (!gst_gl_memory_pbo_setup_buffer (convert->context,
convert->priv->to_texture_target, NULL, &convert->out_info, NULL,
convert->outbuf)) {
convert->priv->result = FALSE;

View file

@ -140,8 +140,8 @@ gst_gl_display_init (GstGLDisplay * display)
GST_TRACE ("init %p", display);
gst_gl_base_buffer_init_once ();
gst_gl_memory_init ();
gst_gl_buffer_init_once ();
gst_gl_memory_pbo_init_once ();
#if GST_GL_HAVE_PLATFORM_EGL
gst_egl_image_memory_init ();

View file

@ -0,0 +1,358 @@
/*
* GStreamer
* Copyright (C) 2015 Matthew Waters <matthew@centricular.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 <gst/gl/gstglformat.h>
#include <gst/gl/gstglcontext.h>
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
#ifndef GL_RGBA8
#define GL_RGBA8 0x8058
#endif
#ifndef GL_RED
#define GL_RED 0x1903
#endif
#ifndef GL_RG
#define GL_RG 0x8227
#endif
#ifndef GL_R8
#define GL_R8 0x8229
#endif
#ifndef GL_RG8
#define GL_RG8 0x822B
#endif
static inline guint
_gl_format_n_components (guint format)
{
switch (format) {
case GST_VIDEO_GL_TEXTURE_TYPE_RGBA:
case GL_RGBA:
return 4;
case GST_VIDEO_GL_TEXTURE_TYPE_RGB:
case GST_VIDEO_GL_TEXTURE_TYPE_RGB16:
case GL_RGB:
return 3;
case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA:
case GST_VIDEO_GL_TEXTURE_TYPE_RG:
case GL_LUMINANCE_ALPHA:
case GL_RG:
return 2;
case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE:
case GST_VIDEO_GL_TEXTURE_TYPE_R:
case GL_LUMINANCE:
case GL_RED:
return 1;
default:
return 0;
}
}
static inline guint
_gl_type_n_components (guint type)
{
switch (type) {
case GL_UNSIGNED_BYTE:
return 1;
case GL_UNSIGNED_SHORT_5_6_5:
return 3;
default:
g_assert_not_reached ();
return 0;
}
}
static inline guint
_gl_type_n_bytes (guint type)
{
switch (type) {
case GL_UNSIGNED_BYTE:
return 1;
case GL_UNSIGNED_SHORT_5_6_5:
return 2;
default:
g_assert_not_reached ();
return 0;
}
}
guint
gst_gl_format_type_n_bytes (guint format, guint type)
{
return _gl_format_n_components (format) / _gl_type_n_components (type) *
_gl_type_n_bytes (type);
}
guint
gst_gl_texture_type_n_bytes (GstVideoGLTextureType tex_format)
{
guint format, type;
format = gst_gl_format_from_gl_texture_type (tex_format);
type = GL_UNSIGNED_BYTE;
if (tex_format == GST_VIDEO_GL_TEXTURE_TYPE_RGB16)
type = GL_UNSIGNED_SHORT_5_6_5;
return gst_gl_format_type_n_bytes (format, type);
}
guint
gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format)
{
switch (tex_format) {
case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA:
return GL_LUMINANCE_ALPHA;
case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE:
return GL_LUMINANCE;
case GST_VIDEO_GL_TEXTURE_TYPE_RGBA:
return GL_RGBA;
case GST_VIDEO_GL_TEXTURE_TYPE_RGB:
case GST_VIDEO_GL_TEXTURE_TYPE_RGB16:
return GL_RGB;
case GST_VIDEO_GL_TEXTURE_TYPE_RG:
return GL_RG;
case GST_VIDEO_GL_TEXTURE_TYPE_R:
return GL_RED;
default:
return GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
}
}
GstVideoGLTextureType
gst_gl_texture_type_from_format (GstGLContext * context,
GstVideoFormat v_format, guint plane)
{
gboolean texture_rg =
gst_gl_context_check_feature (context, "GL_EXT_texture_rg")
|| gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0)
|| gst_gl_context_check_feature (context, "GL_ARB_texture_rg")
|| gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 0);
guint n_plane_components;
switch (v_format) {
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRx:
case GST_VIDEO_FORMAT_xRGB:
case GST_VIDEO_FORMAT_xBGR:
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_BGRA:
case GST_VIDEO_FORMAT_ARGB:
case GST_VIDEO_FORMAT_ABGR:
case GST_VIDEO_FORMAT_AYUV:
n_plane_components = 4;
break;
case GST_VIDEO_FORMAT_RGB:
case GST_VIDEO_FORMAT_BGR:
n_plane_components = 3;
break;
case GST_VIDEO_FORMAT_RGB16:
case GST_VIDEO_FORMAT_BGR16:
return GST_VIDEO_GL_TEXTURE_TYPE_RGB16;
case GST_VIDEO_FORMAT_GRAY16_BE:
case GST_VIDEO_FORMAT_GRAY16_LE:
case GST_VIDEO_FORMAT_YUY2:
case GST_VIDEO_FORMAT_UYVY:
n_plane_components = 2;
break;
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21:
n_plane_components = plane == 0 ? 1 : 2;
break;
case GST_VIDEO_FORMAT_GRAY8:
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y42B:
case GST_VIDEO_FORMAT_Y41B:
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
n_plane_components = 1;
break;
default:
n_plane_components = 4;
g_assert_not_reached ();
break;
}
switch (n_plane_components) {
case 4:
return GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
break;
case 3:
return GST_VIDEO_GL_TEXTURE_TYPE_RGB;
break;
case 2:
return texture_rg ? GST_VIDEO_GL_TEXTURE_TYPE_RG :
GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA;
break;
case 1:
return texture_rg ? GST_VIDEO_GL_TEXTURE_TYPE_R :
GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE;
break;
default:
g_assert_not_reached ();
break;
}
return GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
}
guint
gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
guint format, guint type)
{
gboolean ext_texture_rg =
gst_gl_context_check_feature (context, "GL_EXT_texture_rg");
switch (format) {
case GL_RGBA:
switch (type) {
case GL_UNSIGNED_BYTE:
return USING_GLES2 (context)
&& !USING_GLES3 (context) ? GL_RGBA : GL_RGBA8;
break;
}
break;
case GL_RGB:
switch (type) {
case GL_UNSIGNED_BYTE:
return GL_RGB8;
break;
case GL_UNSIGNED_SHORT_5_6_5:
return GL_RGB;
break;
}
break;
case GL_RG:
switch (type) {
case GL_UNSIGNED_BYTE:
if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
return GL_RG;
return GL_RG8;
break;
}
break;
case GL_RED:
switch (type) {
case GL_UNSIGNED_BYTE:
if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
return GL_RED;
return GL_R8;
break;
}
break;
case GL_LUMINANCE:
return GL_LUMINANCE;
break;
case GL_LUMINANCE_ALPHA:
return GL_LUMINANCE_ALPHA;
break;
case GL_ALPHA:
return GL_ALPHA;
break;
default:
break;
}
g_assert_not_reached ();
return 0;
}
const gchar *
gst_gl_texture_target_to_string (GstGLTextureTarget target)
{
switch (target) {
case GST_GL_TEXTURE_TARGET_2D:
return GST_GL_TEXTURE_TARGET_2D_STR;
case GST_GL_TEXTURE_TARGET_RECTANGLE:
return GST_GL_TEXTURE_TARGET_RECTANGLE_STR;
case GST_GL_TEXTURE_TARGET_EXTERNAL_OES:
return GST_GL_TEXTURE_TARGET_EXTERNAL_OES_STR;
default:
return NULL;
}
}
GstGLTextureTarget
gst_gl_texture_target_from_string (const gchar * str)
{
if (!str)
return GST_GL_TEXTURE_TARGET_NONE;
if (g_strcmp0 (str, GST_GL_TEXTURE_TARGET_2D_STR) == 0)
return GST_GL_TEXTURE_TARGET_2D;
if (g_strcmp0 (str, GST_GL_TEXTURE_TARGET_RECTANGLE_STR) == 0)
return GST_GL_TEXTURE_TARGET_RECTANGLE;
if (g_strcmp0 (str, GST_GL_TEXTURE_TARGET_EXTERNAL_OES_STR) == 0)
return GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
return GST_GL_TEXTURE_TARGET_NONE;
}
guint
gst_gl_texture_target_to_gl (GstGLTextureTarget target)
{
switch (target) {
case GST_GL_TEXTURE_TARGET_2D:
return GL_TEXTURE_2D;
case GST_GL_TEXTURE_TARGET_RECTANGLE:
return GL_TEXTURE_RECTANGLE;
case GST_GL_TEXTURE_TARGET_EXTERNAL_OES:
return GL_TEXTURE_EXTERNAL_OES;
default:
return 0;
}
}
GstGLTextureTarget
gst_gl_texture_target_from_gl (guint target)
{
switch (target) {
case GL_TEXTURE_2D:
return GST_GL_TEXTURE_TARGET_2D;
case GL_TEXTURE_RECTANGLE:
return GST_GL_TEXTURE_TARGET_RECTANGLE;
case GL_TEXTURE_EXTERNAL_OES:
return GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
default:
return GST_GL_TEXTURE_TARGET_NONE;
}
}
const gchar *
gst_gl_texture_target_to_buffer_pool_option (GstGLTextureTarget target)
{
switch (target) {
case GST_GL_TEXTURE_TARGET_2D:
return GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_2D;
case GST_GL_TEXTURE_TARGET_RECTANGLE:
return GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_RECTANGLE;
case GST_GL_TEXTURE_TARGET_EXTERNAL_OES:
return GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_EXTERNAL_OES;
default:
return NULL;
}
}

View file

@ -0,0 +1,58 @@
/*
* GStreamer
* Copyright (C) 2015 Matthew Waters <matthew@centricular.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_FORMAT_H_
#define _GST_GL_FORMAT_H_
#include <gst/gst.h>
#include <gst/gl/gstgl_fwd.h>
#include <gst/video/video.h>
#define GST_GL_TEXTURE_TARGET_2D_STR "2D"
#define GST_GL_TEXTURE_TARGET_RECTANGLE_STR "rectangle"
#define GST_GL_TEXTURE_TARGET_EXTERNAL_OES_STR "external-oes"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_2D "GstBufferPoolOptionGLTextureTarget2D"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_RECTANGLE "GstBufferPoolOptionGLTextureTargetRectangle"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_EXTERNAL_OES "GstBufferPoolOptionGLTextureTargetExternalOES"
G_BEGIN_DECLS
guint gst_gl_format_type_n_bytes (guint format,
guint type);
guint gst_gl_texture_type_n_bytes (GstVideoGLTextureType tex_format);
guint gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format);
GstVideoGLTextureType gst_gl_texture_type_from_format (GstGLContext * context,
GstVideoFormat v_format,
guint plane);
guint gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
guint format,
guint type);
GstGLTextureTarget gst_gl_texture_target_from_string (const gchar * str);
const gchar * gst_gl_texture_target_to_string (GstGLTextureTarget target);
guint gst_gl_texture_target_to_gl (GstGLTextureTarget target);
GstGLTextureTarget gst_gl_texture_target_from_gl (guint target);
const gchar * gst_gl_texture_target_to_buffer_pool_option (GstGLTextureTarget target);
G_END_DECLS
#endif /* _GST_GL_FORMAT_H_ */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
* GStreamer
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -26,39 +26,27 @@
#include <gst/gstmemory.h>
#include <gst/video/video.h>
#include <gst/gl/gstglbasebuffer.h>
#include <gst/gl/gl.h>
#include <gst/gl/gstglbasememory.h>
G_BEGIN_DECLS
#define GST_TYPE_GL_ALLOCATOR (gst_gl_allocator_get_type())
GType gst_gl_allocator_get_type(void);
#define GST_TYPE_GL_MEMORY_ALLOCATOR (gst_gl_memory_allocator_get_type())
GType gst_gl_memory_allocator_get_type(void);
#define GST_IS_GL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_ALLOCATOR))
#define GST_IS_GL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_ALLOCATOR))
#define GST_GL_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_ALLOCATOR, GstGLAllocatorClass))
#define GST_GL_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_ALLOCATOR, GstGLAllocator))
#define GST_GL_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_ALLOCATOR, GstGLAllocatorClass))
#define GST_GL_ALLOCATOR_CAST(obj) ((GstGLAllocator *)(obj))
#define GST_IS_GL_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR))
#define GST_IS_GL_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_MEMORY_ALLOCATOR))
#define GST_GL_MEMORY_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocatorClass))
#define GST_GL_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocator))
#define GST_GL_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_MEMORY_ALLOCATOR, GstGLMemoryAllocatorClass))
#define GST_GL_MEMORY_ALLOCATOR_CAST(obj) ((GstGLMemoryAllocator *)(obj))
typedef enum _GstGLMemoryTransfer
{
/* force a transfer between the texture and the PBO (if available) */
GST_GL_MEMORY_TRANSFER_NEED_UPLOAD = (1 << 0),
GST_GL_MEMORY_TRANSFER_NEED_DOWNLOAD = (1 << 1),
} GstGLMemoryTransfer;
#define GST_GL_MEMORY_CAST(obj) ((GstGLMemory *) obj)
#define GST_GL_MEMORY_ADD_TRANSFER(mem,state) ((GstGLMemory *)mem)->transfer_state |= state
#define GST_GL_TEXTURE_TARGET_2D_STR "2D"
#define GST_GL_TEXTURE_TARGET_RECTANGLE_STR "rectangle"
#define GST_GL_TEXTURE_TARGET_EXTERNAL_OES_STR "external-oes"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_2D "GstBufferPoolOptionGLTextureTarget2D"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_RECTANGLE "GstBufferPoolOptionGLTextureTargetRectangle"
#define GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_EXTERNAL_OES "GstBufferPoolOptionGLTextureTargetExternalOES"
const gchar * gst_gl_texture_target_to_buffer_pool_option (GstGLTextureTarget target);
#define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory"
#define GST_GL_MEMORY_VIDEO_FORMATS_STR \
"{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, RGB, BGR, RGB16, BGR16, " \
"AYUV, I420, YV12, NV12, NV21, YUY2, UYVY, Y41B, Y42B, Y444, " \
"GRAY8, GRAY16_LE, GRAY16_BE }"
/**
* GstGLMemory:
@ -76,7 +64,7 @@ const gchar * gst_gl_texture_target_to_buffer_pool_option (GstGLTextureTarget ta
*/
struct _GstGLMemory
{
GstGLBaseBuffer mem;
GstGLBaseMemory mem;
guint tex_id;
GstGLTextureTarget tex_target;
@ -86,119 +74,82 @@ struct _GstGLMemory
guint plane;
gfloat tex_scaling[2];
/* <private> */
GstGLMemoryTransfer transfer_state;
/* <protected> */
gboolean texture_wrapped;
GDestroyNotify notify;
gpointer user_data;
guint unpack_length;
guint tex_width;
};
#define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory"
#define GST_GL_MEMORY_VIDEO_FORMATS_STR \
"{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, RGB, BGR, RGB16, BGR16, " \
"AYUV, I420, YV12, NV12, NV21, YUY2, UYVY, Y41B, Y42B, Y444, " \
"GRAY8, GRAY16_LE, GRAY16_BE }"
/**
* GstGLMemoryAllocator
*
* Opaque #GstGLMemoryAllocator struct
*/
struct _GstGLMemoryAllocator
{
GstGLBaseMemoryAllocator parent;
};
/**
* GST_GL_MEMORY_ALLOCATOR:
* GstGLMemoryAllocatorClass:
*
* The #GstGLMemoryAllocatorClass only contains private data
*/
struct _GstGLMemoryAllocatorClass
{
GstGLBaseMemoryAllocatorClass parent_class;
GstGLBaseMemoryAllocatorMapFunction map;
GstGLBaseMemoryAllocatorCopyFunction copy;
GstGLBaseMemoryAllocatorUnmapFunction unmap;
};
#include <gst/gl/gstglbasememory.h>
/**
* GST_GL_MEMORY_ALLOCATOR_NAME:
*
* The name of the GL memory allocator
*/
#define GST_GL_MEMORY_ALLOCATOR "GLMemory"
#define GST_GL_MEMORY_ALLOCATOR_NAME "GLMemory"
void gst_gl_memory_init (void);
void gst_gl_memory_init_once (void);
gboolean gst_is_gl_memory (GstMemory * mem);
GstMemory * gst_gl_memory_alloc (GstGLContext * context,
void gst_gl_memory_init (GstGLMemory * mem,
GstAllocator * allocator,
GstMemory * parent,
GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams *params,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign);
GstGLMemory * gst_gl_memory_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer data,
gpointer user_data,
GDestroyNotify notify);
GstGLMemory * gst_gl_memory_wrapped_texture (GstGLContext * context,
guint texture_id,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer user_data,
GDestroyNotify notify);
GDestroyNotify notify,
gpointer user_data);
void gst_gl_memory_download_transfer (GstGLMemory * gl_mem);
void gst_gl_memory_upload_transfer (GstGLMemory * gl_mem);
gboolean gst_gl_memory_copy_into_texture (GstGLMemory *gl_mem,
gboolean gst_gl_memory_copy_into (GstGLMemory *gl_mem,
guint tex_id,
GstGLTextureTarget target,
GstVideoGLTextureType tex_type,
gint width,
gint height,
gint stride,
gboolean respecify);
gint height);
gboolean gst_gl_memory_copy_teximage (GstGLMemory * src,
guint tex_id,
GstGLTextureTarget out_target,
GstVideoGLTextureType out_tex_type,
gint width,
gint height);
gboolean gst_gl_memory_setup_buffer (GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams * params,
GstVideoInfo * info,
GstVideoAlignment *valign,
GstBuffer * buffer);
gboolean gst_gl_memory_setup_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
GstVideoAlignment *valign,
gpointer data[GST_VIDEO_MAX_PLANES],
GstGLMemory *textures[GST_VIDEO_MAX_PLANES],
gpointer user_data,
GDestroyNotify notify);
gboolean gst_gl_memory_read_pixels (GstGLMemory * gl_mem,
gpointer read_pointer);
/* accessors */
gint gst_gl_memory_get_texture_width (GstGLMemory * gl_mem);
gint gst_gl_memory_get_texture_height (GstGLMemory * gl_mem);
/* utility functions */
GstVideoGLTextureType gst_gl_texture_type_from_format (GstGLContext *context,
GstVideoFormat v_format,
guint plane);
guint gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format);
guint gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
guint format,
guint type);
const gchar * gst_gl_texture_target_to_string (GstGLTextureTarget target);
GstGLTextureTarget gst_gl_texture_target_from_string (const gchar * str);
GstGLTextureTarget gst_gl_texture_target_from_gl (guint target);
guint gst_gl_texture_target_to_gl (GstGLTextureTarget target);
/**
* GstGLAllocator
*
* Opaque #GstGLAllocator struct
*/
struct _GstGLAllocator
{
GstGLBaseBufferAllocator parent;
GstMemoryCopyFunction fallback_mem_copy;
};
/**
* GstGLAllocatorClass:
*
* The #GstGLAllocatorClass only contains private data
*/
struct _GstGLAllocatorClass
{
GstGLBaseBufferAllocatorClass parent_class;
};
GstVideoGLTextureType gst_gl_memory_get_texture_type (GstGLMemory * gl_mem);
GstGLTextureTarget gst_gl_memory_get_texture_target (GstGLMemory * gl_mem);
guint gst_gl_memory_get_texture_id (GstGLMemory * gl_mem);
G_END_DECLS

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,139 @@
/*
* GStreamer
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
* Copyright (C) 2015 Matthew Waters <matthew@centricular.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_MEMORY_PBO_H_
#define _GST_GL_MEMORY_PBO_H_
#include <gst/gst.h>
#include <gst/gstallocator.h>
#include <gst/gstmemory.h>
#include <gst/video/video.h>
#include <gst/gl/gstglmemory.h>
G_BEGIN_DECLS
#define GST_TYPE_GL_MEMORY_PBO_ALLOCATOR (gst_gl_memory_pbo_allocator_get_type())
GType gst_gl_memory_pbo_allocator_get_type(void);
#define GST_IS_GL_MEMORY_PBO_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_MEMORY_PBO_ALLOCATOR))
#define GST_IS_GL_MEMORY_PBO_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_MEMORY_PBO_ALLOCATOR))
#define GST_GL_MEMORY_PBO_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_MEMORY_PBO_ALLOCATOR, GstGLMemoryPBOAllocatorClass))
#define GST_GL_MEMORY_PBO_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_MEMORY_PBO_ALLOCATOR, GstGLMemoryPBOAllocator))
#define GST_GL_MEMORY_PBO_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_MEMORY_PBO_ALLOCATOR, GstGLAllocatorClass))
#define GST_GL_MEMORY_PBO_ALLOCATOR_CAST(obj) ((GstGLMemoryPBOAllocator *)(obj))
/**
* GstGLMemoryPBO:
*
* Private instance
*/
struct _GstGLMemoryPBO
{
GstGLMemory mem;
/* <private> */
GstGLBuffer *pbo;
};
/**
* GST_GL_MEMORY_PBO_ALLOCATOR:
*
* The name of the GL Memory PBO allocator
*/
#define GST_GL_MEMORY_PBO_ALLOCATOR_NAME "GLMemoryPBO"
void gst_gl_memory_pbo_init_once (void);
gboolean gst_is_gl_memory_pbo (GstMemory * mem);
GstMemory * gst_gl_memory_pbo_alloc (GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams *params,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign);
GstGLMemoryPBO * gst_gl_memory_pbo_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer data,
gpointer user_data,
GDestroyNotify notify);
GstGLMemoryPBO * gst_gl_memory_pbo_wrapped_texture (GstGLContext * context,
guint texture_id,
GstGLTextureTarget target,
GstVideoInfo * info,
guint plane,
GstVideoAlignment *valign,
gpointer user_data,
GDestroyNotify notify);
void gst_gl_memory_pbo_download_transfer (GstGLMemoryPBO * gl_mem);
void gst_gl_memory_pbo_upload_transfer (GstGLMemoryPBO * gl_mem);
gboolean gst_gl_memory_pbo_copy_into_texture (GstGLMemoryPBO *gl_mem,
guint tex_id,
GstGLTextureTarget target,
GstVideoGLTextureType tex_type,
gint width,
gint height,
gint stride,
gboolean respecify);
gboolean gst_gl_memory_pbo_setup_buffer (GstGLContext * context,
GstGLTextureTarget target,
GstAllocationParams * params,
GstVideoInfo * info,
GstVideoAlignment *valign,
GstBuffer * buffer);
gboolean gst_gl_memory_pbo_setup_wrapped (GstGLContext * context,
GstGLTextureTarget target,
GstVideoInfo * info,
GstVideoAlignment *valign,
gpointer data[GST_VIDEO_MAX_PLANES],
GstGLMemoryPBO *textures[GST_VIDEO_MAX_PLANES],
gpointer user_data,
GDestroyNotify notify);
/**
* GstGLAllocator
*
* Opaque #GstGLAllocator struct
*/
struct _GstGLMemoryPBOAllocator
{
GstGLMemoryAllocator parent;
};
/**
* GstGLAllocatorClass:
*
* The #GstGLAllocatorClass only contains private data
*/
struct _GstGLMemoryPBOAllocatorClass
{
GstGLMemoryAllocatorClass parent_class;
};
G_END_DECLS
#endif /* _GST_GL_MEMORY_PBO_H_ */

View file

@ -347,9 +347,9 @@ gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
gst_gl_composition_overlay_add_transformation (overlay, buf);
comp_gl_memory =
gst_gl_memory_wrapped (overlay->context, GST_GL_TEXTURE_TARGET_2D,
&comp_frame->info, 0, NULL, comp_frame->data[0], comp_frame,
_video_frame_unmap_and_free);
(GstGLMemory *) gst_gl_memory_pbo_wrapped (overlay->context,
GST_GL_TEXTURE_TARGET_2D, &comp_frame->info, 0, NULL,
comp_frame->data[0], comp_frame, _video_frame_unmap_and_free);
overlay_buffer = gst_buffer_new ();
gst_buffer_append_memory (overlay_buffer, (GstMemory *) comp_gl_memory);

View file

@ -223,7 +223,7 @@ _gl_memory_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
GstAllocationParams params;
gst_allocation_params_init (&params);
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR_NAME);
gst_query_add_allocation_param (query, allocator, &params);
gst_object_unref (allocator);
}
@ -308,7 +308,8 @@ _gl_memory_upload_perform (gpointer impl, GstBuffer * buffer,
gl_mem->mem.context))
return GST_GL_UPLOAD_UNSHARED_GL_CONTEXT;
gst_gl_memory_upload_transfer (gl_mem);
if (gst_is_gl_memory_pbo (mem))
gst_gl_memory_pbo_upload_transfer ((GstGLMemoryPBO *) mem);
}
*outbuf = gst_buffer_ref (buffer);
@ -460,8 +461,9 @@ _egl_image_upload_perform_gl_thread (GstGLContext * context,
/* FIXME: buffer pool */
*image->outbuf = gst_buffer_new ();
gst_gl_memory_setup_buffer (image->upload->context, GST_GL_TEXTURE_TARGET_2D,
NULL, &image->upload->priv->out_info, NULL, *image->outbuf);
gst_gl_memory_pbo_setup_buffer (image->upload->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &image->upload->priv->out_info, NULL,
*image->outbuf);
n = gst_buffer_n_memory (image->buffer);
for (i = 0; i < n; i++) {
@ -479,8 +481,8 @@ _egl_image_upload_perform_gl_thread (GstGLContext * context,
}
if (GST_IS_GL_BUFFER_POOL (image->buffer->pool))
gst_gl_buffer_pool_replace_last_buffer (GST_GL_BUFFER_POOL (image->buffer->
pool), image->buffer);
gst_gl_buffer_pool_replace_last_buffer (GST_GL_BUFFER_POOL (image->
buffer->pool), image->buffer);
}
static GstGLUploadReturn
@ -621,11 +623,11 @@ _upload_meta_upload_propose_allocation (gpointer impl, GstQuery * decide_query,
gpointer handle;
gl_apis =
gst_gl_api_to_string (gst_gl_context_get_gl_api (upload->
upload->context));
gst_gl_api_to_string (gst_gl_context_get_gl_api (upload->upload->
context));
platform =
gst_gl_platform_to_string (gst_gl_context_get_gl_platform
(upload->upload->context));
gst_gl_platform_to_string (gst_gl_context_get_gl_platform (upload->
upload->context));
handle = (gpointer) gst_gl_context_get_gl_context (upload->upload->context);
gl_context =
@ -677,8 +679,9 @@ _upload_meta_upload_perform (gpointer impl, GstBuffer * buffer,
/* FIXME: buffer pool */
*outbuf = gst_buffer_new ();
gst_gl_memory_setup_buffer (upload->upload->context, GST_GL_TEXTURE_TARGET_2D,
NULL, &upload->upload->priv->in_info, NULL, *outbuf);
gst_gl_memory_pbo_setup_buffer (upload->upload->context,
GST_GL_TEXTURE_TARGET_2D, NULL, &upload->upload->priv->in_info, NULL,
*outbuf);
for (i = 0; i < GST_GL_UPLOAD_MAX_PLANES; i++) {
guint tex_id = 0;
@ -872,9 +875,10 @@ _raw_data_upload_perform (gpointer impl, GstBuffer * buffer,
GST_VIDEO_MULTIVIEW_MODE_SEPARATED)
max_planes *= GST_VIDEO_INFO_VIEWS (in_info);
gst_gl_memory_setup_wrapped (raw->upload->context, GST_GL_TEXTURE_TARGET_2D,
&raw->upload->priv->in_info, NULL, raw->in_frame->frame.data, in_tex,
raw->in_frame, (GDestroyNotify) _raw_upload_frame_unref);
gst_gl_memory_pbo_setup_wrapped (raw->upload->context,
GST_GL_TEXTURE_TARGET_2D, &raw->upload->priv->in_info, NULL,
raw->in_frame->frame.data, (GstGLMemoryPBO **) in_tex, raw->in_frame,
(GDestroyNotify) _raw_upload_frame_unref);
/* FIXME Use a buffer pool to cache the generated textures */
*outbuf = gst_buffer_new ();

View file

@ -1892,7 +1892,7 @@ static gboolean
_gen_buffer (GstGLViewConvert * viewconvert, GstBuffer ** target)
{
*target = gst_buffer_new ();
if (!gst_gl_memory_setup_buffer (viewconvert->context,
if (!gst_gl_memory_pbo_setup_buffer (viewconvert->context,
viewconvert->to_texture_target, NULL, &viewconvert->out_info, NULL,
*target)) {
return FALSE;
@ -2017,7 +2017,7 @@ _do_view_convert (GstGLContext * context, GstGLViewConvert * viewconvert)
* the attachments i.e. the smallest attachment size */
if (!priv->out_tex[j])
priv->out_tex[j] =
(GstGLMemory *) gst_gl_memory_alloc (context,
(GstGLMemory *) gst_gl_memory_pbo_alloc (context,
viewconvert->to_texture_target, NULL, &temp_info, 0, NULL);
} else {
priv->out_tex[j] = out_tex;
@ -2069,10 +2069,8 @@ out:
res = FALSE;
continue;
}
gst_gl_memory_copy_into_texture (priv->out_tex[j],
out_tex->tex_id, viewconvert->to_texture_target, out_tex->tex_type,
width, height,
GST_VIDEO_INFO_PLANE_STRIDE (&out_tex->info, out_tex->plane), FALSE);
gst_gl_memory_copy_into (priv->out_tex[j], out_tex->tex_id,
viewconvert->to_texture_target, out_tex->tex_type, width, height);
gst_memory_unmap ((GstMemory *) out_tex, &to_info);
}

View file

@ -39,7 +39,7 @@ setup (void)
display = gst_gl_display_new ();
context = gst_gl_context_new (display);
gst_gl_context_create (context, 0, NULL);
gst_gl_memory_init ();
gst_gl_memory_init_once ();
}
static void
@ -60,7 +60,7 @@ GST_START_TEST (test_basic)
GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_I420
};
gl_allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
fail_if (gl_allocator == NULL);
/* test allocator creation */
@ -74,8 +74,8 @@ GST_START_TEST (test_basic)
for (j = 0; j < GST_VIDEO_INFO_N_PLANES (&v_info); j++) {
mem =
gst_gl_memory_alloc (context, GST_GL_TEXTURE_TARGET_2D, NULL, &v_info,
j, NULL);
gst_gl_memory_pbo_alloc (context, GST_GL_TEXTURE_TARGET_2D, NULL,
&v_info, j, NULL);
fail_if (mem == NULL);
gl_mem = (GstGLMemory *) mem;
@ -120,47 +120,47 @@ GST_START_TEST (test_transfer)
GstMemory *mem, *mem2, *mem3;
GstMapInfo map_info;
gl_allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
fail_if (gl_allocator == NULL);
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 1, 1);
/* texture creation */
mem =
(GstMemory *) gst_gl_memory_alloc (context, GST_GL_TEXTURE_TARGET_2D,
(GstMemory *) gst_gl_memory_pbo_alloc (context, GST_GL_TEXTURE_TARGET_2D,
NULL, &v_info, 0, NULL);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* test wrapping raw data */
mem2 =
(GstMemory *) gst_gl_memory_wrapped (context, GST_GL_TEXTURE_TARGET_2D,
&v_info, 0, NULL, rgba_pixel, NULL, NULL);
(GstMemory *) gst_gl_memory_pbo_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL, rgba_pixel, NULL, NULL);
fail_if (mem == NULL);
fail_unless (GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* wrapped texture creation */
mem3 = (GstMemory *) gst_gl_memory_wrapped_texture (context,
mem3 = (GstMemory *) gst_gl_memory_pbo_wrapped_texture (context,
((GstGLMemory *) mem)->tex_id, GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL,
NULL, NULL);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* check data/flags are correct */
fail_unless (gst_memory_map (mem2, &map_info, GST_MAP_READ));
fail_unless (GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
fail_unless (((gchar *) map_info.data)[0] == rgba_pixel[0]);
fail_unless (((gchar *) map_info.data)[1] == rgba_pixel[1]);
@ -170,32 +170,31 @@ GST_START_TEST (test_transfer)
gst_memory_unmap (mem2, &map_info);
fail_unless (GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
fail_unless (gst_memory_map (mem2, &map_info, GST_MAP_READ | GST_MAP_GL));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* test texture copy */
fail_unless (gst_gl_memory_copy_into_texture ((GstGLMemory *) mem2,
fail_unless (gst_gl_memory_copy_into ((GstGLMemory *) mem2,
((GstGLMemory *) mem)->tex_id, GST_GL_TEXTURE_TARGET_2D,
GST_VIDEO_GL_TEXTURE_TYPE_RGBA, 1, 1, 4, FALSE));
GST_MINI_OBJECT_FLAG_SET (mem, GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD);
GST_GL_MEMORY_ADD_TRANSFER (mem, GST_GL_MEMORY_TRANSFER_NEED_DOWNLOAD);
GST_VIDEO_GL_TEXTURE_TYPE_RGBA, 1, 1));
GST_MINI_OBJECT_FLAG_SET (mem, GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem2,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
gst_memory_unmap (mem2, &map_info);
@ -213,9 +212,9 @@ GST_START_TEST (test_transfer)
fail_unless (gst_memory_map (mem3, &map_info, GST_MAP_READ));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
fail_unless (((gchar *) map_info.data)[0] == rgba_pixel[0]);
fail_unless (((gchar *) map_info.data)[1] == rgba_pixel[1]);
@ -229,18 +228,18 @@ GST_START_TEST (test_transfer)
gst_memory_unmap (mem3, &map_info);
fail_unless (GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
/* test download flag */
fail_unless (gst_memory_map (mem3, &map_info, GST_MAP_WRITE | GST_MAP_GL));
gst_memory_unmap (mem3, &map_info);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_UPLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD));
fail_unless (GST_MEMORY_FLAG_IS_SET (mem3,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
if (gst_gl_context_get_error ())
printf ("%s\n", gst_gl_context_get_error ());
@ -261,22 +260,22 @@ GST_START_TEST (test_separate_transfer)
GstMemory *mem;
GstMapInfo info;
gl_allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
gl_allocator = gst_allocator_find (GST_GL_MEMORY_PBO_ALLOCATOR_NAME);
fail_if (gl_allocator == NULL);
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 1, 1);
mem =
(GstMemory *) gst_gl_memory_wrapped (context, GST_GL_TEXTURE_TARGET_2D,
&v_info, 0, NULL, rgba_pixel, NULL, NULL);
(GstMemory *) gst_gl_memory_pbo_wrapped (context,
GST_GL_TEXTURE_TARGET_2D, &v_info, 0, NULL, rgba_pixel, NULL, NULL);
fail_if (mem == NULL);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
gst_gl_memory_upload_transfer ((GstGLMemory *) mem);
gst_gl_memory_pbo_upload_transfer ((GstGLMemoryPBO *) mem);
fail_unless (!GST_MEMORY_FLAG_IS_SET (mem,
GST_GL_BASE_BUFFER_FLAG_NEED_DOWNLOAD));
GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD));
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));