]> git.sesse.net Git - vlc/blob - modules/mux/dummy.c
c5b6cc4fdd8525d0c5e84253e84e703d356ddd3b
[vlc] / modules / mux / dummy.c
1 /*****************************************************************************
2  * dummy.c: dummy muxer module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Eric Petit <titer@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/sout.h>
32
33
34 /*****************************************************************************
35  * Module descriptor
36  *****************************************************************************/
37 static int  Open   ( vlc_object_t * );
38 static void Close  ( vlc_object_t * );
39
40 vlc_module_begin();
41     set_description( _("Dummy/Raw muxer") );
42     set_capability( "sout mux", 5 );
43     add_shortcut( "dummy" );
44     add_shortcut( "raw" );
45     add_shortcut( "es" );
46     set_callbacks( Open, Close );
47 vlc_module_end();
48
49 /*****************************************************************************
50  * Exported prototypes
51  *****************************************************************************/
52 static int Control( sout_mux_t *, int, va_list );
53 static int AddStream( sout_mux_t *, sout_input_t * );
54 static int DelStream( sout_mux_t *, sout_input_t * );
55 static int Mux      ( sout_mux_t * );
56
57 struct sout_mux_sys_t
58 {
59     /* Some streams have special initialization data, we'll output this
60      * data as an header in the stream. */
61     vlc_bool_t b_header;
62 };
63
64 /*****************************************************************************
65  * Open:
66  *****************************************************************************/
67 static int Open( vlc_object_t *p_this )
68 {
69     sout_mux_t *p_mux = (sout_mux_t*)p_this;
70     sout_mux_sys_t  *p_sys;
71
72     msg_Dbg( p_mux, "Dummy/Raw muxer opened" );
73     msg_Info( p_mux, "Open" );
74
75     p_mux->pf_control   = Control;
76     p_mux->pf_addstream = AddStream;
77     p_mux->pf_delstream = DelStream;
78     p_mux->pf_mux       = Mux;
79
80     p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
81     p_sys->b_header      = VLC_TRUE;
82
83     return VLC_SUCCESS;
84 }
85
86 /*****************************************************************************
87  * Close:
88  *****************************************************************************/
89
90 static void Close( vlc_object_t * p_this )
91 {
92     sout_mux_t *p_mux = (sout_mux_t*)p_this;
93     sout_mux_sys_t *p_sys = p_mux->p_sys;
94
95     msg_Dbg( p_mux, "Dummy/Raw muxer closed" );
96     free( p_sys );
97 }
98
99 static int Control( sout_mux_t *p_mux, int i_query, va_list args )
100 {
101     vlc_bool_t *pb_bool;
102
103    switch( i_query )
104    {
105        case MUX_CAN_ADD_STREAM_WHILE_MUXING:
106            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
107            *pb_bool = VLC_TRUE;
108            return VLC_SUCCESS;
109
110        case MUX_GET_ADD_STREAM_WAIT:
111            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
112            *pb_bool = VLC_FALSE;
113            return VLC_SUCCESS;
114
115        case MUX_GET_MIME:   /* Unknown */
116         default:
117             return VLC_EGENERIC;
118    }
119 }
120
121 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
122 {
123     msg_Dbg( p_mux, "adding input" );
124     return VLC_SUCCESS;
125 }
126
127 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
128 {
129     msg_Dbg( p_mux, "removing input" );
130     return VLC_SUCCESS;
131 }
132
133 static int Mux( sout_mux_t *p_mux )
134 {
135     sout_mux_sys_t *p_sys = p_mux->p_sys;
136     int i;
137
138     for( i = 0; i < p_mux->i_nb_inputs; i++ )
139     {
140         block_fifo_t *p_fifo;
141         int i_count;
142
143         if( p_sys->b_header && p_mux->pp_inputs[i]->p_fmt->i_extra )
144         {
145             /* Write header data */
146             block_t *p_data;
147             p_data = block_New( p_mux, p_mux->pp_inputs[i]->p_fmt->i_extra );
148
149             memcpy( p_data->p_buffer, p_mux->pp_inputs[i]->p_fmt->p_extra,
150                     p_mux->pp_inputs[i]->p_fmt->i_extra );
151
152             msg_Dbg( p_mux, "writing header data" );
153             sout_AccessOutWrite( p_mux->p_access, p_data );
154         }
155
156         p_fifo = p_mux->pp_inputs[i]->p_fifo;
157         i_count = p_fifo->i_depth;
158         while( i_count > 0 )
159         {
160             block_t *p_data = block_FifoGet( p_fifo );
161
162             sout_AccessOutWrite( p_mux->p_access, p_data );
163
164             i_count--;
165         }
166     }
167     p_sys->b_header = VLC_FALSE;
168
169     return VLC_SUCCESS;
170 }