GstGLMemory: GStreamer Bad Plugins 1.0 Library Reference Manual

## GstGLMemory GstGLMemory — memory subclass for GL textures |

## Functions

void | gst_gl_video_allocation_params_copy_data ()
void | gst_gl_video_allocation_params_free_data ()
gboolean | gst_gl_video_allocation_params_init_full ()
GstGLVideoAllocationParams * | gst_gl_video_allocation_params_new ()
GstGLVideoAllocationParams * | gst_gl_video_allocation_params_new_wrapped_data ()
GstGLVideoAllocationParams * | gst_gl_video_allocation_params_new_wrapped_gl_handle ()
GstGLVideoAllocationParams * | gst_gl_video_allocation_params_new_wrapped_texture ()
GstGLMemoryAllocator * | gst_gl_memory_allocator_get_default ()
void | gst_gl_memory_init_once ()
void | gst_gl_memory_init ()
gboolean | gst_is_gl_memory ()
gboolean | gst_gl_memory_copy_into ()
gboolean | gst_gl_memory_copy_teximage ()
gboolean | gst_gl_memory_read_pixels ()
void | gst_gl_memory_texsubimage ()
gint | gst_gl_memory_get_texture_height ()
guint | gst_gl_memory_get_texture_id ()
GstGLTextureTarget | gst_gl_memory_get_texture_target ()
GstVideoGLTextureType | gst_gl_memory_get_texture_type ()
gint | gst_gl_memory_get_texture_width ()
gboolean | gst_gl_memory_setup_buffer ()

## Types and Values

#define | GST_GL_MEMORY_VIDEO_FORMATS_STR
struct | GstGLVideoAllocationParams
#define | GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO
| GstGLMemoryAllocator
| GstGLMemoryAllocatorClass
| GstGLMemory
#define | GST_GL_MEMORY_ALLOCATOR_NAME

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GstObject
                ╰── GstAllocator
                    ╰── GstGLBaseMemoryAllocator
                        ╰── GstGLMemoryAllocator
                            ╰── GstGLMemoryPBOAllocator

## Description

GstGLMemory is a GstGLBaseMemory subclass providing support for the mapping of OpenGL textures.

GstGLMemory is created or wrapped through `gst_gl_base_memory_alloc()` with GstGLVideoAllocationParams.

Data is uploaded or downloaded from the GPU as is necessary.

## Functions

### gst_gl_video_allocation_params_copy_data ()

    void
    gst_gl_video_allocation_params_copy_data
                                   (GstGLVideoAllocationParams *src_vid,
                                    GstGLVideoAllocationParams *dest_vid);

Copy and set any dynamically allocated resources in `dest_vid` . Intended for subclass usage only to chain up at the end of a subclass copy function.

#### Parameters

src_vid | source GstGLVideoAllocationParams to copy from |
dest_vid | destination GstGLVideoAllocationParams to copy into |

Since: 1.8

### gst_gl_video_allocation_params_free_data ()

    void
    gst_gl_video_allocation_params_free_data
                                   (GstGLVideoAllocationParams *params);

Unset and free any dynamically allocated resources. Intended for subclass usage only to chain up at the end of a subclass free function.

#### Parameters

params | a GstGLVideoAllocationParams |

Since: 1.8

### gst_gl_video_allocation_params_init_full ()

    gboolean
    gst_gl_video_allocation_params_init_full
                                   (GstGLVideoAllocationParams *params,
                                    gsize struct_size,
                                    guint alloc_flags,
                                    GstGLAllocationParamsCopyFunc copy,
                                    GstGLAllocationParamsFreeFunc free,
                                    GstGLContext *context,
                                    GstAllocationParams *alloc_params,
                                    GstVideoInfo *v_info,
                                    guint plane,
                                    GstVideoAlignment *valign,
                                    GstGLTextureTarget target,
                                    GstVideoGLTextureType tex_type,
                                    gpointer wrapped_data,
                                    gpointer gl_handle,
                                    gpointer user_data,
                                    GDestroyNotify notify);

Intended for subclass usage

#### Parameters

params | a GstGLVideoAllocationParams to initialize |
struct_size | the size of the struct in `params` |
alloc_flags | some allocation flags |
copy | a copy function |
free | a free function |
context | a GstGLContext |
alloc_params | the GstAllocationParams for `wrapped_data` . | [allow-none]
v_info | the GstVideoInfo for `wrapped_data` |
plane | the video plane `wrapped_data` represents |
valign | any GstVideoAlignment applied to symem mappings of `wrapped_data` . | [allow-none]
target | the GstGLTextureTarget |
tex_type | the GstVideoGLTextureType |
wrapped_data | the optional data pointer to wrap. | [allow-none]
gl_handle | the optional OpenGL handle to wrap or 0 |
user_data | user data to call `notify` with. | [allow-none]
notify | a GDestroyNotify. | [allow-none]

