[easytag/wip/taglib-mp4-cxx: 5/12] Use C++ TagLib API for MP4 header information



commit dd4e526c394f202f756446285951dfa3638f8267
Author: David King <amigadave amigadave com>
Date:   Thu Apr 10 16:50:56 2014 +0100

    Use C++ TagLib API for MP4 header information

 Makefile.am                         |    2 +-
 configure.ac                        |    2 +-
 po/POTFILES.in                      |    2 +-
 src/{mp4_header.c => mp4_header.cc} |   81 +++++++++++++++-------------------
 src/mp4_header.h                    |   22 +++------
 src/mp4_tag.cc                      |    4 ++
 6 files changed, 51 insertions(+), 62 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 8065838..f090579 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -59,7 +59,6 @@ easytag_SOURCES = \
        src/misc.c \
        src/monkeyaudio_header.c \
        src/mpeg_header.c \
-       src/mp4_header.c \
        src/mp4_tag.cc \
        src/musepack_header.c \
        src/ogg_header.c \
@@ -249,6 +248,7 @@ dist_noinst_DATA = \
        src/libapetag/README.apetag \
        src/libapetag/id3v2_read.c \
        src/libapetag/id3v2_read.h \
+       src/mp4_header.cc \
        src/win32/resource.h \
        data/icons/win32/easytag.ico \
        data/nsis/easytag-header.bmp \
diff --git a/configure.ac b/configure.ac
index 618881a..a72262f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -283,7 +283,7 @@ dnl ################################################
 dnl # taglib library
 dnl ################################################
 
-TAGLIB_DEPS="taglib_c taglib >= 1.6.0"
+TAGLIB_DEPS="taglib >= 1.6.0"
 AS_IF([test "x$enable_mp4" != "xno"],
       [PKG_CHECK_EXISTS([$TAGLIB_DEPS], [have_taglib=yes], [have_taglib=no])],
       [have_taglib=no])
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c8bdda1..90110cd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -16,7 +16,7 @@ src/id3v24_tag.c
 src/log.c
 src/misc.c
 src/monkeyaudio_header.c
-src/mp4_header.c
+src/mp4_header.cc
 src/mp4_tag.cc
 src/mpeg_header.c
 src/musepack_header.c
diff --git a/src/mp4_header.c b/src/mp4_header.cc
similarity index 71%
rename from src/mp4_header.c
rename to src/mp4_header.cc
index f9952a2..89bf0f4 100644
--- a/src/mp4_header.c
+++ b/src/mp4_header.cc
@@ -1,6 +1,6 @@
-/* mp4_header.c - 2005/02/05 */
 /*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  EasyTAG - Tag editor for audio files
+ *  Copyright (C) 2012-1014  David King <amigadave amigadave com>
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
  *  Copyright (C) 2005  Stewart Whitman <swhitman cox net>
  *
@@ -19,27 +19,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "config.h" // For definition of ENABLE_MP4
-
-#ifdef ENABLE_MP4
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "mp4_header.h"
-#include "easytag.h"
-#include "et_core.h"
-#include "log.h"
-#include "misc.h"
-#include "charset.h"
-
-#include <tag_c.h>
-
+/* This file is intended to be included directly in mp4_tag.cc */
 
 /*
  * Mp4_Header_Read_File_Info:
@@ -48,48 +28,62 @@
  */
 gboolean Mp4_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
 {
-    TagLib_File *file;
-    const TagLib_AudioProperties *properties;
+    TagLib::MP4::Tag *tag;
+    const TagLib::MP4::Properties *properties;
 
     g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
 
     /* Get size of file */
     ETFileInfo->size = et_get_file_size (filename);
 
-    if ((file = taglib_file_new_type(filename, TagLib_File_MP4)) == NULL )
+    TagLib::MP4::File mp4file (filename);
+
+    if (!mp4file.isOpen ())
     {
-        gchar *filename_utf8 = filename_to_display(filename);
-        //g_print(_("Error while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
-        Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
-        g_free(filename_utf8);
+        gchar *filename_utf8 = filename_to_display (filename);
+        Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)."),
+                   filename_utf8,_("MP4 format invalid"));
+        g_free (filename_utf8);
         return FALSE;
     }
 
-    /* Check for audio track */
-    if( !taglib_file_is_valid(file) )
+    if (!(tag = mp4file.tag ()))
     {
-        gchar *filename_utf8 = filename_to_display(filename);
+        gchar *filename_utf8 = filename_to_display (filename);
         Log_Print (LOG_ERROR, _("File contains no audio track: '%s'"),
                    filename_utf8);
-        g_free(filename_utf8);
+        g_free (filename_utf8);
         return FALSE;
     }
 
