]> git.sesse.net Git - vlc/blobdiff - modules/access/dvb/en50221.c
Remove dead RTCP code
[vlc] / modules / access / dvb / en50221.c
index 40ff0a8df92028456eeed20f87e0905b88232970..a9b492d0b5a7258477f1e015b10e387ddeb53603 100644 (file)
@@ -23,7 +23,7 @@
  *****************************************************************************/
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_access.h>
 
 #include <sys/ioctl.h>
 #include <errno.h>
@@ -65,6 +65,8 @@
 
 #include "dvb.h"
 
+#include <vlc_charset.h>
+
 #undef DEBUG_TPDU
 #define HLCI_WAIT_CAM_READY 0
 #define CAM_PROG_MAX MAX_PROGRAMS
@@ -74,6 +76,7 @@ static void ApplicationInformationOpen( access_t * p_access, int i_session_id );
 static void ConditionalAccessOpen( access_t * p_access, int i_session_id );
 static void DateTimeOpen( access_t * p_access, int i_session_id );
 static void MMIOpen( access_t * p_access, int i_session_id );
+static char *dvbsi_to_utf8( char *psz_instring, size_t i_length );
 
 /*****************************************************************************
  * Utility functions
@@ -884,7 +887,7 @@ static void ApplicationInformationEnterMenu( access_t * p_access,
     access_sys_t *p_sys = p_access->p_sys;
     int i_slot = p_sys->p_sessions[i_session_id - 1].i_slot;
 
-    msg_Dbg( p_access, "Entering MMI menus on session %d", i_session_id );
+    msg_Dbg( p_access, "entering MMI menus on session %d", i_session_id );
     APDUSend( p_access, i_session_id, AOT_ENTER_MENU, NULL, 0 );
     p_sys->pb_slot_mmi_expected[i_slot] = VLC_TRUE;
 }
@@ -1542,7 +1545,7 @@ static void MMISendObject( access_t *p_access, int i_session_id,
         i_size = 1 + strlen( p_object->u.answ.psz_answ );
         p_data = malloc( i_size );
         p_data[0] = (p_object->u.answ.b_ok == VLC_TRUE) ? 0x1 : 0x0;
-        strncpy( &p_data[1], p_object->u.answ.psz_answ, i_size - 1 );
+        strncpy( (char *)&p_data[1], p_object->u.answ.psz_answ, i_size - 1 );
         break;
 
     case EN50221_MMI_MENU_ANSW:
@@ -1597,7 +1600,6 @@ static void MMIDisplayReply( access_t *p_access, int i_session_id )
 static char *MMIGetText( access_t *p_access, uint8_t **pp_apdu, int *pi_size )
 {
     int i_tag = APDUGetTag( *pp_apdu, *pi_size );
-    char *psz_text;
     int l;
     uint8_t *d;
 
@@ -1609,13 +1611,11 @@ static char *MMIGetText( access_t *p_access, uint8_t **pp_apdu, int *pi_size )
     }
 
     d = APDUGetLength( *pp_apdu, &l );
-    psz_text = malloc( l + 1 );
-    strncpy( psz_text, (char *)d, l );
-    psz_text[l] = '\0';
 
     *pp_apdu += l + 4;
     *pi_size -= l + 4;
-    return psz_text;
+
+    return dvbsi_to_utf8((char*)d,l);
 }
 
 /*****************************************************************************
@@ -1824,6 +1824,7 @@ static int InitSlot( access_t * p_access, int i_slot )
             continue;
         }
     }
+
     if ( p_sys->pb_active_slot[i_slot] )
     {
         p_sys->i_ca_timeout = 100000;
@@ -1837,6 +1838,7 @@ static int InitSlot( access_t * p_access, int i_slot )
 /*
  * External entry points
  */
+
 /*****************************************************************************
  * en50221_Init : Initialize the CAM for en50221
  *****************************************************************************/
