guint64 offset, guint size, GstBuffer ** buf);
static GstFlowReturn gst_base_src_default_alloc (GstBaseSrc * basesrc,
guint64 offset, guint size, GstBuffer ** buf);
+static gboolean gst_base_src_decide_allocation_default (GstBaseSrc * basesrc,
+ GstQuery * query);
static gboolean gst_base_src_set_flushing (GstBaseSrc * basesrc,
gboolean flushing, gboolean live_play, gboolean unlock, gboolean * playing);
klass->event = GST_DEBUG_FUNCPTR (gst_base_src_default_event);
klass->create = GST_DEBUG_FUNCPTR (gst_base_src_default_create);
klass->alloc = GST_DEBUG_FUNCPTR (gst_base_src_default_alloc);
+ klass->decide_allocation =
+ GST_DEBUG_FUNCPTR (gst_base_src_decide_allocation_default);
/* Registering debug symbols for function pointers */
GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_activate_mode);
return res;
}
+
static gboolean
-gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
+gst_base_src_decide_allocation_default (GstBaseSrc * basesrc, GstQuery * query)
{
- GstBaseSrcClass *bclass;
- gboolean result = TRUE;
- GstQuery *query;
- GstBufferPool *pool = NULL;
- GstAllocator *allocator = NULL;
+ GstCaps *outcaps;
+ GstBufferPool *pool;
guint size, min, max;
+ GstAllocator *allocator;
GstAllocationParams params;
+ GstStructure *config;
+ gboolean update_allocator;
- bclass = GST_BASE_SRC_GET_CLASS (basesrc);
-
- /* make query and let peer pad answer, we don't really care if it worked or
- * not, if it failed, the allocation query would contain defaults and the
- * subclass would then set better values if needed */
- query = gst_query_new_allocation (caps, TRUE);
- if (!gst_pad_peer_query (basesrc->srcpad, query)) {
- /* not a problem, just debug a little */
- GST_DEBUG_OBJECT (basesrc, "peer ALLOCATION query failed");
- }
-
- if (G_LIKELY (bclass->decide_allocation))
- result = bclass->decide_allocation (basesrc, query);
-
- GST_DEBUG_OBJECT (basesrc, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
- query);
+ gst_query_parse_allocation (query, &outcaps, NULL);
+ /* we got configuration from our peer or the decide_allocation method,
+ * parse them */
if (gst_query_get_n_allocation_params (query) > 0) {
/* try the allocator */
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
+ update_allocator = TRUE;
} else {
allocator = NULL;
gst_allocation_params_init (¶ms);
+ update_allocator = FALSE;
}
if (gst_query_get_n_allocation_pools (query) > 0) {
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
if (pool == NULL) {
- /* no pool, just parameters, we can make our own */
+ /* no pool, we can make our own */
GST_DEBUG_OBJECT (basesrc, "no pool, making new pool");
pool = gst_buffer_pool_new ();
}
/* now configure */
if (pool) {
- GstStructure *config;
-
config = gst_buffer_pool_get_config (pool);
- gst_buffer_pool_config_set_params (config, caps, size, min, max);
+ gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
gst_buffer_pool_set_config (pool, config);
}
+ if (update_allocator)
+ gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
+ else
+ gst_query_add_allocation_param (query, allocator, ¶ms);
+ if (allocator)
+ gst_allocator_unref (allocator);
+
+ if (pool) {
+ gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
+ gst_object_unref (pool);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
+{
+ GstBaseSrcClass *bclass;
+ gboolean result = TRUE;
+ GstQuery *query;
+ GstBufferPool *pool = NULL;
+ GstAllocator *allocator = NULL;
+ GstAllocationParams params;
+
+ bclass = GST_BASE_SRC_GET_CLASS (basesrc);
+
+ /* make query and let peer pad answer, we don't really care if it worked or
+ * not, if it failed, the allocation query would contain defaults and the
+ * subclass would then set better values if needed */
+ query = gst_query_new_allocation (caps, TRUE);
+ if (!gst_pad_peer_query (basesrc->srcpad, query)) {
+ /* not a problem, just debug a little */
+ GST_DEBUG_OBJECT (basesrc, "peer ALLOCATION query failed");
+ }
+
+ g_assert (bclass->decide_allocation != NULL);
+ result = bclass->decide_allocation (basesrc, query);
+
+ GST_DEBUG_OBJECT (basesrc, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
+ query);
+
+ if (!result)
+ goto no_decide_allocation;
+
+ /* we got configuration from our peer or the decide_allocation method,
+ * parse them */
+ if (gst_query_get_n_allocation_params (query) > 0) {
+ gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
+ } else {
+ allocator = NULL;
+ gst_allocation_params_init (¶ms);
+ }
+
+ if (gst_query_get_n_allocation_pools (query) > 0)
+ gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
+
result = gst_base_src_set_allocation (basesrc, pool, allocator, ¶ms);
gst_query_unref (query);
return result;
+ /* Errors */
+no_decide_allocation:
+ {
+ GST_WARNING_OBJECT (basesrc, "Subclass failed to decide allocation");
+ gst_query_unref (query);
+
+ return result;
+ }
}
/* default negotiation code.
{
guint i, n_metas;
GstBaseTransformClass *klass;
+ GstCaps *outcaps;
+ GstBufferPool *pool;
+ guint size, min, max;
+ GstAllocator *allocator;
+ GstAllocationParams params;
+ GstStructure *config;
+ gboolean update_allocator;
klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
n_metas--;
}
}
+
+ gst_query_parse_allocation (query, &outcaps, NULL);
+
+ /* we got configuration from our peer or the decide_allocation method,
+ * parse them */
+ if (gst_query_get_n_allocation_params (query) > 0) {
+ /* try the allocator */
+ gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
+ update_allocator = TRUE;
+ } else {
+ allocator = NULL;
+ gst_allocation_params_init (¶ms);
+ update_allocator = FALSE;
+ }
+
+ if (gst_query_get_n_allocation_pools (query) > 0) {
+ gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
+
+ if (pool == NULL) {
+ /* no pool, we can make our own */
+ GST_DEBUG_OBJECT (trans, "no pool, making new pool");
+ pool = gst_buffer_pool_new ();
+ }
+ } else {
+ pool = NULL;
+ size = min = max = 0;
+ }
+
+ /* now configure */
+ if (pool) {
+ config = gst_buffer_pool_get_config (pool);
+ gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
+ gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
+ gst_buffer_pool_set_config (pool, config);
+ }
+
+ if (update_allocator)
+ gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
+ else
+ gst_query_add_allocation_param (query, allocator, ¶ms);
+ if (allocator)
+ gst_allocator_unref (allocator);
+
+ if (pool) {
+ gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
+ gst_object_unref (pool);
+ }
+
return TRUE;
}
{
GstQuery *query;
gboolean result = TRUE;
- GstBufferPool *pool;
- guint size, min, max;
+ GstBufferPool *pool = NULL;
GstBaseTransformClass *klass;
GstBaseTransformPrivate *priv = trans->priv;
GstAllocator *allocator;
klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
GST_DEBUG_OBJECT (trans, "calling decide_allocation");
- if (G_LIKELY (klass->decide_allocation))
- if ((result = klass->decide_allocation (trans, query)) == FALSE)
- goto no_decide_allocation;
+ g_assert (klass->decide_allocation != NULL);
+ result = klass->decide_allocation (trans, query);
+
+ GST_DEBUG_OBJECT (trans, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
+ query);
+
+ if (!result)
+ goto no_decide_allocation;
/* we got configuration from our peer or the decide_allocation method,
* parse them */
if (gst_query_get_n_allocation_params (query) > 0) {
- /* try the allocator */
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
} else {
allocator = NULL;
gst_allocation_params_init (¶ms);
}
- if (gst_query_get_n_allocation_pools (query) > 0) {
- gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
+ if (gst_query_get_n_allocation_pools (query) > 0)
+ gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
- if (pool == NULL) {
- /* no pool, just parameters, we can make our own */
- GST_DEBUG_OBJECT (trans, "no pool, making new pool");
- pool = gst_buffer_pool_new ();
- }
- } else {
- pool = NULL;
- size = min = max = 0;
- }
-
- /* now configure */
- if (pool) {
- GstStructure *config;
-
- config = gst_buffer_pool_get_config (pool);
- gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
- gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
- gst_buffer_pool_set_config (pool, config);
- }
- /* and store */
+ /* now store */
result =
gst_base_transform_set_allocation (trans, pool, allocator, ¶ms,
query);