X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fxa.c;h=3e25547da972e615efd429f0962a5419f0fcf896;hb=b663f4481b91cb87c5bbd55f9ce8348d2cf214bc;hp=6cf89611e2525ade5592c6c946634b96ade410e0;hpb=150509ed7b7388f69da8f8c5a018e4c6ec6baf55;p=vlc diff --git a/modules/demux/xa.c b/modules/demux/xa.c index 6cf89611e2..3e25547da9 100644 --- a/modules/demux/xa.c +++ b/modules/demux/xa.c @@ -1,7 +1,7 @@ /***************************************************************************** - * xa.c : xa file input module for vlc + * xa.c : xa file demux module for vlc ***************************************************************************** - * Copyright (C) 2005 the VideoLAN team + * Copyright (C) 2005 Rémi Denis-Courmont * $Id$ * * Authors: Rémi Denis-Courmont @@ -24,13 +24,14 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include +#include +#include +#include /***************************************************************************** * Module descriptor @@ -38,13 +39,13 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -vlc_module_begin(); - set_description( _("XA demuxer") ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_DEMUX ); - set_capability( "demux2", 10 ); - set_callbacks( Open, Close ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("XA demuxer") ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_DEMUX ) + set_capability( "demux", 10 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Local prototypes @@ -59,6 +60,7 @@ struct demux_sys_t int64_t i_data_offset; unsigned int i_data_size; + unsigned int i_block_frames; date_t pts; }; @@ -76,7 +78,6 @@ typedef struct xa_header_t uint16_t wBitsPerSample; } xa_header_t; - /***************************************************************************** * Open: check file and initializes structures *****************************************************************************/ @@ -85,7 +86,7 @@ static int Open( vlc_object_t * p_this ) demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; xa_header_t p_xa; - uint8_t *p_buf; + const uint8_t *p_buf; /* XA file heuristic */ if( stream_Peek( p_demux->s, &p_buf, sizeof( p_xa ) ) @@ -99,9 +100,13 @@ static int Open( vlc_object_t * p_this ) || ( GetWLE( &p_xa.wBitsPerSample ) != 16) ) return VLC_EGENERIC; + p_sys = malloc( sizeof( demux_sys_t ) ); + if( unlikely( p_sys == NULL ) ) + return VLC_ENOMEM; + p_demux->pf_demux = Demux; p_demux->pf_control = Control; - p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + p_demux->p_sys = p_sys; p_sys->p_es = NULL; /* skip XA header -- cannot fail */ @@ -126,6 +131,8 @@ static int Open( vlc_object_t * p_this ) p_sys->i_data_offset = stream_Tell( p_demux->s ); /* FIXME: better computation */ p_sys->i_data_size = p_xa.iSize * 15 / 56; + /* How many frames per block (1:1 is too CPU intensive) */ + p_sys->i_block_frames = p_sys->fmt.audio.i_rate / (28 * 20) + 1; msg_Dbg( p_demux, "fourcc: %4.4s, channels: %d, " "freq: %d Hz, bitrate: %dKo/s, blockalign: %d", @@ -151,6 +158,7 @@ static int Demux( demux_t *p_demux ) demux_sys_t *p_sys = p_demux->p_sys; block_t *p_block; int64_t i_offset; + unsigned i_frames = p_sys->i_block_frames; i_offset = stream_Tell( p_demux->s ); @@ -161,20 +169,21 @@ static int Demux( demux_t *p_demux ) return 0; } - p_block = stream_Block( p_demux->s, p_sys->fmt.audio.i_bytes_per_frame ); + p_block = stream_Block( p_demux->s, p_sys->fmt.audio.i_bytes_per_frame * + i_frames ); if( p_block == NULL ) { msg_Warn( p_demux, "cannot read data" ); return 0; } - p_block->i_dts = p_block->i_pts = - date_Increment( &p_sys->pts, p_sys->fmt.audio.i_frame_length ); - + i_frames = p_block->i_buffer / p_sys->fmt.audio.i_bytes_per_frame; + p_block->i_dts = p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts ); 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 ); + date_Increment( &p_sys->pts, i_frames * p_sys->fmt.audio.i_frame_length ); + return 1; } @@ -195,7 +204,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) { demux_sys_t *p_sys = p_demux->p_sys; - return demux2_vaControlHelper( p_demux->s, p_sys->i_data_offset, + return demux_vaControlHelper( p_demux->s, p_sys->i_data_offset, p_sys->i_data_size ? p_sys->i_data_offset + p_sys->i_data_size : -1, p_sys->fmt.i_bitrate,