mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 02:31:03 +00:00
asset: simplify if-statement in cache_set_loaded
Summary: Manual iteration can be replaced with foreach function. In addition, this patch fixes mismatched GFunc type for g_list_foreach and adds debug cateory for gst-asset for convenient debugging. Reviewers: thiblahute Reviewed By: thiblahute Differential Revision: https://phabricator.freedesktop.org/D312
This commit is contained in:
parent
46f9cbdf4f
commit
8bce0baf62
1 changed files with 32 additions and 22 deletions
|
@ -87,6 +87,10 @@
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (ges_asset_debug);
|
||||||
|
#undef GST_CAT_DEFAULT
|
||||||
|
#define GST_CAT_DEFAULT ges_asset_debug
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
@ -339,6 +343,8 @@ ges_asset_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GESAssetPrivate *priv = GES_ASSET (object)->priv;
|
GESAssetPrivate *priv = GES_ASSET (object)->priv;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (object, "finalizing");
|
||||||
|
|
||||||
if (priv->id)
|
if (priv->id)
|
||||||
g_free (priv->id);
|
g_free (priv->id);
|
||||||
|
|
||||||
|
@ -377,6 +383,9 @@ ges_asset_class_init (GESAssetClass * klass)
|
||||||
klass->extract = ges_asset_extract_default;
|
klass->extract = ges_asset_extract_default;
|
||||||
klass->request_id_update = ges_asset_request_id_update_default;
|
klass->request_id_update = ges_asset_request_id_update_default;
|
||||||
klass->inform_proxy = NULL;
|
klass->inform_proxy = NULL;
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_INIT (ges_asset_debug, "ges-asset",
|
||||||
|
GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "GES Asset");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -422,9 +431,14 @@ _free_entries (gpointer entry)
|
||||||
g_slice_free (GESAssetCacheEntry, entry);
|
g_slice_free (GESAssetCacheEntry, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_gtask_return_error (GTask * task, GError * error)
|
||||||
|
{
|
||||||
|
g_task_return_error (task, g_error_copy (error));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_gtask_return_true (GTask * task)
|
_gtask_return_true (GTask * task, gpointer udata)
|
||||||
{
|
{
|
||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
}
|
}
|
||||||
|
@ -471,9 +485,12 @@ gboolean
|
||||||
ges_asset_cache_set_loaded (GType extractable_type, const gchar * id,
|
ges_asset_cache_set_loaded (GType extractable_type, const gchar * id,
|
||||||
GError * error)
|
GError * error)
|
||||||
{
|
{
|
||||||
GList *tmp;
|
|
||||||
GESAsset *asset;
|
GESAsset *asset;
|
||||||
GESAssetCacheEntry *entry = NULL;
|
GESAssetCacheEntry *entry = NULL;
|
||||||
|
GList *results = NULL;
|
||||||
|
GFunc user_func = NULL;
|
||||||
|
gpointer user_data = NULL;
|
||||||
|
|
||||||
LOCK_CACHE;
|
LOCK_CACHE;
|
||||||
if ((entry = _lookup_entry (extractable_type, id)) == NULL) {
|
if ((entry = _lookup_entry (extractable_type, id)) == NULL) {
|
||||||
UNLOCK_CACHE;
|
UNLOCK_CACHE;
|
||||||
|
@ -488,36 +505,29 @@ ges_asset_cache_set_loaded (GType extractable_type, const gchar * id,
|
||||||
"callback (Error: %s)", g_type_name (asset->priv->extractable_type),
|
"callback (Error: %s)", g_type_name (asset->priv->extractable_type),
|
||||||
g_list_length (entry->results), error ? error->message : "");
|
g_list_length (entry->results), error ? error->message : "");
|
||||||
|
|
||||||
if (error) {
|
results = entry->results;
|
||||||
GList *results = entry->results;
|
entry->results = NULL;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
asset->priv->state = ASSET_INITIALIZED_WITH_ERROR;
|
asset->priv->state = ASSET_INITIALIZED_WITH_ERROR;
|
||||||
if (asset->priv->error)
|
if (asset->priv->error)
|
||||||
g_error_free (asset->priv->error);
|
g_error_free (asset->priv->error);
|
||||||
asset->priv->error = g_error_copy (error);
|
asset->priv->error = g_error_copy (error);
|
||||||
entry->results = NULL;
|
|
||||||
UNLOCK_CACHE;
|
|
||||||
|
|
||||||
/* In case of error we do not want to emit in idle as we need to recover
|
/* In case of error we do not want to emit in idle as we need to recover
|
||||||
* if possible */
|
* if possible */
|
||||||
for (tmp = results; tmp; tmp = tmp->next) {
|
user_func = (GFunc) _gtask_return_error;
|
||||||
g_task_return_error (tmp->data, g_error_copy (error));
|
user_data = error;
|
||||||
gst_object_unref (tmp->data);
|
GST_DEBUG_OBJECT (asset, "initialized with error");
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free (results);
|
|
||||||
return TRUE;
|
|
||||||
} else {
|
} else {
|
||||||
GList *results;
|
|
||||||
|
|
||||||
asset->priv->state = ASSET_INITIALIZED;
|
asset->priv->state = ASSET_INITIALIZED;
|
||||||
results = entry->results;
|
user_func = (GFunc) _gtask_return_true;
|
||||||
entry->results = NULL;
|
GST_DEBUG_OBJECT (asset, "initialized");
|
||||||
|
}
|
||||||
UNLOCK_CACHE;
|
UNLOCK_CACHE;
|
||||||
|
|
||||||
g_list_foreach (results, (GFunc) _gtask_return_true, NULL);
|
g_list_foreach (results, user_func, user_data);
|
||||||
g_list_free_full (results, gst_object_unref);
|
g_list_free_full (results, g_object_unref);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -753,7 +763,7 @@ ges_asset_request (GType extractable_type, const gchar * id, GError ** error)
|
||||||
break;
|
break;
|
||||||
case ASSET_INITIALIZED_WITH_ERROR:
|
case ASSET_INITIALIZED_WITH_ERROR:
|
||||||
GST_WARNING_OBJECT (asset, "Initialized with error, not returning");
|
GST_WARNING_OBJECT (asset, "Initialized with error, not returning");
|
||||||
if (error)
|
if (asset->priv->error)
|
||||||
*error = g_error_copy (asset->priv->error);
|
*error = g_error_copy (asset->priv->error);
|
||||||
asset = NULL;
|
asset = NULL;
|
||||||
goto done;
|
goto done;
|
||||||
|
|
Loading…
Reference in a new issue