-    properties = taglib_file_audioproperties(file);
+    properties = mp4file.audioProperties ();
+
     if (properties == NULL)
     {
         gchar *filename_utf8 = filename_to_display (filename);
         Log_Print (LOG_ERROR, _("Error reading properties from file: '%s'"),
                    filename_utf8);
         g_free (filename_utf8);
-        taglib_file_free (file);
         return FALSE;
     }
 
     /* Get format/subformat */
     {
-        ETFileInfo->mpc_version = g_strdup("MPEG");
-       ETFileInfo->mpc_profile = g_strdup("4, Unknown");
+        ETFileInfo->mpc_version = g_strdup ("MPEG");
+
+        switch (properties->codec ())
+        {
+            case TagLib::MP4::Properties::AAC:
+                ETFileInfo->mpc_profile = g_strdup ("4, AAC");
+                break;
+            case TagLib::MP4::Properties::ALAC:
+                ETFileInfo->mpc_profile = g_strdup ("4, ALAC");
+                break;
+            case TagLib::MP4::Properties::Unknown:
+            default:
+                ETFileInfo->mpc_profile = g_strdup ("4, Unknown");
+                break;
+        };
     }
 
     ETFileInfo->version = 4;
@@ -97,12 +91,11 @@ gboolean Mp4_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
     ETFileInfo->layer = 14;
 
     ETFileInfo->variable_bitrate = TRUE;
-    ETFileInfo->bitrate = taglib_audioproperties_bitrate(properties);
-    ETFileInfo->samplerate = taglib_audioproperties_samplerate(properties);
-    ETFileInfo->mode = taglib_audioproperties_channels(properties);
-    ETFileInfo->duration = taglib_audioproperties_length(properties);
+    ETFileInfo->bitrate = properties->bitrate ();
+    ETFileInfo->samplerate = properties->sampleRate ();
+    ETFileInfo->mode = properties->channels ();
+    ETFileInfo->duration = properties->length ();
 
-    taglib_file_free(file);
     return TRUE;
 }
 
@@ -170,5 +163,3 @@ gboolean Mp4_Header_Display_File_Info_To_UI(gchar *filename, ET_File_Info *ETFil
 
     return TRUE;
 }
-
-#endif
diff --git a/src/mp4_header.h b/src/mp4_header.h
index a5374a5..97de5b6 100644
--- a/src/mp4_header.h
+++ b/src/mp4_header.h
@@ -1,6 +1,6 @@
-/* mp4_header.h - 2005/02/15 */
 /*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  EasyTAG - Tag editor for audio files
+ *  Copyright (C) 2012-2014  David King <amigadave amigadave com>
  *  Copyright (C) 2000-2005  Jerome Couderc <easytag gmail com>
  *  Copyright (C) 2005  Stewart Whitman <swhitman cox net>
  *
@@ -20,23 +20,17 @@
  */
 
 
-#ifndef __MP4_HEADER_H__
-#define __MP4_HEADER_H__
+#ifndef ET_MP4_HEADER_H_
+#define ET_MP4_HEADER_H_
 
 
 #include "et_core.h"
 
-/****************
- * Declarations *
- ****************/
+G_BEGIN_DECLS
 
-
-/**************
- * Prototypes *
- **************/
-
-gboolean Mp4_Header_Read_File_Info          (gchar *filename, ET_File_Info *ETFileInfo);
+gboolean Mp4_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo);
 gboolean Mp4_Header_Display_File_Info_To_UI (gchar *filename, ET_File_Info *ETFileInfo);
 
+G_END_DECLS
 
-#endif /* __MP4_HEADER_H__ */
+#endif /* ET_MP4_HEADER_H_ */
diff --git a/src/mp4_tag.cc b/src/mp4_tag.cc
index 87a39e6..65aabdc 100644
--- a/src/mp4_tag.cc
+++ b/src/mp4_tag.cc
@@ -28,6 +28,7 @@
 #include <glib/gi18n.h>
 #include <stdlib.h>
 
+#include "mp4_header.h"
 #include "mp4_tag.h"
 #include "picture.h"
 #include "easytag.h"
@@ -41,6 +42,9 @@
 #include <mp4tag.h>
 #include <tpropertymap.h>
 
+/* Include mp4_header.cc directly. */
+#include "mp4_header.cc"
+
 /*
  * Mp4_Tag_Read_File_Tag:
  *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]