[vlc-devel] [PATCHv2 09/13] input/input: remove input_SubtitleFileAdd

Thomas Guillem thomas at gllm.fr
Tue May 3 19:02:36 CEST 2016


And replace it with input_SubtitleFile2Uri that returns a string that can be
used with input_SubtitleAdd.
---
 src/input/input.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index 9910ec3..fa7a040 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -103,7 +103,7 @@ enum {
 };
 
 static void input_SubtitleAdd( input_thread_t *, const char *, unsigned );
-static void input_SubtitleFileAdd( input_thread_t *, const char *, unsigned, bool );
+static char *input_SubtitleFile2Uri( input_thread_t *, const char * );
 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
 
 #undef input_Create
@@ -1034,7 +1034,13 @@ static void LoadSubtitles( input_thread_t *p_input )
     if( psz_subtitle != NULL )
     {
         msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
-        input_SubtitleFileAdd( p_input, psz_subtitle, SUB_FORCED, true );
+        char *psz_uri = input_SubtitleFile2Uri( p_input, psz_subtitle );
+        if( psz_uri != NULL )
+        {
+            free( psz_subtitle );
+            psz_subtitle = psz_uri;
+            input_SubtitleAdd( p_input, psz_uri, SUB_FORCED  );
+        }
     }
 
     if( var_GetBool( p_input, "sub-autodetect-file" ) )
@@ -1963,7 +1969,14 @@ static bool Control( input_thread_t *p_input,
 
         case INPUT_CONTROL_ADD_SUBTITLE:
             if( val.psz_string )
-                input_SubtitleFileAdd( p_input, val.psz_string, SUB_FORCED, true );
+            {
+                char *psz_uri = input_SubtitleFile2Uri( p_input, val.psz_string );
+                if( psz_uri != NULL )
+                {
+                    input_SubtitleAdd( p_input, psz_uri, SUB_FORCED );
+                    free( psz_uri );
+                }
+            }
             break;
 
         case INPUT_CONTROL_ADD_SLAVE:
@@ -2906,14 +2919,13 @@ static void input_SubtitleAdd( input_thread_t *p_input,
     var_FreeList( &list, NULL );
 }
 
-static void input_SubtitleFileAdd( input_thread_t *p_input,
-                                   const char *psz_subtitle, unsigned i_flags,
-                                   bool b_check_idx )
+static char *input_SubtitleFile2Uri( input_thread_t *p_input,
+                                     const char *psz_subtitle )
 {
     /* if we are provided a subtitle.sub file,
      * see if we don't have a subtitle.idx and use it instead */
     char *psz_idxpath = NULL;
-    char *psz_extension = b_check_idx ? strrchr( psz_subtitle, '.') : NULL;
+    char *psz_extension = strrchr( psz_subtitle, '.');
     if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
     {
         psz_idxpath = strdup( psz_subtitle );
@@ -2933,13 +2945,7 @@ static void input_SubtitleFileAdd( input_thread_t *p_input,
         }
     }
 
-    char *url = vlc_path2uri( psz_subtitle, NULL );
-    free( psz_idxpath );
-    if( url == NULL )
-        return;
-
-    input_SubtitleAdd( p_input, url, i_flags );
-    free( url );
+    return vlc_path2uri( psz_subtitle, NULL );
 }
 
 /*****************************************************************************
-- 
2.8.0.rc3



More information about the vlc-devel mailing list