1 /*****************************************************************************
2 * wav.c: wav muxer module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close ( vlc_object_t * );
41 set_description( _("WAV muxer") );
42 set_capability( "sout mux", 5 );
43 set_callbacks( Open, Close );
44 add_shortcut( "wav" );
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Capability(sout_mux_t *, int, void *, void * );
51 static int AddStream( sout_mux_t *, sout_input_t * );
52 static int DelStream( sout_mux_t *, sout_input_t * );
53 static int Mux ( sout_mux_t * );
60 /* Wave header for the output data */
61 WAVEHEADER waveheader;
64 /*****************************************************************************
66 *****************************************************************************/
67 static int Open( vlc_object_t *p_this )
69 sout_mux_t *p_mux = (sout_mux_t*)p_this;
70 sout_mux_sys_t *p_sys;
72 p_mux->pf_capacity = Capability;
73 p_mux->pf_addstream = AddStream;
74 p_mux->pf_delstream = DelStream;
77 p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) );
78 p_sys->b_used = VLC_FALSE;
79 p_sys->b_header = VLC_TRUE;
84 /*****************************************************************************
86 *****************************************************************************/
87 static void Close( vlc_object_t * p_this )
89 sout_mux_t *p_mux = (sout_mux_t*)p_this;
90 sout_mux_sys_t *p_sys = p_mux->p_sys;
95 static int Capability( sout_mux_t *p_mux, int i_query,
96 void *p_args, void *p_answer )
100 case SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME:
101 *(vlc_bool_t*)p_answer = VLC_FALSE;
102 return SOUT_MUX_CAP_ERR_OK;
104 return SOUT_MUX_CAP_ERR_UNIMPLEMENTED;
108 static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
110 sout_mux_sys_t *p_sys = p_mux->p_sys;
111 int i_bytes_per_sample;
113 if( p_input->p_fmt->i_cat != AUDIO_ES )
114 msg_Dbg( p_mux, "not an audio stream" );
118 msg_Dbg( p_mux, "can't add more than 1 stream" );
122 msg_Dbg( p_mux, "adding input %i channels, %iHz",
123 p_input->p_fmt->audio.i_channels,
124 p_input->p_fmt->audio.i_rate );
126 //p_input->p_fmt->i_codec;
128 /* Build a WAV header for the output data */
129 memset( &p_sys->waveheader, 0, sizeof(WAVEHEADER) );
130 SetWLE( &p_sys->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
131 SetWLE( &p_sys->waveheader.BitsPerSample, 16);
132 p_sys->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
133 p_sys->waveheader.Length = 0; /* we just don't know */
134 p_sys->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
135 p_sys->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
136 SetDWLE( &p_sys->waveheader.SubChunkLength, 16 );
137 SetWLE( &p_sys->waveheader.Modus, p_input->p_fmt->audio.i_channels );
138 SetDWLE( &p_sys->waveheader.SampleFreq, p_input->p_fmt->audio.i_rate );
139 i_bytes_per_sample = p_input->p_fmt->audio.i_channels *
140 16 /*BitsPerSample*/ / 8;
141 SetWLE( &p_sys->waveheader.BytesPerSample, i_bytes_per_sample );
142 SetDWLE( &p_sys->waveheader.BytesPerSec,
143 i_bytes_per_sample * p_input->p_fmt->audio.i_rate );
144 p_sys->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
145 p_sys->waveheader.DataLength = 0; /* we just don't know */
147 p_sys->b_used = VLC_TRUE;
152 static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
154 msg_Dbg( p_mux, "removing input" );
158 static int Mux( sout_mux_t *p_mux )
160 sout_mux_sys_t *p_sys = p_mux->p_sys;
162 if( !p_mux->i_nb_inputs ) return VLC_SUCCESS;
164 if( p_sys->b_header )
166 /* Return only the header */
167 block_t *p_block = block_New( p_mux, sizeof( WAVEHEADER ) );
168 memcpy( p_block->p_buffer, &p_sys->waveheader, sizeof(WAVEHEADER) );
170 msg_Dbg( p_mux, "writing header data" );
171 sout_AccessOutWrite( p_mux->p_access, p_block );
173 p_sys->b_header = VLC_FALSE;
175 while( p_mux->pp_inputs[0]->p_fifo->i_depth > 0 )
177 block_t *p_block = block_FifoGet( p_mux->pp_inputs[0]->p_fifo );
178 sout_AccessOutWrite( p_mux->p_access, p_block );