[vlc-devel] [PATCHES] -- three patches to fix issues with input

brezhoneg1 brezhoneg1 at yahoo.fr
Fri May 17 17:28:20 CEST 2013


Hi,

    Please find attached three patches that are related to the input at 
the core level

- patch1: support subtitles provided both as url and local file name
   This fixes errors with the new VLsub0.9 lua extension that fetches 
subtitles on the net

- patch 2: avoid "subpicture heap overflow" when opening a subtitle file 
while an input is running

- patch 3: fix start-time misfunctioning as described previously on this 
mail list

These patches have tested successfully, but additional review is needed 
just in case ....

Erwan
-------------- next part --------------
>From 6b5964459e85d055559d01e3a01cb965e91e4262 Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10 at videolan.org>
Date: Mon, 13 May 2013 21:02:28 +0200
Subject: [PATCH 1/3] Subtitle: support subtitle files provided as a url or a
 local file name

---
 src/input/input.c | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index ebe6350..e14242d 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3123,31 +3123,37 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, unsigned i
     input_source_t *sub;
     vlc_value_t count;
     vlc_value_t list;
-    char *psz_path, *psz_extension;
+
+    /* support psz_subtitle as a url or a local file format */
+    char *psz_file = strstr( psz_subtitle, "://" ) ?
+                     make_path( psz_subtitle ) : strdup( psz_subtitle );
+    if( unlikely( psz_file == NULL ) )
+        return;
 
     /* if we are provided a subtitle.sub file,
      * see if we don't have a subtitle.idx and use it instead */
-    psz_path = strdup( psz_subtitle );
-    if( psz_path )
+    char* psz_extension = strrchr( psz_file, '.');
+    if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
     {
-        psz_extension = strrchr( psz_path, '.');
-        if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
-        {
-            struct stat st;
-
-            strcpy( psz_extension, ".idx" );
+        struct stat st;
 
-            if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
-            {
-                msg_Dbg( p_input, "using %s as subtitle file instead of %s",
-                         psz_path, psz_subtitle );
-                strcpy( psz_subtitle, psz_path );
-            }
+        strcpy( psz_extension, ".idx" );
+        if( !vlc_stat( psz_file, &st ) && S_ISREG( st.st_mode ) )
+        {
+            *psz_extension = '\0';
+            msg_Dbg( p_input, "using %s.idx as subtitle file instead of %s.sub",
+                     psz_file, psz_file );
+            *psz_extension = '.';
+        }
+        else
+        {
+            /* revert with .sub if no suitable .idx file found */
+            strcpy( psz_extension, ".sub" );
         }
-        free( psz_path );
     }
 
-    char *url = vlc_path2uri( psz_subtitle, NULL );
+    char *url = vlc_path2uri( psz_file, NULL );
+    free( psz_file );
 
     var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
 
-- 
1.8.1.2

-------------- next part --------------
>From 7700e9e28547d8e28129fc997f2c56ebd6d4509d Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10 at videolan.org>
Date: Mon, 13 May 2013 20:55:36 +0200
Subject: [PATCH 2/3] Subtitle: fix Subpicture Heap overflow when adding
 subtitles

When the input is launched, the new subtitle file (an input slave)
must be positioned to the current time. Failure to do so is likely to
cause buffer overflows because the next demux then retrieves all data
from time 0 to the current time.

Note that the general case (INPUT_CONTROL_ADD_SLAVE) does it correctly.
---
 src/input/input.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/input/input.c b/src/input/input.c
index e14242d..f2b4a46 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3168,6 +3168,12 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, unsigned i
     free( url );
     TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
 
+    /* Needed because subtitles can be loaded while the input is running.
+       if not set, all subtitles from time 0 to i_time are retrieved on the next
+       demux call, potentially causing subpicture heap overflow */
+    if( p_input->p->i_time )
+        demux_Control( sub->p_demux, DEMUX_SET_TIME, p_input->p->i_time, true );
+
     /* Select the ES */
     if( (i_flags & SUB_FORCED) && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
     {
-- 
1.8.1.2

-------------- next part --------------
>From 1ba104b4902390da0fdd2ca800369430231895f6 Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10 at videolan.org>
Date: Fri, 17 May 2013 02:19:05 +0200
Subject: [PATCH 3/3] input: fix start-time misfunctioning

When the user sets start-time > 0, first starting at time 0 should be avoided
because it causes an unneeded buffering and an unexpected first video frame.

This patch directly executes INPUT_CONTROL_SET_TIME instead of delaying it
to avoid a first demux at time 0. For that matter, a bit of a reordering was
necessary :
- b_fast_seek must be initialized beforehand
- subtitles/slaves must be initialized beforehand
---
 src/input/input.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index f2b4a46..63c493f 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -943,6 +943,9 @@ static void StartTitle( input_thread_t * p_input )
                                      * var_GetFloat( p_input, "stop-time" ));
     p_input->p->i_run   = (int64_t)(1000000.0
                                      * var_GetFloat( p_input, "run-time" ));
+
+    p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
+
     if( p_input->p->i_run < 0 )
     {
         msg_Warn( p_input, "invalid run-time ignored" );
@@ -957,14 +960,15 @@ static void StartTitle( input_thread_t * p_input )
                  (int)( p_input->p->i_start / INT64_C(1000000) ) );
 
         s.i_time = p_input->p->i_start;
-        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
+        /* immediate execution avoids an unneeded buffering at time 0 */
+        Control( p_input, INPUT_CONTROL_SET_TIME, s );
     }
+
     if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
     {
         msg_Warn( p_input, "invalid stop-time ignored" );
         p_input->p->i_stop = 0;
     }
-    p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
 }
 
 static void LoadSubtitles( input_thread_t *p_input )
@@ -1243,9 +1247,9 @@ static int Init( input_thread_t * p_input )
 
     if( !p_input->b_preparsing )
     {
-        StartTitle( p_input );
         LoadSubtitles( p_input );
         LoadSlaves( p_input );
+        StartTitle( p_input );
         InitPrograms( p_input );
 
         double f_rate = var_InheritFloat( p_input, "rate" );
-- 
1.8.1.2



More information about the vlc-devel mailing list