After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 647141 - Add id3v2 encoding detect via enca
Add id3v2 encoding detect via enca
Status: RESOLVED DUPLICATE of bug 451565
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
0.10.32
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-04-08 08:06 UTC by Heiher
Modified: 2011-05-18 20:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Heiher 2011-04-08 08:06:28 UTC
From 6ce30751a6612c6c4e1840eb8e7be2bf9ec4f589 Mon Sep 17 00:00:00 2001
From: Heiher <admin@heiher.info>
Date: Fri, 8 Apr 2011 15:52:38 +0800
Subject: [PATCH] Add id3v2 encoding detect via enca

---
 configure.ac               |   13 +++++++++++++
 gst/id3demux/Makefile.am   |    4 ++--
 gst/id3demux/id3v2frames.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index c7757bb..71108f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1004,6 +1004,18 @@ AG_GST_CHECK_FEATURE(ZLIB, [zlib support for id3demux/qtdemux/matroska],, [
   ])
 ])
 
+dnl *** id3demux prefer to have enca ***
+translit(dnm, m, l) AM_CONDITIONAL(USE_ENCA, true)
+AG_GST_CHECK_FEATURE(ENCA, [enca support for id3demux],, [
+  AG_GST_CHECK_LIBHEADER(ENCA,
+    enca, enca_analyser_alloc,, enca.h, [
+    HAVE_ENCA="yes"
+	ENCA_CFLAGS=""
+    ENCA_LIBS="-lenca"
+    AC_SUBST(ENCA_LIBS)
+  ])
+])
+
 dnl *** matroska prefers to have bz2 ***
 translit(dnm, m, l) AM_CONDITIONAL(USE_BZ2, true)
 AG_GST_CHECK_FEATURE(BZ2, [bz2 library for matroska ],, [
@@ -1049,6 +1061,7 @@ AM_CONDITIONAL(USE_X, false)
 AM_CONDITIONAL(USE_XSHM, false)
 AM_CONDITIONAL(USE_XVIDEO, false)
 AM_CONDITIONAL(USE_ZLIB, false)
+AM_CONDITIONAL(USE_ENCA, false)
 
 fi dnl of EXT plugins
 
diff --git a/gst/id3demux/Makefile.am b/gst/id3demux/Makefile.am
index 3f00443..f02f684 100644
--- a/gst/id3demux/Makefile.am
+++ b/gst/id3demux/Makefile.am
@@ -1,9 +1,9 @@
 plugin_LTLIBRARIES = libgstid3demux.la
 
 libgstid3demux_la_SOURCES = gstid3demux.c id3tags.c id3v2frames.c
-libgstid3demux_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) 
+libgstid3demux_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(ENCA_CFLAGS)
 libgstid3demux_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgsttag-@GST_MAJORMINOR@ \
-	-lgstpbutils-@GST_MAJORMINOR@ $(GST_BASE_LIBS) $(ZLIB_LIBS)
+	-lgstpbutils-@GST_MAJORMINOR@ $(GST_BASE_LIBS) $(ZLIB_LIBS) $(ENCA_LIBS)
 libgstid3demux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
 libgstid3demux_la_LIBTOOLFLAGS = --tag=disable-static
 
diff --git a/gst/id3demux/id3v2frames.c b/gst/id3demux/id3v2frames.c
index e51bbb7..24b242a 100644
--- a/gst/id3demux/id3v2frames.c
+++ b/gst/id3demux/id3v2frames.c
@@ -33,6 +33,10 @@
 #include <zlib.h>
 #endif
 
+#ifdef HAVE_ENCA
+#include <enca.h>
+#endif
+
 #include "id3tags.h"
 
 GST_DEBUG_CATEGORY_EXTERN (id3demux_debug);
@@ -962,6 +966,10 @@ string_utf8_dup (const gchar * start, const guint size)
   const gchar *env;
   gsize bytes_read;
   gchar *utf8;
+#ifdef HAVE_ENCA
+  EncaAnalyser eanalyser;
+  gchar langname[3];
+#endif
 
   /* Should we try the charsets specified
    * via environment variables FIRST ? */
@@ -995,6 +1003,8 @@ string_utf8_dup (const gchar * start, const guint size)
       }
     }
   }
+
+#ifndef HAVE_ENCA
   /* Try current locale (if not UTF-8) */
   if (!g_get_charset (&env)) {
     if ((utf8 = g_locale_to_utf8 (start, size, &bytes_read, NULL, NULL))) {
@@ -1015,11 +1025,40 @@ string_utf8_dup (const gchar * start, const guint size)
 
   g_free (utf8);
   return NULL;
+#else /* HAVE_ENCA */
+  env = g_getenv("LANG");
+  if(NULL == env) {
+	  return NULL;
+  }
+  langname[0] = env[0];
+  langname[1] = env[1];
+  langname[2] = 0;
+
+  eanalyser = enca_analyser_alloc(langname);
+  if(eanalyser) {
+	  EncaEncoding encoding;
+	  const gchar * charset;
+
+	  encoding = enca_analyse(eanalyser, (unsigned char*)start, size);
+	  if(ENCA_CS_UNKNOWN != encoding.charset) {
+		  charset = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
+
+		  utf8 = g_convert (start, size, "UTF-8", charset, &bytes_read, NULL, NULL);
+		  if (utf8 != NULL && bytes_read == size) {
+			  enca_analyser_free(eanalyser);
+			  goto beach;
+		  }
+	  }
+
+	  enca_analyser_free(eanalyser);
+  }
 
-beach:
+  g_free(utf8);
+  return NULL;
+#endif
 
+beach:
   g_strchomp (utf8);
-
   return (utf8);
 }
 
-- 
1.7.4.4
Comment 1 Sebastian Dröge (slomo) 2011-05-18 20:21:00 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.

*** This bug has been marked as a duplicate of bug 451565 ***