stream_filter.c 3.4 KB
Newer Older
1 2 3 4 5 6 7 8
/*****************************************************************************
 * stream_filter.c
 *****************************************************************************
 * Copyright (C) 2008 Laurent Aimar
 * $Id$
 *
 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28 29
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_stream.h>
30
#include <vlc_modules.h>
31 32
#include <libvlc.h>

33 34
#include <assert.h>

35 36 37 38 39 40 41 42
#include "stream.h"

static void StreamDelete( stream_t * );

stream_t *stream_FilterNew( stream_t *p_source,
                            const char *psz_stream_filter )
{
    stream_t *s;
43
    assert( p_source != NULL );
44 45 46 47 48

    s = stream_CommonNew( VLC_OBJECT( p_source ) );
    if( s == NULL )
        return NULL;

49 50
    s->p_input = p_source->p_input;

51
    /* */
52
    s->psz_access = strdup( p_source->psz_access );
53 54 55 56 57 58
    s->psz_path = strdup( p_source->psz_path );
    if( !s->psz_path )
    {
        stream_CommonDelete( s );
        return NULL;
    }
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    s->p_source = p_source;

    /* */
    s->p_module = module_need( s, "stream_filter", psz_stream_filter, true );

    if( !s->p_module )
    {
        stream_CommonDelete( s );
        return NULL;
    }

    s->pf_destroy = StreamDelete;

    return s;
}

Laurent Aimar's avatar
Laurent Aimar committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
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 );

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
111
    /* Add record filter if useful */
Laurent Aimar's avatar
Laurent Aimar committed
112 113 114 115 116 117 118 119 120 121
    if( b_record )
    {
        stream_t *p_filter = stream_FilterNew( p_source,
                                               "stream_filter_record" );
        if( p_filter )
            p_source = p_filter;
    }
    return p_source;
}

122 123 124 125 126 127 128 129 130
static void StreamDelete( stream_t *s )
{
    module_unneed( s, s->p_module );

    if( s->p_source )
        stream_Delete( s->p_source );

    stream_CommonDelete( s );
}