]> git.sesse.net Git - vlc/blobdiff - modules/demux/mp4/mp4.c
Force to specify options flags in input_item_New*.
[vlc] / modules / demux / mp4 / mp4.c
index bd15ad41e419c5d10c2b0670a52cf6d26f50a845..10e9fe07a16a63288cc4b8e5f565570e09329065 100644 (file)
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
-    set_description( N_("MP4 stream demuxer") );
-    set_capability( "demux", 242 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
+    set_description( N_("MP4 stream demuxer") )
+    set_capability( "demux", 242 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -102,6 +102,8 @@ typedef struct
     bool b_selected;  /* is the trak being played */
     bool b_chapter;   /* True when used for chapter only */
 
+    bool b_mac_encoding;
+
     es_format_t fmt;
     es_out_id_t *p_es;
 
@@ -139,6 +141,7 @@ typedef struct
 
     bool b_drms;
     void      *p_drms;
+    MP4_Box_t *p_skcr;
 
 } mp4_track_t;
 
@@ -166,7 +169,7 @@ struct demux_sys_t
 /*****************************************************************************
  * Declaration of local function
  *****************************************************************************/
-static void MP4_TrackCreate ( demux_t *, mp4_track_t *, MP4_Box_t  *);
+static void MP4_TrackCreate ( demux_t *, mp4_track_t *, MP4_Box_t  *, bool b_force_enable );
 static void MP4_TrackDestroy(  mp4_track_t * );
 
 static int  MP4_TrackSelect ( demux_t *, mp4_track_t *, mtime_t );
@@ -180,6 +183,7 @@ static int      MP4_TrackNextSample( demux_t *, mp4_track_t * );
 static void     MP4_TrackSetELST( demux_t *, mp4_track_t *, int64_t );
 
 static void     MP4_UpdateSeekpoint( demux_t * );
+static const char *MP4_ConvertMacCode( uint16_t );
 
 /* Return time in s of a track */
 static inline int64_t MP4_TrackGetDTS( demux_t *p_demux, mp4_track_t *p_track )
@@ -276,6 +280,7 @@ static int Open( vlc_object_t * p_this )
 
     unsigned int    i;
     bool      b_seekable;
+    bool      b_enabled_es;
 
     /* A little test to see if it could be a mp4 */
     if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 ) return VLC_EGENERIC;
@@ -364,9 +369,8 @@ static int Open( vlc_object_t * p_this )
 
         msg_Dbg( p_demux, "detected playlist mov file (%d ref)", i_count );
 
-        input_thread_t * p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
-        input_item_t * p_current = input_GetItem( p_input );
-        p_current->i_type = ITEM_TYPE_PLAYLIST;
+        input_thread_t *p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
+        input_item_t *p_current = input_GetItem( p_input );
 
         for( i = 0; i < i_count; i++ )
         {
@@ -411,12 +415,11 @@ static int Open( vlc_object_t * p_this )
                     psz_ref = psz_absolute;
                     free( psz_path );
                 }
-                input_item_t *p_input;
                 msg_Dbg( p_demux, "adding ref = `%s'", psz_ref );
-                p_input = input_ItemNewExt( p_demux, psz_ref, NULL,
-                                    0, NULL, -1 );
-                input_ItemCopyOptions( p_current, p_input );
-                input_ItemAddSubItem( p_current, p_input );
+                input_item_t *p_input = input_item_NewExt( p_demux, psz_ref
+                                                           , NULL, 0, NULL, 0, -1 );
+                input_item_CopyOptions( p_current, p_input );
+                input_item_AddSubItem( p_current, p_input );
                 vlc_gc_decref( p_input );
             }
             else
@@ -469,24 +472,29 @@ static int Open( vlc_object_t * p_this )
         goto error;
     memset( p_sys->track, 0, p_sys->i_tracks * sizeof( mp4_track_t ) );
 
-    /* Search the first chap reference (like quicktime) */
+    /* Search the first chap reference (like quicktime) and
+     * check that at least 1 stream is enabled */
     p_sys->p_tref_chap = NULL;
+    b_enabled_es = false;
     for( i = 0; i < p_sys->i_tracks; i++ )
     {
         MP4_Box_t *p_trak = MP4_BoxGet( p_sys->p_root, "/moov/trak[%d]", i );
-        MP4_Box_t *p_chap = MP4_BoxGet( p_trak, "tref/chap", i );
-        if( !p_chap || p_chap->data.p_tref_generic->i_entry_count <= 0 )
-            continue;
 
-        p_sys->p_tref_chap = p_chap;
-        break;
+
+        MP4_Box_t *p_tkhd = MP4_BoxGet( p_trak, "tkhd" );
+        if( p_tkhd && (p_tkhd->data.p_tkhd->i_flags&MP4_TRACK_ENABLED) )
+            b_enabled_es = true;
+
+        MP4_Box_t *p_chap = MP4_BoxGet( p_trak, "tref/chap", i );
+        if( p_chap && p_chap->data.p_tref_generic->i_entry_count > 0 && !p_sys->p_tref_chap )
+            p_sys->p_tref_chap = p_chap;
     }
 
     /* now process each track and extract all usefull information */
     for( i = 0; i < p_sys->i_tracks; i++ )
     {
         p_trak = MP4_BoxGet( p_sys->p_root, "/moov/trak[%d]", i );
-        MP4_TrackCreate( p_demux, &p_sys->track[i], p_trak );
+        MP4_TrackCreate( p_demux, &p_sys->track[i], p_trak, !b_enabled_es );
 
         if( p_sys->track[i].b_ok && !p_sys->track[i].b_chapter )
         {
@@ -654,8 +662,24 @@ static int Demux( demux_t *p_demux )
 
                 if( tk->b_drms && tk->p_drms )
                 {
-                    drms_decrypt( tk->p_drms, (uint32_t*)p_block->p_buffer,
-                                  p_block->i_buffer );
+                    if( tk->p_skcr )
+                    {
+                        uint32_t p_key[4];
+                        drms_get_p_key( tk->p_drms, p_key );
+
+                        for( int i_pos = tk->p_skcr->data.p_skcr->i_init; i_pos < p_block->i_buffer; )
+                        {
+                            int n = __MIN( tk->p_skcr->data.p_skcr->i_encr, p_block->i_buffer - i_pos );
+                            drms_decrypt( tk->p_drms, (uint32_t*)&p_block->p_buffer[i_pos], n, p_key );
+                            i_pos += n;
+                            i_pos += __MIN( tk->p_skcr->data.p_skcr->i_decr, p_block->i_buffer - i_pos );
+                        }
+                    }
+                    else
+                    {
+                        drms_decrypt( tk->p_drms, (uint32_t*)p_block->p_buffer,
+                                      p_block->i_buffer, NULL );
+                    }
                 }
                 else if( tk->fmt.i_cat == SPU_ES )
                 {
@@ -750,6 +774,9 @@ static int Seek( demux_t *p_demux, mtime_t i_date )
         MP4_TrackSeek( p_demux, tk, i_date );
     }
     MP4_UpdateSeekpoint( p_demux );
+
+    es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
+
     return VLC_SUCCESS;
 }
 
@@ -1068,7 +1095,7 @@ static void LoadChapter( demux_t  *p_demux )
             }
             if( j < p_sys->i_tracks )
             {
-                LoadChapterApple( p_demux, &p_sys->track[i] );
+                LoadChapterApple( p_demux, &p_sys->track[j] );
                 break;
             }
         }
@@ -1261,6 +1288,9 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
         ck->p_sample_count_dts = calloc( i_entry, sizeof( uint32_t ) );
         ck->p_sample_delta_dts = calloc( i_entry, sizeof( uint32_t ) );
 
+        if( !ck->p_sample_count_dts || !ck->p_sample_delta_dts )
+            return VLC_ENOMEM;
+
         /* now copy */
         i_sample_count = ck->i_sample_count;
         for( i = 0; i < i_entry; i++ )
@@ -1324,6 +1354,8 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
             /* allocate them */
             ck->p_sample_count_pts = calloc( i_entry, sizeof( uint32_t ) );
             ck->p_sample_offset_pts = calloc( i_entry, sizeof( int32_t ) );
