qt: playlist: use item title if available
[vlc.git] / src / input / stream_filter.c
blob40ccbeaf82400bdc68d8cb0c401acbc863470fd2
1 /*****************************************************************************
2 * stream_filter.c
3 *****************************************************************************
4 * Copyright (C) 2008 Laurent Aimar
6 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
28 #include <vlc_stream.h>
29 #include <vlc_modules.h>
30 #include <libvlc.h>
32 #include <assert.h>
34 #include "stream.h"
36 struct vlc_stream_filter_private
38 module_t *module;
41 static void StreamDelete(stream_t *s)
43 struct vlc_stream_filter_private *priv = vlc_stream_Private(s);
45 module_unneed(s, priv->module);
46 vlc_stream_Delete(s->s);
47 free(s->psz_filepath);
50 stream_t *vlc_stream_FilterNew( stream_t *p_source,
51 const char *psz_stream_filter )
53 assert(p_source != NULL);
55 /* Stream filters can only filter byte streams. */
56 if (p_source->pf_read == NULL && p_source->pf_block == NULL)
57 return NULL;
59 struct vlc_stream_filter_private *priv;
60 stream_t *s = vlc_stream_CustomNew(vlc_object_parent(p_source),
61 StreamDelete, sizeof (*priv),
62 "stream filter");
63 if( s == NULL )
64 return NULL;
66 priv = vlc_stream_Private(s);
67 s->p_input_item = p_source->p_input_item;
69 if( p_source->psz_url != NULL )
71 s->psz_url = strdup( p_source->psz_url );
72 if( unlikely(s->psz_url == NULL) )
73 goto error;
75 if( p_source->psz_filepath != NULL )
76 s->psz_filepath = strdup( p_source->psz_filepath );
78 s->s = p_source;
80 /* */
81 priv->module = module_need(s, "stream_filter", psz_stream_filter, true);
82 if (priv->module == NULL)
83 goto error;
85 return s;
86 error:
87 free(s->psz_filepath);
88 stream_CommonDelete( s );
89 return NULL;
92 /* Add automatic stream filter */
93 stream_t *stream_FilterAutoNew( stream_t *p_source )
95 /* Limit number of entries to avoid infinite recursion. */
96 for( unsigned i = 0; i < 16; i++ )
98 stream_t *p_filter = vlc_stream_FilterNew( p_source, NULL );
99 if( p_filter == NULL )
100 break;
102 msg_Dbg( p_filter, "stream filter added to %p", (void *)p_source );
103 p_source = p_filter;
105 return p_source;
108 /* Add specified stream filter(s) */
109 stream_t *stream_FilterChainNew( stream_t *p_source, const char *psz_chain )
111 /* Add user stream filter */
112 char *chain = strdup( psz_chain );
113 if( unlikely(chain == NULL) )
114 return p_source;
116 char *buf;
117 for( const char *name = strtok_r( chain, ":", &buf );
118 name != NULL;
119 name = strtok_r( NULL, ":", &buf ) )
121 stream_t *p_filter = vlc_stream_FilterNew( p_source, name );
122 if( p_filter != NULL )
123 p_source = p_filter;
124 else
125 msg_Warn( p_source, "cannot insert stream filter %s", name );
127 free( chain );
129 return p_source;