mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
basetransform: inprove allocation handling
Add vmethod for subclasses to influence the pool and allocator. Log when query fails. Respect negotiated allocator and alignment.
This commit is contained in:
parent
9c67925fb7
commit
3822eea7cf
2 changed files with 65 additions and 23 deletions
|
@ -252,7 +252,10 @@ struct _GstBaseTransformPrivate
|
||||||
|
|
||||||
GstClockTime position_out;
|
GstClockTime position_out;
|
||||||
|
|
||||||
GstBufferPool *srcpool;
|
GstBufferPool *pool;
|
||||||
|
const GstMemoryAllocator *allocator;
|
||||||
|
guint prefix;
|
||||||
|
guint alignment;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class = NULL;
|
||||||
|
@ -707,12 +710,37 @@ done:
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_base_transform_set_allocation (GstBaseTransform * trans,
|
||||||
|
GstBufferPool * pool, const GstMemoryAllocator * allocator, guint prefix,
|
||||||
|
guint alignment)
|
||||||
|
{
|
||||||
|
GstBufferPool *oldpool;
|
||||||
|
GstBaseTransformPrivate *priv = trans->priv;
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (trans);
|
||||||
|
oldpool = priv->pool;
|
||||||
|
priv->pool = pool;
|
||||||
|
priv->allocator = allocator;
|
||||||
|
priv->prefix = prefix;
|
||||||
|
priv->alignment = alignment;
|
||||||
|
GST_OBJECT_UNLOCK (trans);
|
||||||
|
|
||||||
|
if (oldpool) {
|
||||||
|
gst_buffer_pool_set_active (oldpool, FALSE);
|
||||||
|
gst_object_unref (oldpool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
|
gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
|
||||||
{
|
{
|
||||||
GstQuery *query;
|
GstQuery *query;
|
||||||
|
gboolean result = TRUE;
|
||||||
GstBufferPool *pool = NULL, *oldpool;
|
GstBufferPool *pool = NULL, *oldpool;
|
||||||
guint size, min, max, prefix, alignment;
|
guint size, min, max, prefix, alignment;
|
||||||
|
GstBaseTransformClass *klass;
|
||||||
|
const GstMemoryAllocator *allocator = NULL;
|
||||||
|
|
||||||
/* there are these possibilities:
|
/* there are these possibilities:
|
||||||
*
|
*
|
||||||
|
@ -721,11 +749,11 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* clear old pool */
|
/* clear old pool */
|
||||||
oldpool = trans->priv->srcpool;
|
oldpool = trans->priv->pool;
|
||||||
if (oldpool) {
|
if (oldpool) {
|
||||||
gst_buffer_pool_set_active (oldpool, FALSE);
|
gst_buffer_pool_set_active (oldpool, FALSE);
|
||||||
gst_object_unref (oldpool);
|
gst_object_unref (oldpool);
|
||||||
trans->priv->srcpool = oldpool = NULL;
|
trans->priv->pool = oldpool = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trans->passthrough) {
|
if (trans->passthrough) {
|
||||||
|
@ -740,16 +768,30 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
|
||||||
/* not passthrough, we need to allocate */
|
/* not passthrough, we need to allocate */
|
||||||
/* find a pool for the negotiated caps now */
|
/* find a pool for the negotiated caps now */
|
||||||
query = gst_query_new_allocation (outcaps, TRUE);
|
query = gst_query_new_allocation (outcaps, TRUE);
|
||||||
|
if (!gst_pad_peer_query (trans->srcpad, query)) {
|
||||||
|
/* not a problem, just debug a little */
|
||||||
|
GST_DEBUG_OBJECT (trans, "peer ALLOCATION query failed");
|
||||||
|
}
|
||||||
|
|
||||||
if (!gst_pad_peer_query (trans->srcpad, query))
|
klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
|
||||||
goto query_failed;
|
|
||||||
|
if (G_LIKELY (klass->setup_allocation))
|
||||||
|
result = klass->setup_allocation (trans, query);
|
||||||
|
|
||||||
/* we got configuration from our peer, parse them */
|
/* we got configuration from our peer, parse them */
|
||||||
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
|
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
|
||||||
&alignment, &pool);
|
&alignment, &pool);
|
||||||
gst_query_unref (query);
|
gst_query_unref (query);
|
||||||
|
|
||||||
if (pool == NULL) {
|
if (size == 0) {
|
||||||
|
const gchar *mem = NULL;
|
||||||
|
|
||||||
|
/* no size, we have variable size buffers */
|
||||||
|
if (gst_query_get_n_allocation_memories (query) > 0) {
|
||||||
|
mem = gst_query_parse_nth_allocation_memory (query, 0);
|
||||||
|
}
|
||||||
|
allocator = gst_memory_allocator_find (mem);
|
||||||
|
} else if (pool == NULL) {
|
||||||
GstStructure *config;
|
GstStructure *config;
|
||||||
|
|
||||||
/* we did not get a pool, make one ourselves then */
|
/* we did not get a pool, make one ourselves then */
|
||||||
|
@ -759,24 +801,18 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
|
||||||
gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
|
gst_buffer_pool_config_set (config, outcaps, size, min, max, prefix,
|
||||||
alignment);
|
alignment);
|
||||||
gst_buffer_pool_set_config (pool, config);
|
gst_buffer_pool_set_config (pool, config);
|
||||||
}
|
|
||||||
|
|
||||||
/* activate */
|
/* activate */
|
||||||
if (!gst_buffer_pool_set_active (pool, TRUE))
|
if (!gst_buffer_pool_set_active (pool, TRUE))
|
||||||
goto activate_failed;
|
goto activate_failed;
|
||||||
|
}
|
||||||
|
|
||||||
/* and store */
|
/* and store */
|
||||||
trans->priv->srcpool = pool;
|
gst_base_transform_set_allocation (trans, pool, allocator, prefix, alignment);
|
||||||
|
|
||||||
return TRUE;
|
return result;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
query_failed:
|
|
||||||
{
|
|
||||||
GST_DEBUG_OBJECT (trans, "allocation query failed");
|
|
||||||
gst_query_unref (query);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
activate_failed:
|
activate_failed:
|
||||||
{
|
{
|
||||||
GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
|
GST_ERROR_OBJECT (trans, "failed to activate bufferpool.");
|
||||||
|
@ -1401,12 +1437,13 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
|
||||||
if (trans->passthrough) {
|
if (trans->passthrough) {
|
||||||
GST_DEBUG_OBJECT (trans, "Reusing input buffer");
|
GST_DEBUG_OBJECT (trans, "Reusing input buffer");
|
||||||
*out_buf = in_buf;
|
*out_buf = in_buf;
|
||||||
} else if (priv->srcpool) {
|
} else if (priv->pool) {
|
||||||
GST_DEBUG_OBJECT (trans, "using pool alloc");
|
GST_DEBUG_OBJECT (trans, "using pool alloc");
|
||||||
ret = gst_buffer_pool_acquire_buffer (priv->srcpool, out_buf, NULL);
|
ret = gst_buffer_pool_acquire_buffer (priv->pool, out_buf, NULL);
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
|
GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
|
||||||
*out_buf = gst_buffer_new_allocate (NULL, outsize, 0);
|
*out_buf =
|
||||||
|
gst_buffer_new_allocate (priv->allocator, outsize, priv->alignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2113,6 +2150,8 @@ gst_base_transform_activate (GstBaseTransform * trans, gboolean active)
|
||||||
|
|
||||||
if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
|
if (trans->priv->pad_mode != GST_ACTIVATE_NONE && bclass->stop)
|
||||||
result &= bclass->stop (trans);
|
result &= bclass->stop (trans);
|
||||||
|
|
||||||
|
gst_base_transform_set_allocation (trans, NULL, NULL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -206,17 +206,18 @@ struct _GstBaseTransformClass {
|
||||||
GstCaps* (*transform_caps) (GstBaseTransform *trans,
|
GstCaps* (*transform_caps) (GstBaseTransform *trans,
|
||||||
GstPadDirection direction,
|
GstPadDirection direction,
|
||||||
GstCaps *caps, GstCaps *filter);
|
GstCaps *caps, GstCaps *filter);
|
||||||
|
|
||||||
void (*fixate_caps) (GstBaseTransform *trans,
|
void (*fixate_caps) (GstBaseTransform *trans,
|
||||||
GstPadDirection direction, GstCaps *caps,
|
GstPadDirection direction, GstCaps *caps,
|
||||||
GstCaps *othercaps);
|
GstCaps *othercaps);
|
||||||
gboolean (*accept_caps) (GstBaseTransform *trans, GstPadDirection direction,
|
gboolean (*accept_caps) (GstBaseTransform *trans, GstPadDirection direction,
|
||||||
GstCaps *caps);
|
GstCaps *caps);
|
||||||
|
|
||||||
gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
|
gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
|
||||||
GstCaps *outcaps);
|
GstCaps *outcaps);
|
||||||
|
|
||||||
|
/* setup allocation query */
|
||||||
|
gboolean (*setup_allocation) (GstBaseTransform *trans, GstQuery *query);
|
||||||
|
|
||||||
|
/* transform size */
|
||||||
gboolean (*transform_size) (GstBaseTransform *trans,
|
gboolean (*transform_size) (GstBaseTransform *trans,
|
||||||
GstPadDirection direction,
|
GstPadDirection direction,
|
||||||
GstCaps *caps, gsize size,
|
GstCaps *caps, gsize size,
|
||||||
|
@ -225,6 +226,7 @@ struct _GstBaseTransformClass {
|
||||||
gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
|
gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
|
||||||
gsize *size);
|
gsize *size);
|
||||||
|
|
||||||
|
/* states */
|
||||||
gboolean (*start) (GstBaseTransform *trans);
|
gboolean (*start) (GstBaseTransform *trans);
|
||||||
gboolean (*stop) (GstBaseTransform *trans);
|
gboolean (*stop) (GstBaseTransform *trans);
|
||||||
|
|
||||||
|
@ -237,6 +239,7 @@ struct _GstBaseTransformClass {
|
||||||
|
|
||||||
void (*before_transform) (GstBaseTransform *trans, GstBuffer *buffer);
|
void (*before_transform) (GstBaseTransform *trans, GstBuffer *buffer);
|
||||||
|
|
||||||
|
/* transform */
|
||||||
GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
|
GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
|
||||||
GstBuffer *outbuf);
|
GstBuffer *outbuf);
|
||||||
GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
|
GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
|
||||||
|
|
Loading…
Reference in a new issue