#### Returns

initializes `params` with the parameters specified

Since: 1.8

### gst_gl_video_allocation_params_new ()

    GstGLVideoAllocationParams *
    gst_gl_video_allocation_params_new (GstGLContext *context,
                                        GstAllocationParams *alloc_params,
                                        GstVideoInfo *v_info,
                                        guint plane,
                                        GstVideoAlignment *valign,
                                        GstGLTextureTarget target,
                                        GstVideoGLTextureType tex_type);

#### Parameters

context | a GstGLContext |
alloc_params | the GstAllocationParams for sysmem mappings of the texture. | [allow-none]
v_info | the GstVideoInfo for the texture |
plane | the video plane of `v_info` to allocate |
valign | any GstVideoAlignment applied to symem mappings of the texture. | [allow-none]
target | the GstGLTextureTarget for the created textures |
target | the GstVideoGLTextureType for the created textures |

#### Returns

a new GstGLVideoAllocationParams for allocating GstGLMemory's

Since: 1.8

### gst_gl_video_allocation_params_new_wrapped_data ()

    GstGLVideoAllocationParams *
    gst_gl_video_allocation_params_new_wrapped_data
                                   (GstGLContext *context,
                                    GstAllocationParams *alloc_params,
                                    GstVideoInfo *v_info,
                                    guint plane,
                                    GstVideoAlignment *valign,
                                    GstGLTextureTarget target,
                                    GstVideoGLTextureType tex_type,
                                    gpointer wrapped_data,
                                    gpointer user_data,
                                    GDestroyNotify notify);

#### Parameters

context | a GstGLContext |
alloc_params | the GstAllocationParams for `wrapped_data` . | [allow-none]
v_info | the GstVideoInfo for `wrapped_data` |
plane | the video plane `wrapped_data` represents |
valign | any GstVideoAlignment applied to symem mappings of `wrapped_data` . | [allow-none]
target | the GstGLTextureTarget for `wrapped_data` |
tex_type | the GstVideoGLTextureType for `wrapped_data` |
wrapped_data | the data pointer to wrap |
user_data | user data to call `notify` with. | [allow-none]
notify | a GDestroyNotify. | [allow-none]

#### Returns

a new GstGLVideoAllocationParams for wrapping `wrapped_data`

Since: 1.8

### gst_gl_video_allocation_params_new_wrapped_gl_handle ()

    GstGLVideoAllocationParams *
    gst_gl_video_allocation_params_new_wrapped_gl_handle
                                   (GstGLContext *context,
                                    GstAllocationParams *alloc_params,
                                    GstVideoInfo *v_info,
                                    guint plane,
                                    GstVideoAlignment *valign,
                                    GstGLTextureTarget target,
                                    GstVideoGLTextureType tex_type,
                                    gpointer gl_handle,
                                    gpointer user_data,
                                    GDestroyNotify notify);

`gl_handle` is defined by the specific OpenGL handle being wrapped For GstGLMemory and GstGLMemoryPBO it is an OpenGL texture id. Other memory types may define it to require a different type of parameter.

#### Parameters

context | a GstGLContext |
alloc_params | the GstAllocationParams for `tex_id` . | [allow-none]
v_info | the GstVideoInfo for `tex_id` |
plane | the video plane `tex_id` represents |
valign | any GstVideoAlignment applied to symem mappings of `tex_id` . | [allow-none]
target | the GstGLTextureTarget for `tex_id` |
tex_type | the GstVideoGLTextureType for `tex_id` |
gl_handle | the GL handle to wrap |
user_data | user data to call `notify` with. | [allow-none]
notify | a GDestroyNotify. | [allow-none]

#### Returns

a new GstGLVideoAllocationParams for wrapping `gl_handle`

Since: 1.8

### gst_gl_video_allocation_params_new_wrapped_texture ()

    GstGLVideoAllocationParams *
    gst_gl_video_allocation_params_new_wrapped_texture
                                   (GstGLContext *context,
                                    GstAllocationParams *alloc_params,
                                    GstVideoInfo *v_info,
                                    guint plane,
                                    GstVideoAlignment *valign,
                                    GstGLTextureTarget target,
                                    GstVideoGLTextureType tex_type,
                                    guint tex_id,
                                    gpointer user_data,
                                    GDestroyNotify notify);

#### Parameters

context | a GstGLContext |
alloc_params | the GstAllocationParams for `tex_id` . | [allow-none]
v_info | the GstVideoInfo for `tex_id` |
plane | the video plane `tex_id` represents |
valign | any GstVideoAlignment applied to symem mappings of `tex_id` . | [allow-none]
target | the GstGLTextureTarget for `tex_id` |
tex_type | the GstGLTextureType for `tex_id` |
tex_id | the GL texture to wrap |
user_data | user data to call `notify` with. | [allow-none]
notify | a GDestroyNotify. | [allow-none]

#### Returns

a new GstGLVideoAllocationParams for wrapping `tex_id`

Since: 1.8

### gst_gl_memory_allocator_get_default ()

    GstGLMemoryAllocator *
    gst_gl_memory_allocator_get_default (GstGLContext *context);

#### Parameters

context | a GstGLContext |

#### Returns

the default GstGLMemoryAllocator supported by `context`

Since: 1.8

### gst_gl_memory_init_once ()

    void
    gst_gl_memory_init_once (void);

Initializes the GL Base Texture allocator. It is safe to call this function multiple times. This must be called before any other GstGLMemory operation.

Since: 1.4

### gst_gl_memory_init ()

    void
    gst_gl_memory_init (GstGLMemory *mem,
                        GstAllocator *allocator,
                        GstMemory *parent,
                        GstGLContext *context,
                        GstGLTextureTarget target,
                        GstVideoGLTextureType tex_type,
                        GstAllocationParams *params,
                        GstVideoInfo *info,
                        guint plane,
                        GstVideoAlignment *valign,
                        gpointer user_data,
                        GDestroyNotify notify);

Initializes `mem` with the required parameters. `info` is assumed to have already have been modified with `gst_video_info_align()`.

#### Parameters

mem | the GstGLBaseMemory to initialize |
allocator | the GstAllocator to initialize with |
parent | the parent GstMemory to initialize with. | [allow-none]
context | the GstGLContext to initialize with |
target | the GstGLTextureTarget for this GstGLMemory |
params | the `GstAllocationParams` to initialize with. | [allow-none]
info | the GstVideoInfo for this GstGLMemory |
plane | the plane number (starting from 0) for this GstGLMemory |
valign | optional GstVideoAlignment parameters. | [allow-none]
notify | a GDestroyNotify. | [allow-none]
user_data | user data to call `notify` with. | [allow-none]

Since: 1.8

### gst_is_gl_memory ()

    gboolean
    gst_is_gl_memory (GstMemory *mem);

#### Parameters

mem | a GstMemory |

#### Returns

whether the memory at `mem` is a GstGLMemory

Since: 1.4

### gst_gl_memory_copy_into ()

    gboolean
    gst_gl_memory_copy_into (GstGLMemory *gl_mem,
                             guint tex_id,
                             GstGLTextureTarget target,
                             GstVideoGLTextureType tex_type,
                             gint width,
                             gint height);

Copies `gl_mem` into the texture specfified by `tex_id` . The format of `tex_id` is specified by `tex_type` , `width` and `height` .

#### Parameters

gl_mem | a GstGLMemory |
tex_id | OpenGL texture id |
target | the GstGLTextureTarget |
tex_type | the GstVideoGLTextureType |
width | width of `tex_id` |
height | height of `tex_id` |

#### Returns

Whether the copy suceeded

Since: 1.8

### gst_gl_memory_copy_teximage ()

    gboolean
    gst_gl_memory_copy_teximage (GstGLMemory *src,
                                 guint tex_id,
                                 GstGLTextureTarget out_target,
                                 GstVideoGLTextureType out_tex_type,
                                 gint width,
                                 gint height);

### gst_gl_memory_read_pixels ()

    gboolean
    gst_gl_memory_read_pixels (GstGLMemory *gl_mem,
                               gpointer read_pointer);

Reads the texture in GstGLMemory into `read_pointer` if no buffer is bound to `GL_PIXEL_PACK_BUFFER`. Otherwise `read_pointer` is the byte offset into the currently bound `GL_PIXEL_PACK_BUFFER` buffer to store the result of glReadPixels. See the OpenGL specification for glReadPixels for more details.

#### Parameters

gl_mem | a GstGLMemory |
read_pointer | the data pointer to pass to glReadPixels |

#### Returns

whether theread operation succeeded

Since: 1.8

### gst_gl_memory_texsubimage ()

    void
    gst_gl_memory_texsubimage (GstGLMemory *gl_mem,
                               gpointer read_pointer);

See `gst_gl_memory_read_pixels()` for what `read_pointer` signifies.

