]> git.sesse.net Git - vlc/blob - src/input/stream_filter.c
LGPL
[vlc] / src / input / stream_filter.c
1 /*****************************************************************************
2  * stream_filter.c
3  *****************************************************************************
4  * Copyright (C) 2008 Laurent Aimar
5  * $Id$
6  *
7  * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_stream.h>
30 #include <vlc_modules.h>
31 #include <libvlc.h>
32
33 #include <assert.h>
34
35 #include "stream.h"
36
37 static void StreamDelete( stream_t * );
38
39 stream_t *stream_FilterNew( stream_t *p_source,
40                             const char *psz_stream_filter )
41 {
42     stream_t *s;
43     assert( p_source != NULL );
44
45     s = stream_CommonNew( VLC_OBJECT( p_source ) );
46     if( s == NULL )
47         return NULL;
48
49     s->p_input = p_source->p_input;
50
51     /* */
52     s->psz_access = strdup( p_source->psz_access );
53     s->psz_path = strdup( p_source->psz_path );
54     if( !s->psz_path )
55     {
56         stream_CommonDelete( s );
57         return NULL;
58     }
59     s->p_source = p_source;
60
61     /* */
62     s->p_module = module_need( s, "stream_filter", psz_stream_filter, true );
63
64     if( !s->p_module )
65     {
66         stream_CommonDelete( s );
67         return NULL;
68     }
69
70     s->pf_destroy = StreamDelete;
71
72     return s;
73 }
74
75 stream_t *stream_FilterChainNew( stream_t *p_source,
76                                  const char *psz_chain,
77                                  bool b_record )
78 {
79     /* Add auto stream filter */
80     for( ;; )
81     {
82         stream_t *p_filter = stream_FilterNew( p_source, NULL );
83         if( !p_filter )
84             break;
85
86         msg_Dbg( p_filter, "Inserted a stream filter" );
87         p_source = p_filter;
88     }
89
90     /* Add user stream filter */
91     char *psz_tmp = psz_chain ? strdup( psz_chain ) : NULL;
92     char *psz = psz_tmp;
93     while( psz && *psz )
94     {
95         stream_t *p_filter;
96         char *psz_end = strchr( psz, ':' );
97
98         if( psz_end )
99             *psz_end++ = '\0';
100
101         p_filter = stream_FilterNew( p_source, psz );
102         if( p_filter )
103             p_source = p_filter;
104         else
105             msg_Warn( p_source, "failed to insert stream filter %s", psz );
106
107         psz = psz_end;
108     }
109     free( psz_tmp );
110
111     /* Add record filter if useful */
112     if( b_record )
113     {
114         stream_t *p_filter = stream_FilterNew( p_source,
115                                                "stream_filter_record" );
116         if( p_filter )
117             p_source = p_filter;
118     }
119     return p_source;
120 }
121
122 static void StreamDelete( stream_t *s )
123 {
124     module_unneed( s, s->p_module );
125
126     if( s->p_source )
127         stream_Delete( s->p_source );
128
129     stream_CommonDelete( s );
130 }