[gnac/devel] Code cleanup
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code cleanup
- Date: Sat, 19 Nov 2011 11:28:13 +0000 (UTC)
commit f7bae69a4c628645ff62b7d9c0e74c206ba5dec9
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sat Nov 19 00:48:50 2011 +0000
Code cleanup
libgnac/libgnac-converter.c | 359 +++++++++++++++++-------------------------
libgnac/libgnac-error.c | 45 +++---
libgnac/libgnac-gst-utils.c | 45 ++----
libgnac/libgnac-gst.c | 233 ++++++++++++---------------
libgnac/libgnac-media-item.c | 45 +++---
libgnac/libgnac-metadata.c | 347 ++++++++++++++++------------------------
libgnac/libgnac-output.c | 223 +++++++++++----------------
7 files changed, 530 insertions(+), 767 deletions(-)
---
diff --git a/libgnac/libgnac-converter.c b/libgnac/libgnac-converter.c
index 4d89d92..34af785 100644
--- a/libgnac/libgnac-converter.c
+++ b/libgnac/libgnac-converter.c
@@ -37,8 +37,7 @@
#include "libgnac-profile.h"
-enum
-{
+enum {
PROP_0,
PROP_AUDIO_PIPELINE_DESC,
PROP_MUXER_PIPELINE_DESC,
@@ -279,11 +278,8 @@ libgnac_converter_allow_overwrite_accumulator(GSignalInvocationHint *ihint,
const GValue *handler_return,
gpointer data)
{
- gboolean allow_overwrite;
-
- allow_overwrite = g_value_get_boolean(handler_return);
+ gboolean allow_overwrite = g_value_get_boolean(handler_return);
g_value_set_boolean(return_accu, allow_overwrite);
-
return FALSE;
}
@@ -465,51 +461,45 @@ libgnac_converter_class_init(LibgnacConverterClass *klass)
static gboolean
libgnac_converter_start_next(LibgnacConverter *self)
{
- GError *err = NULL;
- LibgnacConverterPrivate *priv;
- gchar *key = NULL;
- gchar *uri = NULL;
-
g_return_val_if_fail(LIBGNAC_IS_CONVERTER(self), FALSE);
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+
+ GError *error = NULL;
do {
- LibgnacTags *tags;
LibgnacMediaItem *item = NULL;
- key = g_queue_pop_head(priv->queue_copy);
+ gchar *key = g_queue_pop_head(priv->queue_copy);
if (key) {
item = g_hash_table_lookup(priv->file_table, key);
}
if (!item) return FALSE;
- g_clear_error(&err);
-
priv->n_converted++;
-
priv->current = item;
- uri = g_file_get_uri(item->source);
+ gchar *uri = g_file_get_uri(item->source);
g_signal_emit(self, signals[FILE_STARTED], 0, uri);
libgnac_info("File started %s", uri);
- libgnac_item_run(item, &err);
- if (err) {
- g_signal_emit(self, signals[ERROR], 0, uri, err->message, err);
+
+ g_clear_error(&error);
+ libgnac_item_run(item, &error);
+ if (error) {
+ g_signal_emit(self, signals[ERROR], 0, uri, error->message, error);
}
- tags = libgnac_metadata_extract(metadata, item->source, NULL);
- if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL))
- {
+ LibgnacTags *tags = libgnac_metadata_extract(metadata, item->source, NULL);
+ if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL)) {
priv->elapsed_duration += g_value_get_uint64(
LIBGNAC_METADATA_TAG_DURATION(tags));
}
g_free(uri);
- } while (err);
+ } while (error);
return TRUE;
}
@@ -518,26 +508,24 @@ libgnac_converter_start_next(LibgnacConverter *self)
static gboolean
libgnac_converter_restart_current(LibgnacConverter *self)
{
- LibgnacConverterPrivate *priv;
- GError *err = NULL;
-
g_return_val_if_fail(LIBGNAC_IS_CONVERTER(self), FALSE);
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ if (!priv->current) return FALSE;
libgnac_info("Restarting current pipeline");
- if (priv->current)
- {
- libgnac_converter_emit_plugin_installed(self);
- libgnac_item_run(priv->current, &err);
- if (err) {
- g_clear_error(&err);
- return FALSE;
- }
- return TRUE;
+ libgnac_converter_emit_plugin_installed(self);
+
+ GError *error = NULL;
+ libgnac_item_run(priv->current, &error);
+ if (error) {
+ libgnac_debug("%s", error->message);
+ g_clear_error(&error);
+ return FALSE;
}
- return FALSE;
+
+ return TRUE;
}
@@ -584,42 +572,29 @@ libgnac_converter_add(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- LibgnacConverterPrivate *priv;
- LibgnacMediaItem *item;
- gchar *uri;
- gchar *dup_uri;
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
-
- uri = g_file_get_uri(file);
- dup_uri = g_strdup(uri);
-
- if (!g_hash_table_lookup(priv->file_table, uri))
- {
- LibgnacTags *tags;
+ gchar *uri = g_file_get_uri(file);
+ if (g_hash_table_lookup(priv->file_table, uri)) {
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_SAME_FILE,
+ _("File %s is already in the list"), uri);
+ g_free(uri);
+ return;
+ }
- item = libgnac_item_new(file, priv->profile, self);
- // dup uri is freed within the hashtable
- g_queue_push_head(priv->queue, dup_uri);
- g_hash_table_insert(priv->file_table, dup_uri, item);
- g_signal_emit(self, signals[FILE_ADDED], 0, uri);
+ LibgnacMediaItem *item = libgnac_item_new(file, priv->profile, self);
+ gchar *dup_uri = g_strdup(uri);
+ // dup uri is freed within the hashtable
+ g_queue_push_head(priv->queue, dup_uri);
+ g_hash_table_insert(priv->file_table, dup_uri, item);
+ g_signal_emit(self, signals[FILE_ADDED], 0, uri);
- tags = libgnac_metadata_extract(metadata, item->source, NULL);
- if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL))
- {
- priv->total_duration += g_value_get_uint64(
- LIBGNAC_METADATA_TAG_DURATION(tags));
- }
- }
- else
- {
- g_set_error(error,
- LIBGNAC_ERROR,
- LIBGNAC_ERROR_SAME_FILE,
- _("File %s is already in the list"),
- uri);
+ LibgnacTags *tags = libgnac_metadata_extract(metadata, item->source, NULL);
+ if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL)) {
+ priv->total_duration += g_value_get_uint64(
+ LIBGNAC_METADATA_TAG_DURATION(tags));
}
g_free(uri);
@@ -632,49 +607,39 @@ libgnac_converter_remove(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- LibgnacConverterPrivate *priv;
- gchar *uri;
- gpointer key_uri = NULL;
- gpointer item = NULL;
-
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ gchar *uri = g_file_get_uri(file);
- uri = g_file_get_uri(file);
+ gpointer key_uri;
+ gpointer item;
- if (g_hash_table_lookup_extended(priv->file_table, uri, &key_uri, &item))
- {
- GList *elem;
- LibgnacTags *tags;
-
- elem = g_queue_find(priv->queue, key_uri);
-
- g_return_if_fail(elem);
-
- tags = libgnac_metadata_extract(metadata,
- ((LibgnacMediaItem*)item)->source, NULL);
- if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL))
- {
- priv->total_duration -= g_value_get_uint64(
- LIBGNAC_METADATA_TAG_DURATION(tags));
- }
+ if (!g_hash_table_lookup_extended(priv->file_table, uri, &key_uri, &item)) {
+ libgnac_warning("File not found %s", uri);
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_MISSING_FILE,
+ _("File %s is not in the list"), uri);
+ g_free(uri);
+ return;
+ }
- g_queue_remove(priv->queue, elem->data);
- g_hash_table_remove(priv->file_table, uri);
+ GList *elem = g_queue_find(priv->queue, key_uri);
+ if (!elem) {
+ g_free(uri);
+ return;
+ }
- g_signal_emit(self, signals[FILE_REMOVED], 0, uri);
- }
- else
- {
- libgnac_warning("File not found %s", uri);
- g_set_error(error,
- LIBGNAC_ERROR,
- LIBGNAC_ERROR_MISSING_FILE,
- _("File %s is not in the list"),
- uri);
+ LibgnacTags *tags = libgnac_metadata_extract(metadata,
+ ((LibgnacMediaItem *) item)->source, NULL);
+ if (libgnac_metadata_tags_exist(tags, GST_TAG_DURATION, NULL)) {
+ priv->total_duration -= g_value_get_uint64(
+ LIBGNAC_METADATA_TAG_DURATION(tags));
}
+ g_queue_remove(priv->queue, elem->data);
+ g_hash_table_remove(priv->file_table, uri);
+ g_signal_emit(self, signals[FILE_REMOVED], 0, uri);
+
g_free(uri);
}
@@ -684,9 +649,7 @@ libgnac_converter_clear(LibgnacConverter *self)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- LibgnacConverterPrivate *priv;
-
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
g_queue_clear(priv->queue);
g_hash_table_remove_all(priv->file_table);
@@ -702,12 +665,9 @@ libgnac_converter_start(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- LibgnacConverterPrivate *priv;
- gchar *dbg_msg;
-
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
if (priv->queue_copy) {
g_queue_free(priv->queue_copy);
@@ -715,19 +675,18 @@ libgnac_converter_start(LibgnacConverter *self,
}
priv->queue_copy = g_queue_copy(priv->queue);
- g_queue_sort(priv->queue_copy, (GCompareDataFunc)g_strcmp0, NULL);
+ g_queue_sort(priv->queue_copy, (GCompareDataFunc) g_strcmp0, NULL);
priv->n_converted = -1;
priv->elapsed_duration = 0;
g_signal_emit(self, signals[STARTED], 0);
- dbg_msg = g_strdup_printf(_("Encoding pipeline: %s"),
+ gchar *dbg_msg = g_strdup_printf(_("Encoding pipeline: %s"),
priv->profile->audio_desc);
libgnac_info(dbg_msg);
g_free(dbg_msg);
- if (!libgnac_converter_start_next(self))
- {
+ if (!libgnac_converter_start_next(self)) {
g_signal_emit(self, signals[COMPLETION], 0);
}
}
@@ -738,13 +697,11 @@ libgnac_converter_stop(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- GError *err = NULL;
- LibgnacConverterPrivate *priv;
-
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ GError *err = NULL;
libgnac_item_stop(priv->current, &err);
if (err) {
g_propagate_error(error, err);
@@ -763,10 +720,9 @@ libgnac_converter_pause(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- LibgnacConverterPrivate *priv;
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
libgnac_gst_pause(priv->current, error);
}
@@ -776,10 +732,9 @@ libgnac_converter_resume(LibgnacConverter *self,
GError **error)
{
g_return_if_fail(LIBGNAC_IS_CONVERTER(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
- LibgnacConverterPrivate *priv;
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(self);
libgnac_gst_run(priv->current, error);
}
@@ -803,46 +758,39 @@ libgnac_converter_eos_cb(GstBus *bus,
GstMessage *message,
gpointer data)
{
- LibgnacConverter *converter = NULL;
- LibgnacMediaItem *item = NULL;
- gchar *uri;
-
- converter = (LibgnacConverter*)data;
-
+ LibgnacConverter *converter = (LibgnacConverter *) data;
g_return_if_fail(LIBGNAC_IS_CONVERTER(converter));
- item = converter->priv->current;
- uri = g_file_get_uri(item->source);
-
+ LibgnacMediaItem *item = converter->priv->current;
+ gchar *uri = g_file_get_uri(item->source);
g_signal_emit(converter, signals[FILE_COMPLETED], 0, uri);
-
g_free(uri);
/* Start next file conversion */
- if (!libgnac_converter_start_next(converter))
- {
+ if (!libgnac_converter_start_next(converter)) {
converter->priv->n_converted = -1;
g_signal_emit(converter, signals[COMPLETION], 0);
}
}
+
static gboolean
libgnac_converter_error_sink(LibgnacMediaItem *item,
GstMessage *message,
gchar *uri,
GError *error)
{
+ libgnac_debug("Sink error");
+
g_return_val_if_fail(item, FALSE);
g_return_val_if_fail(item->destination, FALSE);
g_return_val_if_fail(error, FALSE);
- GError *err = NULL;
- GFile *folder;
- gboolean folder_creation;
-
/* Get parent folder name */
- folder = g_file_get_parent(item->destination);
- folder_creation = g_file_make_directory_with_parents(folder, NULL, &err);
+ GError *err = NULL;
+ GFile *folder = g_file_get_parent(item->destination);
+ gboolean folder_creation = g_file_make_directory_with_parents(folder,
+ NULL, &err);
g_object_unref(folder);
/* New folder create relaunch pipeline */
@@ -858,11 +806,12 @@ libgnac_converter_error_sink(LibgnacMediaItem *item,
g_clear_error(&err);
return FALSE;
}
+
g_clear_error(&err);
if (!libgnac_error_handle_dest_file_already_exists(item, message, uri)) {
g_signal_emit(item->parent, signals[ERROR], 0, uri,
- _("Unable to access destination file"), error);
+ _("Unable to access destination file"), error);
return FALSE;
}
@@ -876,8 +825,9 @@ libgnac_converter_error_src(LibgnacMediaItem *item,
gchar *uri,
GError *error)
{
+ libgnac_debug("Source error");
g_signal_emit(item->parent, signals[ERROR], 0, uri,
- _("Unable to read source file"), error);
+ _("Unable to read source file"), error);
return FALSE;
}
@@ -888,6 +838,8 @@ libgnac_converter_error_other(LibgnacMediaItem *item,
gchar *uri,
GError *error)
{
+ libgnac_debug("Other error");
+
GError *err = NULL;
g_file_delete(item->destination, NULL, &err);
@@ -897,7 +849,7 @@ libgnac_converter_error_other(LibgnacMediaItem *item,
}
g_signal_emit(item->parent, signals[ERROR], 0, uri,
- _("An error occured during conversion"), error);
+ _("An error occured during conversion"), error);
return FALSE;
}
@@ -908,24 +860,17 @@ libgnac_converter_error_cb(GstBus *bus,
GstMessage *message,
gpointer data)
{
- GError *error = NULL;
- LibgnacConverter *converter = NULL;
- LibgnacMediaItem *item = NULL;
- gchar *uri;
- gchar *out_uri;
- gchar *name;
- gboolean restart = FALSE;
-
- converter = (LibgnacConverter*)data;
+ LibgnacConverter *converter = (LibgnacConverter *) data;
g_return_if_fail(LIBGNAC_IS_CONVERTER(converter));
- item = converter->priv->current;
+ LibgnacMediaItem *item = converter->priv->current;
+
+ gchar *uri = g_file_get_uri(item->source);
+ gchar *out_uri = g_file_get_uri(item->destination);
+ gchar *name = GST_MESSAGE_SRC_NAME(message);
- uri = g_file_get_uri(item->source);
- out_uri = g_file_get_uri(item->destination);
- name = GST_MESSAGE_SRC_NAME(message);
+ GError *error = NULL;
gst_message_parse_error(message, &error, NULL);
- libgnac_debug("An error occured for file %s", uri);
libgnac_debug("An error has occured:\n"
"\tFile: %s\n"
@@ -934,18 +879,17 @@ libgnac_converter_error_cb(GstBus *bus,
"\tError message: %s",
uri, out_uri, name, error->message);
+ gboolean restart = FALSE;
+
if (g_str_has_prefix(name, "giosink")) {
- libgnac_debug("Sink error");
/* flush the bus to avoid receiving the same message twice */
gst_bus_set_flushing(bus, TRUE);
restart = libgnac_converter_error_sink(item, message, uri, error);
/* restore the normal state of the bus */
gst_bus_set_flushing(bus, FALSE);
} else if (g_str_has_prefix(name, "giosrc")) {
- libgnac_debug("Source error");
restart = libgnac_converter_error_src(item, message, uri, error);
} else {
- libgnac_debug("Other error");
restart = libgnac_converter_error_other(item, message, uri, error);
}
@@ -953,15 +897,12 @@ libgnac_converter_error_cb(GstBus *bus,
g_free(uri);
g_free(out_uri);
- if (restart) {
- if (libgnac_converter_restart_current(item->parent)) {
- /* The restart was ok, do not send any signal and do not start next*/
- return;
- }
+ if (restart && libgnac_converter_restart_current(item->parent)) {
+ /* The restart was ok, do not send any signal and do not start next*/
+ return;
}
- if (!libgnac_converter_start_next(converter))
- {
+ if (!libgnac_converter_start_next(converter)) {
converter->priv->n_converted = -1;
g_signal_emit(converter, signals[COMPLETION], 0);
}
@@ -972,16 +913,11 @@ void
libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
gpointer data)
{
- LibgnacConverterPrivate *priv;
- LibgnacConverter *converter = NULL;
- LibgnacMediaItem *item = NULL;
- gchar *uri;
-
- converter = (LibgnacConverter*)data;
+ LibgnacConverter *converter = (LibgnacConverter *) data;
g_return_if_fail(LIBGNAC_IS_CONVERTER(converter));
- priv = converter->priv;
- item = priv->current;
+ LibgnacConverterPrivate *priv = converter->priv;
+ LibgnacMediaItem *item = priv->current;
if (result == GST_INSTALL_PLUGINS_SUCCESS ||
result == GST_INSTALL_PLUGINS_PARTIAL_SUCCESS)
@@ -996,9 +932,9 @@ libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
libgnac_debug("Failed to update GStreamer registry");
}
} else {
- uri = g_file_get_uri(item->source);
+ gchar *uri = g_file_get_uri(item->source);
g_signal_emit(converter, signals[ERROR], 0, uri,
- _("Unable to handle this format"), NULL);
+ _("Unable to handle this format"), NULL);
g_free(uri);
/* ask the user only once */
if (result == GST_INSTALL_PLUGINS_USER_ABORT ||
@@ -1008,8 +944,7 @@ libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
while ((key = g_queue_pop_head(priv->queue_copy))) {
item = g_hash_table_lookup(priv->file_table, key);
if (item) {
- gchar *uri;
- uri = g_file_get_uri(item->source);
+ gchar *uri = g_file_get_uri(item->source);
g_signal_emit(converter, signals[ERROR], 0, uri,
_("Unable to handle this format"), NULL);
g_free(uri);
@@ -1020,8 +955,7 @@ libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
}
}
- if (!libgnac_converter_start_next(converter))
- {
+ if (!libgnac_converter_start_next(converter)) {
converter->priv->n_converted = -1;
g_signal_emit(converter, signals[COMPLETION], 0);
}
@@ -1031,20 +965,8 @@ libgnac_converter_missing_plugin_result_cb(GstInstallPluginsReturn result,
gboolean
libgnac_converter_percentage_cb(LibgnacConverter *converter)
{
- gint64 pos = 0;
- gint64 len = 0;
- guint64 time_left = 0;
- GstState state;
- GstState pending_state;
- gfloat result = 0.0;
- LibgnacConverterPrivate *priv;
- LibgnacMediaItem *item = NULL;
-
- static GstFormat format = GST_FORMAT_TIME;
-
- priv = LIBGNAC_CONVERTER_GET_PRIVATE(converter);
- item = priv->current;
-
+ LibgnacConverterPrivate *priv = LIBGNAC_CONVERTER_GET_PRIVATE(converter);
+ LibgnacMediaItem *item = priv->current;
if (!item) return FALSE;
if (!GST_IS_ELEMENT(item->pipeline)) {
@@ -1052,6 +974,9 @@ libgnac_converter_percentage_cb(LibgnacConverter *converter)
return FALSE;
}
+ GstState state;
+ GstState pending_state;
+
gst_element_get_state(item->pipeline, &state, &pending_state, 0);
if (state == GST_STATE_PAUSED) {
@@ -1063,21 +988,27 @@ libgnac_converter_percentage_cb(LibgnacConverter *converter)
return FALSE;
}
- if (gst_element_query_position(item->pipeline, &format, &pos))
- {
- if (pos != item->pos)
- {
- if (gst_element_query_duration(item->pipeline, &format, &len))
- {
+ gint64 pos;
+ static GstFormat format = GST_FORMAT_TIME;
+
+ if (gst_element_query_position(item->pipeline, &format, &pos)) {
+ if (pos != item->pos) {
+ gint64 len;
+ gfloat result = 0.0f;
+ guint64 time_left = 0;
+
+ if (gst_element_query_duration(item->pipeline, &format, &len)) {
gfloat processed = priv->elapsed_duration + ((pos - len) / GST_SECOND);
- result = CLAMP((gfloat) processed / priv->total_duration, 0.0f, 1.0f);
+ result = CLAMP(processed / priv->total_duration, 0.0f, 1.0f);
/* XXX this is a workaround to prevent the remaining time
* to get crazy when we have to deal with mp3wraped files */
- if (priv->total_duration > processed)
- time_left = priv->total_duration - processed;
+ if (priv->total_duration > processed) {
+ time_left = priv->total_duration - processed;
+ }
}
- g_signal_emit(converter, signals[PROGRESS], 0,
- priv->n_converted+1, result, time_left);
+
+ g_signal_emit(converter, signals[PROGRESS], 0,
+ priv->n_converted+1, result, time_left);
}
}
diff --git a/libgnac/libgnac-error.c b/libgnac/libgnac-error.c
index f8f0605..6adf328 100644
--- a/libgnac/libgnac-error.c
+++ b/libgnac/libgnac-error.c
@@ -44,24 +44,22 @@ void
libgnac_error_handle_missing_plugin(LibgnacMediaItem *item,
const GError *error)
{
- gchar *detail;
- GstMessage *msg;
-
- msg = gst_missing_element_message_new(item->pipeline, error->message);
+ GstMessage *msg = gst_missing_element_message_new(item->pipeline,
+ error->message);
g_return_if_fail(msg);
- detail = gst_missing_plugin_message_get_installer_detail(msg);
+
+ gchar *detail = gst_missing_plugin_message_get_installer_detail(msg);
gst_message_unref(msg);
- if (detail) {
- GstInstallPluginsReturn ret;
- gchar *details[] = { detail, NULL };
- ret = gst_install_plugins_async(details, NULL,
- libgnac_converter_missing_plugin_result_cb, item->parent);
- g_free(detail);
- if (ret != GST_INSTALL_PLUGINS_STARTED_OK) {
- libgnac_warning("Could not launch installer for required plugins");
- } else {
- libgnac_converter_emit_plugin_install(item->parent);
- }
+ if (!detail) return;
+
+ gchar *details[] = { detail, NULL };
+ GstInstallPluginsReturn ret = gst_install_plugins_async(details, NULL,
+ libgnac_converter_missing_plugin_result_cb, item->parent);
+ g_free(detail);
+ if (ret != GST_INSTALL_PLUGINS_STARTED_OK) {
+ libgnac_warning("Could not launch installer for required plugins");
+ } else {
+ libgnac_converter_emit_plugin_install(item->parent);
}
}
@@ -88,12 +86,9 @@ static void
libgnac_error_emit_dest_file_exists_error(LibgnacMediaItem *item,
const gchar *uri)
{
- gchar *msg;
GError *err = NULL;
-
- libgnac_debug("Do not owerwrite file");
-
- msg = g_strdup_printf(_("Destination file %s already exists"), uri);
+ gchar *msg = g_strdup_printf(_("Destination file %s already exists"), uri);
+ libgnac_debug("%s", msg);
g_set_error_literal(&err, LIBGNAC_ERROR,
LIBGNAC_ERROR_FILE_EXISTS, msg);
g_signal_emit(item->parent, signals[ERROR], 0, uri, msg, err);
@@ -107,16 +102,13 @@ libgnac_error_handle_dest_file_already_exists(LibgnacMediaItem *item,
GstMessage *message,
gchar *uri)
{
- gchar *dst_path;
-
- dst_path = g_file_get_path(item->destination);
+ gchar *dst_path = g_file_get_path(item->destination);
if (!g_file_test(dst_path, G_FILE_TEST_EXISTS)) {
g_free(dst_path);
return FALSE;
}
- gchar *src_path;
- src_path = g_file_get_path(item->source);
+ gchar *src_path = g_file_get_path(item->source);
if (g_str_equal(dst_path, src_path)) {
const gchar *msg = _("Source and destination files are identical");
libgnac_debug(msg);
@@ -125,6 +117,7 @@ libgnac_error_handle_dest_file_already_exists(LibgnacMediaItem *item,
g_free(src_path);
return FALSE;
}
+
g_free(src_path);
if (!libgnac_error_handle_overwrite(item, uri)) {
diff --git a/libgnac/libgnac-gst-utils.c b/libgnac/libgnac-gst-utils.c
index 54ae6d2..673947b 100644
--- a/libgnac/libgnac-gst-utils.c
+++ b/libgnac/libgnac-gst-utils.c
@@ -40,20 +40,17 @@ libgnac_gstu_make_pipeline_element(GstElement *bin,
const gchar *name,
GError **error)
{
- GstElement *elem;
-
- elem = gst_element_factory_make(element, name);
+ GstElement *elem = gst_element_factory_make(element, name);
if (!elem) {
libgnac_debug("Failed to create %s element", element);
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_MISSING_PLUGIN, "%s", element);
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_MISSING_PLUGIN,
+ "%s", element);
return NULL;
}
if (!gst_bin_add(GST_BIN(bin), elem)) {
libgnac_debug("Failed to add %s element to the bin", element);
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Failed to add %s element"), element);
return NULL;
}
@@ -65,13 +62,10 @@ libgnac_gstu_make_pipeline_element(GstElement *bin,
GstElement *
libgnac_gstu_pipeline_new(GError **error)
{
- GstElement *pipeline;
-
- pipeline = gst_pipeline_new("pipeline");
+ GstElement *pipeline = gst_pipeline_new("pipeline");
if (!pipeline) {
libgnac_warning("Pipeline creation failed");
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Unable to create pipeline"));
return NULL;
}
@@ -88,8 +82,7 @@ libgnac_gstu_bin_add(GstElement *bin,
if (!gst_bin_add(GST_BIN(bin), elem)) {
gchar *name = gst_element_get_name(elem);
libgnac_debug("Failed to add %s element to the bin", name);
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Failed to add %s element"), name);
g_free(name);
return FALSE;
@@ -104,14 +97,11 @@ libgnac_gstu_element_link(GstElement *src,
GstElement *dst,
GError **error)
{
- gboolean ret;
-
- ret = gst_element_link(src, dst);
+ gboolean ret = gst_element_link(src, dst);
if (!ret) {
libgnac_debug("Failed to link element %s to %s",
gst_element_get_name(src), gst_element_get_name(dst));
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Unable to link element %s to %s"),
gst_element_get_name(src), gst_element_get_name(dst));
}
@@ -125,14 +115,11 @@ libgnac_gstu_pad_link(GstPad *src,
GstPad *sink,
GError **error)
{
- GstPadLinkReturn ret;
-
- ret = gst_pad_link(src, sink);
+ GstPadLinkReturn ret = gst_pad_link(src, sink);
if (ret != GST_PAD_LINK_OK) {
libgnac_debug("Failed to link pad %s to %s",
gst_pad_get_name(src), gst_pad_get_name(sink));
- g_set_error(error, LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Unable to link pad %s to %s"),
gst_pad_get_name(src), gst_pad_get_name(sink));
}
@@ -147,13 +134,9 @@ libgnac_gstu_get_compatible_pad(GstElement *element,
GstCaps *caps,
const gchar *type)
{
- gchar *pad_name;
- gchar *sink_pad_name;
- GstPad *sink_pad;
-
- pad_name = gst_pad_get_name(pad);
+ gchar *pad_name = gst_pad_get_name(pad);
- sink_pad = gst_element_get_compatible_pad(element, pad, caps);
+ GstPad *sink_pad = gst_element_get_compatible_pad(element, pad, caps);
if (!sink_pad) {
gchar *caps_str = gst_caps_to_string(caps);
libgnac_debug("Unable to find a compatible %s pad "
@@ -164,7 +147,7 @@ libgnac_gstu_get_compatible_pad(GstElement *element,
return FALSE;
}
- sink_pad_name = gst_pad_get_name(sink_pad);
+ gchar *sink_pad_name = gst_pad_get_name(sink_pad);
libgnac_debug("%s: %s -> %s", type, pad_name, sink_pad_name);
diff --git a/libgnac/libgnac-gst.c b/libgnac/libgnac-gst.c
index 32baa45..567422b 100644
--- a/libgnac/libgnac-gst.c
+++ b/libgnac/libgnac-gst.c
@@ -82,11 +82,10 @@ libgnac_gst_parse_error_missing_elem(GstParseContext *ctx,
if (g_error_matches(*error, GST_PARSE_ERROR,
GST_PARSE_ERROR_NO_SUCH_ELEMENT))
{
- gchar **missing;
/* clean up the "old" error */
g_clear_error(error);
/* get the name of the missing elements */
- missing = gst_parse_context_get_missing_elements(ctx);
+ gchar **missing = gst_parse_context_get_missing_elements(ctx);
libgnac_debug("Failed to parse description: %s", descr);
/* set the "new" error */
g_set_error(error, LIBGNAC_ERROR,
@@ -103,45 +102,40 @@ libgnac_gst_get_audio_bin(LibgnacMediaItem *item,
LibgnacProfile *profile,
GError **error)
{
- GstElement *bin;
- GstElement *conv;
- GstElement *enc;
- GstElement *rate;
- GstElement *resample;
- GstPad *pad;
- GstParseContext *ctx;
+ GstElement *bin = gst_bin_new("audio_bin");
- bin = gst_bin_new("audio_bin");
+ GstElement *converter = libgnac_gstu_make_pipeline_element(bin,
+ "audioconvert", NULL, error);
+ g_return_val_if_fail(converter, NULL);
- conv = libgnac_gstu_make_pipeline_element(bin, "audioconvert", NULL, error);
- g_return_val_if_fail(conv, NULL);
-
- resample = libgnac_gstu_make_pipeline_element(bin, "audioresample",
- NULL, error);
+ GstElement *resample = libgnac_gstu_make_pipeline_element(bin,
+ "audioresample", NULL, error);
g_return_val_if_fail(resample, NULL);
- rate = libgnac_gstu_make_pipeline_element(bin, "audiorate", NULL, error);
+ GstElement *rate = libgnac_gstu_make_pipeline_element(bin,
+ "audiorate", NULL, error);
g_return_val_if_fail(rate, NULL);
- ctx = gst_parse_context_new();
- enc = gst_parse_bin_from_description_full(profile->audio_desc, TRUE, ctx,
- GST_PARSE_FLAG_NONE, error);
- if (!enc) {
- libgnac_gst_parse_error_missing_elem(ctx, profile->audio_desc, error);
+ GstParseContext *context = gst_parse_context_new();
+
+ GstElement *encoder = gst_parse_bin_from_description_full(
+ profile->audio_desc, TRUE, context, GST_PARSE_FLAG_NONE, error);
+ if (!encoder) {
+ libgnac_gst_parse_error_missing_elem(context, profile->audio_desc, error);
return NULL;
}
- g_return_val_if_fail(gst_bin_add(GST_BIN(bin), enc), NULL);
+ g_return_val_if_fail(gst_bin_add(GST_BIN(bin), encoder), NULL);
g_return_val_if_fail(
- gst_element_link_many(conv, resample, rate, enc, NULL),
+ gst_element_link_many(converter, resample, rate, encoder, NULL),
NULL);
/* ghost pads */
- pad = gst_element_get_static_pad(conv, "sink");
+ GstPad *pad = gst_element_get_static_pad(converter, "sink");
libgnac_gst_element_add_ghost_pad(bin, pad, "sink");
gst_object_unref(pad);
- pad = gst_element_get_static_pad(enc, "src");
+ pad = gst_element_get_static_pad(encoder, "src");
libgnac_gst_element_add_ghost_pad(bin, pad, "src");
gst_object_unref(pad);
@@ -154,41 +148,36 @@ libgnac_gst_get_video_bin(LibgnacMediaItem *item,
LibgnacProfile *profile,
GError **error)
{
- GstElement *bin;
- GstElement *conv;
- GstElement *enc;
- GstElement *rate;
- GstPad *pad;
- GstParseContext *ctx;
+ GstElement *bin = gst_bin_new("video_bin");
- bin = gst_bin_new("video_bin");
+ GstElement *converter = libgnac_gstu_make_pipeline_element(bin,
+ "ffmpegcolorspace", NULL, error);
+ g_return_val_if_fail(converter, NULL);
- conv = libgnac_gstu_make_pipeline_element(bin, "ffmpegcolorspace",
- NULL, error);
- g_return_val_if_fail(conv, NULL);
-
- rate = libgnac_gstu_make_pipeline_element(bin, "videorate", NULL, error);
+ GstElement *rate = libgnac_gstu_make_pipeline_element(bin,
+ "videorate", NULL, error);
g_return_val_if_fail(rate, NULL);
- ctx = gst_parse_context_new();
- enc = gst_parse_bin_from_description_full(profile->video_desc, TRUE, ctx,
- GST_PARSE_FLAG_NONE, error);
- if (!enc) {
- libgnac_gst_parse_error_missing_elem(ctx, profile->video_desc, error);
+ GstParseContext *context = gst_parse_context_new();
+
+ GstElement *encoder = gst_parse_bin_from_description_full(
+ profile->video_desc, TRUE, context, GST_PARSE_FLAG_NONE, error);
+ if (!encoder) {
+ libgnac_gst_parse_error_missing_elem(context, profile->video_desc, error);
return NULL;
}
- g_return_val_if_fail(gst_bin_add(GST_BIN(bin), enc), NULL);
+ g_return_val_if_fail(gst_bin_add(GST_BIN(bin), encoder), NULL);
g_return_val_if_fail(
- gst_element_link_many(conv, rate, enc, NULL),
+ gst_element_link_many(converter, rate, encoder, NULL),
NULL);
/* ghost pads */
- pad = gst_element_get_static_pad(conv, "sink");
+ GstPad *pad = gst_element_get_static_pad(converter, "sink");
libgnac_gst_element_add_ghost_pad(bin, pad, "video_sink");
gst_object_unref(pad);
- pad = gst_element_get_static_pad(enc, "src");
+ pad = gst_element_get_static_pad(encoder, "src");
libgnac_gst_element_add_ghost_pad(bin, pad, "src");
gst_object_unref(pad);
@@ -202,151 +191,141 @@ libgnac_gst_build_pipeline(LibgnacMediaItem *item,
gboolean has_video,
GError **error)
{
- GError *encoder_error = NULL;
- GstElement *source = NULL;
- GstElement *decodebin;
- GstElement *sink = NULL;
- GstElement *audio_bin;
-
g_return_if_fail(!error || !*error);
+ GError *err = NULL;
+
/* pipeline */
- item->pipeline = libgnac_gstu_pipeline_new(&encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ item->pipeline = libgnac_gstu_pipeline_new(&err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
-
/* bus */
item->bus = gst_element_get_bus(GST_ELEMENT(item->pipeline));
gst_bus_add_signal_watch(item->bus);
- /* source */
- source = libgnac_gstu_make_pipeline_element(item->pipeline, "giosrc", NULL,
- &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ /* source */
+ GstElement *source = libgnac_gstu_make_pipeline_element(item->pipeline,
+ "giosrc", NULL, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
+
g_object_set(G_OBJECT(source), "file", item->source, NULL);
/* decodebin */
- decodebin = libgnac_gstu_make_pipeline_element(item->pipeline, "decodebin",
- NULL, &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ GstElement *decodebin = libgnac_gstu_make_pipeline_element(item->pipeline,
+ "decodebin", NULL, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
- libgnac_gstu_element_link(source, decodebin, &encoder_error);
- if (encoder_error) {
+ libgnac_gstu_element_link(source, decodebin, &err);
+ if (err) {
libgnac_debug("link source->decodebin failed");
- g_propagate_error(error, encoder_error);
+ g_propagate_error(error, err);
return;
}
/* audio_bin */
- audio_bin = libgnac_gst_get_audio_bin(item, profile, &encoder_error);
- if (encoder_error) {
+ GstElement *audio_bin = libgnac_gst_get_audio_bin(item, profile, &err);
+ if (err) {
libgnac_debug("audio_bin creation failed");
- g_propagate_error(error, encoder_error);
+ g_propagate_error(error, err);
return;
}
item->audio_encoder = audio_bin;
- libgnac_gstu_bin_add(item->pipeline, audio_bin, &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ libgnac_gstu_bin_add(item->pipeline, audio_bin, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
/* sink */
- sink = libgnac_gstu_make_pipeline_element(item->pipeline, "giosink", NULL,
- &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ GstElement *sink = libgnac_gstu_make_pipeline_element(item->pipeline,
+ "giosink", NULL, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
- g_object_set(G_OBJECT(sink), "file", item->destination, NULL);
- if (has_video && item->video_channel != -1)
- {
- GstElement *audio_queue;
- GstElement *mux;
- GstElement *video_bin;
- GstElement *video_queue;
+ g_object_set(G_OBJECT(sink), "file", item->destination, NULL);
+ if (has_video && item->video_channel != -1) {
/* muxer */
- mux = libgnac_gstu_make_pipeline_element(item->pipeline, profile->muxer_desc,
- NULL, &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ GstElement *muxer = libgnac_gstu_make_pipeline_element(item->pipeline,
+ profile->muxer_desc, NULL, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
- item->muxer = mux;
- libgnac_gstu_element_link(mux, sink, &encoder_error);
- if (encoder_error) {
+ item->muxer = muxer;
+
+ libgnac_gstu_element_link(muxer, sink, &err);
+ if (err) {
libgnac_debug("link encoder->sink failed");
- g_propagate_error(error, encoder_error);
+ g_propagate_error(error, err);
return;
}
/* audio */
- audio_queue = libgnac_gstu_make_pipeline_element(item->pipeline, "queue",
- "audio_queue", &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ GstElement *audio_queue = libgnac_gstu_make_pipeline_element(item->pipeline,
+ "queue", "audio_queue", &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
+
item->audio_encoder = audio_queue;
- if (!gst_element_link_many(audio_queue, audio_bin, mux, NULL)) {
- g_set_error(error,
- LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ if (!gst_element_link_many(audio_queue, audio_bin, muxer, NULL)) {
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Failed to link many audio elements"));
return;
}
/* video */
- video_queue = libgnac_gstu_make_pipeline_element(item->pipeline, "queue",
- "video_queue", &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ GstElement *video_queue = libgnac_gstu_make_pipeline_element(item->pipeline,
+ "queue", "video_queue", &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
+
item->video_encoder = video_queue;
- video_bin = libgnac_gst_get_video_bin(item, profile, &encoder_error);
- if (encoder_error) {
+ GstElement *video_bin = libgnac_gst_get_video_bin(item, profile, &err);
+ if (err) {
libgnac_debug("video_bin creation failed");
- g_propagate_error(error, encoder_error);
+ g_propagate_error(error, err);
return;
}
- libgnac_gstu_bin_add(item->pipeline, video_bin, &encoder_error);
- if (encoder_error) {
- g_propagate_error(error, encoder_error);
+ libgnac_gstu_bin_add(item->pipeline, video_bin, &err);
+ if (err) {
+ g_propagate_error(error, err);
return;
}
- if (!gst_element_link_many(video_queue, video_bin, mux, NULL)) {
- g_set_error(error,
- LIBGNAC_ERROR,
- LIBGNAC_ERROR_PIPELINE_CREATION,
+ if (!gst_element_link_many(video_queue, video_bin, muxer, NULL)) {
+ g_set_error(error, LIBGNAC_ERROR, LIBGNAC_ERROR_PIPELINE_CREATION,
_("Failed to link many video elements"));
return;
}
}
else /* audio file */
{
- libgnac_gstu_element_link(audio_bin, sink, &encoder_error);
- if (encoder_error) {
+ libgnac_gstu_element_link(audio_bin, sink, &err);
+ if (err) {
libgnac_debug("link encoder->sink failed");
- g_propagate_error(error, encoder_error);
+ g_propagate_error(error, err);
return;
}
}
@@ -362,8 +341,7 @@ libgnac_gst_clean_pipeline(LibgnacMediaItem *item)
if (!item) return;
if (item->pipeline) {
- if (!gst_element_set_state(item->pipeline, GST_STATE_NULL))
- {
+ if (!gst_element_set_state(item->pipeline, GST_STATE_NULL)) {
libgnac_debug("Unable to set state to null");
return;
}
@@ -387,13 +365,8 @@ libgnac_gst_newpad_cb(GstElement *decodebin,
gboolean last,
gpointer data)
{
- const gchar *mimetype;
- GstCaps *caps;
- GstStructure *structure;
- LibgnacMediaItem *item;
-
- item = (LibgnacMediaItem *) data;
- caps = gst_pad_get_caps(pad);
+ LibgnacMediaItem *item = (LibgnacMediaItem *) data;
+ GstCaps *caps = gst_pad_get_caps(pad);
if (gst_caps_is_empty(caps) || gst_caps_is_any(caps)) {
libgnac_debug("Got a bad caps: %s", gst_caps_to_string(caps));
@@ -401,8 +374,8 @@ libgnac_gst_newpad_cb(GstElement *decodebin,
return;
}
- structure = gst_caps_get_structure(caps, 0);
- mimetype = gst_structure_get_name(structure);
+ GstStructure *structure = gst_caps_get_structure(caps, 0);
+ const gchar *mimetype = gst_structure_get_name(structure);
if (g_str_has_prefix(mimetype, "audio/")) {
if (!libgnac_gstu_get_compatible_pad(item->audio_encoder, pad,
@@ -419,7 +392,7 @@ libgnac_gst_newpad_cb(GstElement *decodebin,
return;
}
} else {
- /* unhandled mimetype */
+ libgnac_debug("Unhandled mime-type: %s", mimetype);
}
gst_caps_unref(caps);
diff --git a/libgnac/libgnac-media-item.c b/libgnac/libgnac-media-item.c
index 5a88d0d..5754bb4 100644
--- a/libgnac/libgnac-media-item.c
+++ b/libgnac/libgnac-media-item.c
@@ -49,9 +49,8 @@ libgnac_item_new(GFile *source,
LibgnacProfile *profile,
gpointer parent)
{
- LibgnacMediaItem *item;
-
- item = (LibgnacMediaItem*)g_malloc(sizeof(LibgnacMediaItem));
+ LibgnacMediaItem *item = (LibgnacMediaItem *)
+ g_malloc(sizeof(LibgnacMediaItem));
item->parent = parent;
item->source = g_file_dup(source);
@@ -72,18 +71,16 @@ void
libgnac_item_build(LibgnacMediaItem *item,
GError **error)
{
- g_return_if_fail(error == NULL || *error == NULL);
-
- gboolean has_video = FALSE;
- GError *err = NULL;
- LibgnacOutputConfig *config;
+ g_return_if_fail(!error || !*error);
- config = libgnac_converter_get_config(item->parent);
+ LibgnacOutputConfig *config = libgnac_converter_get_config(item->parent);
if (item->destination) {
g_object_unref(item->destination);
item->destination = NULL;
}
+
+ GError *err = NULL;
item->destination = libgnac_output_build_output(item->source, config, &err);
libgnac_converter_free_config(config);
@@ -94,7 +91,7 @@ libgnac_item_build(LibgnacMediaItem *item,
return;
}
- has_video = libgnac_item_has_video(item);
+ gboolean has_video = libgnac_item_has_video(item);
libgnac_gst_build_pipeline(item, item->profile, has_video, &err);
if (err) {
@@ -128,11 +125,11 @@ libgnac_item_build(LibgnacMediaItem *item,
static gboolean
libgnac_item_has_video(LibgnacMediaItem *item)
{
- LibgnacTags *tags;
- tags = libgnac_metadata_extract(metadata, item->source, NULL);
+ LibgnacTags *tags = libgnac_metadata_extract(metadata, item->source, NULL);
if (tags && libgnac_metadata_tag_exists(tags, GNAC_TAG_HAS_VIDEO)) {
return TRUE;
}
+
return FALSE;
}
@@ -141,13 +138,13 @@ void
libgnac_item_run(LibgnacMediaItem *item,
GError **error)
{
+ g_return_if_fail(!error || !*error);
+
GError *err = NULL;
- g_return_if_fail(error == NULL || *error == NULL);
/* Build pipeline if doesn't exist */
libgnac_item_build(item, &err);
- if(err)
- {
+ if(err) {
g_propagate_error(error, err);
return;
}
@@ -168,17 +165,17 @@ void
libgnac_item_stop(LibgnacMediaItem *item,
GError **error)
{
- GError *err = NULL;
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_if_fail(!error || !*error);
if (!item) return;
+ GError *err = NULL;
+
libgnac_item_clear_event_src(item);
libgnac_gst_stop(item, &err);
/* Remove not completed file */
- if (G_IS_FILE(item->destination))
- {
+ if (G_IS_FILE(item->destination)) {
g_file_delete(item->destination, NULL, &err);
if (err) {
libgnac_warning("Unable to remove partial file");
@@ -214,7 +211,7 @@ void
libgnac_item_init_event_src(LibgnacMediaItem *item)
{
item->timeout_id = g_timeout_add(PROGRESS_TIMEOUT,
- (GSourceFunc)libgnac_converter_percentage_cb, item->parent);
+ (GSourceFunc) libgnac_converter_percentage_cb, item->parent);
}
@@ -236,9 +233,7 @@ libgnac_item_eos_cb(GstBus *bus,
GstMessage *message,
gpointer data)
{
- LibgnacMediaItem *item;
-
- item = (LibgnacMediaItem*)data;
+ LibgnacMediaItem *item = (LibgnacMediaItem *) data;
libgnac_item_clear_event_src(item);
libgnac_gst_clean_pipeline(item);
}
@@ -249,8 +244,6 @@ libgnac_item_error_cb(GstBus *bus,
GstMessage *message,
gpointer data)
{
- LibgnacMediaItem *item;
-
- item = (LibgnacMediaItem*)data;
+ LibgnacMediaItem *item = (LibgnacMediaItem *) data;
libgnac_item_clear_event_src(item);
}
diff --git a/libgnac/libgnac-metadata.c b/libgnac/libgnac-metadata.c
index 1286548..e559378 100644
--- a/libgnac/libgnac-metadata.c
+++ b/libgnac/libgnac-metadata.c
@@ -67,8 +67,7 @@ libgnac_metadata_destroy_pipeline(LibgnacMetadata *md)
{
if (!md->priv->pipeline) return;
- GstBus *bus;
- bus = gst_element_get_bus(md->priv->pipeline);
+ GstBus *bus = gst_element_get_bus(md->priv->pipeline);
gst_element_set_state(md->priv->pipeline, GST_STATE_NULL);
gst_bus_set_sync_handler(bus, NULL, NULL);
gst_object_unref(GST_OBJECT(bus));
@@ -122,8 +121,7 @@ libgnac_metadata_finalize(GObject *object)
static void
libgnac_metadata_class_init(LibgnacMetadataClass *klass)
{
- GObjectClass *object_class;
- object_class = G_OBJECT_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(LibgnacMetadataPrivate));
@@ -138,7 +136,7 @@ libgnac_metadata_init(LibgnacMetadata *md)
LibgnacMetadataPrivate *priv = md->priv = LIBGNAC_METADATA_GET_PRIVATE(md);
priv->tags_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- (GDestroyNotify)libgnac_metadata_tags_free);
+ (GDestroyNotify) libgnac_metadata_tags_free);
}
@@ -177,24 +175,19 @@ libgnac_metadata_process_tag_image(const GstTagList *taglist,
{
gint i;
for (i = 0; i < count; i++) {
- const GValue *val;
- gint image_type;
- GstBuffer *buffer;
-
- val = gst_tag_list_get_value_index(taglist, tag_name, i);
+ const GValue *val = gst_tag_list_get_value_index(taglist, tag_name, i);
- buffer = gst_value_get_buffer(val);
+ GstBuffer *buffer = gst_value_get_buffer(val);
g_return_if_fail(buffer);
+ gint image_type;
+
/* GST_TAG_PREVIEW_IMAGE does not have an "image-type" field */
if (g_str_equal(tag_name, GST_TAG_IMAGE)) {
- GstCaps *caps;
- GstStructure *structure;
-
- caps = GST_BUFFER_CAPS(buffer);
+ GstCaps *caps = GST_BUFFER_CAPS(buffer);
g_return_if_fail(caps);
- structure = gst_caps_get_structure(caps, 0);
+ GstStructure *structure = gst_caps_get_structure(caps, 0);
g_return_if_fail(structure);
gst_structure_get_enum(structure, "image-type",
@@ -207,20 +200,15 @@ libgnac_metadata_process_tag_image(const GstTagList *taglist,
(image_type == GST_TAG_IMAGE_TYPE_FRONT_COVER) ||
(image_type == GST_TAG_IMAGE_TYPE_UNDEFINED && count == 1))
{
- GdkPixbuf *pixbuf;
- GdkPixbufLoader *loader;
- GError *error = NULL;
- guint size;
- guint8 *data;
- GValue *newval;
-
- loader = gdk_pixbuf_loader_new();
+ GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
g_signal_connect(loader, "size-prepared",
G_CALLBACK(libgnac_metadata_size_prepared_cb), NULL);
- data = GST_BUFFER_DATA(buffer);
- size = GST_BUFFER_SIZE(buffer);
+ guint8 *data = GST_BUFFER_DATA(buffer);
+ guint size = GST_BUFFER_SIZE(buffer);
+
+ GError *error = NULL;
if (!gdk_pixbuf_loader_write(loader, data, size, &error)) {
libgnac_debug("Error writing data to pixbuf: %s", error->message);
@@ -235,10 +223,10 @@ libgnac_metadata_process_tag_image(const GstTagList *taglist,
return;
}
- pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
g_return_if_fail(pixbuf);
- newval = g_new0(GValue, 1);
+ GValue *newval = g_new0(GValue, 1);
g_value_init(newval, G_TYPE_OBJECT);
g_value_set_object(newval, pixbuf);
@@ -256,22 +244,16 @@ libgnac_metadata_process_tag_value(GstStructure *structure,
gchar *tag_name,
LibgnacMetadata *md)
{
- const GValue *val;
-
- val = gst_structure_get_value(structure, tag_name);
+ const GValue *val = gst_structure_get_value(structure, tag_name);
if (!val) return;
if (GST_VALUE_HOLDS_FRACTION(val)) {
- GValue *newval;
- gint numerator;
- gint denominator;
-
- numerator = gst_value_get_fraction_numerator(val);
- denominator = gst_value_get_fraction_denominator(val);
+ gint numerator = gst_value_get_fraction_numerator(val);
+ gint denominator = gst_value_get_fraction_denominator(val);
- newval = g_new0(GValue, 1);
+ GValue *newval = g_new0(GValue, 1);
g_value_init(newval, G_TYPE_FLOAT);
- g_value_set_float(newval, (gfloat)numerator/denominator);
+ g_value_set_float(newval, (gfloat) numerator / denominator);
g_hash_table_insert(md->priv->metadata, tag_name, newval);
}
}
@@ -284,8 +266,7 @@ libgnac_metadata_process_tag_int(GstStructure *structure,
{
gint int_val;
if (gst_structure_get_int(structure, tag_name, &int_val)) {
- GValue *val;
- val = g_new0(GValue, 1);
+ GValue *val = g_new0(GValue, 1);
g_value_init(val, G_TYPE_INT);
g_value_set_int(val, int_val);
g_hash_table_insert(md->priv->metadata, tag_name, val);
@@ -298,12 +279,7 @@ libgnac_metadata_process_tag(const GstTagList *taglist,
const gchar *tag_name,
LibgnacMetadata *md)
{
- gint count;
- GValue *newval;
- const GValue *val;
- GType type;
-
- count = gst_tag_list_get_tag_size(taglist, tag_name);
+ gint count = gst_tag_list_get_tag_size(taglist, tag_name);
if (count < 1) return;
if (g_str_equal(tag_name, GST_TAG_IMAGE) ||
@@ -313,9 +289,9 @@ libgnac_metadata_process_tag(const GstTagList *taglist,
return;
}
- val = gst_tag_list_get_value_index(taglist, tag_name, 0);
- type = gst_tag_get_type(tag_name);
- newval = g_new0(GValue, 1);
+ const GValue *val = gst_tag_list_get_value_index(taglist, tag_name, 0);
+ GType type = gst_tag_get_type(tag_name);
+ GValue *newval = g_new0(GValue, 1);
g_value_init(newval, type);
if (!g_value_transform(val, newval)) {
libgnac_metadata_free_gvalue(newval);
@@ -323,10 +299,8 @@ libgnac_metadata_process_tag(const GstTagList *taglist,
}
if (type == G_TYPE_STRING) {
- gchar *str;
- str = g_value_dup_string(newval);
- if (!g_utf8_validate(str, -1, NULL))
- {
+ gchar *str = g_value_dup_string(newval);
+ if (!g_utf8_validate(str, -1, NULL)) {
libgnac_info("%s: %s", _("Invalid UTF-8 tag"), tag_name);
g_free(str);
libgnac_metadata_free_gvalue(newval);
@@ -336,17 +310,15 @@ libgnac_metadata_process_tag(const GstTagList *taglist,
g_value_take_string(newval, str);
}
- if (g_str_equal(tag_name, GST_TAG_BITRATE))
+ if (g_str_equal(tag_name, GST_TAG_BITRATE))
{
- guint32 bitrate;
- bitrate = g_value_get_uint(newval);
+ guint32 bitrate = g_value_get_uint(newval);
g_value_set_uint(newval, bitrate);
- if (libgnac_metadata_tag_exists(md->priv->metadata, (gpointer)tag_name)) {
- guint32 old;
- old = g_value_get_uint(LIBGNAC_METADATA_TAG_BITRATE(md->priv->metadata));
- if (bitrate != old) {
- GValue *vbr;
- vbr = g_new0(GValue, 1);
+ if (libgnac_metadata_tag_exists(md->priv->metadata, tag_name)) {
+ guint32 old_bitrate = g_value_get_uint(
+ LIBGNAC_METADATA_TAG_BITRATE(md->priv->metadata));
+ if (bitrate != old_bitrate) {
+ GValue *vbr = g_new0(GValue, 1);
g_value_init(vbr, G_TYPE_UINT);
g_value_set_uint(vbr, bitrate);
g_hash_table_insert(md->priv->metadata, GNAC_TAG_VBR, vbr);
@@ -355,10 +327,9 @@ libgnac_metadata_process_tag(const GstTagList *taglist,
}
else if (g_str_equal(tag_name, GST_TAG_DURATION))
{
- guint64 duration;
- duration = g_value_get_uint64(newval);
+ guint64 duration = g_value_get_uint64(newval);
/* convert the duration from ns to seconds */
- g_value_set_uint64(newval, duration/GST_SECOND);
+ g_value_set_uint64(newval, duration / GST_SECOND);
}
else if (g_str_equal(tag_name, GST_TAG_DATE))
{
@@ -416,7 +387,7 @@ libgnac_metadata_on_message_tag(GstBus *bus,
gst_message_parse_tag(message, &taglist);
if (GST_IS_TAG_LIST(taglist)) {
gst_tag_list_foreach(taglist,
- (GstTagForeachFunc)libgnac_metadata_process_tag, md);
+ (GstTagForeachFunc) libgnac_metadata_process_tag, md);
gst_tag_list_free(taglist);
}
}
@@ -468,12 +439,7 @@ libgnac_metadata_new_decoded_pad_cb(GstElement *element,
gboolean last,
LibgnacMetadata *md)
{
- GstCaps *caps;
- GstPad *sink_pad;
- GstStructure *structure;
- const gchar *mimetype;
-
- sink_pad = gst_element_get_pad(md->priv->sink, "sink");
+ GstPad *sink_pad = gst_element_get_pad(md->priv->sink, "sink");
if (GST_PAD_IS_LINKED(sink_pad)) {
g_object_unref(sink_pad);
return;
@@ -482,20 +448,19 @@ libgnac_metadata_new_decoded_pad_cb(GstElement *element,
g_return_if_fail(
libgnac_gstu_pad_link(pad, sink_pad, NULL) == GST_PAD_LINK_OK);
- caps = gst_pad_get_caps(pad);
+ GstCaps *caps = gst_pad_get_caps(pad);
if (gst_caps_is_empty(caps) || gst_caps_is_any(caps)) {
gst_caps_unref(caps);
g_object_unref(sink_pad);
return;
}
- structure = gst_caps_get_structure(caps, 0);
- mimetype = gst_structure_get_name(structure);
+ GstStructure *structure = gst_caps_get_structure(caps, 0);
+ const gchar *mimetype = gst_structure_get_name(structure);
if (g_str_has_prefix(mimetype, "video"))
{
- GValue *val;
- val = g_new0(GValue, 1);
+ GValue *val = g_new0(GValue, 1);
g_value_init(val, G_TYPE_BOOLEAN);
g_value_set_boolean(val, TRUE);
g_hash_table_insert(md->priv->metadata, GNAC_TAG_HAS_VIDEO, val);
@@ -516,15 +481,12 @@ libgnac_metadata_autoplug_continue_cb(GstElement *decodebin,
GstCaps *caps,
LibgnacMetadata *md)
{
- const gchar *mimetype;
- GstStructure *structure;
-
g_return_val_if_fail(LIBGNAC_IS_METADATA(md), TRUE);
if (!gst_caps_is_fixed(caps)) return TRUE;
- structure = gst_caps_get_structure(caps, 0);
- mimetype = gst_structure_get_name(structure);
+ GstStructure *structure = gst_caps_get_structure(caps, 0);
+ const gchar *mimetype = gst_structure_get_name(structure);
libgnac_metadata_process_tag_int(structure, GNAC_TAG_RATE, md);
libgnac_metadata_process_tag_int(structure, GNAC_TAG_CHANNELS, md);
@@ -542,15 +504,9 @@ libgnac_metadata_autoplug_continue_cb(GstElement *decodebin,
static void
libgnac_metadata_get_file_info(GFile *uri, LibgnacMetadata *md)
{
- gchar *path;
- GError *error = NULL;
- GFileInfo *info;
- GValue *file_size_value;
- GValue *filename_value;
- GValue *location_value;
- const gchar *thumbnail_path;
-
- info = g_file_query_info(uri,
+ GError *error = NULL;
+
+ GFileInfo *info = g_file_query_info(uri,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_ICON ","
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
@@ -563,39 +519,36 @@ libgnac_metadata_get_file_info(GFile *uri, LibgnacMetadata *md)
}
/* file size */
- file_size_value = g_new0(GValue, 1);
+ GValue *file_size_value = g_new0(GValue, 1);
g_value_init(file_size_value, G_TYPE_INT64);
g_value_set_int64(file_size_value, g_file_info_get_size(info));
g_hash_table_insert(md->priv->metadata, GNAC_TAG_FILE_SIZE, file_size_value);
/* location */
- path = g_file_get_path(uri);
- location_value = g_new0(GValue, 1);
+ gchar *path = g_file_get_path(uri);
+ GValue *location_value = g_new0(GValue, 1);
g_value_init(location_value, G_TYPE_STRING);
g_value_set_string(location_value, path);
+ g_free(path);
g_hash_table_insert(md->priv->metadata, GST_TAG_LOCATION, location_value);
/* filename */
- filename_value = g_new0(GValue, 1);
+ GValue *filename_value = g_new0(GValue, 1);
g_value_init(filename_value, G_TYPE_STRING);
g_value_set_string(filename_value, g_file_info_get_display_name(info));
g_hash_table_insert(md->priv->metadata, GNAC_TAG_FILENAME, filename_value);
/* image */
- thumbnail_path = g_file_info_get_attribute_byte_string(info,
+ const gchar *thumbnail_path = g_file_info_get_attribute_byte_string(info,
G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path) {
- GdkPixbuf *pixbuf;
- GValue *value;
- pixbuf = gdk_pixbuf_new_from_file(thumbnail_path, NULL);
- value = g_new0(GValue, 1);
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(thumbnail_path, NULL);
+ GValue *value = g_new0(GValue, 1);
g_value_init(value, G_TYPE_OBJECT);
g_value_set_object(value, pixbuf);
g_hash_table_insert(md->priv->metadata, GST_TAG_IMAGE, value);
}
- /* cleanup */
- g_free(path);
g_object_unref(info);
}
@@ -608,19 +561,10 @@ libgnac_metadata_extract(LibgnacMetadata *md,
g_return_val_if_fail(LIBGNAC_IS_METADATA(md), NULL);
g_return_val_if_fail(uri, NULL);
- gchar *string_uri;
- GError *metadata_error = NULL;
- LibgnacTags *tags = NULL;
-
- string_uri = g_file_get_uri(uri);
- tags = g_hash_table_lookup(md->priv->tags_table, string_uri);
+ gchar *string_uri = g_file_get_uri(uri);
+ LibgnacTags *tags = g_hash_table_lookup(md->priv->tags_table, string_uri);
if (!tags) {
- GstElement *pipeline = NULL;
- GstElement *source = NULL;
- GstElement *decodebin = NULL;
- GstBus *bus;
-
/* make sure we start with a clean base */
libgnac_metadata_reset(md);
@@ -632,30 +576,33 @@ libgnac_metadata_extract(LibgnacMetadata *md,
/* store file-size, location and filename */
libgnac_metadata_get_file_info(uri, md);
- pipeline = libgnac_gstu_pipeline_new(&metadata_error);
+ GError *metadata_error = NULL;
+
+ GstElement *pipeline = libgnac_gstu_pipeline_new(&metadata_error);
if (metadata_error) {
g_propagate_error(error, metadata_error);
return NULL;
}
- source = libgnac_gstu_make_pipeline_element(pipeline, "giosrc",
- NULL, &metadata_error);
+ GstElement *source = libgnac_gstu_make_pipeline_element(pipeline,
+ "giosrc", NULL, &metadata_error);
if (metadata_error) {
libgnac_debug("source creation failed");
g_propagate_error(error, metadata_error);
return NULL;
}
+
g_object_set(G_OBJECT(source), "file", md->priv->uri, NULL);
- decodebin = libgnac_gstu_make_pipeline_element(pipeline, "decodebin2",
- NULL, &metadata_error);
+ GstElement *decodebin = libgnac_gstu_make_pipeline_element(pipeline,
+ "decodebin2", NULL, &metadata_error);
if (metadata_error) {
g_propagate_error(error, metadata_error);
return NULL;
}
- md->priv->sink = libgnac_gstu_make_pipeline_element(pipeline, "fakesink",
- NULL, &metadata_error);
+ md->priv->sink = libgnac_gstu_make_pipeline_element(pipeline,
+ "fakesink", NULL, &metadata_error);
if (metadata_error) {
g_propagate_error(error, metadata_error);
return NULL;
@@ -671,37 +618,36 @@ libgnac_metadata_extract(LibgnacMetadata *md,
FALSE);
md->priv->pipeline = pipeline;
- bus = gst_element_get_bus(GST_ELEMENT(pipeline));
+ GstBus *bus = gst_element_get_bus(GST_ELEMENT(pipeline));
gst_bus_set_sync_handler(bus,
- (GstBusSyncHandler)libgnac_metadata_bus_sync_handler, md);
+ (GstBusSyncHandler) libgnac_metadata_bus_sync_handler, md);
gst_object_unref(bus);
- GstStateChangeReturn state_return;
+
+ GstStateChangeReturn state_return = gst_element_set_state(
+ md->priv->pipeline, GST_STATE_PAUSED);
+
gint timeout_cycle;
- state_return = gst_element_set_state(md->priv->pipeline, GST_STATE_PAUSED);
for (timeout_cycle = 0; timeout_cycle < 5; timeout_cycle++) {
- GstState current_state;
if (state_return != GST_STATE_CHANGE_ASYNC || md->priv->eos) {
break;
}
- state_return = gst_element_get_state(md->priv->pipeline, ¤t_state,
- NULL, GST_SECOND);
+ state_return = gst_element_get_state(md->priv->pipeline,
+ NULL, NULL, GST_SECOND);
}
if ((state_return == GST_STATE_CHANGE_FAILURE) ||
(state_return == GST_STATE_CHANGE_ASYNC && !md->priv->eos))
{
libgnac_debug("An error occured while extracting metadata from file %s",
- string_uri);
+ string_uri);
}
else if (state_return == GST_STATE_CHANGE_SUCCESS) {
- if (g_hash_table_lookup(md->priv->metadata, GST_TAG_DURATION) == NULL) {
+ if (!g_hash_table_lookup(md->priv->metadata, GST_TAG_DURATION)) {
GstFormat format = GST_FORMAT_TIME;
gint64 length;
- GValue *newval;
-
if (gst_element_query_duration(md->priv->sink, &format, &length)) {
g_assert(format == GST_FORMAT_TIME);
- newval = g_new0(GValue, 1);
+ GValue *newval = g_new0(GValue, 1);
g_value_init(newval, G_TYPE_UINT64);
g_value_set_uint64(newval, length/GST_SECOND);
g_hash_table_insert(md->priv->metadata, GST_TAG_DURATION, newval);
@@ -711,8 +657,8 @@ libgnac_metadata_extract(LibgnacMetadata *md,
else if (state_return != GST_STATE_CHANGE_FAILURE) {
GstBus *message_bus = gst_element_get_bus(md->priv->pipeline);
if (message_bus) {
- gst_bus_post(message_bus, gst_message_new_application(GST_OBJECT(
- md->priv->pipeline), NULL));
+ gst_bus_post(message_bus, gst_message_new_application(
+ GST_OBJECT(md->priv->pipeline), NULL));
gst_object_unref(message_bus);
}
while (!md->priv->eos);
@@ -734,7 +680,7 @@ void
libgnac_metadata_tags_free(LibgnacTags *tags)
{
if (tags) {
- g_hash_table_destroy((GHashTable*)tags);
+ g_hash_table_destroy((GHashTable *) tags);
}
}
@@ -751,7 +697,7 @@ gboolean
libgnac_metadata_tags_exist(LibgnacTags *tags, ...)
{
gboolean missing = FALSE;
- gchar *name = NULL;
+ gchar *name;
va_list names;
va_start(names, tags);
@@ -770,79 +716,64 @@ LibgnacTags *
libgnac_metadata_get_dummy_tags(void)
{
if (!dummy_tags) {
- dummy_tags = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify)libgnac_metadata_tags_free);
-
- GValue *filename_value;
- filename_value = g_new0(GValue, 1);
- g_value_init(filename_value, G_TYPE_STRING);
+ dummy_tags = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify) libgnac_metadata_tags_free);
+
+ GValue *filename = g_new0(GValue, 1);
+ g_value_init(filename, G_TYPE_STRING);
/* Translators: example filename used in the preview label (do not remove the extension) */
- g_value_set_static_string(filename_value, _("filename.oga"));
- g_hash_table_insert(dummy_tags, GNAC_TAG_FILENAME, filename_value);
-
- GValue *album_value;
- album_value = g_new0(GValue, 1);
- g_value_init(album_value, G_TYPE_STRING);
- g_value_set_static_string(album_value, "Today!");
- g_hash_table_insert(dummy_tags, GST_TAG_ALBUM, album_value);
+ g_value_set_static_string(filename, _("filename.oga"));
+ g_hash_table_insert(dummy_tags, GNAC_TAG_FILENAME, filename);
+
+ GValue *album = g_new0(GValue, 1);
+ g_value_init(album, G_TYPE_STRING);
+ g_value_set_static_string(album, "Today!");
+ g_hash_table_insert(dummy_tags, GST_TAG_ALBUM, album);
- GValue *artist_value;
- artist_value = g_new0(GValue, 1);
- g_value_init(artist_value, G_TYPE_STRING);
- g_value_set_static_string(artist_value, "The Beach Boys");
- g_hash_table_insert(dummy_tags, GST_TAG_ARTIST, artist_value);
-
- GValue *title_value;
- title_value = g_new0(GValue, 1);
- g_value_init(title_value, G_TYPE_STRING);
- g_value_set_static_string(title_value, "Do You Wanna Dance?");
- g_hash_table_insert(dummy_tags, GST_TAG_TITLE, title_value);
-
- GValue *genre_value;
- genre_value = g_new0(GValue, 1);
- g_value_init(genre_value, G_TYPE_STRING);
- g_value_set_static_string(genre_value, "Rock");
- g_hash_table_insert(dummy_tags, GST_TAG_GENRE, genre_value);
-
- GValue *comment_value;
- comment_value = g_new0(GValue, 1);
- g_value_init(comment_value, G_TYPE_STRING);
- g_value_set_static_string(comment_value, _("Converted by Gnac"));
- g_hash_table_insert(dummy_tags, GST_TAG_COMMENT, comment_value);
-
- GValue *date_value;
- date_value = g_new0(GValue, 1);
- g_value_init(date_value, G_TYPE_UINT);
- g_value_set_uint(date_value, 1965);
- g_hash_table_insert(dummy_tags, GST_TAG_DATE, date_value);
-
- GValue *track_count_value;
- track_count_value = g_new0(GValue, 1);
- g_value_init(track_count_value, G_TYPE_UINT);
- g_value_set_uint(track_count_value, 6);
- g_hash_table_insert(dummy_tags, GST_TAG_TRACK_COUNT, track_count_value);
-
- GValue *track_number_value;
- track_number_value = g_new0(GValue, 1);
- g_value_init(track_number_value, G_TYPE_UINT);
- g_value_set_uint(track_number_value, 1);
- g_hash_table_insert(dummy_tags, GST_TAG_TRACK_NUMBER, track_number_value);
-
- GValue *disc_number_value;
- disc_number_value = g_new0(GValue, 1);
- g_value_init(disc_number_value, G_TYPE_UINT);
- g_value_set_uint(disc_number_value, 1);
- g_hash_table_insert(dummy_tags, GST_TAG_ALBUM_VOLUME_NUMBER,
- disc_number_value);
-
- GValue *disc_count_value;
- disc_count_value = g_new0(GValue, 1);
- g_value_init(disc_count_value, G_TYPE_UINT);
- g_value_set_uint(disc_count_value, 2);
- g_hash_table_insert(dummy_tags, GST_TAG_ALBUM_VOLUME_COUNT,
- disc_count_value);
+ GValue *artist = g_new0(GValue, 1);
+ g_value_init(artist, G_TYPE_STRING);
+ g_value_set_static_string(artist, "The Beach Boys");
+ g_hash_table_insert(dummy_tags, GST_TAG_ARTIST, artist);
+
+ GValue *title = g_new0(GValue, 1);
+ g_value_init(title, G_TYPE_STRING);
+ g_value_set_static_string(title, "Do You Wanna Dance?");
+ g_hash_table_insert(dummy_tags, GST_TAG_TITLE, title);
+
+ GValue *genre = g_new0(GValue, 1);
+ g_value_init(genre, G_TYPE_STRING);
+ g_value_set_static_string(genre, "Rock");
+ g_hash_table_insert(dummy_tags, GST_TAG_GENRE, genre);
+
+ GValue *comment = g_new0(GValue, 1);
+ g_value_init(comment, G_TYPE_STRING);
+ g_value_set_static_string(comment, _("Converted by Gnac"));
+ g_hash_table_insert(dummy_tags, GST_TAG_COMMENT, comment);
+
+ GValue *date = g_new0(GValue, 1);
+ g_value_init(date, G_TYPE_UINT);
+ g_value_set_uint(date, 1965);
+ g_hash_table_insert(dummy_tags, GST_TAG_DATE, date);
+
+ GValue *track_count = g_new0(GValue, 1);
+ g_value_init(track_count, G_TYPE_UINT);
+ g_value_set_uint(track_count, 6);
+ g_hash_table_insert(dummy_tags, GST_TAG_TRACK_COUNT, track_count);
+
+ GValue *track_number = g_new0(GValue, 1);
+ g_value_init(track_number, G_TYPE_UINT);
+ g_value_set_uint(track_number, 1);
+ g_hash_table_insert(dummy_tags, GST_TAG_TRACK_NUMBER, track_number);
+
+ GValue *disc_number = g_new0(GValue, 1);
+ g_value_init(disc_number, G_TYPE_UINT);
+ g_value_set_uint(disc_number, 1);
+ g_hash_table_insert(dummy_tags, GST_TAG_ALBUM_VOLUME_NUMBER, disc_number);
+
+ GValue *disc_count = g_new0(GValue, 1);
+ g_value_init(disc_count, G_TYPE_UINT);
+ g_value_set_uint(disc_count, 2);
+ g_hash_table_insert(dummy_tags, GST_TAG_ALBUM_VOLUME_COUNT, disc_count);
}
return dummy_tags;
diff --git a/libgnac/libgnac-output.c b/libgnac/libgnac-output.c
index a504043..0a56422 100644
--- a/libgnac/libgnac-output.c
+++ b/libgnac/libgnac-output.c
@@ -77,14 +77,13 @@ libgnac_output_remove_extension(const gchar *filename)
g_return_val_if_fail(filename, NULL);
g_return_val_if_fail(g_utf8_validate(filename, -1, NULL), NULL);
- gchar *ext;
-
- ext = g_utf8_strrchr(filename, -1, '.');
- if (ext) {
- glong flen = g_utf8_strlen(filename, -1);
- glong elen = g_utf8_strlen(ext, -1);
- gchar output[flen-elen+1];
- g_utf8_strncpy(output, filename, flen-elen);
+ gchar *extension = g_utf8_strrchr(filename, -1, '.');
+ if (extension) {
+ glong filename_len = g_utf8_strlen(filename, -1);
+ glong extension_len = g_utf8_strlen(extension, -1);
+ glong new_len = filename_len - extension_len;
+ gchar output[new_len + 1];
+ g_utf8_strncpy(output, filename, new_len);
return g_strdup(output);
}
@@ -96,24 +95,21 @@ static gchar *
libgnac_output_remove_extension_from_file(GFile *source_uri,
GError **error)
{
- const gchar *filename;
- GError *err = NULL;
- GFileInfo *info;
-
g_return_val_if_fail(!error || !*error, NULL);
g_return_val_if_fail(source_uri, NULL);
- info = g_file_query_info(source_uri,
+ GError *err = NULL;
+
+ GFileInfo *info = g_file_query_info(source_uri,
G_FILE_ATTRIBUTE_STANDARD_NAME,
G_FILE_QUERY_INFO_NONE, NULL, &err);
-
if (err) {
libgnac_debug("Unable to query GFile information");
g_propagate_error(error, err);
return NULL;
}
- filename = g_file_info_get_name(info);
+ const gchar *filename = g_file_info_get_name(info);
g_object_unref(info);
return libgnac_output_remove_extension(filename);
@@ -124,27 +120,27 @@ static gchar*
libgnac_output_sanitize_path(const gchar *str,
gboolean strip_special)
{
- gchar *res = NULL;
- gchar *s;
+ gchar *result = NULL;
+ gchar *temp;
/* Skip leading periods, otherwise files disappear... */
while (*str == '.') str++;
- s = g_strdup(str);
+ temp = g_strdup(str);
- if (strip_special)
- {
+ if (strip_special) {
/* Replace separators with a hyphen */
- g_strdelimit(s, "\\:|", '-');
+ g_strdelimit(temp, "\\:|", '-');
/* Replace all other weird characters to whitespace */
- g_strdelimit(s, "*?&!\'\"$`{}()[]<>", ' ');
+ g_strdelimit(temp, "*?&!\'\"$`{}()[]<>", ' ');
/* Replace all whitespace with underscores */
- g_strdelimit(s, "\t ", '_');
+ g_strdelimit(temp, "\t ", '_');
}
- res = g_filename_from_utf8(s, -1, NULL, NULL, NULL);
- g_free(s);
- return res ? res : g_strdup(str);
+ result = g_filename_from_utf8(temp, -1, NULL, NULL, NULL);
+ g_free(temp);
+
+ return result ? result : g_strdup(str);
}
@@ -153,14 +149,11 @@ libgnac_output_rename_pattern_new(const gchar pattern)
{
g_return_val_if_fail(pattern, NULL);
- gchar *full_pattern;
- LibgnacRenamePattern *rename_pattern;
-
- rename_pattern = g_malloc(sizeof(LibgnacRenamePattern));
+ LibgnacRenamePattern *rename_pattern = g_malloc(sizeof(LibgnacRenamePattern));
g_return_val_if_fail(rename_pattern, NULL);
- full_pattern = g_strdup_printf("%c%c",
- RENAME_PATTERN_SEPARATOR, pattern);
+ gchar *full_pattern = g_strdup_printf("%c%c",
+ RENAME_PATTERN_SEPARATOR, pattern);
rename_pattern->id = pattern;
rename_pattern->regex = g_regex_new(full_pattern, G_REGEX_OPTIMIZE, 0, NULL);
@@ -186,112 +179,89 @@ libgnac_output_replace_pattern(LibgnacRenamePattern *pattern,
{
g_return_val_if_fail(pattern, NULL);
- GValue *val = NULL;
-
switch (LIBGNAC_RENAME_PATTERN_GET_ID(pattern))
{
- case RENAME_PATTERN_ARTIST:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_ARTIST))
- {
- val = LIBGNAC_METADATA_TAG_ARTIST(tags);
+ case RENAME_PATTERN_ARTIST:
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_ARTIST)) {
+ GValue *val = LIBGNAC_METADATA_TAG_ARTIST(tags);
return g_value_dup_string(val);
}
return RENAME_PATTERN_DEFAULT_ARTIST;
- }
+
case RENAME_PATTERN_ALBUM:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM))
- {
- val = LIBGNAC_METADATA_TAG_ALBUM(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM)) {
+ GValue *val = LIBGNAC_METADATA_TAG_ALBUM(tags);
return g_value_dup_string(val);
- }
+ }
return RENAME_PATTERN_DEFAULT_ALBUM;
- }
+
case RENAME_PATTERN_DISC_NUMBER:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM_VOLUME_NUMBER))
- {
- val = LIBGNAC_METADATA_TAG_ALBUM_VOLUME_NUMBER(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM_VOLUME_NUMBER)) {
+ GValue *val = LIBGNAC_METADATA_TAG_ALBUM_VOLUME_NUMBER(tags);
return g_strdup_printf("%d", g_value_get_uint(val));
- }
+ }
return RENAME_PATTERN_DEFAULT_DISC_NUMBER;
- }
+
case RENAME_PATTERN_DISC_COUNT:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM_VOLUME_COUNT))
- {
- val = LIBGNAC_METADATA_TAG_ALBUM_VOLUME_COUNT(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_ALBUM_VOLUME_COUNT)) {
+ GValue *val = LIBGNAC_METADATA_TAG_ALBUM_VOLUME_COUNT(tags);
return g_strdup_printf("%d", g_value_get_uint(val));
}
return RENAME_PATTERN_DEFAULT_DISC_NUMBER;
- }
+
case RENAME_PATTERN_COMMENT:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_COMMENT))
- {
- val = LIBGNAC_METADATA_TAG_COMMENT(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_COMMENT)) {
+ GValue *val = LIBGNAC_METADATA_TAG_COMMENT(tags);
return g_value_dup_string(val);
- }
+ }
return RENAME_PATTERN_DEFAULT_COMMENT;
- }
+
case RENAME_PATTERN_DATE:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_DATE))
- {
- val = LIBGNAC_METADATA_TAG_DATE(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_DATE)) {
+ GValue *val = LIBGNAC_METADATA_TAG_DATE(tags);
return g_strdup_printf("%d", g_value_get_uint(val));
}
return RENAME_PATTERN_DEFAULT_DATE;
- }
+
case RENAME_PATTERN_FILENAME:
- {
- if (libgnac_metadata_tag_exists(tags, GNAC_TAG_FILENAME))
- {
- val = LIBGNAC_METADATA_TAG_FILENAME(tags);
+ if (libgnac_metadata_tag_exists(tags, GNAC_TAG_FILENAME)) {
+ GValue *val = LIBGNAC_METADATA_TAG_FILENAME(tags);
return libgnac_output_remove_extension(g_value_get_string(val));
}
return RENAME_PATTERN_DEFAULT_FILENAME;
- }
+
case RENAME_PATTERN_GENRE:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_GENRE))
- {
- val = LIBGNAC_METADATA_TAG_GENRE(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_GENRE)) {
+ GValue *val = LIBGNAC_METADATA_TAG_GENRE(tags);
return g_value_dup_string(val);
}
return RENAME_PATTERN_DEFAULT_GENRE;
- }
+
case RENAME_PATTERN_TITLE:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_TITLE))
- {
- val = LIBGNAC_METADATA_TAG_TITLE(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_TITLE)) {
+ GValue *val = LIBGNAC_METADATA_TAG_TITLE(tags);
return g_value_dup_string(val);
}
return RENAME_PATTERN_DEFAULT_TITLE;
- }
+
case RENAME_PATTERN_TRACK_COUNT:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_TRACK_COUNT))
- {
- val = LIBGNAC_METADATA_TAG_TRACK_COUNT(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_TRACK_COUNT)) {
+ GValue *val = LIBGNAC_METADATA_TAG_TRACK_COUNT(tags);
return g_strdup_printf("%02d", g_value_get_uint(val));
}
return RENAME_PATTERN_DEFAULT_TRACK_NUMBER;
- }
+
case RENAME_PATTERN_TRACK_NUMBER:
- {
- if (libgnac_metadata_tag_exists(tags, GST_TAG_TRACK_NUMBER))
- {
- val = LIBGNAC_METADATA_TAG_TRACK_NUMBER(tags);
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_TRACK_NUMBER)) {
+ GValue *val = LIBGNAC_METADATA_TAG_TRACK_NUMBER(tags);
return g_strdup_printf("%02d", g_value_get_uint(val));
}
return RENAME_PATTERN_DEFAULT_TRACK_NUMBER;
- }
+
default:
libgnac_debug("Unknown pattern: %s", pattern);
}
+
return g_strdup_printf("%s", LIBGNAC_RENAME_PATTERN_GET_PATTERN(pattern));
}
@@ -299,19 +269,19 @@ libgnac_output_replace_pattern(LibgnacRenamePattern *pattern,
static void
libgnac_output_rename_patterns_init(LibgnacTags *tags)
{
- if (!rename_patterns)
- {
+ if (!rename_patterns) {
gint i;
for (i = 0; rename_pattern_id[i] != -1; i++)
{
rename_patterns = g_slist_append(rename_patterns,
- libgnac_output_rename_pattern_new(rename_pattern_id[i]));
+ libgnac_output_rename_pattern_new(rename_pattern_id[i]));
};
}
+
/* update the replacement values according to
* the tags of the current file */
g_slist_foreach(rename_patterns,
- (GFunc)libgnac_output_rename_pattern_set_replace, tags);
+ (GFunc) libgnac_output_rename_pattern_set_replace, tags);
}
@@ -327,7 +297,7 @@ libgnac_output_rename_pattern_process(LibgnacRenamePattern *pattern,
gchar **output)
{
*output = g_regex_replace(pattern->regex, *output, -1, 0,
- pattern->replace, 0, NULL);
+ pattern->replace, 0, NULL);
}
@@ -336,22 +306,19 @@ libgnac_output_get_filename(GFile *source,
const gchar *rename_pattern,
GError **error)
{
- GError *err = NULL;
- LibgnacTags *tags = NULL;
- gchar *output = NULL;
+ gchar *output = NULL;
- tags = libgnac_metadata_extract(metadata, source, NULL);
+ LibgnacTags *tags = libgnac_metadata_extract(metadata, source, NULL);
if (tags) {
libgnac_output_rename_patterns_init(tags);
-
output = g_strdup(rename_pattern);
-
/* replace all known patterns by their value for the given file */
g_slist_foreach(rename_patterns,
- (GFunc)libgnac_output_rename_pattern_process, &output);
+ (GFunc) libgnac_output_rename_pattern_process, &output);
}
if (!output) {
+ GError *err = NULL;
output = libgnac_output_remove_extension_from_file(source, &err);
if (err) {
libgnac_debug("Unable to remove extension");
@@ -376,18 +343,14 @@ libgnac_output_build_output(GFile *source,
LibgnacOutputConfig *config,
GError **error)
{
- GFile *destination;
+ g_return_val_if_fail(!error || !*error, NULL);
+
GError *output_error = NULL;
GFile *out_directory;
- GFile *parent;
- gchar *filename = NULL;
gchar *output_name;
- gchar *sanitized;
- g_return_val_if_fail(!error || !*error, NULL);
-
- filename = libgnac_output_get_filename(source, config->rename_pattern,
- &output_error);
+ gchar *filename = libgnac_output_get_filename(source,
+ config->rename_pattern, &output_error);
if (output_error) {
libgnac_debug("Filename creation failed");
g_propagate_error(error, output_error);
@@ -396,11 +359,12 @@ libgnac_output_build_output(GFile *source,
switch (config->folder_type)
{
- case FOLDER_SUBDIRECTORY:
- parent = g_file_get_parent(source);
+ case FOLDER_SUBDIRECTORY: {
+ GFile *parent = g_file_get_parent(source);
out_directory = g_file_get_child(parent, config->folder_path);
g_object_unref(parent);
- break;
+ break;
+ }
case FOLDER_SELECTED:
out_directory = g_file_new_for_uri(config->folder_path);
@@ -418,12 +382,11 @@ libgnac_output_build_output(GFile *source,
{
/* replace all known patterns by their value */
g_slist_foreach(rename_patterns,
- (GFunc)libgnac_output_rename_pattern_process,
+ (GFunc) libgnac_output_rename_pattern_process,
&(config->folder_hierarchy));
/* build the output filename */
output_name = g_strdup_printf("%s%c%s.%s",
- config->folder_hierarchy, G_DIR_SEPARATOR, filename,
- config->extension);
+ config->folder_hierarchy, G_DIR_SEPARATOR, filename, config->extension);
}
else
{
@@ -431,12 +394,12 @@ libgnac_output_build_output(GFile *source,
}
/* sanitize the whole path */
- sanitized = libgnac_output_sanitize_path(output_name, config->strip_special);
+ gchar *sanitized = libgnac_output_sanitize_path(output_name,
+ config->strip_special);
/* create the folder hierarchy and destination file */
- destination = g_file_get_child(out_directory, sanitized);
+ GFile *destination = g_file_get_child(out_directory, sanitized);
- /* cleanup */
g_object_unref(out_directory);
g_free(output_name);
g_free(sanitized);
@@ -450,22 +413,17 @@ gchar *
libgnac_output_get_preview_from_pattern(const gchar *pattern,
gboolean strip_special)
{
- gchar *preview;
- gchar *sanitized;
- LibgnacTags *tags;
-
- preview = g_strdup(pattern);
- tags = libgnac_metadata_get_dummy_tags();
+ gchar *preview = g_strdup(pattern);
+ LibgnacTags *tags = libgnac_metadata_get_dummy_tags();
libgnac_output_rename_patterns_init(tags);
/* replace all known patterns by their value for the given file */
g_slist_foreach(rename_patterns,
- (GFunc)libgnac_output_rename_pattern_process, &preview);
+ (GFunc) libgnac_output_rename_pattern_process, &preview);
/* sanitize the filename */
- sanitized = libgnac_output_sanitize_path(preview, strip_special);
+ gchar *sanitized = libgnac_output_sanitize_path(preview, strip_special);
- /* cleanup */
g_free(preview);
return sanitized;
@@ -476,9 +434,10 @@ gboolean
libgnac_output_overwrite_dest_file(LibgnacMediaItem *item,
const gchar *uri)
{
+ libgnac_debug("Overwrite file");
+
GError *err = NULL;
- libgnac_debug("Overwrite file");
g_file_delete(item->destination, NULL, &err);
if (err) {
libgnac_warning("Unable to overwrite file %s: %s", uri, err->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]