[vlc-devel] [PATCH 3/3] input: refactor input_AddSubtitleOSD()

Filip Roséen filip at atch.se
Thu Jan 12 19:34:42 CET 2017


From: Thomas Guillem <thomas at gllm.fr>

This function now use slaves control directly.
---
 include/vlc_input.h        | 27 ++++++++++---------------
 src/input/control.c        | 14 -------------
 src/input/input.c          | 50 +++++++++++++++++++++++++++++++---------------
 src/input/input_internal.h |  2 --
 src/libvlccore.sym         |  1 +
 5 files changed, 45 insertions(+), 49 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index 76ecee5267..7518910f7d 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -464,7 +464,6 @@ enum input_query_e
 
     /* On the fly input slave */
     INPUT_ADD_SLAVE,       /* arg1= enum slave_type, arg2= const char *, arg3= bool */
-    INPUT_ADD_SUBTITLE,    /* arg1= const char *, arg2=bool b_check_extension */
 
     /* On the fly record while playing */
     INPUT_SET_RECORD_STATE, /* arg1=bool    res=can fail */
@@ -575,23 +574,17 @@ static inline vout_thread_t *input_GetVout( input_thread_t *p_input )
 /**
  * It will add a new subtitle source to the input.
  * Provided for convenience.
+ *
+ * @param p_input an input thread
+ * @param psz_subtitle subtitle URI or local path
+ * @param b_strict_extensions, do nothing if the subtitle extension doesn't
+ *        match any known subtitles
+ * @param b_osd display the subtitle status in OSD
+ * @return VLC_SUCCESS or a VLC error code
  */
-static inline int input_AddSubtitleOSD( input_thread_t *p_input, const char *psz_path,
-        bool b_check_extension, bool b_osd )
-{
-    int i_result = input_Control( p_input, INPUT_ADD_SUBTITLE, psz_path, b_check_extension );
-    if( i_result != VLC_SUCCESS || !b_osd )
-        return i_result;
-
-    vout_thread_t *p_vout = input_GetVout( p_input );
-    if( p_vout )
-    {
-        vout_OSDMessage(p_vout, SPU_DEFAULT_CHANNEL, "%s",
-                        vlc_gettext("Subtitle track added") );
-        vlc_object_release( (vlc_object_t *)p_vout );
-    }
-    return i_result;
-}
+VLC_API int input_AddSubtitleOSD( input_thread_t *p_input,
+                                  const char *psz_subtitle,
+                                  bool b_strict_extensions, bool b_osd );
 #define input_AddSubtitle(a, b, c) input_AddSubtitleOSD(a, b, c, false)
 
 static inline int input_AddSlave( input_thread_t *p_input, enum slave_type type,
diff --git a/src/input/control.c b/src/input/control.c
index e662a23cb0..f5bd8aa834 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -447,19 +447,6 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             return VLC_SUCCESS;
         }
 
-        case INPUT_ADD_SUBTITLE:
-            psz = (char*)va_arg( args, char * );
-            b_bool = (bool)va_arg( args, int );
-
-            if( !psz || *psz == '\0' )
-                return VLC_EGENERIC;
-            if( b_bool && !subtitles_Filter( psz ) )
-                return VLC_EGENERIC;
-
-            val.psz_string = strdup( psz );
-            input_ControlPush( p_input, INPUT_CONTROL_ADD_SUBTITLE, &val );
-            return VLC_SUCCESS;
-
         case INPUT_GET_ATTACHMENTS: /* arg1=input_attachment_t***, arg2=int*  res=can fail */
         {
             input_attachment_t ***ppp_attachment = (input_attachment_t***)va_arg( args, input_attachment_t *** );
@@ -647,4 +634,3 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
     }
     input_SendEventBookmark( p_input );
 }
-
diff --git a/src/input/input.c b/src/input/input.c
index d0b9f208b2..8a4cedd938 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1660,9 +1660,6 @@ static void ControlRelease( int i_type, vlc_value_t val )
 {
     switch( i_type )
     {
-    case INPUT_CONTROL_ADD_SUBTITLE:
-        free( val.psz_string );
-        break;
     case INPUT_CONTROL_ADD_SLAVE:
         if( val.p_address )
             input_item_slave_Delete( val.p_address );
@@ -2050,19 +2047,6 @@ static bool Control( input_thread_t *p_input,
             break;
         }
 
-        case INPUT_CONTROL_ADD_SUBTITLE:
-            if( val.psz_string )
-            {
-                char *psz_uri = input_GetSubtitleURI( p_input, val.psz_string, false );
-                if( psz_uri != NULL )
-                {
-                    input_SlaveSourceAdd( p_input, SLAVE_TYPE_SPU, psz_uri,
-                                          SLAVE_ADD_FORCED );
-                    free( psz_uri );
-                }
-            }
-            break;
-
         case INPUT_CONTROL_ADD_SLAVE:
             if( val.p_address )
             {
@@ -3312,3 +3296,37 @@ char *input_CreateFilename(input_thread_t *input, const char *dir,
     free(filename);
     return path;
 }
+
+int input_AddSubtitleOSD( input_thread_t *p_input, const char *psz_subtitle,
+                          bool b_strict_extensions, bool b_osd )
+{
+    if( !psz_subtitle )
+        return VLC_EGENERIC;
+
+    char *psz_uri = input_GetSubtitleURI( p_input, psz_subtitle,
+                                          b_strict_extensions );
+    if( !psz_uri )
+        return VLC_EGENERIC;
+
+    input_item_slave_t *p_slave =
+        input_item_slave_New( psz_uri, SLAVE_TYPE_SPU, SLAVE_PRIORITY_USER );
+    free( psz_uri );
+    if( !p_slave )
+        return VLC_ENOMEM;
+    p_slave->b_forced = true;
+
+    input_ControlPush( p_input, INPUT_CONTROL_ADD_SLAVE,
+                       & (vlc_value_t ){.p_address = p_slave} );
+
+    if( !b_osd )
+        return VLC_SUCCESS;
+
+    vout_thread_t *p_vout = input_GetVout( p_input );
+    if( p_vout )
+    {
+        vout_OSDMessage(p_vout, SPU_DEFAULT_CHANNEL, "%s",
+                        vlc_gettext("Subtitle track added") );
+        vlc_object_release( (vlc_object_t *)p_vout );
+    }
+    return VLC_SUCCESS;
+}
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index f05013ec41..c7594c9798 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -225,8 +225,6 @@ enum input_control_e
 
     INPUT_CONTROL_ADD_SLAVE,
 
-    INPUT_CONTROL_ADD_SUBTITLE,
-
     INPUT_CONTROL_SET_RECORD_STATE,
 
     INPUT_CONTROL_SET_FRAME_NEXT,
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 7b9657a4b1..b53f55d624 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -166,6 +166,7 @@ image_HandlerDelete
 image_Mime2Fourcc
 image_Type2Fourcc
 InitMD5
+input_AddSubtitleOSD
 input_Control
 input_Create
 input_CreateFilename
-- 
2.11.0



More information about the vlc-devel mailing list