]> git.sesse.net Git - vlc/blob - modules/mux/dummy.c
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / modules / mux / dummy.c
1 /*****************************************************************************
2  * dummy.c: dummy muxer module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc/vlc.h>
34 #include <vlc_sout.h>
35 #include <vlc_block.h>
36
37 /*****************************************************************************
38  * Module descriptor
39  *****************************************************************************/
40 static int  Open   ( vlc_object_t * );
41 static void Close  ( vlc_object_t * );
42
43 vlc_module_begin();
44     set_description( _("Dummy/Raw muxer") );
45     set_capability( "sout mux", 5 );
46     set_category( CAT_SOUT );
47     set_subcategory( SUBCAT_SOUT_MUX );
48     add_shortcut( "dummy" );
49     add_shortcut( "raw" );
50     add_shortcut( "es" );
51     set_callbacks( Open, Close );
52 vlc_module_end();
53
54 /*****************************************************************************
55  * Exported prototypes
56  *****************************************************************************/
57 static int Control( sout_mux_t *, int, va_list );
58 static int AddStream( sout_mux_t *, sout_input_t * );
59 static int DelStream( sout_mux_t *, sout_input_t * );
60 static int Mux      ( sout_mux_t * );
61
62 struct sout_mux_sys_t
63 {
64     /* Some streams have special initialization data, we'll output this
65      * data as an header in the stream. */
66     bool b_header;
67 };
68
69 /*****************************************************************************
70  * Open:
71  *****************************************************************************/
72 static int Open( vlc_object_t *p_this )
73 {
74     sout_mux_t *p_mux = (sout_mux_t*)p_this;
75     sout_mux_sys_t  *p_sys;
76
77     msg_Dbg( p_mux, "Dummy/Raw muxer opened" );
78     msg_Info( p_mux, "Open" );
79
80     p_mux->pf_control   = Control;
81     p_mux->pf_addstream = AddStream;
82     p_mux->pf_delstream = DelStream;
83     p_mux->pf_mux       = Mux;
84
85     p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
86     p_sys->b_header      = true;
87
88     return VLC_SUCCESS;
89 }
90
91 /*****************************************************************************
92  * Close:
93  *****************************************************************************/
94
95 static void Close( vlc_object_t * p_this )
96 {
97     sout_mux_t *p_mux = (sout_mux_t*)p_this;
98     sout_mux_sys_t *p_sys = p_mux->p_sys;
99
100     msg_Dbg( p_mux, "Dummy/Raw muxer closed" );
101     free( p_sys );
102 }
103
104 static int Control( sout_mux_t *p_mux, int i_query, va_list args )
105 {
106     VLC_UNUSED(p_mux);
107     bool *pb_bool;
108
109     switch( i_query )
110     {
111         case MUX_CAN_ADD_STREAM_WHILE_MUXING:
112             pb_bool = (bool*)va_arg( args, bool * );
113             *pb_bool = true;
114             return VLC_SUCCESS;
115
116         case MUX_GET_ADD_STREAM_WAIT:
117             pb_bool = (bool*)va_arg( args, bool * );
118             *pb_bool = false;
119             return VLC_SUCCESS;
120
121         case MUX_GET_MIME:   /* Unknown */
122         default:
123             return VLC_EGENERIC;
124    }
125 }
126
127 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
128 {
129     VLC_UNUSED(p_input);
130     msg_Dbg( p_mux, "adding input" );
131     return VLC_SUCCESS;
132 }
133
134 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
135 {
136     VLC_UNUSED(p_input);
137     msg_Dbg( p_mux, "removing input" );
138     return VLC_SUCCESS;
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         int i_count;
150
151         if( p_sys->b_header && p_mux->pp_inputs[i]->p_fmt->i_extra )
152         {
153             /* Write header data */
154             block_t *p_data;
155             p_data = block_New( p_mux, p_mux->pp_inputs[i]->p_fmt->i_extra );
156
157             memcpy( p_data->p_buffer, p_mux->pp_inputs[i]->p_fmt->p_extra,
158                     p_mux->pp_inputs[i]->p_fmt->i_extra );
159
160             msg_Dbg( p_mux, "writing header data" );
161             sout_AccessOutWrite( p_mux->p_access, p_data );
162         }
163
164         p_fifo = p_mux->pp_inputs[i]->p_fifo;
165         i_count = block_FifoCount( p_fifo );
166         while( i_count > 0 )
167         {
168             block_t *p_data = block_FifoGet( p_fifo );
169
170             sout_AccessOutWrite( p_mux->p_access, p_data );
171
172             i_count--;
173         }
174     }
175     p_sys->b_header = false;
176
177     return VLC_SUCCESS;
178 }