[easytag/wip/unstable] Remove ancient libmpg123 code, bug 692410



commit 02d431c72fa913eb4f158fda6c39ac4ec77ae13b
Author: David King <amigadave amigadave com>
Date:   Mon Apr 8 18:01:48 2013 +0100

    Remove ancient libmpg123 code, bug 692410
    
    Use id3lib for reading the MPEG header instead of the internal version
    of mpg123. With only id3tag support (and no id3lib support) the MPEG
    header is not read, but ID3v2.4 tag reading and writing still works.
    Modify ifdefs and update .gitignore appropriately for libmpg123 removal.
    Move ID3_INVALID_GENRE to src/id3_tag.h to avoid a warning.

 .gitignore               |   10 +-
 Makefile.am              |   12 -
 src/et_core.c            |    4 +-
 src/genres.h             |    1 -
 src/id3_tag.c            |    4 +-
 src/id3_tag.h            |    2 +-
 src/id3v24_tag.c         |    1 -
 src/libmpg123/README     |   35 -
 src/libmpg123/common.c   |  746 ----------------
 src/libmpg123/dxhead.c   |  165 ----
 src/libmpg123/dxhead.h   |   60 --
 src/libmpg123/getbits.h  |   46 -
 src/libmpg123/huffman.h  |  329 --------
 src/libmpg123/l2tables.h |  997 ----------------------
 src/libmpg123/layer1.c   |  189 -----
 src/libmpg123/layer2.c   |  338 --------
 src/libmpg123/layer3.c   | 2100 ----------------------------------------------
 src/libmpg123/mpg123.c   |  172 ----
 src/libmpg123/mpg123.h   |  144 ----
 src/mpeg_header.c        |  174 +----
 src/wavpack_header.c     |    2 +-
 21 files changed, 20 insertions(+), 5511 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ec664f6..bf14331 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,12 +28,8 @@ ltmain.sh
 /po/POTFILES
 /po/easytag.pot
 /po/stamp-it
-src/.deps/
-src/id3lib/.deps/
-src/id3lib/libid3bugfix.a
-src/libapetag/.deps/
-src/libapetag/libapetag.a
-src/libmpg123/.deps/
-src/libmpg123/libmpg123.a
+/src/.deps/
+/src/id3lib/.deps/
+/src/libapetag/.deps/
 /src/win32/.deps/
 stamp-h1
diff --git a/Makefile.am b/Makefile.am
index eef9037..211eab3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -37,12 +37,6 @@ easytag_SOURCES = \
        src/libapetag/is_tag.c \
        src/libapetag/info_mac.c \
        src/libapetag/info_mpc.c \
-       src/libmpg123/common.c \
-       src/libmpg123/dxhead.c \
-       src/libmpg123/layer1.c \
-       src/libmpg123/layer2.c \
-       src/libmpg123/layer3.c \
-       src/libmpg123/mpg123.c \
        src/about.c \
        src/ape_tag.c \
        src/application.c \
@@ -84,11 +78,6 @@ easytag_headers = \
        src/libapetag/is_tag.h \
        src/libapetag/info_mac.h \
        src/libapetag/info_mpc.h \
-       src/libmpg123/dxhead.h \
-       src/libmpg123/getbits.h \
-       src/libmpg123/huffman.h \
-       src/libmpg123/l2tables.h \
-       src/libmpg123/mpg123.h \
        src/about.h \
        src/ape_tag.h \
        src/application.h \
@@ -212,7 +201,6 @@ dist_noinst_DATA = \
        src/libapetag/README.apetag \
        src/libapetag/id3v2_read.c \
        src/libapetag/id3v2_read.h \
-       src/libmpg123/README \
        src/win32/easytag.rc \
        src/win32/gtkwin32dep.c \
        src/win32/gtkwin32dep.h \
