[vlc-devel] [PATCH 2/3] Use input_AddSlave instead of input_AddSubtitleOSD

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Sep 21 12:42:17 CEST 2017


---
 lib/video.c                             | 11 +++++++++--
 modules/gui/macosx/VLCCoreInteraction.m | 11 +++++++----
 modules/gui/macosx/VLCPlaylist.m        | 15 ++++++---------
 modules/gui/qt/dialogs_provider.cpp     |  3 +--
 modules/gui/qt/main_interface.cpp       |  5 ++---
 modules/gui/skins2/src/top_window.cpp   |  8 ++------
 modules/lua/libs/input.c                |  7 ++++++-
 7 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/lib/video.c b/lib/video.c
index f6e16ba601..c41c6e35ff 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -38,6 +38,7 @@
 #include <vlc_modules.h>
 #include <vlc_input.h>
 #include <vlc_vout.h>
+#include <vlc_url.h>
 
 #include "libvlc_internal.h"
 #include "media_player_internal.h"
@@ -402,8 +403,14 @@ int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
 
     if( p_input_thread )
     {
-        if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
-            b_ret = true;
+        char* psz_mrl = vlc_path2uri( psz_subtitle, NULL );
+        if( psz_mrl )
+        {
+            if( !input_AddSlave( p_input_thread, SLAVE_TYPE_SPU, psz_mrl,
+                                 true, false ) )
+                b_ret = true;
+            free( psz_mrl );
+        }
         vlc_object_release( p_input_thread );
     }
     return b_ret;
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index 102d8c775a..970895df4c 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -608,12 +608,15 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
     NSUInteger count = [paths count];
 
     for (int i = 0; i < count ; i++) {
-        const char *path = [[[paths objectAtIndex:i] path] UTF8String];
-        msg_Dbg(getIntf(), "loading subs from %s", path);
+        char *mrl = vlc_path2uri([[[paths objectAtIndex:i] path] UTF8String], NULL);
+        if (!mrl)
+            continue;
+        msg_Dbg(getIntf(), "loading subs from %s", mrl);
 
-        int i_result = input_AddSubtitleOSD(p_input, path, true, true);
+        int i_result = input_AddSlave(p_input, SLAVE_TYPE_SPU, mrl, true, true);
         if (i_result != VLC_SUCCESS)
-            msg_Warn(getIntf(), "unable to load subtitles from '%s'", path);
+            msg_Warn(getIntf(), "unable to load subtitles from '%s'", mrl);
+        free(mrl);
     }
     vlc_object_release(p_input);
 }
diff --git a/modules/gui/macosx/VLCPlaylist.m b/modules/gui/macosx/VLCPlaylist.m
index abd6cdea99..bfb0d0f0a5 100644
--- a/modules/gui/macosx/VLCPlaylist.m
+++ b/modules/gui/macosx/VLCPlaylist.m
@@ -606,15 +606,12 @@
 {
     input_thread_t *p_input = pl_CurrentInput(getIntf());
     if (isSubtitle && array.count == 1 && p_input) {
-        char *path = vlc_uri2path([[[array firstObject] objectForKey:@"ITEM_URL"] UTF8String]);
-
-        if (path) {
-            int i_result = input_AddSubtitleOSD(p_input, path, true, true);
-            free(path);
-            if (i_result == VLC_SUCCESS) {
-                vlc_object_release(p_input);
-                return;
-            }
+        int i_result = input_AddSlave(p_input, SLAVE_TYPE_SPU,
+                    [[[array firstObject] objectForKey:@"ITEM_URL"] UTF8String],
+                    true, true);
+        if (i_result == VLC_SUCCESS) {
+            vlc_object_release(p_input);
+            return;
         }
     }
 
diff --git a/modules/gui/qt/dialogs_provider.cpp b/modules/gui/qt/dialogs_provider.cpp
index 3d404fc29a..ec645ab62a 100644
--- a/modules/gui/qt/dialogs_provider.cpp
+++ b/modules/gui/qt/dialogs_provider.cpp
@@ -806,8 +806,7 @@ void DialogsProvider::loadSubtitlesFile()
     free( path2 );
     foreach( const QString &qsUrl, qsl )
     {
-        if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( QUrl( qsUrl ).toLocalFile() ) ),
-                    true, true ) )
+        if( input_AddSlave( p_input, SLAVE_TYPE_SPU, qtu( qsUrl ), true, true ) )
             msg_Warn( p_intf, "unable to load subtitles from '%s'",
                       qtu( qsUrl ) );
     }
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index bddd8c943f..3a52373ad0 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -1452,9 +1452,8 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play, bool b_playli
     /* D&D of a subtitles file, add it on the fly */
     if( mimeData->urls().count() == 1 && THEMIM->getIM()->hasInput() )
     {
-        if( !input_AddSubtitleOSD( THEMIM->getInput(),
-                 qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
-                 true, true ) )
+        if( !input_AddSlave( THEMIM->getInput(), SLAVE_TYPE_SPU,
+                 qtu( mimeData->urls()[0].toString() ), true, true ) )
         {
             event->accept();
             return;
diff --git a/modules/gui/skins2/src/top_window.cpp b/modules/gui/skins2/src/top_window.cpp
index f447457111..403eda6af5 100644
--- a/modules/gui/skins2/src/top_window.cpp
+++ b/modules/gui/skins2/src/top_window.cpp
@@ -264,12 +264,8 @@ void TopWindow::processEvent( EvtDragDrop &rEvtDragDrop )
         if( files.size() == 1 && pInput != NULL )
         {
             std::list<std::string>::const_iterator it = files.begin();
-            char* psz_file = vlc_uri2path( it->c_str() );
-            if( psz_file )
-            {
-                is_subtitle = !input_AddSubtitleOSD( pInput, psz_file, true, true );
-                free( psz_file );
-            }
+            is_subtitle = !input_AddSlave( pInput, SLAVE_TYPE_SPU,
+                                           it->c_str(), true, true );
         }
         if( !is_subtitle )
         {
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index b5ca73ab4c..7ec51959eb 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -232,7 +232,12 @@ static int vlclua_input_add_subtitle( lua_State *L )
     if( !lua_isstring( L, 1 ) )
         return luaL_error( L, "vlc.input.add_subtitle() usage: (path)" );
     const char *psz_path = luaL_checkstring( L, 1 );
-    input_AddSubtitle( p_input, psz_path, false );
+    char* psz_mrl = vlc_path2uri( psz_path, NULL );
+    if( psz_mrl )
+    {
+        input_AddSlave( p_input, SLAVE_TYPE_SPU, psz_mrl, false, false );
+        free( psz_mrl );
+    }
     vlc_object_release( p_input );
     return 1;
 }
-- 
2.11.0



More information about the vlc-devel mailing list