[vlc-commits] stream_filter: revector, use strtok_r()

Rémi Denis-Courmont git at videolan.org
Tue Aug 25 20:33:15 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 25 20:51:47 2015 +0300| [682e16024a3d348c0310b2e39cfa38cbf7f083d4] | committer: Rémi Denis-Courmont

stream_filter: revector, use strtok_r()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=682e16024a3d348c0310b2e39cfa38cbf7f083d4
---

 src/input/input.c         |   10 ++++++----
 src/input/stream_filter.c |   29 ++++++++++++-----------------
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index 8092f3b..9731ab3 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -2311,10 +2311,12 @@ static int InputSourceInit( input_thread_t *p_input,
         /* Add stream filters */
         p_stream = stream_FilterAutoNew( p_stream );
 
-        char *psz_stream_filter = var_GetNonEmptyString( p_input,
-                                                         "stream-filter" );
-        p_stream = stream_FilterChainNew( p_stream, psz_stream_filter );
-        free( psz_stream_filter );
+        char *filters = var_GetNonEmptyString( p_input, "stream-filter" );
+        if( filters != NULL )
+        {
+            p_stream = stream_FilterChainNew( p_stream, filters );
+            free( filters );
+        }
 
         if( var_GetBool( p_input, "input-record-native" ) )
             p_stream = stream_FilterChainNew( p_stream, "record" );
diff --git a/src/input/stream_filter.c b/src/input/stream_filter.c
index 6013713..4bd9854 100644
--- a/src/input/stream_filter.c
+++ b/src/input/stream_filter.c
@@ -88,31 +88,26 @@ stream_t *stream_FilterAutoNew( stream_t *p_source )
     return p_source;
 }
 
+/* Add specified stream filter(s) */
 stream_t *stream_FilterChainNew( stream_t *p_source, const char *psz_chain )
 {
-    if( psz_chain == NULL )
+    /* Add user stream filter */
+    char *chain = strdup( psz_chain );
+    if( unlikely(chain == NULL) )
         return p_source;
 
-    /* Add user stream filter */
-    char *psz_tmp = strdup( psz_chain );
-    char *psz = psz_tmp;
-    while( psz && *psz )
+    char *buf;
+    for( const char *name = strtok_r( chain, ":", &buf );
+         name != NULL;
+         name = strtok_r( NULL, ":", &buf ) )
     {
-        stream_t *p_filter;
-        char *psz_end = strchr( psz, ':' );
-
-        if( psz_end )
-            *psz_end++ = '\0';
-
-        p_filter = stream_FilterNew( p_source, psz );
-        if( p_filter )
+        stream_t *p_filter = stream_FilterNew( p_source, name );
+        if( p_filter != NULL )
             p_source = p_filter;
         else
-            msg_Warn( p_source, "failed to insert stream filter %s", psz );
-
-        psz = psz_end;
+            msg_Warn( p_source, "cannot insert stream filter %s", name );
     }
-    free( psz_tmp );
+    free( chain );
 
     return p_source;
 }



More information about the vlc-commits mailing list