dummy.c 5.38 KB
Newer Older
1
/*****************************************************************************
2
 * dummy.c: dummy muxer module for vlc
3
 *****************************************************************************
4
 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
5
 * $Id$
6 7 8 9
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *          Eric Petit <titer@videolan.org>
 *
10 11 12
 * 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
13 14 15 16
 * (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
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
20 21 22
 * 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.
23 24 25 26 27 28
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
34
#include <vlc_plugin.h>
35 36
#include <vlc_sout.h>
#include <vlc_block.h>
37 38 39 40

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
41 42 43
static int  Open   ( vlc_object_t * );
static void Close  ( vlc_object_t * );

44 45 46 47 48
vlc_module_begin ()
    set_description( N_("Dummy/Raw muxer") )
    set_capability( "sout mux", 5 )
    set_category( CAT_SOUT )
    set_subcategory( SUBCAT_SOUT_MUX )
49
    add_shortcut( "dummy", "raw", "es" )
50 51
    set_callbacks( Open, Close )
vlc_module_end ()
52

53 54 55
/*****************************************************************************
 * Exported prototypes
 *****************************************************************************/
56 57
static int Control( sout_mux_t *, int, va_list );
static int AddStream( sout_mux_t *, sout_input_t * );
58
static void DelStream( sout_mux_t *, sout_input_t * );
59
static int Mux      ( sout_mux_t * );
60

61 62 63 64
struct sout_mux_sys_t
{
    /* Some streams have special initialization data, we'll output this
     * data as an header in the stream. */
65
    bool b_header;
66 67
};

68 69 70 71 72
/*****************************************************************************
 * Open:
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
73
    sout_mux_t *p_mux = (sout_mux_t*)p_this;
74
    sout_mux_sys_t  *p_sys;
75

76
    msg_Dbg( p_mux, "Dummy/Raw muxer opened" );
77
    msg_Info( p_mux, "Open" );
78

79
    p_mux->pf_control   = Control;
80 81 82
    p_mux->pf_addstream = AddStream;
    p_mux->pf_delstream = DelStream;
    p_mux->pf_mux       = Mux;
83

84
    p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
85 86
    if( !p_sys )
        return VLC_ENOMEM;
87
    p_sys->b_header      = true;
88

89 90 91 92 93 94 95 96 97
    return VLC_SUCCESS;
}

/*****************************************************************************
 * Close:
 *****************************************************************************/

static void Close( vlc_object_t * p_this )
{
98
    sout_mux_t *p_mux = (sout_mux_t*)p_this;
99
    sout_mux_sys_t *p_sys = p_mux->p_sys;
100

101
    msg_Dbg( p_mux, "Dummy/Raw muxer closed" );
102
    free( p_sys );
103 104
}

105
static int Control( sout_mux_t *p_mux, int i_query, va_list args )
106
{
107
    VLC_UNUSED(p_mux);
108
    bool *pb_bool;
109

110 111 112
    switch( i_query )
    {
        case MUX_CAN_ADD_STREAM_WHILE_MUXING:
113 114
            pb_bool = (bool*)va_arg( args, bool * );
            *pb_bool = true;
115
            return VLC_SUCCESS;
116

117
        case MUX_GET_ADD_STREAM_WAIT:
118 119
            pb_bool = (bool*)va_arg( args, bool * );
            *pb_bool = false;
120
            return VLC_SUCCESS;
121

122
        case MUX_GET_MIME:   /* Unknown */
123
        default:
124
            return VLC_EGENERIC;
125 126
   }
}
127

128
static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
129
{
130
    VLC_UNUSED(p_input);
131
    msg_Dbg( p_mux, "adding input" );
132
    return VLC_SUCCESS;
133 134
}

135
static void DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
136
{
137
    VLC_UNUSED(p_input);
138
    msg_Dbg( p_mux, "removing input" );
139 140
}

141
static int Mux( sout_mux_t *p_mux )
142
{
143
    sout_mux_sys_t *p_sys = p_mux->p_sys;
144
    int i;
145

146
    for( i = 0; i < p_mux->i_nb_inputs; i++ )
147
    {
148
        block_fifo_t *p_fifo;
149 150
        int i_count;

151 152 153
        if( p_sys->b_header && p_mux->pp_inputs[i]->p_fmt->i_extra )
        {
            /* Write header data */
154
            block_t *p_data;
155
            p_data = block_Alloc( p_mux->pp_inputs[i]->p_fmt->i_extra );
156 157 158 159

            memcpy( p_data->p_buffer, p_mux->pp_inputs[i]->p_fmt->p_extra,
                    p_mux->pp_inputs[i]->p_fmt->i_extra );

160 161
            p_data->i_flags |= BLOCK_FLAG_HEADER;

162 163 164 165
            msg_Dbg( p_mux, "writing header data" );
            sout_AccessOutWrite( p_mux->p_access, p_data );
        }

166
        p_fifo = p_mux->pp_inputs[i]->p_fifo;
167
        i_count = block_FifoCount( p_fifo );
168 169
        while( i_count > 0 )
        {
170
            block_t *p_data = block_FifoGet( p_fifo );
171

172
            sout_AccessOutWrite( p_mux->p_access, p_data );
173 174 175 176

            i_count--;
        }
    }
177
    p_sys->b_header = false;
178

179 180
    return VLC_SUCCESS;
}