[vlc-devel] [PATCH] Rawaudio input demux (version 2)

Laurent Aimar fenrir at via.ecp.fr
Mon May 4 07:54:14 CEST 2009


Hi,

On Wed, Apr 29, 2009, Jarmo Torvinen wrote:
> Here is the version 2 of the rawaudio input demux plugin. It resolves the 
> issues highlighted by Rémi.

> +/*****************************************************************************
> + * Open: initializes raw audio demuxer
> + *****************************************************************************/
> +static int Open( vlc_object_t * p_this )
> +{
> +    demux_t     *p_demux = (demux_t*)p_this;
> +    demux_sys_t *p_sys;
> +    int i_samples;
> +    
> +    /* Set p_input field */
> +    p_demux->pf_demux   = Demux;
> +    p_demux->pf_control = Control;
> +    p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
> +    if( !p_sys )
> +        return VLC_ENOMEM;
> +
> +
> +    es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
> +
> +    const char *psz_fourcc = var_CreateGetString( p_demux, "rawaud-fourcc" );
 You cannot use const here as you will need to free it.
> +
> +    p_sys->fmt.i_codec = VLC_FOURCC( psz_fourcc[0], psz_fourcc[1], psz_fourcc[2], psz_fourcc[3] ); 
 You need to check if psz_fourcc is non NULL and is exactly(or at least) 4
bytes to protect against invalid/broken parameter.

> +
> +    free(psz_fourcc);
> +    // get the bits per sample ratio based on codec
> +    switch (p_sys->fmt.i_codec)
 Coding style.

> +    msg_Dbg( p_demux, "frame size is %d bytes ", p_sys->i_frame_size);
> +
> +    p_sys->i_frame_length = (mtime_t)1000000 *
> +                            (mtime_t)i_samples /
> +                            (mtime_t)p_sys->fmt.audio.i_rate;
 This is not exact and so will create a drift in the computed values.
Using date_Init/Set/Increment will take care of that for you (you can have
a look at the current wav.c to see how they are used).

> +/*****************************************************************************
> + * Demux: reads and demuxes data packets
> + *****************************************************************************
> + * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
> + *****************************************************************************/
> +static int Demux( demux_t *p_demux )
> +{
> +    demux_sys_t *p_sys  = p_demux->p_sys;
> +    block_t     *p_block;
> +
> +    /* Call the pace control */
> +    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time );
 You have not initialized p_sys->i_time. Becarefull that you need to start with
a value greater or equal to 1 (0 is invalid, 1 is best if you want to be able
to use it with input slaves functionnalities). After converting to date_* it is
just a simple date_Set( &p_sys->time, 1 ) in the open function.

> +/*****************************************************************************
> + * Control:
> + *****************************************************************************/
> +static int Control( demux_t *p_demux, int i_query, va_list args )
> +{
> +    demux_sys_t *p_sys  = p_demux->p_sys;
> +
> +    return demux_vaControlHelper( p_demux->s, 0, -1,
> +                                   p_sys->fmt.i_bitrate, 1, i_query, args );
 You should not use 1 here but the size of the minimal unit at which you can seek
which is I think:
p_sys->fmt.audio.i_channels * ( (p_sys->fmt.audio.i_bitspersample + 7) / 8 );

Regards,

-- 
fenrir




More information about the vlc-devel mailing list