+            if( !ck->p_sample_count_pts || !ck->p_sample_offset_pts )
+                return VLC_ENOMEM;
 
             /* now copy */
             i_sample_count = ck->i_sample_count;
@@ -1369,6 +1401,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
     MP4_Box_t   *p_sample;
     MP4_Box_t   *p_esds;
     MP4_Box_t   *p_box;
+    MP4_Box_t   *p_frma;
 
     if( pp_es )
         *pp_es = NULL;
@@ -1393,6 +1426,13 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
 
     p_track->p_sample = p_sample;
 
+    if( ( p_frma = MP4_BoxGet( p_track->p_sample, "sinf/frma" ) ) )
+    {
+        msg_Warn( p_demux, "Original Format Box: %4.4s", (char *)&p_frma->data.p_frma->i_type );
+
+        p_sample->i_type = p_frma->data.p_frma->i_type;
+    }
+
     if( p_track->fmt.i_cat == AUDIO_ES && ( p_track->i_sample_size == 1 || p_track->i_sample_size == 2 ) )
     {
         MP4_Box_data_sample_soun_t *p_soun;
@@ -1451,8 +1491,13 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
     {
         case( VLC_FOURCC( '.', 'm', 'p', '3' ) ):
         case( VLC_FOURCC( 'm', 's', 0x00, 0x55 ) ):
+        {
+            MP4_Box_data_sample_soun_t *p_soun = p_sample->data.p_sample_soun;
             p_track->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
+            if( p_track->i_sample_size > 1 )
+                p_soun->i_qt_version = 0;
             break;
+        }
 
         case( VLC_FOURCC( 'r', 'a', 'w', ' ' ) ):
         case( VLC_FOURCC( 'N', 'O', 'N', 'E' ) ):
@@ -1492,7 +1537,10 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
             p_track->fmt.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
             /* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */
             /* FIXME UTF-8 doesn't work here ? */
-            p_track->fmt.subs.psz_encoding = strdup( "UTF-8" );
+            if( p_track->b_mac_encoding )
+                p_track->fmt.subs.psz_encoding = strdup( "MAC" );
+            else
+                p_track->fmt.subs.psz_encoding = strdup( "UTF-8" );
             break;
 
         case VLC_FOURCC('y','v','1','2'):
@@ -1644,7 +1692,6 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
                 break;
             case VLC_FOURCC( 'Q', 'D', 'M', 'C' ):
             case VLC_FOURCC( 'Q', 'D', 'M', '2' ):
-            case VLC_FOURCC( 'Q', 'c', 'l', 'p' ):
             case VLC_FOURCC( 's', 'a', 'm', 'r' ):
             case VLC_FOURCC( 'a', 'l', 'a', 'c' ):
                 p_track->fmt.i_extra =
@@ -1666,9 +1713,12 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
                 if( p_avcC )
                 {
                     p_track->fmt.i_extra = p_avcC->data.p_avcC->i_avcC;
-                    p_track->fmt.p_extra = malloc( p_avcC->data.p_avcC->i_avcC );
-                    memcpy( p_track->fmt.p_extra, p_avcC->data.p_avcC->p_avcC,
-                            p_track->fmt.i_extra );
+                    if( p_track->fmt.i_extra > 0 )
+                    {
+                        p_track->fmt.p_extra = malloc( p_avcC->data.p_avcC->i_avcC );
+                        memcpy( p_track->fmt.p_extra, p_avcC->data.p_avcC->p_avcC,
+                                p_track->fmt.i_extra );
+                    }
                 }
                 else
                 {
@@ -1679,6 +1729,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
 
             case VLC_FOURCC('m','s',0x00,0x02):
             case VLC_FOURCC('m','s',0x00,0x11):
+            case VLC_FOURCC('Q','c','l','p'):
                 p_track->fmt.audio.i_blockalign = p_sample->data.p_sample_soun->i_bytes_per_frame;
                 break;
 
@@ -1692,7 +1743,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
     /* some last initialisation */
     switch( p_track->fmt.i_cat )
     {
-    case( VIDEO_ES ):
+    case VIDEO_ES:
         p_track->fmt.video.i_width = p_sample->data.p_sample_vide->i_width;
         p_track->fmt.video.i_height = p_sample->data.p_sample_vide->i_height;
         p_track->fmt.video.i_bits_per_pixel =
@@ -1729,7 +1780,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
 
         break;
 
-    case( AUDIO_ES ):
+    case AUDIO_ES:
         p_track->fmt.audio.i_channels =
             p_sample->data.p_sample_soun->i_channelcount;
         p_track->fmt.audio.i_rate =
@@ -1739,6 +1790,13 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
                 p_sample->data.p_sample_soun->i_samplesize;
         p_track->fmt.audio.i_bitspersample =
             p_sample->data.p_sample_soun->i_samplesize;
+
+        if( p_track->i_sample_size != 0 &&
+            p_sample->data.p_sample_soun->i_qt_version == 1 && p_sample->data.p_sample_soun->i_sample_per_packet <= 0 )
+        {
+            msg_Err( p_demux, "Invalid sample per packet value for qt_version 1" );
+            return VLC_EGENERIC;
+        }
         break;
 
     default:
@@ -1923,9 +1981,9 @@ static int TrackGotoChunkSample( demux_t *p_demux, mp4_track_t *p_track,
     bool b_reselect = false;
 
     /* now see if actual es is ok */
-    if( (p_track->i_chunk >= p_track->i_chunk_count - 1) ||
-        (p_track->chunk[p_track->i_chunk].i_sample_description_index !=
-            p_track->chunk[i_chunk].i_sample_description_index) )
+    if( p_track->i_chunk >= p_track->i_chunk_count ||
+        p_track->chunk[p_track->i_chunk].i_sample_description_index !=
+            p_track->chunk[i_chunk].i_sample_description_index )
     {
         msg_Warn( p_demux, "recreate ES for track[Id 0x%x]",
                   p_track->i_track_ID );
@@ -1967,7 +2025,8 @@ static int TrackGotoChunkSample( demux_t *p_demux, mp4_track_t *p_track,
  * If it succeed b_ok is set to 1 else to 0
  ****************************************************************************/
 static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
-                             MP4_Box_t *p_box_trak )
+                             MP4_Box_t *p_box_trak,
+                             bool b_force_enable )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
 
@@ -1994,6 +2053,7 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
     p_track->b_enable   = false;
     p_track->b_selected = false;
     p_track->b_chapter  = false;
+    p_track->b_mac_encoding = false;
 
     es_format_Init( &p_track->fmt, UNKNOWN_ES, 0 );
 
@@ -2029,11 +2089,19 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
     if( !p_track->i_timescale )
         return;
 
-    for( i = 0; i < 3; i++ )
+    if( p_mdhd->data.p_mdhd->i_language_code < 0x800 )
+    {
+        /* We can convert i_language_code into iso 639 code,
+         * I won't */
+        strcpy( language, MP4_ConvertMacCode( p_mdhd->data.p_mdhd->i_language_code ) );
+        p_track->b_mac_encoding = true;
+    }
+    else
     {
-        language[i] = p_mdhd->data.p_mdhd->i_language[i];
+        for( i = 0; i < 3; i++ )
+            language[i] = p_mdhd->data.p_mdhd->i_language[i];
+        language[3] = '\0';
     }
-    language[3] = '\0';
 
     switch( p_hdlr->data.p_hdlr->i_handler_type )
     {
@@ -2056,6 +2124,7 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
         case( FOURCC_text ):
         case( FOURCC_subp ):
         case( FOURCC_tx3g ):
+        case( FOURCC_sbtl ):
             p_track->fmt.i_cat = SPU_ES;
             break;
 
@@ -2100,8 +2169,19 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
     p_track->p_drms = p_track->b_drms ?
         p_drms->data.p_sample_soun->p_drms : NULL;
 
+    if ( !p_drms )
+    {
+        p_drms = MP4_BoxGet( p_track->p_stsd, "drmi" );
+        p_track->b_drms = p_drms != NULL;
+        p_track->p_drms = p_track->b_drms ?
+            p_drms->data.p_sample_vide->p_drms : NULL;
+    }
+
+    if( p_drms )
+        p_track->p_skcr = MP4_BoxGet( p_drms, "sinf/skcr" );
+
     /* Set language */
-    if( strcmp( language, "```" ) && strcmp( language, "und" ) )
+    if( *language && strcmp( language, "```" ) && strcmp( language, "und" ) )
     {
         p_track->fmt.psz_language = strdup( language );
     }
@@ -2134,7 +2214,7 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
     p_track->i_sample = 0;
 
     /* Mark chapter only track */
-    if( !p_track->b_enable && p_sys->p_tref_chap )
+    if( p_sys->p_tref_chap )
     {
         MP4_Box_data_tref_generic_t *p_chap = p_sys->p_tref_chap->data.p_tref_generic;
         unsigned int i;
@@ -2144,12 +2224,22 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
             if( p_track->i_track_ID == p_chap->i_track_ID[i] )
             {
                 p_track->b_chapter = true;
+                p_track->b_enable = false;
                 break;
             }
         }
     }
 
     /* now create es */
+    if( b_force_enable &&
+        ( p_track->fmt.i_cat == VIDEO_ES || p_track->fmt.i_cat == AUDIO_ES ) )
+    {
+        msg_Warn( p_demux, "Enabling track[Id 0x%x] (buggy file without enabled track)",
+                  p_track->i_track_ID );
+        p_track->b_enable = true;
+        p_track->fmt.i_priority = 0;
+    }
+
     p_track->p_es = NULL;
     if( TrackCreateES( p_demux,
                        p_track, p_track->i_chunk,
@@ -2269,15 +2359,9 @@ static int MP4_TrackSeek( demux_t *p_demux, mp4_track_t *p_track,
 
     p_track->b_selected = true;
 
-    if( TrackGotoChunkSample( p_demux, p_track, i_chunk, i_sample ) ==
-        VLC_SUCCESS )
-    {
+    if( !TrackGotoChunkSample( p_demux, p_track, i_chunk, i_sample ) )
         p_track->b_selected = true;
 
-        es_out_Control( p_demux->out, ES_OUT_SET_NEXT_DISPLAY_TIME,
-                        p_track->p_es, i_start );
-    }
-
     return p_track->b_selected ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
@@ -2306,8 +2390,11 @@ static int MP4_TrackSampleSize( mp4_track_t *p_track )
 
     if( p_soun->i_qt_version == 1 )
     {
-        i_size = p_track->chunk[p_track->i_chunk].i_sample_count /
-            p_soun->i_sample_per_packet * p_soun->i_bytes_per_frame;
+        int i_samples = p_track->chunk[p_track->i_chunk].i_sample_count;
+        if( p_track->fmt.audio.i_blockalign > 1 )
+            i_samples = p_soun->i_sample_per_packet;
+
+        i_size = i_samples / p_soun->i_sample_per_packet * p_soun->i_bytes_per_frame;
     }
     else if( p_track->i_sample_size > 256 )
     {
@@ -2350,8 +2437,10 @@ static uint64_t MP4_TrackGetPos( mp4_track_t *p_track )
         }
         else
         {
-            /* we read chunk by chunk */
-            i_pos += 0;
+            /* we read chunk by chunk unless a blockalign is requested */
+            if( p_track->fmt.audio.i_blockalign > 1 )
+                i_pos += ( p_track->i_sample - p_track->chunk[p_track->i_chunk].i_sample_first ) /
+                                p_soun->i_sample_per_packet * p_soun->i_bytes_per_frame;
         }
     }
     else
@@ -2376,10 +2465,11 @@ static int MP4_TrackNextSample( demux_t *p_demux, mp4_track_t *p_track )
 
         if( p_soun->i_qt_version == 1 )
         {
-            /* chunk by chunk */
-            p_track->i_sample =
-                p_track->chunk[p_track->i_chunk].i_sample_first +
-                p_track->chunk[p_track->i_chunk].i_sample_count;
+            /* we read chunk by chunk unless a blockalign is requested */
+            if( p_track->fmt.audio.i_blockalign > 1 )
+                p_track->i_sample += p_soun->i_sample_per_packet;
+            else
+                p_track->i_sample += p_track->chunk[p_track->i_chunk].i_sample_count;
         }
         else if( p_track->i_sample_size > 256 )
         {
@@ -2487,3 +2577,44 @@ static void MP4_TrackSetELST( demux_t *p_demux, mp4_track_t *tk,
         msg_Warn( p_demux, "elst old=%d new=%d", i_elst_last, tk->i_elst );
     }
 }
+
+/* */
+static const char *MP4_ConvertMacCode( uint16_t i_code )
+{
+    static const struct { const char *psz_iso639_1; uint16_t i_code; } p_cvt[] = {
+        { "en",   0 }, { "fr",   1 }, { "de",   2 }, { "it",   3 }, { "nl",   4 },
+        { "sv",   5 }, { "es",   6 }, { "da",   7 }, { "pt",   8 }, { "no",   9 },
+        { "he",  10 }, { "ja",  11 }, { "ar",  12 }, { "fi",  13 }, { "el",  14 },
+        { "is",  15 }, { "mt",  16 }, { "tr",  17 }, { "hr",  18 }, { "zh",  19 },
+        { "ur",  20 }, { "hi",  21 }, { "th",  22 }, { "ko",  23 }, { "lt",  24 },
+        { "pl",  25 }, { "hu",  26 }, { "et",  27 }, { "lv",  28 }, //{ "??",  29 },
+        { "fo",  30 }, { "fa",  31 }, { "ru",  32 }, { "zh",  33 }, { "nl",  34 },
+        { "ga",  35 }, { "sq",  36 }, { "ro",  37 }, { "cs",  38 }, { "sk",  39 },
+        { "sl",  40 }, { "yi",  41 }, { "sr",  42 }, { "mk",  43 }, { "bg",  44 },
+        { "uk",  45 }, { "be",  46 }, { "uz",  47 }, { "az",  48 }, { "kk",  48 },
+        { "az",  50 }, { "hy",  51 }, { "ka",  52 }, { "mo",  53 }, { "ky",  54 },
+        { "tg",  55 }, { "tk",  56 }, { "mn",  57 }, { "mn",  58 }, { "ps",  59 },
+        { "ku",  60 }, { "ks",  61 }, { "sd",  62 }, { "bo",  63 }, { "ne",  64 },
+        { "sa",  65 }, { "mr",  66 }, { "bn",  67 }, { "as",  68 }, { "gu",  69 },
+        { "pa",  70 }, { "or",  71 }, { "ml",  72 }, { "kn",  73 }, { "ta",  74 },
+        { "te",  75 }, { "si",  76 }, { "my",  77 }, { "km",  78 }, { "lo",  79 },
+        { "vi",  80 }, { "id",  81 }, { "tl",  82 }, { "ms",  83 }, { "ms",  84 },
+        { "am",  85 }, { "ti",  86 }, { "om",  87 }, { "so",  88 }, { "sw",  89 },
+        { "rw",  90 }, { "rn",  91 }, { "ny",  92 }, { "mg",  93 }, { "eo",  94 },
+
+                                                     { "cy", 128 }, { "eu", 129 },
+        { "ca", 130 }, { "la", 131 }, { "qu", 132 }, { "gn", 133 }, { "ay", 134 },
+        { "tt", 135 }, { "ug", 136 }, { "dz", 137 }, { "jv", 138 }, { "su", 139 },
+        { "gl", 140 }, { "af", 141 }, { "br", 142 }, { "iu", 143 }, { "gd", 144 },
+        { "gv", 145 }, { "ga", 146 }, { "to", 147 }, { "el", 148 },
+        /* */
+        { NULL, 0 }
+    };
+    int i;
+    for( i = 0; p_cvt[i].psz_iso639_1 != NULL; i++ )
+    {
+        if( p_cvt[i].i_code == i_code )
+            return p_cvt[i].psz_iso639_1;
+    }
+    return "";
+}