]> git.sesse.net Git - vlc/blobdiff - modules/demux/subtitle.c
* modules/demux/mp4/mp4.c: couple of fixes for audio demuxing.
[vlc] / modules / demux / subtitle.c
index 2683c4cac0f4ba81210fe6fccaa6922ea8d88385..0aedae1310fef6f937b4335ade82556a1bb83e0f 100644 (file)
@@ -28,7 +28,9 @@
 #include <stdlib.h>
 
 #include <errno.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+#   include <sys/types.h>
+#endif
 #include <ctype.h>
 
 #include <vlc/vlc.h>
@@ -66,6 +68,9 @@ vlc_module_begin();
     add_float( "sub-fps", 0.0, NULL,
                N_("Frames per second"),
                SUB_FPS_LONGTEXT, VLC_TRUE );
+    add_integer( "sub-delay", 0, NULL,
+               N_("Subtitles delay"),
+               SUB_DELAY_LONGTEXT, VLC_TRUE );
     add_string( "sub-type", "auto", NULL, "Subtitles fileformat",
                 SUB_TYPE_LONGTEXT, VLC_TRUE );
         change_string_list( ppsz_sub_type, 0, 0 );
@@ -87,7 +92,6 @@ enum
     SUB_TYPE_VPLAYER,
     SUB_TYPE_SAMI,
     SUB_TYPE_SUBVIEWER,
-    NULL
 };
 
 typedef struct
@@ -101,8 +105,8 @@ static void TextUnload( text_t * );
 
 typedef struct
 {
-    mtime_t i_start;
-    mtime_t i_stop;
+    int64_t i_start;
+    int64_t i_stop;
 
     char    *psz_text;
 } subtitle_t;
@@ -117,12 +121,12 @@ struct demux_sys_t
     int64_t     i_next_demux_date;
 
     int64_t     i_microsecperframe;
+    int64_t     i_original_mspf;
 
     char        *psz_header;
     int         i_subtitle;
     int         i_subtitles;
     subtitle_t  *subtitle;
-    mtime_t     i_original_mspf;
 
     int64_t     i_length;
 };
@@ -183,15 +187,27 @@ static int Open ( vlc_object_t *p_this )
     p_sys->i_subtitle = 0;
     p_sys->i_subtitles= 0;
     p_sys->subtitle   = NULL;
-    p_sys->i_original_mspf = 0;
 
 
     /* Get the FPS */
-    p_sys->i_microsecperframe = 40000; /* default to 25 fps */
     f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
     if( f_fps >= 1.0 )
     {
-        p_sys->i_microsecperframe = (mtime_t)( (float)1000000 / f_fps );
+        p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
+    }
+    else
+    {
+        p_sys->i_microsecperframe = 0;
+    }
+
+    f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" );
+    if( f_fps >= 1.0 )
+    {
+        p_sys->i_original_mspf = (int64_t)( (float)1000000 / f_fps );
+    }
+    else
+    {
+        p_sys->i_original_mspf = 0;
     }
 
     /* Get or probe the type */
@@ -663,10 +679,14 @@ static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle )
     char *s;
 
     char buffer_text[MAX_LINE + 1];
-    unsigned int    i_start;
-    unsigned int    i_stop;
+    int    i_start;
+    int    i_stop;
     unsigned int i;
 
+    int i_microsecperframe = 40000; /* default to 25 fps */
+    if( p_sys->i_microsecperframe > 0 ) 
+        i_microsecperframe = p_sys->i_microsecperframe;
+    
     p_subtitle->i_start = 0;
     p_subtitle->i_stop  = 0;
     p_subtitle->psz_text = NULL;
@@ -696,8 +716,8 @@ static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle )
         }
     }
 
-    p_subtitle->i_start = (mtime_t)i_start * p_sys->i_microsecperframe;
-    p_subtitle->i_stop  = (mtime_t)i_stop  * p_sys->i_microsecperframe;
+    p_subtitle->i_start = (int64_t)i_start * i_microsecperframe;
+    p_subtitle->i_stop  = (int64_t)i_stop  * i_microsecperframe;
     p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
     return( 0 );
 }
@@ -719,8 +739,8 @@ static int  ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle )
     char *s;
     char buffer_text[ 10 * MAX_LINE];
     int  i_buffer_text;
-    mtime_t     i_start;
-    mtime_t     i_stop;
+    int64_t     i_start;
+    int64_t     i_stop;
 
     p_subtitle->i_start = 0;
     p_subtitle->i_stop  = 0;
