]> git.sesse.net Git - vlc/blobdiff - modules/demux/subtitle.c
MP4: better debug message when FOURCC not recognized
[vlc] / modules / demux / subtitle.c
index ce9701236600bf2af67f7aecd2f03ed605279c26..2c2428277082951d12334294d18a9a820ee5f6a8 100644 (file)
@@ -36,9 +36,6 @@
 #include <vlc_input.h>
 #include <vlc_memory.h>
 
-#ifdef HAVE_SYS_TYPES_H
-#   include <sys/types.h>
-#endif
 #include <ctype.h>
 
 #include <vlc_demux.h>
@@ -56,11 +53,9 @@ static void Close( vlc_object_t *p_this );
     N_("Override the normal frames per second settings. " \
     "This will only work with MicroDVD and SubRIP (SRT) subtitles.")
 #define SUB_TYPE_LONGTEXT \
-    N_("Force the subtiles format. Valid values are : \"microdvd\", " \
-    "\"subrip\", \"subviewer\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\", " \
-    "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\", "\
-    "\"mpsub\", \"jacosub\", \"psb\", \"realtext\", \"dks\", \"subviewer1\", " \
-    " and \"auto\" (meaning autodetection, this should always work).")
+    N_("Force the subtiles format. Selecting \"auto\" means autodetection and should always work.")
+#define SUB_DESCRIPTION_LONGTEXT \
+    N_("Override the default track description.")
 
 static const char *const ppsz_sub_type[] =
 {
@@ -76,15 +71,17 @@ vlc_module_begin ()
     set_capability( "demux", 0 )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_DEMUX )
-    add_float( "sub-fps", 0.0, NULL,
+    add_float( "sub-fps", 0.0,
                N_("Frames per second"),
                SUB_FPS_LONGTEXT, true )
-    add_integer( "sub-delay", 0, NULL,
+    add_integer( "sub-delay", 0,
                N_("Subtitles delay"),
                SUB_DELAY_LONGTEXT, true )
-    add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
+    add_string( "sub-type", "auto", N_("Subtitles format"),
                 SUB_TYPE_LONGTEXT, true )
         change_string_list( ppsz_sub_type, NULL, NULL )
+    add_string( "sub-description", NULL, N_("Subtitles description"),
+                SUB_DESCRIPTION_LONGTEXT, true )
     set_callbacks( Open, Close )
 
     add_shortcut( "subtitle" )
@@ -225,7 +222,7 @@ static const struct
 static int Demux( demux_t * );
 static int Control( demux_t *, int, va_list );
 
-/*static void Fix( demux_t * );*/
+static void Fix( demux_t * );
 
 /*****************************************************************************
  * Module initializer
@@ -517,18 +514,25 @@ static int Open ( vlc_object_t *p_this )
              p_sys->i_type == SUB_TYPE_SSA2_4 ||
              p_sys->i_type == SUB_TYPE_ASS )
     {
+        Fix( p_demux );
         es_format_Init( &fmt, SPU_ES, VLC_CODEC_SSA );
     }
     else
     {
         es_format_Init( &fmt, SPU_ES, VLC_CODEC_SUBT );
     }
+    char *psz_description = var_InheritString( p_demux, "sub-description" );
+    if( psz_description && *psz_description )
+        fmt.psz_description = psz_description;
+    else
+        free( psz_description );
     if( p_sys->psz_header != NULL )
     {
         fmt.i_extra = strlen( p_sys->psz_header ) + 1;
         fmt.p_extra = strdup( p_sys->psz_header );
     }
     p_sys->es = es_out_Add( p_demux->out, &fmt );
+    es_format_Clean( &fmt );
 
     return VLC_SUCCESS;
 }
@@ -628,6 +632,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
             return VLC_SUCCESS;
 
+        case DEMUX_GET_PTS_DELAY:
         case DEMUX_GET_FPS:
         case DEMUX_GET_META:
         case DEMUX_GET_ATTACHMENTS:
@@ -701,24 +706,22 @@ static int Demux( demux_t *p_demux )
 /*****************************************************************************
  * Fix: fix time stamp and order of subtitle
  *****************************************************************************/
-#ifdef USE_THIS_UNUSED_PIECE_OF_CODE
 static void Fix( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     bool b_done;
-    int     i_index;
 
     /* *** fix order (to be sure...) *** */
     /* We suppose that there are near in order and this durty bubble sort
-     * wont take too much time
+     * would not take too much time
      */
     do
     {
         b_done = true;
-        for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
+        for( int i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
         {
             if( p_sys->subtitle[i_index].i_start <
-                    p_sys->subtitle[i_index - 1].i_start )
+                p_sys->subtitle[i_index - 1].i_start )
             {
                 subtitle_t sub_xch;
                 memcpy( &sub_xch,
@@ -735,7 +738,6 @@ static void Fix( demux_t *p_demux )
         }
     } while( !b_done );
 }
-#endif
 
 static int TextLoad( text_t *txt, stream_t *s )
 {
@@ -1620,10 +1622,10 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
 
             strcpy( psz_text, s );
 
-            switch( toupper( psz_text[1] ) )
+            switch( toupper( (unsigned char)psz_text[1] ) )
             {
             case 'S':
-                 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
+                 shift = isalpha( (unsigned char)psz_text[2] ) ? 6 : 2 ;
 
                  if( sscanf( &psz_text[shift], "%d", &h ) )
                  {
@@ -1660,7 +1662,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
                  break;
 
             case 'T':
-                shift = isalpha( psz_text[2] ) ? 8 : 2 ;
+                shift = isalpha( (unsigned char)psz_text[2] ) ? 8 : 2 ;
 
                 sscanf( &psz_text[shift], "%d", &p_sys->jss.i_time_resolution );
                 break;
@@ -1675,7 +1677,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
             continue;
         }
     }
-       
+
     while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
     {
         const char *s2 = TextGetLine( txt );
@@ -1696,7 +1698,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
         if( !psz_text )
              return VLC_ENOMEM;
 
-               psz_orig = psz_text;
+        psz_orig = psz_text;
         strcat( psz_text, s2 );
     }
 
@@ -1704,7 +1706,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
     while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
 
     /* Parse the directives */
-    if( isalpha( *psz_text ) || *psz_text == '[' )
+    if( isalpha( (unsigned char)*psz_text ) || *psz_text == '[' )
     {
         while( *psz_text != ' ' )
         { psz_text++ ;};
@@ -1761,8 +1763,8 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
                 psz_text2++;
                 break;
             }
-            if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
-                    ( toupper(*(psz_text + 1 ) ) == 'F' ) )
+            if( ( toupper((unsigned char)*(psz_text + 1 ) ) == 'C' ) ||
+                    ( toupper((unsigned char)*(psz_text + 1 ) ) == 'F' ) )
             {
                 psz_text++; psz_text++;
                 break;
@@ -1781,7 +1783,7 @@ static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
             else if( *(psz_text + 1 ) == '\r' ||  *(psz_text + 1 ) == '\n' ||
                      *(psz_text + 1 ) == '\0' )
             {
-                               psz_text++;
+                psz_text++;
             }
             break;
         default:
@@ -1848,7 +1850,7 @@ static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
 
 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
 {
-    if( strlen( psz ) == 0 ) return 0;
+    if( *psz == '\0' ) return 0;
     if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
             sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
             sscanf( psz, "%d.%d", s, f ) == 2 ||