[vlc-devel] [PATCH 2/2] input/input: input_SubtitleFile2Uri: handle URIs

Rémi Denis-Courmont remi at remlab.net
Fri Nov 18 08:52:27 CET 2016


On November 18, 2016 4:59:40 AM GMT+02:00, "Filip Roséen" <filip at atch.se> wrote:
>The previous implementation assumed that the data passed was a local
>path, which limited the usability of the function (effectively
>preventing subtitles passed as URIs from being added).
>
>These changes allow both local paths and URIs to be handled by the
>function, effectively making sure that file://... are subject to
>transformation (while leaving other entities untouched).
>
>refs #17657
>---
> src/input/input.c | 47 ++++++++++++++++++++++++++++-------------------
> 1 file changed, 28 insertions(+), 19 deletions(-)
>
>diff --git a/src/input/input.c b/src/input/input.c
>index cfcb92f..09a4309 100644
>--- a/src/input/input.c
>+++ b/src/input/input.c
>@@ -3041,31 +3041,40 @@ static int input_SlaveSourceAdd( input_thread_t
>*p_input,
> static char *input_SubtitleFile2Uri( input_thread_t *p_input,
>                                      const char *psz_subtitle )
> {
>+    vlc_url_t url;
>+    vlc_UrlParse( &url, psz_subtitle );
>+
>+    bool b_proto = url.psz_protocol;
>+    bool b_local = b_proto == false || !strcasecmp( url.psz_protocol,
>"file" );
>+
>+    vlc_UrlClean( &url );
>+
>+    if( !b_local )
>+        return strdup( psz_subtitle );
>+
>+    char* psz_local = b_proto ? vlc_uri2path( psz_subtitle )
>+                              : strdup( psz_subtitle );
>+    if( psz_local == NULL )
>+        return NULL;
>+
>     /* 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 = strrchr( psz_subtitle, '.');
>-    if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
>-    {
>-        psz_idxpath = strdup( psz_subtitle );
>-        if( psz_idxpath )
>-        {
>-            struct stat st;
> 
>-            psz_extension = psz_extension - psz_subtitle +
>psz_idxpath;
>-            strcpy( psz_extension, ".idx" );
>+    char *psz_ext = strrchr( psz_local, '.');
>+    if( psz_ext && strcmp( psz_ext, ".sub" ) == 0 )
>+    {
>+        struct stat st;
>+        strcpy( psz_ext, ".idx" );
> 
>-            if( !vlc_stat( psz_idxpath, &st ) && S_ISREG( st.st_mode )
>)
>-            {
>-                msg_Dbg( p_input, "using %s as subtitle file instead
>of %s",
>-                         psz_idxpath, psz_subtitle );
>-                psz_subtitle = psz_idxpath;
>-            }
>-        }
>+        if( vlc_stat( psz_local, &st ) || !S_ISREG( st.st_mode ) )
>+            strcpy( psz_ext, ".sub" ); /* reset extension */
>+        else
>+            msg_Dbg( p_input, "using %s as subtitle file instead of
>%s",
>+                     psz_local, psz_subtitle );
>     }
> 
>-    char *psz_uri = vlc_path2uri( psz_subtitle, NULL );
>-    free( psz_idxpath );
>+    char *psz_uri = vlc_path2uri( psz_local, NULL );
>+    free( psz_local );
>     return psz_uri;
> }
> 
>-- 
>2.10.2
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

The function name implies path as input so nack. Maybe rename the function, but AFAIR, wz already have support for adding slaves as URI.
-- 
Rémi Denis-Courmont
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20161118/4df171da/attachment.html>


More information about the vlc-devel mailing list