#### Parameters

gl_mem | a GstGLMemory |
read_pointer | the data pointer to pass to glTexSubImage |

Since: 1.8

### gst_gl_memory_get_texture_height ()

    gint
    gst_gl_memory_get_texture_height (GstGLMemory *gl_mem);

#### Parameters

gl_mem | a GstGLMemory |

#### Returns

the texture height of `gl_mem`

Since: 1.8

### gst_gl_memory_get_texture_id ()

    guint
    gst_gl_memory_get_texture_id (GstGLMemory *gl_mem);

#### Parameters

gl_mem | a GstGLMemory |

#### Returns

the OpenGL texture handle of `gl_mem`

Since: 1.8

### gst_gl_memory_get_texture_target ()

    GstGLTextureTarget
    gst_gl_memory_get_texture_target (GstGLMemory *gl_mem);

#### Parameters

gl_mem | a GstGLMemory |

#### Returns

the GstGLTextureTarget of `gl_mem`

Since: 1.8

### gst_gl_memory_get_texture_type ()

    GstVideoGLTextureType
    gst_gl_memory_get_texture_type (GstGLMemory *gl_mem);

#### Parameters

gl_mem | a GstGLMemory |

#### Returns

the GstVideoGLTextureType of `gl_mem`

Since: 1.8

### gst_gl_memory_get_texture_width ()

    gint
    gst_gl_memory_get_texture_width (GstGLMemory *gl_mem);

#### Parameters

gl_mem | a GstGLMemory |

#### Returns

the texture width of `gl_mem`

Since: 1.8

### gst_gl_memory_setup_buffer ()

    gboolean
    gst_gl_memory_setup_buffer (GstGLMemoryAllocator *allocator,
                                GstBuffer *buffer,
                                GstGLVideoAllocationParams *params,
                                GstVideoGLTextureType *tex_types,
                                gpointer *wrapped_data,
                                gsize n_wrapped_pointers);

#### Parameters

allocator | the `GstGLMemoryAllocator` to allocate from |
buffer | a GstBuffer to setup |
params | the GstGLVideoAllocationParams to allocate with |
tex_types | a list of GstVideoGLTextureType's to allocate with. | [allow-none]

#### Returns

whether the buffer was correctly setup

Since: 1.8

## Types and Values

### GST_GL_MEMORY_VIDEO_FORMATS_STR

    #define             GST_GL_MEMORY_VIDEO_FORMATS_STR

### struct GstGLVideoAllocationParams

    struct GstGLVideoAllocationParams {
      GstGLAllocationParams  parent;

      GstVideoInfo          *v_info;
      guint                  plane;
      GstVideoAlignment     *valign;
      GstGLTextureTarget     target;
      GstVideoGLTextureType  tex_type;
    };

### GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO

    #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO (1 << 3)

### GstGLMemoryAllocator

    typedef struct _GstGLMemoryAllocator GstGLMemoryAllocator;

Opaque GstGLMemoryAllocator struct

### GstGLMemoryAllocatorClass

    typedef struct {
      GstGLBaseMemoryAllocatorClass             parent_class;

      GstGLBaseMemoryAllocatorMapFunction       map;
      GstGLBaseMemoryAllocatorCopyFunction      copy;
      GstGLBaseMemoryAllocatorUnmapFunction     unmap;
    } GstGLMemoryAllocatorClass;

The GstGLMemoryAllocatorClass only contains private data

### GstGLMemory

    typedef struct {
      GstGLBaseMemory           mem;

      guint                     tex_id;
      GstGLTextureTarget        tex_target;
      GstVideoGLTextureType     tex_type;
      GstVideoInfo              info;
      GstVideoAlignment         valign;
      guint                     plane;
      gfloat                    tex_scaling[2];
    } GstGLMemory;

Represents information about a GL texture

#### Members

GstGLBaseMemory `mem`; | the parent object |
guint `tex_id`; | the GL texture id for this memory |
GstGLTextureTarget `tex_target`; | the GL texture target for this memory |
GstVideoGLTextureType `tex_type`; | the texture type |
GstVideoInfo `info`; | the texture's GstVideoInfo |
GstVideoAlignment `valign`; | data alignment for system memory mapping |
guint `plane`; | data plane in `info` |
gfloat `tex_scaling`[2]; | GL shader scaling parameters for `valign` and/or width/height |

### GST_GL_MEMORY_ALLOCATOR_NAME

    #define GST_GL_MEMORY_ALLOCATOR_NAME   "GLMemory"

The name of the GL memory allocator

## See Also

GstMemory, GstAllocator, GstGLBufferPool