bufferpool: Add an helper to validate config

When we call gst_buffer_pool_set_config() the pool may return FALSE and
slightly change the parameters. This helper is useful to do the minial required
validation before accepting the modified configuration.

https://bugzilla.gnome.org/show_bug.cgi?id=727916
This commit is contained in:
Nicolas Dufresne 2014-05-08 12:47:43 -04:00
parent 43acfbbb86
commit 194db480e0
5 changed files with 65 additions and 0 deletions

View file

@ -308,6 +308,7 @@ gst_buffer_pool_new
gst_buffer_pool_config_get_params
gst_buffer_pool_config_set_params
gst_buffer_pool_config_validate_params
gst_buffer_pool_config_get_allocator
gst_buffer_pool_config_set_allocator

View file

@ -1006,6 +1006,44 @@ gst_buffer_pool_config_get_allocator (GstStructure * config,
return TRUE;
}
/**
* gst_buffer_pool_config_validate_params:
* @config: (transfer none): a #GstBufferPool configuration
* @caps: (transfer none): the excepted caps of buffers
* @size: the expected size of each buffer, not including prefix and padding
* @min_buffers: the expected minimum amount of buffers to allocate.
* @max_buffers: the expect maximum amount of buffers to allocate or 0 for unlimited.
*
* Validate that changes made to @config are still valid in the context of the
* expected parameters. This function is a helper that can be used to validate
* changes made by a pool to a config when gst_buffer_pool_set_config()
* returns %FALSE. This expects that @caps and @size haven't changed, and that
* @min_buffers aren't lower then what we initially expected. This does not check
* if options or allocator parameters.
*
* Since: 1.4
*
* Returns: %TRUE, if the parameters are valid in this context.
*/
gboolean
gst_buffer_pool_config_validate_params (GstStructure * config, GstCaps * caps,
guint size, guint min_buffers, G_GNUC_UNUSED guint max_buffers)
{
GstCaps *newcaps;
guint newsize, newmin;
gboolean ret = FALSE;
g_return_val_if_fail (config != NULL, FALSE);
gst_buffer_pool_config_get_params (config, &newcaps, &newsize, &newmin, NULL);
if (gst_caps_is_equal (caps, newcaps) && (size == newsize)
&& (newmin >= min_buffers))
ret = TRUE;
return ret;
}
static GstFlowReturn
default_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
GstBufferPoolAcquireParams * params)

View file

@ -201,6 +201,8 @@ guint gst_buffer_pool_config_n_options (GstStructure *config);
void gst_buffer_pool_config_add_option (GstStructure *config, const gchar *option);
const gchar * gst_buffer_pool_config_get_option (GstStructure *config, guint index);
gboolean gst_buffer_pool_config_has_option (GstStructure *config, const gchar *option);
gboolean gst_buffer_pool_config_validate_params (GstStructure *config, GstCaps *caps,
guint size, guint min_buffers, guint max_buffers);
/* buffer management */
GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,

View file

@ -220,6 +220,28 @@ GST_START_TEST (test_pool_activation_and_config)
GST_END_TEST;
GST_START_TEST (test_pool_config_validate)
{
GstBufferPool *pool = create_pool (5, 4, 30);
GstStructure *config = gst_buffer_pool_get_config (pool);
GstCaps *caps = gst_caps_new_empty_simple ("test/data");
fail_unless (gst_buffer_pool_config_validate_params (config, caps, 5, 4, 0));
fail_unless (gst_buffer_pool_config_validate_params (config, caps, 5, 2, 0));
fail_if (gst_buffer_pool_config_validate_params (config, caps, 5, 6, 0));
fail_if (gst_buffer_pool_config_validate_params (config, caps, 4, 4, 0));
gst_caps_unref (caps);
caps = gst_caps_new_empty_simple ("test/data2");
fail_if (gst_buffer_pool_config_validate_params (config, caps, 5, 4, 0));
gst_caps_unref (caps);
gst_structure_free (config);
gst_object_unref (pool);
}
GST_END_TEST;
static Suite *
gst_buffer_pool_suite (void)
{
@ -236,6 +258,7 @@ gst_buffer_pool_suite (void)
tcase_add_test (tc_chain, test_inactive_pool_returns_flushing);
tcase_add_test (tc_chain, test_buffer_modify_discard);
tcase_add_test (tc_chain, test_pool_activation_and_config);
tcase_add_test (tc_chain, test_pool_config_validate);
return s;
}

View file

@ -148,6 +148,7 @@ EXPORTS
gst_buffer_pool_config_n_options
gst_buffer_pool_config_set_allocator
gst_buffer_pool_config_set_params
gst_buffer_pool_config_validate_params
gst_buffer_pool_get_config
gst_buffer_pool_get_options
gst_buffer_pool_get_type