--- gst-plugins-0.8.7~/ext/mad/gstid3tag.c	2004-11-08 20:44:21 +0200
+++ gst-plugins-0.8.7/ext/mad/gstid3tag.c	2005-01-24 10:52:02 +0200
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <gst/gsttaginterface.h>
+#include <enca.h>
+#include <locale.h>
 
 #define ID3_TYPE_FIND_SIZE 40960
 GST_DEBUG_CATEGORY_STATIC (gst_id3_tag_debug);
@@ -537,8 +539,8 @@
     const union id3_field *field;
     unsigned int nstrings, j;
     const gchar *tag_name;
-
-    /* find me the function to query the frame id */
+    enum id3_field_textencoding encoding = 0xff;
+	/* find me the function to query the frame id */
     gchar *id = g_strndup (frame->id, 5);
 
     tag_name = gst_tag_from_id3_tag (id);
@@ -567,6 +569,10 @@
       g_free (utf8);
       continue;
     }
+    
+    field = id3_frame_field(frame, 0);
+    if(id3_field_type(field) == ID3_FIELD_TYPE_TEXTENCODING)
+    encoding = field->number.value;
 
     field = &frame->fields[1];
     nstrings = id3_field_getnstrings (field);
@@ -577,9 +583,39 @@
 
       if (strcmp (id, ID3_FRAME_GENRE) == 0)
         ucs4 = id3_genre_name (ucs4);
-
-      utf8 = id3_ucs4_utf8duplicate (ucs4);
-      if (utf8 == 0)
+      
+      utf8 = NULL;
+      if(encoding == ID3_FIELD_TEXTENCODING_ISO_8859_1) {
+    	EncaAnalyser analyser;
+  		EncaEncoding encoding;
+		char * unknown;
+		
+		unknown = id3_ucs4_latin1duplicate(ucs4);
+
+		analyser = enca_analyser_alloc(g_strndup (setlocale(LC_ALL,""), 2));
+		encoding = enca_analyse(analyser, unknown, strlen(unknown));
+	
+		if (!enca_charset_is_known(encoding.charset)) {
+			utf8 = g_convert(unknown, strlen(unknown), "UTF8", "CP1251",
+										NULL, NULL, NULL);
+			g_printerr("Enca error: %s\n", enca_strerror(analyser,
+													enca_errno(analyser))); 
+		} else {
+			utf8 = g_convert(unknown,
+						strlen(unknown), 
+						"UTF8", 
+						enca_charset_name(encoding.charset, 
+											ENCA_NAME_STYLE_ICONV),
+						NULL, 
+						NULL,
+						NULL);
+    	}
+		enca_analyser_free(analyser);	
+		free(unknown);
+	}
+    if (utf8 == 0) 
+		utf8 = id3_ucs4_utf8duplicate (ucs4);
+    if (utf8 == 0)
         continue;
 
       if (!g_utf8_validate (utf8, -1, NULL)) {
@@ -660,11 +696,12 @@
       }
       free (utf8);
     }
-    g_free (id);
+	g_free (id);	
   }
 
   return tag_list;
 }
+
 static void
 tag_list_to_id3_tag_foreach (const GstTagList * list, const gchar * tag_name,
     gpointer user_data)
@@ -1069,7 +1106,7 @@
       if (tag->v1tag_size == 128) {
         GstTagList *newtag;
 
-        newtag = gst_tag_list_new_from_id3v1 (GST_BUFFER_DATA (tag->buffer));
+        newtag = gst_tag_list_new_from_id3v1 (GST_BUFFER_DATA(tag->buffer));
         GST_LOG_OBJECT (tag, "have read ID3v1 tag");
         if (newtag) {
           if (tag->parsed_tags) {