@@ -1865,6 +1867,7 @@ int E_(en50221_Init)( access_t * p_access )
     else
     {
         struct ca_slot_info info;
+        info.num = 0;
 
         /* We don't reset the CAM in that case because it's done by the
          * ASIC. */
@@ -1945,28 +1948,65 @@ int E_(en50221_Poll)( access_t * p_access )
     for ( i_slot = 0; i_slot < p_sys->i_nb_slots; i_slot++ )
     {
         uint8_t i_tag;
+        ca_slot_info_t sinfo;
 
-        if ( !p_sys->pb_active_slot[i_slot] )
+        sinfo.num = i_slot;
+        if ( ioctl( p_sys->i_ca_handle, CA_GET_SLOT_INFO, &sinfo ) != 0 )
         {
-            ca_slot_info_t sinfo;
-            sinfo.num = i_slot;
-            if ( ioctl( p_sys->i_ca_handle, CA_GET_SLOT_INFO, &sinfo ) != 0 )
+            msg_Err( p_access, "en50221_Poll: couldn't get info on slot %d",
+                     i_slot );
+            continue;
+        }
+
+        if ( !(sinfo.flags & CA_CI_MODULE_READY) )
+        {
+            if ( p_sys->pb_active_slot[i_slot] )
             {
-                msg_Err( p_access, "en50221_Poll: couldn't get info on slot %d",
+                msg_Dbg( p_access, "en50221_Poll: slot %d has been removed",
                          i_slot );
-                continue;
+                p_sys->pb_active_slot[i_slot] = VLC_FALSE;
+                p_sys->pb_slot_mmi_expected[i_slot] = VLC_FALSE;
+                p_sys->pb_slot_mmi_undisplayed[i_slot] = VLC_FALSE;
+
+                /* Close all sessions for this slot. */
+                for ( i_session_id = 1; i_session_id <= MAX_SESSIONS;
+                      i_session_id++ )
+                {
+                    if ( p_sys->p_sessions[i_session_id - 1].i_resource_id
+                          && p_sys->p_sessions[i_session_id - 1].i_slot
+                               == i_slot )
+                    {
+                        if ( p_sys->p_sessions[i_session_id - 1].pf_close
+                              != NULL )
+                        {
+                            p_sys->p_sessions[i_session_id - 1].pf_close(
+                                                p_access, i_session_id );
+                        }
+                        p_sys->p_sessions[i_session_id - 1].i_resource_id = 0;
+                    }
+                }
             }
 
-            if ( sinfo.flags & CA_CI_MODULE_READY )
+            continue;
+        }
+        else if ( !p_sys->pb_active_slot[i_slot] )
+        {
+            InitSlot( p_access, i_slot );
+
+            if ( !p_sys->pb_active_slot[i_slot] )
             {
-                msg_Dbg( p_access, "en50221_Poll: slot %d is active",
-                         i_slot );
-                p_sys->pb_active_slot[i_slot] = VLC_TRUE;
-            }
-            else
+                msg_Dbg( p_access, "en50221_Poll: resetting slot %d", i_slot );
+
+                if ( ioctl( p_sys->i_ca_handle, CA_RESET, 1 << i_slot) != 0 )
+                {
+                    msg_Err( p_access, "en50221_Poll: couldn't reset slot %d",
+                             i_slot );
+                }
                 continue;
+            }
 
-            InitSlot( p_access, i_slot );
+            msg_Dbg( p_access, "en50221_Poll: slot %d is active",
+                     i_slot );
         }
 
         if ( !p_sys->pb_tc_has_data[i_slot] )
@@ -2269,3 +2309,107 @@ void E_(en50221_End)( access_t * p_access )
      * program. */
 }
 
+static inline void *FixUTF8( char *p )
+{
+    EnsureUTF8( p );
+    return p;
+}
+
+static char *dvbsi_to_utf8( char *psz_instring, size_t i_length )
+{
+    const char *psz_encoding;
+    char *psz_stringstart, *psz_outstring, *psz_tmp;
+    char psz_encbuf[12];
+    size_t i_in, i_out;
+    vlc_iconv_t iconv_handle;
+    if( i_length < 1 ) return NULL;
+    if( psz_instring[0] < 0 || psz_instring[0] >= 0x20 )
+    {
+        psz_stringstart = psz_instring;
+        psz_encoding = "ISO_8859-1"; /* should be ISO6937 according to spec, but this seems to be the one used */
+    } else switch( psz_instring[0] )
+    {
+    case 0x01:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-5";
+        break;
+    case 0x02:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-6";
+        break;
+    case 0x03:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-7";
+        break;
+    case 0x04:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-8";
+        break;
+    case 0x05:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-9";
+        break;
+    case 0x06:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-10";
+        break;
+    case 0x07:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-11";
+        break;
+    case 0x08:
+        psz_stringstart = &psz_instring[1]; /*possibly reserved?*/
+        psz_encoding = "ISO_8859-12";
+        break;
+    case 0x09:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-13";
+        break;
+    case 0x0a:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-14";
+        break;
+    case 0x0b:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "ISO_8859-15";
+        break;
+    case 0x10:
+        if( i_length < 3 || psz_instring[1] != '\0' || psz_instring[2] > 0x0f
+            || psz_instring[2] == 0 )
+            return FixUTF8(strndup(psz_instring,i_length));
+        sprintf( psz_encbuf, "ISO_8859-%d", psz_instring[2] );
+        psz_stringstart = &psz_instring[3];
+        psz_encoding = psz_encbuf;
+        break;
+    case 0x11:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "UTF-16";
+        break;
+    case 0x12:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "KSC5601-1987";
+        break;
+    case 0x13:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "GB2312";/*GB-2312-1980 */
+        break;
+    case 0x14:
+        psz_stringstart = &psz_instring[1];
+        psz_encoding = "BIG-5";
+        break;
+    case 0x15:
+        return FixUTF8(strndup(&psz_instring[1],i_length-1));
+        break;
+    default:
+        /* invalid */
+        return FixUTF8(strndup(psz_instring,i_length));
+    }
+    iconv_handle = vlc_iconv_open( "UTF-8", psz_encoding );
+    i_in = i_length - (psz_stringstart - psz_instring );
+    i_out = i_in * 6;
+    psz_outstring = psz_tmp = (char*)malloc( i_out * sizeof(char) + 1 );
+    vlc_iconv( iconv_handle, &psz_stringstart, &i_in, &psz_tmp, &i_out );
+    vlc_iconv_close( iconv_handle );
+    *psz_tmp = '\0';
+    return psz_outstring;
+}