[easytag/wip/opus-support] Improved support for Opus files.
- From: Abhinav Jangda <abhijangda src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/opus-support] Improved support for Opus files.
- Date: Wed, 26 Mar 2014 14:06:11 +0000 (UTC)
commit 300ac3115a589bf77aa5cdf8a8161908e989f1ff
Author: Abhinav <abhijangda hotmail com>
Date: Wed Mar 26 19:32:27 2014 +0530
Improved support for Opus files.
src/et_core.c | 12 ++++--
src/misc.c | 2 +-
src/ogg_tag.c | 2 +-
src/ogg_tag.h | 2 +-
src/opus_header.c | 94 +++++++++++++++++++++++++++++++---------------------
src/opus_header.h | 11 +++---
src/opus_tag.c | 25 +++++++++----
src/opus_tag.h | 2 +-
8 files changed, 90 insertions(+), 60 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index c71f81d..9154c7e 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -467,6 +467,8 @@ GList *ET_Add_File_To_File_List (gchar *filename)
if (!filename)
return ETCore->ETFileList;
+ file = g_file_new_for_path (filename);
+
/* Primary Key for this file */
ETFileKey = ET_File_Key_New();
@@ -531,7 +533,7 @@ GList *ET_Add_File_To_File_List (gchar *filename)
#endif
#ifdef ENABLE_OPUS
case OPUS_TAG:
- if (!et_opus_tag_read_file_tag (filename, FileTag, &error))
+ if (!et_opus_tag_read_file_tag (file, FileTag, &error))
{
Log_Print (LOG_ERROR,
_("Error reading tag from opus file (%s)"),
@@ -590,7 +592,7 @@ GList *ET_Add_File_To_File_List (gchar *filename)
#endif
#ifdef ENABLE_OPUS
case OPUS_FILE:
- if (!et_opus_read_file_info (filename, ETFileInfo, &error))
+ if (!et_opus_read_file_info (file, ETFileInfo, &error))
{
Log_Print (LOG_ERROR, _("Error while querying information for file: '%s' (%s)"),
filename_utf8, error->message);
@@ -617,7 +619,6 @@ GList *ET_Add_File_To_File_List (gchar *filename)
/* Store the modification time of the file to check if the file was changed
* before saving */
- file = g_file_new_for_path (filename);
fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
g_object_unref (file);
@@ -2677,6 +2678,7 @@ void ET_Display_File_Data_To_UI (ET_File *ETFile)
gchar *cur_filename;
gchar *cur_filename_utf8;
gchar *msg;
+ GFile *file;
g_return_if_fail (ETFile != NULL &&
((GList *)ETFile->FileNameCur)->data != NULL);
@@ -2803,7 +2805,9 @@ void ET_Display_File_Data_To_UI (ET_File *ETFile)
#ifdef ENABLE_OPUS
case OPUS_FILE:
gtk_frame_set_label(GTK_FRAME(FileFrame),_("Opus File"));
- et_opus_header_display_file_info_to_ui (cur_filename, ETFile->ETFileInfo);
+ file = g_file_new_for_path (cur_filename);
+ et_opus_header_display_file_info_to_ui (file, ETFile->ETFileInfo);
+ g_object_unref (file);
break;
#endif
case UNKNOWN_FILE:
diff --git a/src/misc.c b/src/misc.c
index 7a6e2ae..721b081 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1913,7 +1913,7 @@ void Open_Search_File_Window (void)
N_("Original Artist"),
N_("Copyright"),
N_("URL"),
- N_("Endffcoded By")
+ N_("Encoded By")
};
diff --git a/src/ogg_tag.c b/src/ogg_tag.c
index 7c400f2..df2ee7f 100644
--- a/src/ogg_tag.c
+++ b/src/ogg_tag.c
@@ -186,7 +186,7 @@ read_guint32_from_byte (guchar *str, gsize start)
void
et_add_file_tags_from_vorbis_comments (vorbis_comment *vc, File_Tag *FileTag,
- gchar *filename_utf8)
+ const gchar *filename_utf8)
{
gchar *string = NULL;
gchar *string1 = NULL;
diff --git a/src/ogg_tag.h b/src/ogg_tag.h
index 6d62fbe..e37eb77 100644
--- a/src/ogg_tag.h
+++ b/src/ogg_tag.h
@@ -35,6 +35,6 @@ gboolean ogg_tag_read_file_tag (gchar *filename, File_Tag *FileTag,
gboolean ogg_tag_write_file_tag (ET_File *ETFile, GError **error);
void
et_add_file_tags_from_vorbis_comments (vorbis_comment *vc, File_Tag *FileTag,
- gchar *filename_utf8);
+ const gchar *filename_utf8);
#endif /* __OGG_TAG_H__ */
diff --git a/src/opus_header.c b/src/opus_header.c
index e85d6ee..5f7a93c 100644
--- a/src/opus_header.c
+++ b/src/opus_header.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <config.h> // For definition of ENABLE_OPUS
+#include <config.h> /* For definition of ENABLE_OPUS */
#ifdef ENABLE_OPUS
@@ -40,9 +40,9 @@
/*
* et_ogg_error_quark:
*
- * To get EtOGGError domain.
+ * To get EtOpusError domain.
*
- * Returns: GQuark for EtOGGError domain
+ * Returns: GQuark for EtOpusError domain
*/
GQuark
et_opus_error_quark (void)
@@ -51,7 +51,7 @@ et_opus_error_quark (void)
}
/*
- * et_op_open_file:
+ * et_opus_open_file:
* @filename: Filepath to open
* @error: GError or NULL
*
@@ -60,15 +60,19 @@ et_opus_error_quark (void)
* Returns: a OggOpusFile on success or NULL on error.
*/
OggOpusFile *
-et_op_open_file (const gchar *filename, GError **error)
+et_opus_open_file (GFile *gfile, GError **error)
{
OggOpusFile *file;
+ gchar *path;
int error_val;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- g_return_val_if_fail (filename != NULL, NULL);
+ g_return_val_if_fail (gfile != NULL, NULL);
+
+ path = g_file_get_path (gfile);
+ file = op_open_file (path, &error_val);
+ g_free (path);
- file = op_open_file (filename, &error_val);
if (!file)
{
/* Got error while opening opus file */
@@ -144,28 +148,42 @@ et_op_open_file (const gchar *filename, GError **error)
* Returns: TRUE if sucessfull otherwise FALSE
*/
gboolean
-et_opus_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo,
+et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo,
GError **error)
{
OggOpusFile *file;
const OpusHead* head;
+ GFileInfo *info;
- g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+ g_return_val_if_fail (gfile != NULL && ETFileInfo != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- file = et_op_open_file (filename, error);
+ file = et_opus_open_file (gfile, error);
if (!file)
{
g_assert (error == NULL || *error != NULL);
return FALSE;
}
+ info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
head = op_head (file, -1);
ETFileInfo->version = head->version;
ETFileInfo->bitrate = op_bitrate (file, -1);
ETFileInfo->samplerate = head->input_sample_rate;
ETFileInfo->mode = head->channel_count;
- ETFileInfo->size = et_get_file_size (filename);
+
+ if (info)
+ {
+ ETFileInfo->size = g_file_info_get_size (info);
+ g_object_unref (info);
+ }
+ else
+ {
+ ETFileInfo->size = 0;
+ }
+
ETFileInfo->duration = op_pcm_total (file, -1);
op_free (file);
@@ -183,7 +201,7 @@ et_opus_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo,
* Returns: TRUE if successfull otherwise FALSE
*/
gboolean
-et_opus_header_display_file_info_to_ui (gchar *filename,
+et_opus_header_display_file_info_to_ui (GFile *file,
ET_File_Info *ETFileInfo)
{
gchar *text;
@@ -193,44 +211,44 @@ et_opus_header_display_file_info_to_ui (gchar *filename,
gchar *size1 = NULL;
/* Encoder version */
- gtk_label_set_text(GTK_LABEL(VersionLabel),_("Encoder:"));
- text = g_strdup_printf("%d",ETFileInfo->version);
- gtk_label_set_text(GTK_LABEL(VersionValueLabel),text);
- g_free(text);
+ gtk_label_set_text (GTK_LABEL (VersionLabel), _("Encoder:"));
+ text = g_strdup_printf ("%d", ETFileInfo->version);
+ gtk_label_set_text (GTK_LABEL (VersionValueLabel), text);
+ g_free (text);
/* Bitrate */
- text = g_strdup_printf(_("%d kb/s"),ETFileInfo->bitrate);
- gtk_label_set_text(GTK_LABEL(BitrateValueLabel),text);
- g_free(text);
+ text = g_strdup_printf (_("%d kb/s"), ETFileInfo->bitrate);
+ gtk_label_set_text (GTK_LABEL (BitrateValueLabel), text);
+ g_free (text);
/* Samplerate */
- text = g_strdup_printf(_("%d Hz"),ETFileInfo->samplerate);
- gtk_label_set_text(GTK_LABEL(SampleRateValueLabel),text);
- g_free(text);
+ text = g_strdup_printf (_("%d Hz"), ETFileInfo->samplerate);
+ gtk_label_set_text (GTK_LABEL (SampleRateValueLabel), text);
+ g_free (text);
/* Mode */
- gtk_label_set_text(GTK_LABEL(ModeLabel),_("Channels:"));
- text = g_strdup_printf("%d",ETFileInfo->mode);
- gtk_label_set_text(GTK_LABEL(ModeValueLabel),text);
- g_free(text);
+ gtk_label_set_text (GTK_LABEL (ModeLabel), _("Channels:"));
+ text = g_strdup_printf ("%d", ETFileInfo->mode);
+ gtk_label_set_text (GTK_LABEL (ModeValueLabel), text);
+ g_free (text);
/* Size */
size = g_format_size (ETFileInfo->size);
size1 = g_format_size (ETCore->ETFileDisplayedList_TotalSize);
- text = g_strdup_printf("%s (%s)",size,size1);
- gtk_label_set_text(GTK_LABEL(SizeValueLabel),text);
- g_free(size);
- g_free(size1);
- g_free(text);
+ text = g_strdup_printf ("%s (%s)", size, size1);
+ gtk_label_set_text (GTK_LABEL (SizeValueLabel), text);
+ g_free (size);
+ g_free (size1);
+ g_free (text);
/* Duration */
- time = Convert_Duration(ETFileInfo->duration);
- time1 = Convert_Duration(ETCore->ETFileDisplayedList_TotalDuration);
- text = g_strdup_printf("%s (%s)",time,time1);
- gtk_label_set_text(GTK_LABEL(DurationValueLabel),text);
- g_free(time);
- g_free(time1);
- g_free(text);
+ time = Convert_Duration (ETFileInfo->duration);
+ time1 = Convert_Duration (ETCore->ETFileDisplayedList_TotalDuration);
+ text = g_strdup_printf ("%s (%s)", time, time1);
+ gtk_label_set_text (GTK_LABEL (DurationValueLabel), text);
+ g_free (time);
+ g_free (time1);
+ g_free (text);
return TRUE;
}
diff --git a/src/opus_header.h b/src/opus_header.h
index 87b5781..eaa4dc9 100644
--- a/src/opus_header.h
+++ b/src/opus_header.h
@@ -34,7 +34,7 @@ GQuark et_opus_error_quark (void);
#define ET_OPUS_ERROR et_opus_error_quark ()
/*
- * EtOPUSError:
+ * EtOpusError:
* @ET_OPUS_ERROR_READ: Error reading file
* @ET_OPUS_ERROR_FAULT: Memory allocation failure or internal library error
* @ET_OPUS_ERROR_IMPL: Stream used an unimplemented feature
@@ -58,20 +58,19 @@ typedef enum
ET_OPUS_ERROR_VERSION,
ET_OPUS_ERROR_BADLINK,
ET_OPUS_ERROR_BADTIMESTAMP,
-} EtOggError;
+} EtOpusError;
/**************
* Prototypes *
**************/
gboolean
-et_opus_read_file_info (const gchar *filename,
- ET_File_Info *ETFileInfo,
+et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo,
GError **error);
OggOpusFile *
-et_op_open_file (const gchar *filename, GError **error);
+et_opus_open_file (GFile *gfile, GError **error);
gboolean
-et_opus_header_display_file_info_to_ui (gchar *filename,
+et_opus_header_display_file_info_to_ui (GFile *gfile,
ET_File_Info *ETFileInfo);
#endif /* __OPUS_HEADER_H__ */
diff --git a/src/opus_tag.c b/src/opus_tag.c
index 2be35d5..d3d660d 100644
--- a/src/opus_tag.c
+++ b/src/opus_tag.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "config.h" // For definition of ENABLE_OPUS
+#include "config.h" /* For definition of ENABLE_OPUS */
#ifdef ENABLE_OPUS
@@ -56,17 +56,18 @@
* Returns: TRUE if successfull otherwise FALSE
*/
gboolean
-et_opus_tag_read_file_tag (gchar *filename, File_Tag *FileTag,
+et_opus_tag_read_file_tag (GFile *gfile, File_Tag *FileTag,
GError **error)
{
OggOpusFile *file;
const OpusTags *tags;
- gchar *filename_utf8;
+ GFileInfo *info;
- g_return_val_if_fail (filename != NULL && FileTag != NULL, FALSE);
+ g_return_val_if_fail (gfile != NULL && FileTag != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- file = et_op_open_file (filename, error);
+ file = et_opus_open_file (gfile, error);
+
if (!file)
{
g_assert (error == NULL || *error != NULL);
@@ -74,12 +75,20 @@ et_opus_tag_read_file_tag (gchar *filename, File_Tag *FileTag,
}
tags = op_tags (file, 0);
- filename_utf8 = filename_to_display (filename);
+ info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, error);
+
+ if (!info)
+ {
+ op_free (file);
+ g_assert (error == NULL || *error != NULL);
+ return FALSE;
+ }
et_add_file_tags_from_vorbis_comments ((vorbis_comment *)tags, FileTag,
- filename_utf8);
+ g_file_info_get_display_name (info));
+ g_object_unref (info);
op_free (file);
- g_free(filename_utf8);
g_assert (error == NULL || *error == NULL);
return TRUE;
diff --git a/src/opus_tag.h b/src/opus_tag.h
index 1a49c4f..1f51fbe 100644
--- a/src/opus_tag.h
+++ b/src/opus_tag.h
@@ -29,7 +29,7 @@
**************/
gboolean
-et_opus_tag_read_file_tag (gchar *filename, File_Tag *FileTag,
+et_opus_tag_read_file_tag (GFile *file, File_Tag *FileTag,
GError **error);
#endif /* __OPUS_TAG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]