[PATCH] Add id3v2 encoding detect via enca
Heiher
admin at heiher.info
Fri Apr 8 00:52:38 PDT 2011
---
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- at GST_MAJORMINOR@
\
- -lgstpbutils- at GST_MAJORMINOR@ $(GST_BASE_LIBS) $(ZLIB_LIBS)
+ -lgstpbutils- at 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
--
Configure bugmail: https://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the gstreamer-bugs
mailing list