Commit 3d76e601 authored by Wim Taymans's avatar Wim Taymans

query: also include padding in ALLOCATION query

Negotiating padding is needed on second thought so include it in the
ALLOCATION query.
Make the bufferpool take padding into account when allocating.
Make basesrc take padding into account.
Use padding and prefix when allocating in basetransform.
parent 72ac5f51
......@@ -70,6 +70,7 @@ struct _GstBufferPoolPrivate
guint min_buffers;
guint max_buffers;
guint prefix;
guint padding;
guint align;
};
......@@ -133,7 +134,7 @@ gst_buffer_pool_init (GstBufferPool * pool)
pool->priv->started = FALSE;
pool->priv->config =
gst_structure_new_id_empty (GST_QUARK (BUFFER_POOL_CONFIG));
gst_buffer_pool_config_set (pool->priv->config, NULL, 0, 0, 0, 0, 0);
gst_buffer_pool_config_set (pool->priv->config, NULL, 0, 0, 0, 0, 0, 0);
gst_poll_write_control (pool->priv->poll);
GST_DEBUG_OBJECT (pool, "created");
......@@ -184,7 +185,9 @@ default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
*buffer = gst_buffer_new ();
mem = gst_allocator_alloc (NULL, priv->size + priv->prefix, priv->align);
mem =
gst_allocator_alloc (NULL, priv->size + priv->prefix + priv->padding,
priv->align);
gst_memory_resize (mem, priv->prefix, priv->size);
gst_buffer_take_memory (*buffer, -1, mem);
......@@ -431,11 +434,11 @@ default_set_config (GstBufferPool * pool, GstStructure * config)
GstBufferPoolPrivate *priv = pool->priv;
const GstCaps *caps;
guint size, min_buffers, max_buffers;
guint prefix, align;
guint prefix, padding, align;
/* parse the config and keep around */
if (!gst_buffer_pool_config_get (config, &caps, &size, &min_buffers,
&max_buffers, &prefix, &align))
&max_buffers, &prefix, &padding, &align))
goto wrong_config;
GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
......@@ -444,6 +447,7 @@ default_set_config (GstBufferPool * pool, GstStructure * config)
priv->min_buffers = min_buffers;
priv->max_buffers = max_buffers;
priv->prefix = prefix;
priv->padding = padding;
priv->align = align;
return TRUE;
......@@ -621,17 +625,19 @@ gst_buffer_pool_has_option (GstBufferPool * pool, const gchar * option)
* gst_buffer_pool_config_set:
* @config: a #GstBufferPool configuration
* @caps: caps for the buffers
* @size: the size of each buffer, not including prefix
* @size: the size of each buffer, not including prefix and padding
* @min_buffers: the minimum amount of buffers to allocate.
* @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
* @prefix: prefix each buffer with this many bytes
* @padding: pad each buffer with this many bytes
* @align: alignment of the buffer data.
*
* Configure @config with the given parameters.
*/
void
gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
guint size, guint min_buffers, guint max_buffers, guint prefix, guint align)
guint size, guint min_buffers, guint max_buffers, guint prefix,
guint padding, guint align)
{
g_return_if_fail (config != NULL);
......@@ -641,6 +647,7 @@ gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
GST_QUARK (PADDING), G_TYPE_UINT, padding,
GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
}
......@@ -772,10 +779,11 @@ gst_buffer_pool_config_has_option (GstStructure * config, const gchar * option)
* gst_buffer_pool_config_get:
* @config: (transfer none): a #GstBufferPool configuration
* @caps: (out): the caps of buffers
* @size: (out): the size of each buffer, not including prefix
* @size: (out): the size of each buffer, not including prefix and padding
* @min_buffers: (out): the minimum amount of buffers to allocate.
* @max_buffers: (out): the maximum amount of buffers to allocate or 0 for unlimited.
* @prefix: (out): prefix each buffer with this many bytes
* @padding: (out): pad each buffer with this many bytes
* @align: (out): alignment of the buffer data.
*
* Get the configuration values from @config.
......@@ -783,7 +791,7 @@ gst_buffer_pool_config_has_option (GstStructure * config, const gchar * option)
gboolean
gst_buffer_pool_config_get (GstStructure * config, const GstCaps ** caps,
guint * size, guint * min_buffers, guint * max_buffers, guint * prefix,
guint * align)
guint * padding, guint * align)
{
g_return_val_if_fail (config != NULL, FALSE);
......@@ -793,6 +801,7 @@ gst_buffer_pool_config_get (GstStructure * config, const GstCaps ** caps,
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
GST_QUARK (PADDING), G_TYPE_UINT, padding,
GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
}
......
......@@ -128,7 +128,7 @@ struct _GstBufferPool {
* be released when there are no buffers available.
* @alloc_buffer: allocate a buffer. the default implementation allocates
* buffers from the default memory allocator and with the configured
* size, prefix and alignment. All metadata that is present on the
* size, prefix, padding and alignment. All metadata that is present on the
* allocated buffer will be marked as #GST_META_FLAG_POOLED and will not
* be removed from the buffer in @reset_buffer.
* @reset_buffer: reset the buffer to its state when it was freshly allocated.
......@@ -182,10 +182,10 @@ gboolean gst_buffer_pool_has_option (GstBufferPool *pool, const gch
/* helpers for configuring the config structure */
void gst_buffer_pool_config_set (GstStructure *config, const GstCaps *caps,
guint size, guint min_buffers, guint max_buffers,
guint prefix, guint align);
guint prefix, guint padding, guint align);
gboolean gst_buffer_pool_config_get (GstStructure *config, const GstCaps **caps,
guint *size, guint *min_buffers, guint *max_buffers,
guint *prefix, guint *align);
guint *prefix, guint *padding, guint *align);
/* options */
guint gst_buffer_pool_config_n_options (GstStructure *config);
......
......@@ -51,7 +51,7 @@ static const gchar *_quark_strings[] = {
"message", "GstMessageQOS", "running-time", "stream-time", "jitter",
"quality", "processed", "dropped", "buffering-ranges", "GstMessageProgress",
"code", "text", "percent", "timeout", "GstBufferPoolConfig", "caps", "size",
"min-buffers", "max-buffers", "prefix", "postfix", "align", "time",
"min-buffers", "max-buffers", "prefix", "padding", "align", "time",
"GstQueryAllocation", "need-pool", "meta", "pool", "GstEventCaps",
"GstEventReconfigure", "segment", "GstQueryScheduling", "pull-mode",
"allocator", "GstEventFlushStop", "options", "GstQueryAcceptCaps",
......
......@@ -138,7 +138,7 @@ typedef enum _GstQuarkId
GST_QUARK_MIN_BUFFERS = 109,
GST_QUARK_MAX_BUFFERS = 110,
GST_QUARK_PREFIX = 111,
GST_QUARK_POSTFIX = 112,
GST_QUARK_PADDING = 112,
GST_QUARK_ALIGN = 113,
GST_QUARK_TIME = 114,
GST_QUARK_QUERY_ALLOCATION = 115,
......
......@@ -1484,6 +1484,7 @@ gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
GST_QUARK (PREFIX), G_TYPE_UINT, 0,
GST_QUARK (PADDING), G_TYPE_UINT, 0,
GST_QUARK (ALIGN), G_TYPE_UINT, 0,
GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
......@@ -1523,6 +1524,7 @@ gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
* @min_buffers: the min buffers
* @max_buffers: the max buffers
* @prefix: the prefix
* @padding: the padding
* @alignment: the alignment
* @pool: the #GstBufferPool
*
......@@ -1530,7 +1532,7 @@ gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
*/
void
gst_query_set_allocation_params (GstQuery * query, guint size,
guint min_buffers, guint max_buffers, guint prefix,
guint min_buffers, guint max_buffers, guint prefix, guint padding,
guint alignment, GstBufferPool * pool)
{
GstStructure *structure;
......@@ -1546,6 +1548,7 @@ gst_query_set_allocation_params (GstQuery * query, guint size,
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
GST_QUARK (PADDING), G_TYPE_UINT, padding,
GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
}
......@@ -1557,6 +1560,7 @@ gst_query_set_allocation_params (GstQuery * query, guint size,
* @min_buffers: (out) (allow-none): the min buffers
* @max_buffers: (out) (allow-none): the max buffers
* @prefix: (out) (allow-none): the prefix
* @padding: (out) (allow-none): the padding
* @alignment: (out) (allow-none): the alignment
* @pool: (out) (allow-none) (transfer full): the #GstBufferPool
*
......@@ -1565,7 +1569,7 @@ gst_query_set_allocation_params (GstQuery * query, guint size,
void
gst_query_parse_allocation_params (GstQuery * query, guint * size,
guint * min_buffers, guint * max_buffers, guint * prefix,
guint * alignment, GstBufferPool ** pool)
guint * padding, guint * alignment, GstBufferPool ** pool)
{
GstStructure *structure;
......@@ -1577,6 +1581,7 @@ gst_query_parse_allocation_params (GstQuery * query, guint * size,
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
GST_QUARK (PADDING), G_TYPE_UINT, padding,
GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
}
......
......@@ -402,11 +402,11 @@ GstQuery * gst_query_new_allocation (GstCaps *caps, gboolean need_
void gst_query_parse_allocation (GstQuery *query, GstCaps **caps, gboolean *need_pool);
void gst_query_set_allocation_params (GstQuery *query, guint size, guint min_buffers,
guint max_buffers, guint prefix, guint alignment,
GstBufferPool *pool);
guint max_buffers, guint prefix, guint padding,
guint alignment, GstBufferPool *pool);
void gst_query_parse_allocation_params (GstQuery *query, guint *size, guint *min_buffers,
guint *max_buffers, guint *prefix, guint *alignment,
GstBufferPool **pool);
guint *max_buffers, guint *prefix, guint *padding,
guint *alignment, GstBufferPool **pool);
void gst_query_add_allocation_meta (GstQuery *query, GType api);
guint gst_query_get_n_allocation_metas (GstQuery *query);
......
......@@ -247,6 +247,7 @@ struct _GstBaseSrcPrivate
GstBufferPool *pool;
GstAllocator *allocator;
guint prefix;
guint padding;
guint alignment;
};
......@@ -1357,13 +1358,13 @@ gst_base_src_default_alloc (GstBaseSrc * src, guint64 offset,
GstMemory *mem;
guint maxsize;
maxsize = size + priv->prefix;
maxsize = size + priv->prefix + priv->padding;
mem = gst_allocator_alloc (priv->allocator, maxsize, priv->alignment);
if (G_UNLIKELY (mem == NULL))
goto alloc_failed;
if (priv->prefix != 0)
if (priv->prefix != 0 || priv->padding != 0)
gst_memory_resize (mem, priv->prefix, size);
*buffer = gst_buffer_new ();
......@@ -2722,7 +2723,7 @@ null_buffer:
static gboolean
gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool,
GstAllocator * allocator, guint prefix, guint alignment)
GstAllocator * allocator, guint prefix, guint padding, guint alignment)
{
GstAllocator *oldalloc;
GstBufferPool *oldpool;
......@@ -2742,6 +2743,7 @@ gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool,
priv->allocator = allocator;
priv->prefix = prefix;
priv->padding = padding;
priv->alignment = alignment;
GST_OBJECT_UNLOCK (basesrc);
......@@ -2793,7 +2795,7 @@ gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
GstQuery *query;
GstBufferPool *pool = NULL;
GstAllocator *allocator = NULL;
guint size, min, max, prefix, alignment;
guint size, min, max, prefix, padding, alignment;
bclass = GST_BASE_SRC_GET_CLASS (basesrc);
......@@ -2812,7 +2814,7 @@ gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
GST_DEBUG_OBJECT (basesrc, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
query);
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
&alignment, &pool);
&padding, &alignment, &pool);
if (size == 0) {
/* no size, we have variable size buffers */
......@@ -2831,14 +2833,15 @@ gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_set (config, caps, size, min, max, prefix,
alignment);
padding, alignment);
gst_buffer_pool_set_config (pool, config);
}
gst_query_unref (query);
result =
gst_base_src_set_allocation (basesrc, pool, allocator, prefix, alignment);
gst_base_src_set_allocation (basesrc, pool, allocator, prefix, padding,
alignment);
return result;
......@@ -3195,7 +3198,7 @@ gst_base_src_stop (GstBaseSrc * basesrc)
if (bclass->stop)
result = bclass->stop (basesrc);
gst_base_src_set_allocation (basesrc, NULL, NULL, 0, 0);
gst_base_src_set_allocation (basesrc, NULL, NULL, 0, 0, 0);
return result;
......
......@@ -256,6 +256,7 @@ struct _GstBaseTransformPrivate
gboolean pool_active;
GstAllocator *allocator;
guint prefix;
guint padding;
guint alignment;
GstQuery *query;
};
......@@ -744,7 +745,7 @@ done:
static gboolean
gst_base_transform_set_allocation (GstBaseTransform * trans,
GstBufferPool * pool, GstAllocator * allocator, guint prefix,
guint alignment, GstQuery * query)
guint padding, guint alignment, GstQuery * query)
{
GstAllocator *oldalloc;
GstBufferPool *oldpool;
......@@ -760,6 +761,7 @@ gst_base_transform_set_allocation (GstBaseTransform * trans,
oldquery = priv->query;
priv->query = query;
priv->prefix = prefix;
priv->padding = padding;
priv->alignment = alignment;
GST_OBJECT_UNLOCK (trans);
......@@ -827,7 +829,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
GstQuery *query;
gboolean result = TRUE;
GstBufferPool *pool = NULL;
guint size, min, max, prefix, alignment;
guint size, min, max, prefix, padding, alignment;
GstBaseTransformClass *klass;
GstAllocator *allocator = NULL;
......@@ -846,7 +848,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
* let the upstream element decide if it wants to use a bufferpool and
* then we will proxy the downstream pool */
GST_DEBUG_OBJECT (trans, "we're passthough, delay bufferpool");
gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, NULL);
gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, 0, NULL);
return TRUE;
}
......@@ -868,7 +870,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
/* we got configuration from our peer, parse them */
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
&alignment, &pool);
&padding, &alignment, &pool);
if (size == 0) {
/* no size, we have variable size buffers */
......@@ -886,14 +888,14 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
GST_DEBUG_OBJECT (trans, "no pool, making one");
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
alignment);
padding, alignment);
gst_buffer_pool_set_config (pool, config);
}
/* and store */
result =
gst_base_transform_set_allocation (trans, pool, allocator, prefix,
alignment, query);
padding, alignment, query);
return result;
......@@ -1460,7 +1462,8 @@ default_prepare_output_buffer (GstBaseTransform * trans,
GstFlowReturn ret = GST_FLOW_OK;
GstBaseTransformClass *bclass;
GstCaps *incaps, *outcaps;
gsize insize, outsize;
gsize insize, outsize, maxsize;
GstMemory *mem;
gboolean res;
priv = trans->priv;
......@@ -1519,7 +1522,13 @@ default_prepare_output_buffer (GstBaseTransform * trans,
goto unknown_size;
GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
*outbuf = gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
maxsize = outsize + priv->prefix + priv->padding;
mem = gst_allocator_alloc (priv->allocator, maxsize, priv->alignment);
if (priv->prefix != 0 || priv->padding != 0)
gst_memory_resize (mem, priv->prefix, outsize);
*outbuf = gst_buffer_new ();
gst_buffer_take_memory (*outbuf, -1, mem);
copy_meta:
/* copy the metadata */
......@@ -2236,7 +2245,7 @@ gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
if (trans->priv->pad_mode != GST_PAD_MODE_NONE && bclass->stop)
result &= bclass->stop (trans);
gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, NULL);
gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0, 0, NULL);
}
return result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment