gstreamer分配器与pool的那些事

1、pool

allocator和pool一同使用时,pool被设置为active时会根据pool配置的参数调用alloc方法。


/**
 * gst_buffer_pool_set_active:
 * @pool: a #GstBufferPool
 * @active: the new active state
 *
 * Control the active state of @pool. When the pool is inactive, new calls to
 * gst_buffer_pool_acquire_buffer() will return with %GST_FLOW_FLUSHING.
 *
 * Activating the bufferpool will preallocate all resources in the pool based on
 * the configuration of the pool.
 *
 * Deactivating will free the resources again when there are no outstanding
 * buffers. When there are outstanding buffers, they will be freed as soon as
 * they are all returned to the pool.
 *
 * Returns: %FALSE when the pool was not configured or when preallocation of the
 * buffers failed.
 */
gboolean
gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
{
  gboolean res = TRUE;
  GstBufferPoolPrivate *priv;

  g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);

  GST_LOG_OBJECT (pool, "active %d", active);

根据源码更进一步说明,alloc会被调用。

gst_buffer_pool_config_set_params(config, caps, size, min, max);

这里的size是单个buffer的大小.
min,max是指有多少个buffer。
min,max影响在buffer被使用多少次后free掉。

gboolean gst_buffer_map(GstBuffer *buffer, GstMapInfo *info, GstMapFlags flags);

如果info参数有效,效调用allocator的mem_map_full方法,相反,如果为NULL则调用mem_map方法。

2、allocator

allocator不是必须要注册表系统中。
使用

G_DEFINE_TYPE

定义在插件被加载时会自动调用init方法。
class_init中只需要一些必要的初始化,可以不加入系统中。

可以使用

gpointer g_object_new(GType object_type, const gchar *first_property_name, ...)

获取到之前初始化好的allocator并设置一些全局参数。

使用

gpointer g_object_new(GType object_type, const gchar *first_property_name, ...)

获取到allocator后需要调用

gpointer gst_object_ref_sink(gpointer object)

设置引用计数.

gst_allocator_alloc

GstMemory *gst_allocator_alloc(GstAllocator *allocator, gsize size, GstAllocationParams *params)

除allocator和params可以为NULL,size也可以设置为0.
这样可以规避alloc被调用,导致真实内存分配,在使用mmap时很有用。
当设备支持MMAP时,不需要实际的内存分配。只需在map时调用mmap对设备内存进行实际的mmap操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值