bool gst_vlc_picture_plane_allocator_alloc( GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer ) { int i_plane; gsize i_max_size, i_align, i_offset, i_size; picture_t *p_pic; p_pic = &p_allocator->pic_info; for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ ) { GstVlcPicturePlane *p_mem = (GstVlcPicturePlane*) g_slice_new0( GstVlcPicturePlane ); i_size = p_pic->p[ i_plane ].i_pitch * p_pic->p[ i_plane ].i_lines; i_max_size = p_pic->p[ i_plane ].i_pitch * p_pic->p[ i_plane ].i_lines; i_align = 0; i_offset = 0; gst_memory_init( GST_MEMORY_CAST( p_mem ), GST_MEMORY_FLAG_NO_SHARE, GST_ALLOCATOR_CAST( p_allocator ), NULL, i_max_size, i_align, i_offset, i_size ); gst_buffer_append_memory( p_buffer, (GstMemory*) p_mem ); } return true; }
/** * gst_fd_allocator_alloc: * @allocator: allocator to be used for this memory * @fd: file descriptor * @size: memory size * @flags: extra #GstFdMemoryFlags * * Return a %GstMemory that wraps a generic file descriptor. * * Returns: (transfer full): a GstMemory based on @allocator. * When the buffer will be released the allocator will close the @fd. * The memory is only mmapped on gst_buffer_mmap() request. * * Since: 1.6 */ GstMemory * gst_fd_allocator_alloc (GstAllocator * allocator, gint fd, gsize size, GstFdMemoryFlags flags) { #ifdef HAVE_MMAP GstFdMemory *mem; g_return_val_if_fail (GST_IS_FD_ALLOCATOR (allocator), NULL); mem = g_slice_new0 (GstFdMemory); gst_memory_init (GST_MEMORY_CAST (mem), 0, GST_ALLOCATOR_CAST (allocator), NULL, size, 0, 0, size); mem->flags = flags; mem->fd = fd; g_mutex_init (&mem->lock); GST_DEBUG ("%p: fd: %d size %" G_GSIZE_FORMAT, mem, mem->fd, mem->mem.maxsize); return (GstMemory *) mem; #else /* !HAVE_MMAP */ return NULL; #endif }
static GstGLMemoryEGL * _gl_mem_egl_alloc (GstGLBaseMemoryAllocator * allocator, GstGLVideoAllocationParams * params) { guint alloc_flags = params->parent.alloc_flags; GstGLMemoryEGL *mem; g_return_val_if_fail (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_VIDEO, NULL); g_return_val_if_fail ((alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM) == 0, NULL); if (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) { g_return_val_if_fail (GST_IS_EGL_IMAGE (params->parent.gl_handle), NULL); } mem = g_new0 (GstGLMemoryEGL, 1); if (alloc_flags & GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE) { if (params->target != GST_GL_TEXTURE_TARGET_2D) { g_free (mem); GST_CAT_ERROR (GST_CAT_GL_MEMORY, "GstGLMemoryEGL only supports wrapping " "2D textures"); return NULL; } mem->image = gst_egl_image_ref (params->parent.gl_handle); } gst_gl_memory_init (GST_GL_MEMORY_CAST (mem), GST_ALLOCATOR_CAST (allocator), NULL, params->parent.context, params->target, params->tex_type, params->parent.alloc_params, params->v_info, params->plane, params->valign, params->parent.user_data, params->parent.notify); return mem; }
static void gst_ios_gl_memory_allocator_init (GstIOSGLMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_IOS_GL_MEMORY_ALLOCATOR_NAME; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
GstAllocator * gst_vaapi_video_allocator_new (GstVaapiDisplay * display, const GstVideoInfo * vip, guint flags) { GstVaapiVideoAllocator *allocator; g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (vip != NULL, NULL); allocator = g_object_new (GST_VAAPI_TYPE_VIDEO_ALLOCATOR, NULL); if (!allocator) return NULL; allocator->video_info = *vip; allocator_configure_surface_info (display, allocator); allocator->surface_pool = gst_vaapi_surface_pool_new_full (display, &allocator->surface_info, flags); if (!allocator->surface_pool) goto error_create_surface_pool; allocator_configure_image_info (display, allocator); allocator->image_pool = gst_vaapi_image_pool_new (display, &allocator->image_info); if (!allocator->image_pool) goto error_create_image_pool; gst_allocator_set_vaapi_video_info (GST_ALLOCATOR_CAST (allocator), &allocator->image_info, 0); return GST_ALLOCATOR_CAST (allocator); /* ERRORS */ error_create_surface_pool: { GST_ERROR ("failed to allocate VA surface pool"); gst_object_unref (allocator); return NULL; } error_create_image_pool: { GST_ERROR ("failed to allocate VA image pool"); gst_object_unref (allocator); return NULL; } }
static void gst_gl_buffer_allocator_init (GstGLBufferAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_GL_BUFFER_ALLOCATOR_NAME; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_gl_memory_pbo_allocator_init (GstGLMemoryPBOAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_GL_MEMORY_PBO_ALLOCATOR_NAME; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_wl_shm_allocator_init (GstWlShmAllocator * self) { GstAllocator *alloc = GST_ALLOCATOR_CAST (self); alloc->mem_type = GST_ALLOCATOR_WL_SHM; GST_OBJECT_FLAG_UNSET (self, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void my_memory_allocator_init (MyMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = "MyMemory"; alloc->mem_map = (GstMemoryMapFunction) _my_mem_map; alloc->mem_unmap = (GstMemoryUnmapFunction) _my_mem_unmap; alloc->mem_share = (GstMemoryShareFunction) _my_mem_share; }
static void gst_allocator_fast_malloc_init(GstAllocatorFastMalloc* allocator) { GstAllocator* baseAllocator = GST_ALLOCATOR_CAST(allocator); baseAllocator->mem_type = "FastMalloc"; baseAllocator->mem_map = reinterpret_cast<GstMemoryMapFunction>(gst_allocator_fast_malloc_mem_map); baseAllocator->mem_unmap = reinterpret_cast<GstMemoryUnmapFunction>(gst_allocator_fast_malloc_mem_unmap); baseAllocator->mem_copy = reinterpret_cast<GstMemoryCopyFunction>(gst_allocator_fast_malloc_mem_copy); baseAllocator->mem_share = reinterpret_cast<GstMemoryShareFunction>(gst_allocator_fast_malloc_mem_share); baseAllocator->mem_is_span = reinterpret_cast<GstMemoryIsSpanFunction>(gst_allocator_fast_malloc_mem_is_span); }
static void gst_msdk_system_allocator_init (GstMsdkSystemAllocator * allocator) { GstAllocator *const base_allocator = GST_ALLOCATOR_CAST (allocator); base_allocator->mem_type = GST_MSDK_SYSTEM_MEMORY_NAME; base_allocator->mem_map_full = gst_msdk_system_memory_map_full; base_allocator->mem_unmap = gst_msdk_system_memory_unmap; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void moz_gfx_memory_allocator_init (MozGfxMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = "moz-gfx-image"; alloc->mem_map = (GstMemoryMapFunction) moz_gfx_memory_map; alloc->mem_unmap = (GstMemoryUnmapFunction) moz_gfx_memory_unmap; alloc->mem_share = (GstMemoryShareFunction) moz_gfx_memory_share; /* fallback copy and is_span */ }
static void gst_vulkan_memory_allocator_init (GstVulkanMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_VULKAN_MEMORY_ALLOCATOR_NAME; alloc->mem_map_full = (GstMemoryMapFullFunction) _vk_mem_map_full; alloc->mem_unmap_full = (GstMemoryUnmapFullFunction) _vk_mem_unmap_full; alloc->mem_copy = (GstMemoryCopyFunction) _vk_mem_copy; alloc->mem_share = (GstMemoryShareFunction) _vk_mem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _vk_mem_is_span; }
static void gst_gl_base_buffer_allocator_init (GstGLBaseBufferAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_GL_MEMORY_ALLOCATOR; alloc->mem_map_full = (GstMemoryMapFullFunction) _mem_map_full; alloc->mem_unmap_full = (GstMemoryUnmapFullFunction) _mem_unmap_full; alloc->mem_copy = (GstMemoryCopyFunction) _mem_copy; alloc->mem_share = (GstMemoryShareFunction) _mem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _mem_is_span; }
static void gst_vdp_video_allocator_init (GstVdpVideoAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_VDP_VIDEO_MEMORY_ALLOCATOR; alloc->mem_map = (GstMemoryMapFunction) _vdp_video_mem_map; alloc->mem_unmap = (GstMemoryUnmapFunction) _vdp_video_mem_unmap; alloc->mem_copy = (GstMemoryCopyFunction) _vdp_video_mem_copy; alloc->mem_share = (GstMemoryShareFunction) _vdp_video_mem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _vdp_video_mem_is_span; }
static void ximage_memory_allocator_init (GstXImageMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_XIMAGE_ALLOCATOR_NAME; alloc->mem_map = (GstMemoryMapFunction) ximage_memory_map; alloc->mem_unmap = (GstMemoryUnmapFunction) ximage_memory_unmap; alloc->mem_share = (GstMemoryShareFunction) ximage_memory_share; /* fallback copy and is_span */ GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_vlc_picture_plane_allocator_init( GstVlcPicturePlaneAllocator *p_allocator ) { GstAllocator *p_alloc = GST_ALLOCATOR_CAST( p_allocator ); p_alloc->mem_type = GST_VLC_PICTURE_PLANE_ALLOCATOR_NAME; p_alloc->mem_map = (GstMemoryMapFunction) gst_vlc_picture_plane_map; p_alloc->mem_unmap = (GstMemoryUnmapFunction) gst_vlc_picture_plane_unmap; p_alloc->mem_copy = (GstMemoryShareFunction) gst_vlc_picture_plane_copy; /* fallback is_span */ GST_OBJECT_FLAG_SET( p_allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC ); }
static void gst_fd_allocator_init (GstFdAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_ALLOCATOR_FD; alloc->mem_map = gst_fd_mem_map; alloc->mem_unmap = gst_fd_mem_unmap; alloc->mem_share = gst_fd_mem_share; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_apple_core_video_allocator_init (GstAppleCoreVideoAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_APPLE_CORE_VIDEO_ALLOCATOR_NAME; alloc->mem_map = gst_apple_core_video_mem_map; alloc->mem_unmap = gst_apple_core_video_mem_unmap; alloc->mem_share = gst_apple_core_video_mem_share; alloc->mem_is_span = gst_apple_core_video_mem_is_span; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void dmabuf_mem_allocator_init (GstDmaBufAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = ALLOCATOR_NAME; alloc->mem_map = gst_dmabuf_mem_map; alloc->mem_unmap = gst_dmabuf_mem_unmap; alloc->mem_share = gst_dmabuf_mem_share; /* Use the default, fallback copy function */ GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
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 void gst_omx_memory_allocator_init (GstOMXMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_OMX_MEMORY_TYPE; alloc->mem_map = gst_omx_memory_map; alloc->mem_unmap = gst_omx_memory_unmap; alloc->mem_share = gst_omx_memory_share; /* default copy & is_span */ GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_mmal_opaque_allocator_init (GstMMALOpaqueAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_MMAL_OPAQUE_MEMORY_TYPE; alloc->mem_map = gst_mmal_opaque_mem_map; alloc->mem_unmap = gst_mmal_opaque_mem_unmap; alloc->mem_share = gst_mmal_opaque_mem_share; alloc->mem_copy = gst_mmal_opaque_mem_copy; alloc->mem_is_span = gst_mmal_opaque_mem_is_span; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static GstMemory * gst_shm_sink_allocator_alloc_locked (GstShmSinkAllocator * self, gsize size, GstAllocationParams * params) { GstMemory *memory = NULL; ShmBlock *block = NULL; gsize maxsize = size + params->prefix + params->padding; gsize align = params->align; /* ensure configured alignment */ align |= gst_memory_alignment; /* allocate more to compensate for alignment */ maxsize += align; block = sp_writer_alloc_block (self->sink->pipe, maxsize); if (block) { GstShmSinkMemory *mymem; gsize aoffset, padding; GST_LOG_OBJECT (self, "Allocated block %p with %" G_GSIZE_FORMAT " bytes at %p", block, size, sp_writer_block_get_buf (block)); mymem = g_slice_new0 (GstShmSinkMemory); memory = GST_MEMORY_CAST (mymem); mymem->data = sp_writer_block_get_buf (block); mymem->sink = gst_object_ref (self->sink); mymem->block = block; /* do alignment */ if ((aoffset = ((guintptr) mymem->data & align))) { aoffset = (align + 1) - aoffset; mymem->data += aoffset; maxsize -= aoffset; } if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED)) memset (mymem->data, 0, params->prefix); padding = maxsize - (params->prefix + size); if (padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED)) memset (mymem->data + params->prefix + size, 0, padding); gst_memory_init (memory, params->flags, GST_ALLOCATOR_CAST (g_object_ref (self)), NULL, maxsize, align, params->prefix, size); } return memory; }
static void gst_allocator_sysmem_init (GstAllocatorSysmem * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); GST_CAT_DEBUG (GST_CAT_MEMORY, "init allocator %p", allocator); alloc->mem_type = GST_ALLOCATOR_SYSMEM; alloc->mem_map = (GstMemoryMapFunction) _sysmem_map; alloc->mem_unmap = (GstMemoryUnmapFunction) _sysmem_unmap; alloc->mem_copy = (GstMemoryCopyFunction) _sysmem_copy; alloc->mem_share = (GstMemoryShareFunction) _sysmem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _sysmem_is_span; }
GstAllocator * gst_msdk_system_allocator_new (GstVideoInfo * image_info) { GstMsdkSystemAllocator *allocator; g_return_val_if_fail (image_info != NULL, NULL); allocator = g_object_new (GST_TYPE_MSDK_SYSTEM_ALLOCATOR, NULL); if (!allocator) return NULL; allocator->image_info = *image_info; return GST_ALLOCATOR_CAST (allocator); }
static void gst_gl_base_memory_allocator_init (GstGLBaseMemoryAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); /* Keep the fallback copy function around, we will need it when copying with * at an offset or smaller size */ allocator->fallback_mem_copy = alloc->mem_copy; alloc->mem_map_full = (GstMemoryMapFullFunction) _mem_map_full; alloc->mem_unmap_full = (GstMemoryUnmapFullFunction) _mem_unmap_full; alloc->mem_copy = (GstMemoryCopyFunction) _mem_copy; alloc->mem_share = (GstMemoryShareFunction) _mem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _mem_is_span; }
static void gst_v4l2_allocator_init (GstV4l2Allocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); alloc->mem_type = GST_V4L2_MEMORY_TYPE; alloc->mem_map = (GstMemoryMapFunction) _v4l2mem_map; alloc->mem_unmap = (GstMemoryUnmapFunction) _v4l2mem_unmap; alloc->mem_share = (GstMemoryShareFunction) _v4l2mem_share; alloc->mem_is_span = (GstMemoryIsSpanFunction) _v4l2mem_is_span; /* Use the default, fallback copy function */ allocator->free_queue = gst_atomic_queue_new (VIDEO_MAX_FRAME); GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }
static void gst_vaapi_video_allocator_init (GstVaapiVideoAllocator * allocator) { GstAllocator *const base_allocator = GST_ALLOCATOR_CAST (allocator); base_allocator->mem_type = GST_VAAPI_VIDEO_MEMORY_NAME; base_allocator->mem_map = (GstMemoryMapFunction) gst_vaapi_video_memory_map; base_allocator->mem_unmap = (GstMemoryUnmapFunction) gst_vaapi_video_memory_unmap; base_allocator->mem_copy = (GstMemoryCopyFunction) gst_vaapi_video_memory_copy; base_allocator->mem_share = (GstMemoryShareFunction) gst_vaapi_video_memory_share; base_allocator->mem_is_span = (GstMemoryIsSpanFunction) gst_vaapi_video_memory_is_span; }
static void droid_media_buffer_allocator_init (GstDroidMediaBufferAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); GST_DEBUG_OBJECT (alloc, "init"); alloc->mem_type = GST_ALLOCATOR_DROID_MEDIA_BUFFER; alloc->mem_map = gst_droid_media_buffer_memory_map; alloc->mem_unmap = gst_droid_media_buffer_memory_unmap; alloc->mem_copy = NULL; alloc->mem_share = NULL; alloc->mem_is_span = NULL; GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); }