access: rist: fix misspellings on help text
[vlc.git] / src / input / stream_filter.c
blobea6fd308a7a21eaabbdf7725b3c243b84df88f9a
1 /*****************************************************************************
2 * stream_filter.c
3 *****************************************************************************
4 * Copyright (C) 2008 Laurent Aimar
5 * $Id$
7 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
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.
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.
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
29 #include <vlc_stream.h>
30 #include <vlc_modules.h>
31 #include <libvlc.h>
33 #include <assert.h>
35 #include "stream.h"
37 struct vlc_stream_filter_private
39 module_t *module;
42 static void StreamDelete(stream_t *s)
44 struct vlc_stream_filter_private *priv = vlc_stream_Private(s);
46 module_unneed(s, priv->module);
47 vlc_stream_Delete(s->s);
48 free(s->psz_filepath);
51 stream_t *vlc_stream_FilterNew( stream_t *p_source,
52 const char *psz_stream_filter )
54 assert(p_source != NULL);
56 struct vlc_stream_filter_private *priv;
57 stream_t *s = vlc_stream_CustomNew(p_source->obj.parent, StreamDelete,
58 sizeof (*priv), "stream filter");
59 if( s == NULL )
60 return NULL;
62 priv = vlc_stream_Private(s);
63 s->p_input_item = p_source->p_input_item;
65 if( p_source->psz_url != NULL )
67 s->psz_url = strdup( p_source->psz_url );
68 if( unlikely(s->psz_url == NULL) )
69 goto error;
71 if( p_source->psz_filepath != NULL )
72 s->psz_filepath = strdup( p_source->psz_filepath );
74 s->s = p_source;
76 /* */
77 priv->module = module_need(s, "stream_filter", psz_stream_filter, true);
78 if (priv->module == NULL)
79 goto error;
81 return s;
82 error:
83 free(s->psz_filepath);
84 stream_CommonDelete( s );
85 return NULL;
88 /* Add automatic stream filter */
89 stream_t *stream_FilterAutoNew( stream_t *p_source )
91 /* Limit number of entries to avoid infinite recursion. */
92 for( unsigned i = 0; i < 16; i++ )
94 stream_t *p_filter = vlc_stream_FilterNew( p_source, NULL );
95 if( p_filter == NULL )
96 break;
98 msg_Dbg( p_filter, "stream filter added to %p", (void *)p_source );
99 p_source = p_filter;
101 return p_source;
104 /* Add specified stream filter(s) */
105 stream_t *stream_FilterChainNew( stream_t *p_source, const char *psz_chain )
107 /* Add user stream filter */
108 char *chain = strdup( psz_chain );
109 if( unlikely(chain == NULL) )
110 return p_source;
112 char *buf;
113 for( const char *name = strtok_r( chain, ":", &buf );
114 name != NULL;
115 name = strtok_r( NULL, ":", &buf ) )
117 stream_t *p_filter = vlc_stream_FilterNew( p_source, name );
118 if( p_filter != NULL )
119 p_source = p_filter;
120 else
121 msg_Warn( p_source, "cannot insert stream filter %s", name );
123 free( chain );
125 return p_source;