Commit 8b807a4e authored by Gildas Bazin's avatar Gildas Bazin

* modules/demux/wav.c: misc improvements.

parent d4ccb69d
......@@ -57,18 +57,19 @@ struct demux_sys_t
int64_t i_data_pos;
unsigned int i_data_size;
mtime_t i_time;
unsigned int i_frame_size;
mtime_t i_frame_length;
int i_frame_samples;
date_t pts;
};
#define __EVEN( x ) ( ( (x)%2 != 0 ) ? ((x)+1) : (x) )
static int ChunkFind( demux_t *, char *, unsigned int * );
static void FrameInfo_IMA_ADPCM( demux_t *, unsigned int *, mtime_t * );
static void FrameInfo_MS_ADPCM ( demux_t *, unsigned int *, mtime_t * );
static void FrameInfo_PCM ( demux_t *, unsigned int *, mtime_t * );
static void FrameInfo_IMA_ADPCM( demux_t *, unsigned int *, int * );
static void FrameInfo_MS_ADPCM ( demux_t *, unsigned int *, int * );
static void FrameInfo_PCM ( demux_t *, unsigned int *, int * );
/*****************************************************************************
* Open: check file and initializes structures
......@@ -100,7 +101,6 @@ static int Open( vlc_object_t * p_this )
p_demux->pf_control = Control;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->p_es = NULL;
p_sys->i_time = 1;
/* skip riff header */
stream_Read( p_demux->s, NULL, 12 ); /* cannot fail as peek succeed */
......@@ -173,21 +173,22 @@ static int Open( vlc_object_t * p_this )
case VLC_FOURCC( 'a', 'f', 'l', 't' ):
case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
case VLC_FOURCC( 'a', 'l', 'a', 'w' ):
FrameInfo_PCM( p_demux, &p_sys->i_frame_size, &p_sys->i_frame_length );
FrameInfo_PCM( p_demux, &p_sys->i_frame_size,
&p_sys->i_frame_samples );
break;
case VLC_FOURCC( 'm', 's', 0x00, 0x02 ):
FrameInfo_MS_ADPCM( p_demux, &p_sys->i_frame_size,
&p_sys->i_frame_length );
&p_sys->i_frame_samples );
break;
case VLC_FOURCC( 'm', 's', 0x00, 0x11 ):
FrameInfo_IMA_ADPCM( p_demux, &p_sys->i_frame_size,
&p_sys->i_frame_length );
&p_sys->i_frame_samples );
break;
case VLC_FOURCC( 'm', 's', 0x00, 0x61 ):
case VLC_FOURCC( 'm', 's', 0x00, 0x62 ):
/* FIXME not sure at all FIXME */
FrameInfo_MS_ADPCM( p_demux, &p_sys->i_frame_size,
&p_sys->i_frame_length );
&p_sys->i_frame_samples );
break;
case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
case VLC_FOURCC( 'a', '5', '2', ' ' ):
......@@ -212,10 +213,14 @@ static int Open( vlc_object_t * p_this )
if( p_sys->fmt.i_bitrate <= 0 )
{
p_sys->fmt.i_bitrate = (mtime_t)p_sys->i_frame_size *
I64C(8000000) / p_sys->i_frame_length;
p_sys->fmt.audio.i_rate * 8 / p_sys->i_frame_samples;
}
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 );
date_Set( &p_sys->pts, 1 );
return VLC_SUCCESS;
error:
......@@ -249,15 +254,15 @@ static int Demux( demux_t *p_demux )
msg_Warn( p_demux, "cannot read data" );
return 0;
}
p_block->i_dts = p_block->i_pts = p_sys->i_time;
p_block->i_dts = p_block->i_pts =
date_Increment( &p_sys->pts, p_sys->i_frame_samples );
/* set PCR */
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time );
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
es_out_Send( p_demux->out, p_sys->p_es, p_block );
p_sys->i_time += p_sys->i_frame_length;
return 1;
}
......@@ -279,21 +284,22 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
int64_t i_end = -1;
if( p_sys->i_data_size > 0 )
{
i_end = p_sys->i_data_pos + p_sys->i_data_size;
}
return demux2_vaControlHelper( p_demux->s,
p_sys->i_data_pos, i_end,
p_sys->fmt.i_bitrate, p_sys->fmt.audio.i_blockalign,
return demux2_vaControlHelper( p_demux->s, p_sys->i_data_pos, i_end,
p_sys->fmt.i_bitrate,
p_sys->fmt.audio.i_blockalign,
i_query, args );
}
/*****************************************************************************
* Local functions
*****************************************************************************/
static int ChunkFind( demux_t *p_demux,
char *fcc, unsigned int *pi_size )
static int ChunkFind( demux_t *p_demux, char *fcc, unsigned int *pi_size )
{
uint8_t *p_peek;
......@@ -328,26 +334,16 @@ static int ChunkFind( demux_t *p_demux,
}
}
static void FrameInfo_PCM( demux_t *p_demux,
unsigned int *pi_size,
mtime_t *pi_length )
static void FrameInfo_PCM( demux_t *p_demux, unsigned int *pi_size,
int *pi_samples )
{
demux_sys_t *p_sys = p_demux->p_sys;
int i_samples;
int i_bytes;
int i_modulo;
int i_bytes, i_modulo;
/* read samples for 50ms of */
i_samples = __MAX( p_sys->fmt.audio.i_rate / 20, 1 );
*pi_samples = __MAX( p_sys->fmt.audio.i_rate / 20, 1 );
*pi_length = (mtime_t)1000000 *
(mtime_t)i_samples /
(mtime_t)p_sys->fmt.audio.i_rate;
i_bytes = i_samples * p_sys->fmt.audio.i_channels *
i_bytes = *pi_samples * p_sys->fmt.audio.i_channels *
( (p_sys->fmt.audio.i_bitspersample + 7) / 8 );
if( p_sys->fmt.audio.i_blockalign > 0 )
......@@ -361,38 +357,24 @@ static void FrameInfo_PCM( demux_t *p_demux,
*pi_size = i_bytes;
}
static void FrameInfo_MS_ADPCM( demux_t *p_demux,
unsigned int *pi_size,
mtime_t *pi_length )
static void FrameInfo_MS_ADPCM( demux_t *p_demux, unsigned int *pi_size,
int *pi_samples )
{
demux_sys_t *p_sys = p_demux->p_sys;
int i_samples;
i_samples = 2 + 2 * ( p_sys->fmt.audio.i_blockalign -
*pi_samples = 2 + 2 * ( p_sys->fmt.audio.i_blockalign -
7 * p_sys->fmt.audio.i_channels ) / p_sys->fmt.audio.i_channels;
*pi_length = (mtime_t)1000000 * (mtime_t)i_samples /
(mtime_t)p_sys->fmt.audio.i_rate;
*pi_size = p_sys->fmt.audio.i_blockalign;
}
static void FrameInfo_IMA_ADPCM( demux_t *p_demux,
unsigned int *pi_size,
mtime_t *pi_length )
static void FrameInfo_IMA_ADPCM( demux_t *p_demux, unsigned int *pi_size,
int *pi_samples )
{
demux_sys_t *p_sys = p_demux->p_sys;
int i_samples;
i_samples = 2 * ( p_sys->fmt.audio.i_blockalign -
*pi_samples = 2 * ( p_sys->fmt.audio.i_blockalign -
4 * p_sys->fmt.audio.i_channels ) / p_sys->fmt.audio.i_channels;
*pi_length = (mtime_t)1000000 * (mtime_t)i_samples /
(mtime_t)p_sys->fmt.audio.i_rate;
*pi_size = p_sys->fmt.audio.i_blockalign;
}
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