diff --git a/src/et_core.c b/src/et_core.c
index 252c4ab..adc626f 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -526,7 +526,7 @@ GList *ET_Add_File_To_File_List (gchar *filename)
 
     switch (ETFileDescription->FileType)
     {
-#ifdef ENABLE_MP3
+#if defined ENABLE_MP3 && defined ENABLE_ID3LIB
         case MP3_FILE:
         case MP2_FILE:
             Mpeg_Header_Read_File_Info(filename,ETFileInfo);
@@ -2613,7 +2613,7 @@ void ET_Display_File_Data_To_UI (ET_File *ETFile)
     /* Display file data, header data and file type */
     switch (ETFileDescription->FileType)
     {
-#ifdef ENABLE_MP3
+#if defined ENABLE_MP3 && defined ENABLE_ID3LIB
         case MP3_FILE:
             gtk_frame_set_label(GTK_FRAME(FileFrame),_("MP3 File"));
             Mpeg_Header_Display_File_Info_To_UI(cur_filename,ETFile->ETFileInfo);
diff --git a/src/genres.h b/src/genres.h
index d75253a..171ff46 100644
--- a/src/genres.h
+++ b/src/genres.h
@@ -25,7 +25,6 @@
 
 /* GENRE_MAX is the last genre number that can be used */
 #define GENRE_MAX ( sizeof(id3_genres)/sizeof(id3_genres[0]) - 1 )
-#define ID3_INVALID_GENRE 255
 
 /**
     \def genre_no(IndeX) 
diff --git a/src/id3_tag.c b/src/id3_tag.c
index a88d1ca..95814e1 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -18,7 +18,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
@@ -1379,7 +1379,7 @@ gboolean Id3tag_Write_File_Tag (ET_File *ETFile)
         return Id3tag_Write_File_v23Tag(ETFile);
 #else
     return Id3tag_Write_File_v24Tag(ETFile);
-#endif
+#endif /* !ENABLE_ID3LIB */
 }
 
 #endif /* ENABLE_MP3 */
diff --git a/src/id3_tag.h b/src/id3_tag.h
index 4bbf44f..0e0da13 100644
--- a/src/id3_tag.h
+++ b/src/id3_tag.h
@@ -30,7 +30,7 @@
 /****************
  * Declarations *
  ****************/
-
+#define ID3_INVALID_GENRE 255
 
 
 /**************
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 029e869..17004a8 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -36,7 +36,6 @@
 #include "picture.h"
 #include "easytag.h"
 #include "browser.h"
-#include "genres.h"
 #include "setting.h"
 #include "misc.h"
 #include "log.h"
diff --git a/src/mpeg_header.c b/src/mpeg_header.c
index a5f5ee6..c2e18d0 100644
--- a/src/mpeg_header.c
+++ b/src/mpeg_header.c
@@ -18,33 +18,19 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
+
+#if defined ENABLE_MP3 && defined ENABLE_ID3LIB
 
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
 
 #include "mpeg_header.h"
 #include "easytag.h"
-#include "et_core.h"
-#include "log.h"
 #include "misc.h"
-#include "charset.h"
-
-// Set to :
-// - 1 to use ID3lib for reading headers
-// - 0 to use mpeg123 for reading headers
-#define USE_ID3LIB_4_HEADER 0
-
-#if USE_ID3LIB_4_HEADER
-#   include <id3.h>
-#   include "id3lib/id3_bugfix.h"
-#else
-#   include "libmpg123/mpg123.h"
-#endif
 
+#include <id3.h>
+#include "id3lib/id3_bugfix.h"
 
 
 
@@ -90,138 +76,19 @@ static gchar* channel_mode_name(int mode)
 /*
  * Read infos into header of first frame
  */
-gboolean Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
+gboolean
+Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
 {
-#if (!USE_ID3LIB_4_HEADER)
-    FILE *file;
-    gulong filesize;
-
-
-    if (!filename || !ETFileInfo)
-        return FALSE;
-
-    /* Get size of file */
-    filesize         = Get_File_Size(filename);
-    ETFileInfo->size = filesize;
-
-
-    /*
-     * This part was taken from XMMS
-     */
-    if ((file = fopen(filename, "rb")) != NULL)
-    {
-        guint32 head;
-        unsigned char tmp[4];
-        struct frame frm;
-
-        if (fread(tmp, 1, 4, file) != 4)
-        {
-            fclose(file);
-            return FALSE;
-        }
-
-        // Skip data of the ID3v2.x tag (It may contain data similar to mpeg frame 
-        // as, for example, in the id3 APIC frame) (patch from Artur Polaczynski)
-        if (tmp[0] == 'I' && tmp[1] == 'D' && tmp[2] == '3' && tmp[3] < 0xFF)
-        {
-            // ID3v2 tag skipeer $49 44 33 yy yy xx zz zz zz zz [zz size]
-            long id3v2size;
-            fseek(file, 2, SEEK_CUR); // Size is 6-9 position
-            if (fread(tmp, 1, 4, file) != 4) // Read bytes of tag size
-            {
-                fclose(file);
-                return FALSE;
-            }
-            id3v2size = 10 + ( (long)(tmp[3]) | ((long)(tmp[2]) << 7) | ((long)(tmp[1]) << 14) | 
((long)(tmp[0]) << 21) );
-            fseek(file, id3v2size, SEEK_SET);
-            if (fread(tmp, 1, 4, file) != 4) // Read mpeg header
-            {
-                fclose(file);
-                return FALSE;
-            }
-        }
-
-        head = ((guint32) tmp[0] << 24) | ((guint32) tmp[1] << 16) | ((guint32) tmp[2] << 8) | (guint32) 
tmp[3];
-        while (!mpg123_head_check(head))
-        {
-            head <<= 8;
-            if (fread(tmp, 1, 1, file) != 1)
-            {
-                fclose(file);
-                return FALSE;
-            }
-            head |= tmp[0];
-        }
-        if (mpg123_decode_header(&frm, head))
-        {
-            guchar *buf;
-            gdouble tpf;
-            XHEADDATA xing_header;
-
-            buf = g_malloc(frm.framesize + 4);
-            fseek(file, -4, SEEK_CUR);
-            fread(buf, 1, frm.framesize + 4, file);
-            xing_header.toc = NULL;
-            tpf = mpg123_compute_tpf(&frm);
-            // MPEG and Layer version
-            ETFileInfo->mpeg25 = frm.mpeg25;
-            if (!ETFileInfo->mpeg25)
-                ETFileInfo->version = frm.lsf+1;
-            ETFileInfo->layer = frm.lay;
-            //if (ETFileInfo->mpeg25) g_print("mpeg_level: MPEG 2.5, layer %d\n",ETFileInfo->layer);
-            //else                    g_print("mpeg_level: MPEG %d, layer 
%d\n",ETFileInfo->version,ETFileInfo->layer);
-
-            fseek(file, 0, SEEK_END);
-            // Variable bitrate? + bitrate
-            if ( (ETFileInfo->variable_bitrate=mpg123_get_xing_header(&xing_header,buf)) )
-            {
-                ETFileInfo->bitrate = (gint) ((xing_header.bytes * 8) / (tpf * xing_header.frames * 1000));
-                /* g_print ("Bitrate: Variable,\navg. bitrate: %d kb/s\n",ETFileInfo->bitrate); */
-            } else
-            {
-                ETFileInfo->bitrate = tabsel_123[frm.lsf][frm.lay - 1][frm.bitrate_index];
-                /* g_print ("Bitrate: %d kb/s\n",ETFileInfo->bitrate); */
-            }
-            /* Samplerate. */
-            ETFileInfo->samplerate = mpg123_freqs[frm.sampling_frequency];
-            /* Mode. */
-            ETFileInfo->mode = frm.mode;
-            /* g_print ("Samplerate: %ld Hz\n", mpg123_freqs[frm.sampling_frequency]);
-            g_print ("%s\nError protection: %s\nCopyright: %s\nOriginal: %s\nEmphasis: %s\n", 
channel_mode_name(frm.mode), bool_label[frm.error_protection], bool_label[frm.copyright], 
bool_label[frm.original], emphasis[frm.emphasis]);
-            g_print ("Filesize: %lu B\n", ftell(file)); */
-            g_free (buf);
-        }
-
-        // Duration
-        ETFileInfo->duration = mpg123_get_song_time(file)/1000;
-        //g_print("time %s\n",Convert_Duration(ETFileInfo->duration));
-
-        fclose(file);
-    }else
-    {
-        gchar *filename_utf8 = filename_to_display(filename);
-        Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
-        g_free(filename_utf8);
-        return FALSE;
-    }
-
-#else
-    // Needs to uncomment some #include at the beginning
-
     /*
      * With id3lib, the header frame couldn't be read if the file contains an ID3v2 tag with an APIC frame
      */
-    gulong filesize;
     ID3Tag *id3_tag = NULL;    /* Tag defined by the id3lib */
     const Mp3_Headerinfo* headerInfo = NULL;
 
-
-    if (!filename || !ETFileInfo)
-        return FALSE;
+    g_return_val_if_fail (filename != NULL || ETFileInfo != NULL, FALSE);
 
     /* Get size of file */
-    filesize         = Get_File_Size(filename);
-    ETFileInfo->size = filesize;
+    ETFileInfo->size = Get_File_Size (filename);
 
     /* Get data from tag */
     if ( (id3_tag = ID3Tag_New()) == NULL )
@@ -230,25 +97,6 @@ gboolean Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
     /* Link the file to the tag (uses ID3TT_ID3V2 to get header if APIC is present in Tag) */
     ID3Tag_LinkWithFlags(id3_tag,filename,ID3TT_ID3V2);
 
-    /*ID3_STRUCT(Mp3_Headerinfo)
-    {
-      Mpeg_Layers layer;
-      Mpeg_Version version;
-      MP3_BitRates bitrate;
-      Mp3_ChannelMode channelmode;
-      Mp3_ModeExt modeext;
-      Mp3_Emphasis emphasis;
-      Mp3_Crc crc;
-      uint32 vbr_bitrate;           // avg bitrate from xing header
-      uint32 frequency;             // samplerate
-      uint32 framesize;
-      uint32 frames;                // nr of frames
-      uint32 time;                  // nr of seconds in song
-      bool privatebit;
-      bool copyrighted;
-      bool original;
-    };*/
-
     if ( (headerInfo = ID3Tag_GetMp3HeaderInfo(id3_tag)) )
     {
         switch (headerInfo->version)
@@ -324,8 +172,6 @@ gboolean Mpeg_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo)
     /* Free allocated data */
     ID3Tag_Delete(id3_tag);
 
-#endif
-
     return TRUE;
 }
 
@@ -392,3 +238,5 @@ gboolean Mpeg_Header_Display_File_Info_To_UI(gchar *filename_utf8, ET_File_Info
 
     return TRUE;
 }
+
+#endif /* defined ENABLE_MP3 && defined ENABLE_ID3LIB */
diff --git a/src/wavpack_header.c b/src/wavpack_header.c
index c6dde6d..a7c4d7f 100644
--- a/src/wavpack_header.c
+++ b/src/wavpack_header.c
@@ -111,4 +111,4 @@ gboolean Wavpack_Header_Display_File_Info_To_UI(gchar *filename_utf8, ET_File_In
     return TRUE;
 }
 
-#endif /* ENABLE_FLAC */
+#endif /* ENABLE_WAVPACK */


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