/*****************************************************************************
* wav.c: wav muxer module for vlc
*****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004, 2006 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h>
#include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <vlc/sout.h>
-
-#include "codecs.h"
+#include <vlc_aout.h>
+#include <vlc_sout.h>
+#include <vlc_block.h>
+#include <vlc_codecs.h>
/*****************************************************************************
* Module descriptor
vlc_module_begin();
set_description( _("WAV muxer") );
set_capability( "sout mux", 5 );
+ set_category( CAT_SOUT );
+ set_subcategory( SUBCAT_SOUT_MUX );
set_callbacks( Open, Close );
add_shortcut( "wav" );
vlc_module_end();
static int DelStream( sout_mux_t *, sout_input_t * );
static int Mux ( sout_mux_t * );
+#define MAX_CHANNELS 6
+
struct sout_mux_sys_t
{
vlc_bool_t b_used;
uint32_t i_channel_mask;
vlc_bool_t b_chan_reorder; /* do we need channel reordering */
- int *pi_chan_table;
+ int pi_chan_table[AOUT_CHAN_MAX];
};
-static const uint32_t pi_channels_in[] =
+
+static const uint32_t pi_channels_src[] =
{ AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
+ AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
- AOUT_CHAN_CENTER, AOUT_CHAN_LFE };
-static const uint32_t pi_channels_out[] =
+ AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
+static const uint32_t pi_channels_in[] =
{ WAVE_SPEAKER_FRONT_LEFT, WAVE_SPEAKER_FRONT_RIGHT,
+ WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT,
WAVE_SPEAKER_BACK_LEFT, WAVE_SPEAKER_BACK_RIGHT,
- WAVE_SPEAKER_FRONT_CENTER, WAVE_SPEAKER_LOW_FREQUENCY };
-static const uint32_t pi_channels_ordered[] =
+ WAVE_SPEAKER_FRONT_CENTER, WAVE_SPEAKER_LOW_FREQUENCY, 0 };
+static const uint32_t pi_channels_out[] =
{ WAVE_SPEAKER_FRONT_LEFT, WAVE_SPEAKER_FRONT_RIGHT,
WAVE_SPEAKER_FRONT_CENTER, WAVE_SPEAKER_LOW_FREQUENCY,
- WAVE_SPEAKER_BACK_LEFT, WAVE_SPEAKER_BACK_RIGHT };
-
-static void CheckReordering( sout_mux_t *p_mux, int i_nb_channels );
-static void InterleaveS16( int16_t *p_buf, int i_buf, int *pi_chan_table,
- int i_nb_channels );
-static void InterleaveFloat32( float *p_buf, int i_buf, int *pi_chan_table,
- int i_nb_channels );
+ WAVE_SPEAKER_BACK_LEFT, WAVE_SPEAKER_BACK_RIGHT,
+ WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT, 0 };
/*****************************************************************************
* Open:
p_sys->b_header = VLC_TRUE;
p_sys->i_data = 0;
- p_sys->pi_chan_table = NULL;
p_sys->b_chan_reorder = 0;
return VLC_SUCCESS;
{
sout_mux_t *p_mux = (sout_mux_t*)p_this;
sout_mux_sys_t *p_sys = p_mux->p_sys;
-
- if( p_sys->pi_chan_table ) free( p_sys->pi_chan_table );
free( p_sys );
}
GUID subformat_guid = {0, 0, 0x10,{0x80, 0, 0, 0xaa, 0, 0x38, 0x9b, 0x71}};
sout_mux_sys_t *p_sys = p_mux->p_sys;
WAVEFORMATEX *p_waveformat = &p_sys->waveformat.Format;
- int i_bytes_per_sample, i_format, i;
+ int i_bytes_per_sample, i_format;
vlc_bool_t b_ext;
if( p_input->p_fmt->i_cat != AUDIO_ES )
return VLC_EGENERIC;
}
- msg_Dbg( p_mux, "adding input %i channels, %iHz",
+ msg_Dbg( p_mux, "adding %i input channels, %iHz",
p_input->p_fmt->audio.i_channels,
p_input->p_fmt->audio.i_rate );
p_sys->i_channel_mask = 0;
if( p_input->p_fmt->audio.i_physical_channels )
{
+ unsigned int i;
+
for( i = 0; i < sizeof(pi_channels_in)/sizeof(uint32_t); i++ )
{
- if( p_input->p_fmt->audio.i_physical_channels & pi_channels_in[i] )
- p_sys->i_channel_mask |= pi_channels_out[i];
+ if( p_input->p_fmt->audio.i_physical_channels & pi_channels_src[i])
+ p_sys->i_channel_mask |= pi_channels_in[i];
}
- msg_Dbg( p_mux, "channel mask: %x", p_sys->i_channel_mask );
- CheckReordering( p_mux, p_input->p_fmt->audio.i_channels );
+
+ p_sys->b_chan_reorder =
+ aout_CheckChannelReorder( pi_channels_in, pi_channels_out,
+ p_sys->i_channel_mask,
+ p_input->p_fmt->audio.i_channels,
+ p_sys->pi_chan_table );
+
+ msg_Dbg( p_mux, "channel mask: %x, reordering: %i",
+ p_sys->i_channel_mask, (int)p_sys->b_chan_reorder );
}
i_format = p_input->p_fmt->i_codec == VLC_FOURCC('f', 'l', '3', '2') ?
/* Do the channel reordering */
if( p_sys->b_chan_reorder )
- {
- if( p_input->p_fmt->i_codec == VLC_FOURCC('s','1','6','l') )
- InterleaveS16( (int16_t *)p_block->p_buffer,
- p_block->i_buffer, p_sys->pi_chan_table,
- p_input->p_fmt->audio.i_channels );
- else if( p_input->p_fmt->i_codec == VLC_FOURCC('f','l','3','2') )
- InterleaveFloat32( (float *)p_block->p_buffer,
- p_block->i_buffer, p_sys->pi_chan_table,
- p_input->p_fmt->audio.i_channels );
- }
+ aout_ChannelReorder( p_block->p_buffer, p_block->i_buffer,
+ p_input->p_fmt->audio.i_channels,
+ p_sys->pi_chan_table,
+ p_input->p_fmt->audio.i_bitspersample );
sout_AccessOutWrite( p_mux->p_access, p_block );
}
return VLC_SUCCESS;
}
-
-/*****************************************************************************
- * CheckReordering: Check if we need to do some channel re-ordering
- * (our channel order is different from the one chosen by Microsoft).
- *****************************************************************************/
-static void CheckReordering( sout_mux_t *p_mux, int i_nb_channels )
-{
- sout_mux_sys_t *p_sys = p_mux->p_sys;
- int i, j, k, l;
-
- p_sys->b_chan_reorder = VLC_FALSE;
-
- p_sys->pi_chan_table = malloc( i_nb_channels * sizeof(int) );
- if( !p_sys->pi_chan_table ) return;
-
- for( i = 0, j = 0;
- i < (int)(sizeof(pi_channels_out)/sizeof(uint32_t)); i++ )
- {
- if( p_sys->i_channel_mask & pi_channels_out[i] )
- {
- for( k = 0, l = 0;
- pi_channels_out[i] != pi_channels_ordered[k]; k++ )
- {
- if( p_sys->i_channel_mask & pi_channels_ordered[k] )
- {
- l++;
- }
- }
-
- p_sys->pi_chan_table[j] = l;
-
- j++;
- }
- }
-
- for( i = 0; i < i_nb_channels; i++ )
- {
- if( p_sys->pi_chan_table[i] != i ) p_sys->b_chan_reorder = VLC_TRUE;
- }
-
- if( p_sys->b_chan_reorder ) msg_Dbg( p_mux, "channel reordering needed" );
-}
-
-/*****************************************************************************
- * InterleaveFloat32/S16: change the channel order to the Microsoft one.
- *****************************************************************************/
-static void InterleaveFloat32( float *p_buf, int i_buf, int *pi_chan_table,
- int i_nb_channels )
-{
- int i, j;
- float p_tmp[10];
-
- for( i = 0; i < i_buf / i_nb_channels / sizeof(float); i++ )
- {
- for( j = 0; j < i_nb_channels; j++ )
- {
- p_tmp[pi_chan_table[j]] = p_buf[i*i_nb_channels + j];
- }
-
- memcpy( &p_buf[i*i_nb_channels], p_tmp,
- i_nb_channels * sizeof(float) );
- }
-}
-
-static void InterleaveS16( int16_t *p_buf, int i_buf, int *pi_chan_table,
- int i_nb_channels )
-{
- int i, j;
- int16_t p_tmp[10];
-
- for( i = 0; i < i_buf / i_nb_channels / sizeof(int16_t); i++ )
- {
- for( j = 0; j < i_nb_channels; j++ )
- {
- p_tmp[pi_chan_table[j]] = p_buf[i*i_nb_channels + j];
- }
-
- memcpy( &p_buf[i*i_nb_channels], p_tmp,
- i_nb_channels * sizeof(int16_t) );
- }
-}