]> git.sesse.net Git - vlc/blob - modules/mux/dummy.c
* modules/codec/flac.c: added a FLAC encoder.
[vlc] / modules / mux / dummy.c
1 /*****************************************************************************
2  * dummy.c: dummy muxer module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id: dummy.c,v 1.9 2003/11/21 20:49:14 gbazin Exp $
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/input.h>
32 #include <vlc/sout.h>
33
34 #include "codecs.h"
35
36 /*****************************************************************************
37  * Module descriptor
38  *****************************************************************************/
39 static int  Open   ( vlc_object_t * );
40 static void Close  ( vlc_object_t * );
41
42 vlc_module_begin();
43     set_description( _("Dummy/Raw muxer") );
44     set_capability( "sout mux", 5 );
45     add_shortcut( "dummy" );
46     add_shortcut( "es" );
47     set_callbacks( Open, Close );
48 vlc_module_end();
49
50 /*****************************************************************************
51  * Exported prototypes
52  *****************************************************************************/
53 static int  Capability(sout_mux_t *, int, void *, void * );
54 static int  AddStream( sout_mux_t *, sout_input_t * );
55 static int  DelStream( sout_mux_t *, sout_input_t * );
56 static int  Mux      ( sout_mux_t * );
57
58 struct sout_mux_sys_t
59 {
60     /* Some streams have special initialization data, we'll output this
61      * data as an header in the stream. */
62     vlc_bool_t b_header;
63 };
64
65 /*****************************************************************************
66  * Open:
67  *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
69 {
70     sout_mux_t *p_mux = (sout_mux_t*)p_this;
71     sout_mux_sys_t  *p_sys;
72
73     msg_Dbg( p_mux, "Dummy/Raw muxer opened" );
74     msg_Info( p_mux, "Open" );
75
76     p_mux->pf_capacity  = Capability;
77     p_mux->pf_addstream = AddStream;
78     p_mux->pf_delstream = DelStream;
79     p_mux->pf_mux       = Mux;
80
81     p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
82     p_sys->b_header      = VLC_TRUE;
83
84     return VLC_SUCCESS;
85 }
86
87 /*****************************************************************************
88  * Close:
89  *****************************************************************************/
90
91 static void Close( vlc_object_t * p_this )
92 {
93     sout_mux_t *p_mux = (sout_mux_t*)p_this;
94     sout_mux_sys_t *p_sys = p_mux->p_sys;
95
96     msg_Dbg( p_mux, "Dummy/Raw muxer closed" );
97     free( p_sys );
98 }
99
100 static int Capability( sout_mux_t *p_mux, int i_query,
101                        void *p_args, void *p_answer )
102 {
103    switch( i_query )
104    {
105         case SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME:
106             *(vlc_bool_t*)p_answer = VLC_TRUE;
107             return( SOUT_MUX_CAP_ERR_OK );
108         default:
109             return( SOUT_MUX_CAP_ERR_UNIMPLEMENTED );
110    }
111 }
112
113 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
114 {
115     msg_Dbg( p_mux, "adding input" );
116     return VLC_SUCCESS;
117 }
118
119 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
120 {
121     msg_Dbg( p_mux, "removing input" );
122     return VLC_SUCCESS;
123 }
124
125 static int Mux( sout_mux_t *p_mux )
126 {
127     sout_mux_sys_t *p_sys = p_mux->p_sys;
128     int i;
129
130     for( i = 0; i < p_mux->i_nb_inputs; i++ )
131     {
132         int i_count;
133         sout_fifo_t *p_fifo;
134
135         if( p_sys->b_header && p_mux->pp_inputs[i]->p_fmt->i_extra )
136         {
137             /* Write header data */
138             sout_buffer_t *p_data;
139             p_data = sout_BufferNew( p_mux->p_sout,
140                                      p_mux->pp_inputs[i]->p_fmt->i_extra );
141
142             memcpy( p_data->p_buffer, p_mux->pp_inputs[i]->p_fmt->p_extra,
143                     p_mux->pp_inputs[i]->p_fmt->i_extra );
144
145             p_data->i_size = p_mux->pp_inputs[i]->p_fmt->i_extra;
146             p_data->i_dts = p_data->i_pts = p_data->i_length = 0;
147
148             msg_Dbg( p_mux, "writing header data" );
149             sout_AccessOutWrite( p_mux->p_access, p_data );
150         }
151
152         p_fifo = p_mux->pp_inputs[i]->p_fifo;
153         i_count = p_fifo->i_depth;
154         while( i_count > 0 )
155         {
156             sout_buffer_t *p_data;
157
158             p_data = sout_FifoGet( p_fifo );
159
160             sout_AccessOutWrite( p_mux->p_access, p_data );
161
162             i_count--;
163         }
164
165     }
166     p_sys->b_header = VLC_FALSE;
167
168     return VLC_SUCCESS;
169 }