From 23e69d98d8a6dd84faa97926cab7c2e5cf274f0a Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 15 Apr 2014 14:17:00 -0400 Subject: [PATCH] pool-nego: Retry setting configuration with modified config Buffer pool set_config() may return FALSE if requested configuration needed small changes. Reget the config and try setting it again (validating the changes first). This ensure we have a configured pool if possible. https://bugzilla.gnome.org/show_bug.cgi?id=727916 --- libs/gst/base/gstbasesrc.c | 24 +++++++++++++++++++++++- libs/gst/base/gstbasetransform.c | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index 14ed000076..8b84e61d3a 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -3055,7 +3055,23 @@ gst_base_src_decide_allocation_default (GstBaseSrc * basesrc, GstQuery * query) 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); + + /* buffer pool may have to do some changes */ + if (!gst_buffer_pool_set_config (pool, config)) { + config = gst_buffer_pool_get_config (pool); + + /* If change are not acceptable, fallback to generic pool */ + if (!gst_buffer_pool_config_validate_params (config, outcaps, size, min, + max)) { + GST_DEBUG_OBJECT (basesrc, "unsuported pool, making new pool"); + + gst_object_unref (pool); + pool = gst_buffer_pool_new (); + } + + if (!gst_buffer_pool_set_config (pool, config)) + goto config_failed; + } } if (update_allocator) @@ -3071,6 +3087,12 @@ gst_base_src_decide_allocation_default (GstBaseSrc * basesrc, GstQuery * query) } return TRUE; + +config_failed: + GST_ELEMENT_ERROR (basesrc, RESOURCE, SETTINGS, + ("Failed to configure the buffer pool"), + ("Configuration is most likely invalid, please report this issue.")); + return FALSE; } static gboolean diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index e2e5e140ca..dbc4da98da 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -899,7 +899,23 @@ gst_base_transform_default_decide_allocation (GstBaseTransform * trans, 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); + + /* buffer pool may have to do some changes */ + if (!gst_buffer_pool_set_config (pool, config)) { + config = gst_buffer_pool_get_config (pool); + + /* If change are not acceptable, fallback to generic pool */ + if (!gst_buffer_pool_config_validate_params (config, outcaps, size, min, + max)) { + GST_DEBUG_OBJECT (trans, "unsuported pool, making new pool"); + + gst_object_unref (pool); + pool = gst_buffer_pool_new (); + } + + if (!gst_buffer_pool_set_config (pool, config)) + goto config_failed; + } } if (update_allocator) @@ -915,6 +931,12 @@ gst_base_transform_default_decide_allocation (GstBaseTransform * trans, } return TRUE; + +config_failed: + GST_ELEMENT_ERROR (trans, RESOURCE, SETTINGS, + ("Failed to configure the buffer pool"), + ("Configuration is most likely invalid, please report this issue.")); + return FALSE; } static gboolean