]> git.sesse.net Git - vlc/blob - src/input/stream_filter.c
Implement access_GetParentInput and demux_GetParentInput and use.
[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
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, 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 <libvlc.h>
31
32 #include "stream.h"
33
34 static void StreamDelete( stream_t * );
35
36 stream_t *stream_FilterNew( stream_t *p_source,
37                             const char *psz_stream_filter )
38 {
39     stream_t *s;
40
41     s = stream_CommonNew( VLC_OBJECT( p_source ) );
42     if( s == NULL )
43         return NULL;
44
45     s->p_input = p_source->p_input;
46
47     /* */
48     s->psz_path = strdup( p_source->psz_path );
49     if( !s->psz_path )
50     {
51         stream_CommonDelete( s );
52         return NULL;
53     }
54     s->p_source = p_source;
55
56     /* */
57     vlc_object_attach( s, p_source );
58
59     s->p_module = module_need( s, "stream_filter", psz_stream_filter, true );
60
61     if( !s->p_module )
62     {
63         stream_CommonDelete( s );
64         return NULL;
65     }
66
67     s->pf_destroy = StreamDelete;
68
69     return s;
70 }
71
72 stream_t *stream_FilterChainNew( stream_t *p_source,
73                                  const char *psz_chain,
74                                  bool b_record )
75 {
76     /* Add auto stream filter */
77     for( ;; )
78     {
79         stream_t *p_filter = stream_FilterNew( p_source, NULL );
80         if( !p_filter )
81             break;
82
83         msg_Dbg( p_filter, "Inserted a stream filter" );
84         p_source = p_filter;
85     }
86
87     /* Add user stream filter */
88     char *psz_tmp = psz_chain ? strdup( psz_chain ) : NULL;
89     char *psz = psz_tmp;
90     while( psz && *psz )
91     {
92         stream_t *p_filter;
93         char *psz_end = strchr( psz, ':' );
94
95         if( psz_end )
96             *psz_end++ = '\0';
97
98         p_filter = stream_FilterNew( p_source, psz );
99         if( p_filter )
100             p_source = p_filter;
101         else
102             msg_Warn( p_source, "failed to insert stream filter %s", psz );
103
104         psz = psz_end;
105     }
106     free( psz_tmp );
107
108     /* Add record filter if usefull */
109     if( b_record )
110     {
111         stream_t *p_filter = stream_FilterNew( p_source,
112                                                "stream_filter_record" );
113         if( p_filter )
114             p_source = p_filter;
115     }
116     return p_source;
117 }
118
119 static void StreamDelete( stream_t *s )
120 {
121     module_unneed( s, s->p_module );
122
123     if( s->p_source )
124         stream_Delete( s->p_source );
125
126     stream_CommonDelete( s );
127 }
128