]> git.sesse.net Git - vlc/blob - modules/mux/dummy.c
c99eeefc080812fd9250eec9e2ff715abdcbfcb4
[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     set_category( CAT_SOUT );
44     set_subcategory( SUBCAT_SOUT_MUX );
45     add_shortcut( "dummy" );
46     add_shortcut( "raw" );
47     add_shortcut( "es" );
48     set_callbacks( Open, Close );
49 vlc_module_end();
50
51 /*****************************************************************************
52  * Exported prototypes
53  *****************************************************************************/
54 static int Control( sout_mux_t *, int, va_list );
55 static int AddStream( sout_mux_t *, sout_input_t * );
56 static int DelStream( sout_mux_t *, sout_input_t * );
57 static int Mux      ( sout_mux_t * );
58
59 struct sout_mux_sys_t
60 {
61     /* Some streams have special initialization data, we'll output this
62      * data as an header in the stream. */
63     vlc_bool_t b_header;
64 };
65
66 /*****************************************************************************
67  * Open:
68  *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
70 {
71     sout_mux_t *p_mux = (sout_mux_t*)p_this;
72     sout_mux_sys_t  *p_sys;
73
74     msg_Dbg( p_mux, "Dummy/Raw muxer opened" );
75     msg_Info( p_mux, "Open" );
76
77     p_mux->pf_control   = Control;
78     p_mux->pf_addstream = AddStream;
79     p_mux->pf_delstream = DelStream;
80     p_mux->pf_mux       = Mux;
81
82     p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
83     p_sys->b_header      = VLC_TRUE;
84
85     return VLC_SUCCESS;
86 }
87
88 /*****************************************************************************
89  * Close:
90  *****************************************************************************/
91
92 static void Close( vlc_object_t * p_this )
93 {
94     sout_mux_t *p_mux = (sout_mux_t*)p_this;
95     sout_mux_sys_t *p_sys = p_mux->p_sys;
96
97     msg_Dbg( p_mux, "Dummy/Raw muxer closed" );
98     free( p_sys );
99 }
100
101 static int Control( sout_mux_t *p_mux, int i_query, va_list args )
102 {
103     vlc_bool_t *pb_bool;
104
105    switch( i_query )
106    {
107        case MUX_CAN_ADD_STREAM_WHILE_MUXING:
108            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
109            *pb_bool = VLC_TRUE;
110            return VLC_SUCCESS;
111
112        case MUX_GET_ADD_STREAM_WAIT:
113            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
114            *pb_bool = VLC_FALSE;
115            return VLC_SUCCESS;
116
117        case MUX_GET_MIME:   /* Unknown */
118         default:
119             return VLC_EGENERIC;
120    }
121 }
122
123 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
124 {
125     msg_Dbg( p_mux, "adding input" );
126     return VLC_SUCCESS;
127 }
128
129 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
130 {
131     msg_Dbg( p_mux, "removing input" );
132     return VLC_SUCCESS;
133 }
134
135 static int Mux( sout_mux_t *p_mux )
136 {
137     sout_mux_sys_t *p_sys = p_mux->p_sys;
138     int i;
139
140     for( i = 0; i < p_mux->i_nb_inputs; i++ )
141     {
142         block_fifo_t *p_fifo;
143         int i_count;
144
145         if( p_sys->b_header && p_mux->pp_inputs[i]->p_fmt->i_extra )
146         {
147             /* Write header data */
148             block_t *p_data;
149             p_data = block_New( p_mux, p_mux->pp_inputs[i]->p_fmt->i_extra );
150
151             memcpy( p_data->p_buffer, p_mux->pp_inputs[i]->p_fmt->p_extra,
152                     p_mux->pp_inputs[i]->p_fmt->i_extra );
153
154             msg_Dbg( p_mux, "writing header data" );
155             sout_AccessOutWrite( p_mux->p_access, p_data );
156         }
157
158         p_fifo = p_mux->pp_inputs[i]->p_fifo;
159         i_count = p_fifo->i_depth;
160         while( i_count > 0 )
161         {
162             block_t *p_data = block_FifoGet( p_fifo );
163
164             sout_AccessOutWrite( p_mux->p_access, p_data );
165
166             i_count--;
167         }
168     }
169     p_sys->b_header = VLC_FALSE;
170
171     return VLC_SUCCESS;
172 }