文章目录
- 前言
 - 一、gstreamer 默认的内存 alloctor
 - 
   
- 1. gstreamer 中默认的内存 allocator 为 GST_ALLOCATOR_SYSMEM (即SystemMemory)
 - 2. GST_ALLOCATOR_SYSMEM 申请内存实例
 
 - 二、gstreamer 目前支持的几种内存 alloctor
 - 
   
- 1.GstDmaBufAllocator
 - 
     
- 1.1 GstDmaBufAllocator 介绍
 - 1.2 GstDmaBufAllocator 相关函数接口介绍
 - 
       
- 1.2.1 gst_dmabuf_allocator_new
 - 1.2.2 gst_dmabuf_allocator_alloc
 - 1.2.3 gst_dmabuf_allocator_alloc_with_flags
 - 1.2.4 gst_dmabuf_memory_get_fd
 - 1.2.5 gst_is_dmabuf_memory
 
 - 1.3 使用 GST_ALLOCATOR_DMABUF 申请内存实例
 
 - 2.GstDRMDumbAllocator
 - 3.GstFdAllocator
 - 
     
- 3.1 GstFdAllocator介绍
 - 3.2 GstFdAllocator 相关函数接口介绍
 - 
       
- 3.2.1 gst_fd_allocator_new
 - 3.2.2 gst_fd_allocator_alloc
 - 3.2.3 gst_fd_memory_get_fd
 - 3.2.4 gst_is_fd_memory
 
 - 3.3 GstFdAllocator 内存申请实例
 
 - 4. GstPhysMemoryAllocator
 - 5. GstShmAllocator
 
 - 总结
 - 参考资料
 
前言
本文主要介绍 gstreamer 中目前支持的内存 allocator , 包括 gstreamer 默认的system 内存 alloctor ,以及一些其他的常用的内存 allocator
 软硬件环境:
 硬件:PC
 软件:Ubuntu22.04 gstreamer1.20.3
一、gstreamer 默认的内存 alloctor
1. gstreamer 中默认的内存 allocator 为 GST_ALLOCATOR_SYSMEM (即SystemMemory)
详细的介绍可以查看之前的文章《gstreamer 中 GstAllocator 介绍》
 GST_ALLOCATOR_SYSMEM 即 SystemMemory
 
2. GST_ALLOCATOR_SYSMEM 申请内存实例
如下所示,是使用gstreamer 默认的 内存 allocator(GST_ALLOCATOR_SYSMEM) 申请一块内存(大小为4096byte)的代码实例 galloctor_test.c
 gst_allocator_alloc() 函数第一个参数传NULL, 就是使用默认的内存 allocator(GST_ALLOCATOR_SYSMEM) 申请内存
#include <stdio.h>
#include <string.h>
#include <gst/gst.h>
int main(int argc, char *argv[])
{
   
    GstAllocator *alloc;
    GstMemory *mem;
    GstMapInfo map;
    gst_init(&argc, &argv);
	
	//申请 mem
    mem = gst_allocator_alloc(NULL, 4096, NULL);
	
	//映射内存
    if(gst_memory_map(mem, &map, GST_MAP_READWRITE)) {
   
        g_print("map.size = %ld\n", map.size);
		//写入数据
        memset(map.data, 0, map.size);
        g_print("map.data[0] = %d\n", map.data[0]);
    } else {
   
        g_printerr("gst_memory_map failed!\n");
    }
	//解除内存映射
    gst_memory_unmap(mem, &map);
	
	//释放内存
    gst_memory_unref(mem);
    return 0;
}
 
编译命令:
gcc galloctor_test.c -o galloctor_test `pkg-config --cflags --libs gstreamer-1.0`
 
执行结果:
 









![[含文档+PPT+源码等]精品大数据项目-基于python爬虫实现的大数据岗位的挖掘与分析](https://img-blog.csdnimg.cn/img_convert/bcd835087bdf6be5c5115e4af597adaa.png)