@@ -738,15 +758,15 @@ static int  ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle )
                     &h1, &m1, &s1, &d1,
                     &h2, &m2, &s2, &d2 ) == 8 )
         {
-            i_start = ( (mtime_t)h1 * 3600*1000 +
-                        (mtime_t)m1 * 60*1000 +
-                        (mtime_t)s1 * 1000 +
-                        (mtime_t)d1 ) * 1000;
+            i_start = ( (int64_t)h1 * 3600*1000 +
+                        (int64_t)m1 * 60*1000 +
+                        (int64_t)s1 * 1000 +
+                        (int64_t)d1 ) * 1000;
 
-            i_stop  = ( (mtime_t)h2 * 3600*1000 +
-                        (mtime_t)m2 * 60*1000 +
-                        (mtime_t)s2 * 1000 +
-                        (mtime_t)d2 ) * 1000;
+            i_stop  = ( (int64_t)h2 * 3600*1000 +
+                        (int64_t)m2 * 60*1000 +
+                        (int64_t)s2 * 1000 +
+                        (int64_t)d2 ) * 1000;
 
             /* Now read text until an empty line */
             for( i_buffer_text = 0;; )
@@ -769,12 +789,12 @@ static int  ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle )
                     if( p_sys->i_microsecperframe != 0 &&
                         p_sys->i_original_mspf != 0)
                     {
-                        p_subtitle->i_start = (mtime_t)i_start *
-                                              p_sys->i_original_mspf /
-                                              p_sys->i_microsecperframe;
-                        p_subtitle->i_stop  = (mtime_t)i_stop  *
-                                              p_sys->i_original_mspf /
-                                              p_sys->i_microsecperframe;
+                        p_subtitle->i_start = (int64_t)i_start *
+                                              p_sys->i_microsecperframe/
+                                              p_sys->i_original_mspf;
+                        p_subtitle->i_stop  = (int64_t)i_stop  *
+                                              p_sys->i_microsecperframe /
+                                              p_sys->i_original_mspf;
                     }
                     return 0;
                 }
@@ -812,8 +832,8 @@ static int  ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle )
     char *s;
     char buffer_text[ 10 * MAX_LINE];
     int  i_buffer_text;
-    mtime_t     i_start;
-    mtime_t     i_stop;
+    int64_t     i_start;
+    int64_t     i_stop;
 
     p_subtitle->i_start = 0;
     p_subtitle->i_stop  = 0;
@@ -831,15 +851,15 @@ static int  ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle )
                     &h1, &m1, &s1, &d1,
                     &h2, &m2, &s2, &d2 ) == 8 )
         {
-            i_start = ( (mtime_t)h1 * 3600*1000 +
-                        (mtime_t)m1 * 60*1000 +
-                        (mtime_t)s1 * 1000 +
-                        (mtime_t)d1 ) * 1000;
+            i_start = ( (int64_t)h1 * 3600*1000 +
+                        (int64_t)m1 * 60*1000 +
+                        (int64_t)s1 * 1000 +
+                        (int64_t)d1 ) * 1000;
 
-            i_stop  = ( (mtime_t)h2 * 3600*1000 +
-                        (mtime_t)m2 * 60*1000 +
-                        (mtime_t)s2 * 1000 +
-                        (mtime_t)d2 ) * 1000;
+            i_stop  = ( (int64_t)h2 * 3600*1000 +
+                        (int64_t)m2 * 60*1000 +
+                        (int64_t)s2 * 1000 +
+                        (int64_t)d2 ) * 1000;
 
             /* Now read text until an empty line */
             for( i_buffer_text = 0;; )
@@ -899,8 +919,8 @@ static int  ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle )
 
     char buffer_text[ 10 * MAX_LINE];
     char *s;
-    mtime_t     i_start;
-    mtime_t     i_stop;
+    int64_t     i_start;
+    int64_t     i_stop;
 
     p_subtitle->i_start = 0;
     p_subtitle->i_stop  = 0;
@@ -924,15 +944,15 @@ static int  ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle )
                     &h2, &m2, &s2, &c2,
                     buffer_text ) == 10 )
         {
-            i_start = ( (mtime_t)h1 * 3600*1000 +
-                        (mtime_t)m1 * 60*1000 +
-                        (mtime_t)s1 * 1000 +
-                        (mtime_t)c1 * 10 ) * 1000;
+            i_start = ( (int64_t)h1 * 3600*1000 +
+                        (int64_t)m1 * 60*1000 +
+                        (int64_t)s1 * 1000 +
+                        (int64_t)c1 * 10 ) * 1000;
 
-            i_stop  = ( (mtime_t)h2 * 3600*1000 +
-                        (mtime_t)m2 * 60*1000 +
-                        (mtime_t)s2 * 1000 +
-                        (mtime_t)c2 * 10 ) * 1000;
+            i_stop  = ( (int64_t)h2 * 3600*1000 +
+                        (int64_t)m2 * 60*1000 +
+                        (int64_t)s2 * 1000 +
+                        (int64_t)c2 * 10 ) * 1000;
 
             /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
             if( p_sys->i_type == SUB_TYPE_SSA1 )
@@ -991,7 +1011,7 @@ static int  ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle )
      */
     char *p;
     char buffer_text[MAX_LINE + 1];
-    mtime_t    i_start;
+    int64_t    i_start;
     unsigned int i;
 
     p_subtitle->i_start = 0;
@@ -1013,9 +1033,9 @@ static int  ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle )
         memset( buffer_text, '\0', MAX_LINE );
         if( sscanf( p, "%d:%d:%d%[ :]%[^\r\n]", &h, &m, &s, &c, buffer_text ) == 5 )
         {
-            i_start = ( (mtime_t)h * 3600*1000 +
-                        (mtime_t)m * 60*1000 +
-                        (mtime_t)s * 1000 ) * 1000;
+            i_start = ( (int64_t)h * 3600*1000 +
+                        (int64_t)m * 60*1000 +
+                        (int64_t)s * 1000 ) * 1000;
             break;
         }
     }
@@ -1072,7 +1092,7 @@ static int  ParseSami( demux_t *p_demux, subtitle_t *p_subtitle )
     text_t      *txt = &p_sys->txt;
 
     char *p;
-    int i_start;
+    int64_t i_start;
 
     int  i_text;
     char buffer_text[10*MAX_LINE + 1];