>From ea7ab5a995c2f01f1fbc835be9860918b275c499 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Marian=20=C4=8Eurkovi=C4=8D?= <md@bts.sk>
Date: Thu, 3 Sep 2009 07:43:17 +0200
Subject: [PATCH] Fix EPG default charset (closes #3054)

---
 modules/demux/ts.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/modules/demux/ts.c b/modules/demux/ts.c
index 9754126..1400ff9 100644
--- a/modules/demux/ts.c
+++ b/modules/demux/ts.c
@@ -2573,7 +2573,7 @@ static void ValidateDVBMeta( demux_t *p_demux, int i_pid )
 #ifdef TS_USE_DVB_SI
 /* FIXME same than dvbsi_to_utf8 from dvb access */
 static char *EITConvertToUTF8( const unsigned char *psz_instring,
-                               size_t i_length )
+                               size_t i_length, const char *psz_lang )
 {
     const char *psz_encoding;
     char *psz_outstring;
@@ -2584,9 +2584,17 @@ static char *EITConvertToUTF8( const unsigned char *psz_instring,
     if( i_length < 1 ) return NULL;
     if( psz_instring[0] >= 0x20 )
     {
-        psz_encoding = "ISO_8859-1";
         /* According to the specification, this should be ISO6937,
-         * but it seems Latin-1 is used instead. */
+         * but CanalSat FR uses ISO8859-1 without properly selecting it */ 
+        if ( !strncasecmp( psz_lang, "fre", 3 ) ||
+             !strncasecmp( psz_lang, "fra", 3 ) )
+        {
+            psz_encoding = "ISO_8859-1";
+        }
+        else
+        {
+            psz_encoding = "ISO_6937";
+        }
         offset = 0;
     }
     else switch( psz_instring[0] )
@@ -2766,9 +2774,9 @@ static void SDTCallBack( demux_t *p_demux, dvbpsi_sdt_t *p_sdt )
                 char *str2 = NULL;
 
                 str1 = EITConvertToUTF8(pD->i_service_provider_name,
-                                        pD->i_service_provider_name_length);
+                                        pD->i_service_provider_name_length, "xxx");
                 str2 = EITConvertToUTF8(pD->i_service_name,
-                                        pD->i_service_name_length);
+                                        pD->i_service_name_length, "xxx");
 
                 msg_Dbg( p_demux, "    - type=%d provider=%s name=%s",
                          pD->i_service_type, str1, str2 );
@@ -2916,8 +2924,8 @@ static void EITCallBack( demux_t *p_demux,
 
                 if( pE )
                 {
-                    psz_name = EITConvertToUTF8( pE->i_event_name, pE->i_event_name_length);
-                    psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length );
+                    psz_name = EITConvertToUTF8( pE->i_event_name, pE->i_event_name_length, pE->i_iso_639_code);
+                    psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length, pE->i_iso_639_code );
                     msg_Dbg( p_demux, "    - short event lang=%3.3s '%s' : '%s'",
                              pE->i_iso_639_code, psz_name, psz_text );
                 }
@@ -2933,7 +2941,7 @@ static void EITCallBack( demux_t *p_demux,
 
                     if( pE->i_text_length > 0 )
                     {
-                        char *psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length );
+                        char *psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length, pE->i_iso_639_code );
                         if( psz_text )
                         {
                             msg_Dbg( p_demux, "       - text='%s'", psz_text );
@@ -2947,8 +2955,8 @@ static void EITCallBack( demux_t *p_demux,
                     for( int i = 0; i < pE->i_entry_count; i++ )
                     {
                         char *psz_dsc = EITConvertToUTF8( pE->i_item_description[i],
-                                                          pE->i_item_description_length[i] );
-                        char *psz_itm = EITConvertToUTF8( pE->i_item[i], pE->i_item_length[i] );
+                                                          pE->i_item_description_length[i], pE->i_iso_639_code );
+                        char *psz_itm = EITConvertToUTF8( pE->i_item[i], pE->i_item_length[i], pE->i_iso_639_code );
 
                         if( psz_dsc && psz_itm )
                         {
-- 
1.5.3.3

