Commit 88386ce7 authored by Gildas Bazin's avatar Gildas Bazin

* modules/stream_out/transcode.c, modules/audio_filter/format.c: fixed a bunch of stupid mistakes.

parent 499a2fea
......@@ -40,6 +40,7 @@ static int Open ( vlc_object_t * );
static block_t *Float32toS16( filter_t *, block_t * );
static block_t *Float32toU16( filter_t *, block_t * );
static block_t *S16toFloat32( filter_t *, block_t * );
static block_t *S16Invert ( filter_t *, block_t * );
/*****************************************************************************
* Module descriptor
......@@ -62,16 +63,23 @@ static int Open( vlc_object_t *p_this )
{
p_filter->pf_audio_filter = Float32toS16;
}
else if ( p_filter->fmt_in.i_codec == VLC_FOURCC('f','l','3','2') &&
p_filter->fmt_out.i_codec == AUDIO_FMT_U16_NE )
else if( p_filter->fmt_in.i_codec == VLC_FOURCC('f','l','3','2') &&
p_filter->fmt_out.i_codec == AUDIO_FMT_U16_NE )
{
p_filter->pf_audio_filter = Float32toU16;
}
else if ( p_filter->fmt_in.i_codec == AUDIO_FMT_S16_NE &&
p_filter->fmt_out.i_codec == VLC_FOURCC('f','l','3','2') )
else if( p_filter->fmt_in.i_codec == AUDIO_FMT_S16_NE &&
p_filter->fmt_out.i_codec == VLC_FOURCC('f','l','3','2') )
{
p_filter->pf_audio_filter = S16toFloat32;
}
else if( ( p_filter->fmt_in.i_codec == VLC_FOURCC('s','1','6','l') &&
p_filter->fmt_out.i_codec == VLC_FOURCC('s','1','6','b') ) ||
( p_filter->fmt_in.i_codec == VLC_FOURCC('s','1','6','b') &&
p_filter->fmt_out.i_codec == VLC_FOURCC('s','1','6','l') ) )
{
p_filter->pf_audio_filter = S16Invert;
}
else return VLC_EGENERIC;
msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i",
......@@ -91,7 +99,7 @@ static block_t *Float32toS16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer;
int16_t *p_out = (int16_t *)p_in;
for( i = p_block->i_buffer/ p_filter->fmt_in.audio.i_bitspersample; i-- ; )
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
{
#if 0
/* Slow version. */
......@@ -119,7 +127,7 @@ static block_t *Float32toU16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer;
uint16_t *p_out = (uint16_t *)p_in;
for( i = p_block->i_buffer/ p_filter->fmt_in.audio.i_bitspersample; i-- ; )
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
{
if ( *p_in >= 1.0 ) *p_out = 65535;
else if ( *p_in < -1.0 ) *p_out = 0;
......@@ -146,10 +154,10 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
return NULL;
}
p_in = (int16_t *)(p_block->p_buffer + p_block->i_buffer) - 1;
p_out = (float *)(p_block_out->p_buffer + p_block_out->i_buffer) - 1;
p_in = (int16_t *)p_block->p_buffer;
p_out = (float *)p_block_out->p_buffer;
for( i = p_block->i_buffer/ p_filter->fmt_in.audio.i_bitspersample; i-- ; )
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
{
#if 0
/* Slow version */
......@@ -163,7 +171,7 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
*p_out = u.f - 384.0;
#endif
p_in--; p_out--;
p_in++; p_out++;
}
p_block_out->i_samples = p_block->i_samples;
......@@ -172,5 +180,23 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
p_block_out->i_length = p_block->i_length;
p_block_out->i_rate = p_block->i_rate;
p_block->pf_release( p_block );
return p_block_out;
}
static block_t *S16Invert( filter_t *p_filter, block_t *p_block )
{
int i;
uint8_t *p_in = (uint8_t *)p_block->p_buffer;
uint8_t tmp;
for( i = 0; i < p_block->i_buffer / 2; i++ )
{
tmp = p_in[0];
p_in[0] = p_in[1];
p_in[1] = tmp;
p_in += 2;
}
return p_block;
}
......@@ -818,17 +818,30 @@ int audio_BitsPerSample( vlc_fourcc_t i_format )
{
case VLC_FOURCC('u','8',' ',' '):
case VLC_FOURCC('s','8',' ',' '):
return 1;
return 8;
case VLC_FOURCC('u','1','6','l'):
case VLC_FOURCC('s','1','6','l'):
case VLC_FOURCC('u','1','6','b'):
case VLC_FOURCC('s','1','6','b'):
return 2;
return 16;
case VLC_FOURCC('u','2','4','l'):
case VLC_FOURCC('s','2','4','l'):
case VLC_FOURCC('u','2','4','b'):
case VLC_FOURCC('s','2','4','b'):
return 24;
case VLC_FOURCC('u','3','2','l'):
case VLC_FOURCC('s','3','2','l'):
case VLC_FOURCC('u','3','2','b'):
case VLC_FOURCC('s','3','2','b'):
case VLC_FOURCC('f','l','3','2'):
case VLC_FOURCC('f','i','3','2'):
return 4;
return 32;
case VLC_FOURCC('f','l','6','4'):
return 64;
}
return 0;
......@@ -892,7 +905,8 @@ static int transcode_audio_new( sout_stream_t *p_stream,
id->p_encoder->fmt_out.audio.i_physical_channels;
id->p_encoder->fmt_in.audio.i_channels =
id->p_encoder->fmt_out.audio.i_channels;
id->p_encoder->fmt_in.audio.i_bitspersample = 16;
id->p_encoder->fmt_in.audio.i_bitspersample =
audio_BitsPerSample( id->p_encoder->fmt_in.i_codec );
id->p_encoder->p_cfg = p_stream->p_sys->p_audio_cfg;
......@@ -906,6 +920,8 @@ static int transcode_audio_new( sout_stream_t *p_stream,
return VLC_EGENERIC;
}
id->p_encoder->fmt_in.audio.i_format = id->p_encoder->fmt_in.i_codec;
id->p_encoder->fmt_in.audio.i_bitspersample =
audio_BitsPerSample( id->p_encoder->fmt_in.i_codec );
/* Check if we need a filter for chroma conversion or resizing */
if( id->p_decoder->fmt_out.i_codec !=
......@@ -934,6 +950,9 @@ static int transcode_audio_new( sout_stream_t *p_stream,
return VLC_EGENERIC;
}
id->pp_filter[0]->fmt_out.audio.i_bitspersample =
audio_BitsPerSample( id->pp_filter[0]->fmt_out.i_codec );
/* Try a 2 stage conversion */
if( id->pp_filter[0]->fmt_out.i_codec !=
id->p_encoder->fmt_in.i_codec )
......@@ -1067,7 +1086,7 @@ static aout_buffer_t *audio_new_buffer( decoder_t *p_dec, int i_samples )
if( p_dec->fmt_out.audio.i_bitspersample )
{
i_size = i_samples * p_dec->fmt_out.audio.i_bitspersample *
i_size = i_samples * p_dec->fmt_out.audio.i_bitspersample / 8 *
p_dec->fmt_out.audio.i_channels;
}
else if( p_dec->fmt_out.audio.i_bytes_per_frame &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment