]> git.sesse.net Git - vlc/blobdiff - src/input/stream_filter.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / input / stream_filter.c
index 7ad7d6a4103221d2104497b5299f43af48995909..73255e5555f0709a6601c29d20eb7ebe4c9bc013 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_stream.h>
+#include <vlc_modules.h>
 #include <libvlc.h>
 
+#include <assert.h>
+
 #include "stream.h"
 
 static void StreamDelete( stream_t * );
@@ -37,12 +40,21 @@ stream_t *stream_FilterNew( stream_t *p_source,
                             const char *psz_stream_filter )
 {
     stream_t *s;
+    assert( p_source != NULL );
 
     s = stream_CommonNew( VLC_OBJECT( p_source ) );
     if( s == NULL )
         return NULL;
 
+    s->p_input = p_source->p_input;
+
     /* */
+    s->psz_path = strdup( p_source->psz_path );
+    if( !s->psz_path )
+    {
+        stream_CommonDelete( s );
+        return NULL;
+    }
     s->p_source = p_source;
 
     /* */
@@ -61,6 +73,53 @@ stream_t *stream_FilterNew( stream_t *p_source,
     return s;
 }
 
+stream_t *stream_FilterChainNew( stream_t *p_source,
+                                 const char *psz_chain,
+                                 bool b_record )
+{
+    /* Add auto stream filter */
+    for( ;; )
+    {
+        stream_t *p_filter = stream_FilterNew( p_source, NULL );
+        if( !p_filter )
+            break;
+
+        msg_Dbg( p_filter, "Inserted a stream filter" );
+        p_source = p_filter;
+    }
+
+    /* Add user stream filter */
+    char *psz_tmp = psz_chain ? strdup( psz_chain ) : NULL;
+    char *psz = psz_tmp;
+    while( psz && *psz )
+    {
+        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 )
+            p_source = p_filter;
+        else
+            msg_Warn( p_source, "failed to insert stream filter %s", psz );
+
+        psz = psz_end;
+    }
+    free( psz_tmp );
+
+    /* Add record filter if useful */
+    if( b_record )
+    {
+        stream_t *p_filter = stream_FilterNew( p_source,
+                                               "stream_filter_record" );
+        if( p_filter )
+            p_source = p_filter;
+    }
+    return p_source;
+}
+
 static void StreamDelete( stream_t *s )
 {
     module_unneed( s, s->p_module );