#include <mad.h>
#include <vlc/vlc.h>
-#include "audio_output.h"
+#include <vlc/decoder.h>
#include "aout_internal.h"
+#include "vlc_filter.h"
/*****************************************************************************
* Local prototypes
static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
aout_buffer_t * );
+static int OpenFilter ( vlc_object_t * );
+static void CloseFilter( vlc_object_t * );
+static block_t *Convert( filter_t *, block_t * );
+
/*****************************************************************************
* Local structures
*****************************************************************************/
-struct aout_filter_sys_t
+struct filter_sys_t
{
struct mad_stream mad_stream;
struct mad_frame mad_frame;
set_description( _("MPEG audio decoder") );
set_capability( "audio filter", 100 );
set_callbacks( Create, Destroy );
+
+ add_submodule();
+ set_description( _("MPEG audio decoder") );
+ set_capability( "audio filter2", 100 );
+ set_callbacks( OpenFilter, CloseFilter );
vlc_module_end();
/*****************************************************************************
* Create:
*****************************************************************************/
-static int Create( vlc_object_t * _p_filter )
+static int Create( vlc_object_t *p_this )
{
- aout_filter_t * p_filter = (aout_filter_t *)_p_filter;
- struct aout_filter_sys_t * p_sys;
+ aout_filter_t *p_filter = (aout_filter_t *)p_this;
+ struct filter_sys_t *p_sys;
if ( (p_filter->input.i_format != VLC_FOURCC('m','p','g','a')
&& p_filter->input.i_format != VLC_FOURCC('m','p','g','3'))
}
/* Allocate the memory needed to store the module's structure */
- p_sys = p_filter->p_sys = malloc( sizeof(struct aout_filter_sys_t) );
+ p_sys = malloc( sizeof(filter_sys_t) );
+ p_filter->p_sys = (struct aout_filter_sys_t *)p_sys;
if( p_sys == NULL )
{
msg_Err( p_filter, "out of memory" );
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
- struct aout_filter_sys_t * p_sys = p_filter->p_sys;
+ filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_samples * sizeof(vlc_fixed_t) *
mad_fixed_t const * p_right = p_pcm->samples[1];
float f_temp = (float)FIXED32_ONE;
- switch ( p_pcm->channels )
+ switch ( p_pcm->channels )
{
case 2:
while ( i_samples-- )
/*****************************************************************************
* Destroy : deallocate data structures
*****************************************************************************/
-static void Destroy( vlc_object_t * _p_filter )
+static void Destroy( vlc_object_t *p_this )
{
- aout_filter_t * p_filter = (aout_filter_t *)_p_filter;
- struct aout_filter_sys_t * p_sys = p_filter->p_sys;
+ aout_filter_t *p_filter = (aout_filter_t *)p_this;
+ filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
mad_synth_finish( &p_sys->mad_synth );
mad_frame_finish( &p_sys->mad_frame );
free( p_sys );
}
+/*****************************************************************************
+ * OpenFilter:
+ *****************************************************************************/
+static int OpenFilter( vlc_object_t *p_this )
+{
+ filter_t *p_filter = (filter_t *)p_this;
+ filter_sys_t *p_sys;
+
+ if( p_filter->fmt_in.i_codec != VLC_FOURCC('m','p','g','a') &&
+ p_filter->fmt_in.i_codec != VLC_FOURCC('m','p','g','3') )
+ {
+ return VLC_EGENERIC;
+ }
+
+ /* Allocate the memory needed to store the module's structure */
+ p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) );
+ if( p_sys == NULL )
+ {
+ msg_Err( p_filter, "out of memory" );
+ return -1;
+ }
+
+ p_filter->pf_audio_filter = Convert;
+
+ /* Initialize libmad */
+ mad_stream_init( &p_sys->mad_stream );
+ mad_frame_init( &p_sys->mad_frame );
+ mad_synth_init( &p_sys->mad_synth );
+ mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
+
+ msg_Err( p_this, "%4.4s->%4.4s, bits per sample: %i",
+ (char *)&p_filter->fmt_in.i_codec,
+ (char *)&p_filter->fmt_out.i_codec,
+ p_filter->fmt_out.audio.i_bitspersample );
+
+ p_filter->fmt_out.i_codec =
+ p_filter->fmt_out.audio.i_format = VLC_FOURCC('f','l','3','2');
+ p_filter->fmt_out.audio.i_bitspersample = sizeof(float);
+
+ return 0;
+}
+
+/*****************************************************************************
+ * CloseFilter : deallocate data structures
+ *****************************************************************************/
+static void CloseFilter( vlc_object_t *p_this )
+{
+ filter_t *p_filter = (filter_t *)p_this;
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ mad_synth_finish( &p_sys->mad_synth );
+ mad_frame_finish( &p_sys->mad_frame );
+ mad_stream_finish( &p_sys->mad_stream );
+ free( p_sys );
+}
+
+static block_t *Convert( filter_t *p_filter, block_t *p_block )
+{
+ aout_filter_t aout_filter;
+ aout_buffer_t in_buf, out_buf;
+ block_t *p_out;
+
+ int i_out_size = p_block->i_samples *
+ p_filter->fmt_out.audio.i_bitspersample *
+ p_filter->fmt_out.audio.i_channels;
+
+ p_out = p_filter->pf_audio_buffer_new( p_filter, i_out_size );
+ if( !p_out )
+ {
+ msg_Warn( p_filter, "can't get output buffer" );
+ return NULL;
+ }
+
+ p_out->i_samples = p_block->i_samples;
+ p_out->i_dts = p_block->i_dts;
+ p_out->i_pts = p_block->i_pts;
+ p_out->i_length = p_block->i_length;
+
+ aout_filter.p_sys = (struct aout_filter_sys_t *)p_filter->p_sys;
+ aout_filter.input = p_filter->fmt_in.audio;
+ aout_filter.input.i_format = p_filter->fmt_in.i_codec;
+ aout_filter.output = p_filter->fmt_out.audio;
+ aout_filter.output.i_format = p_filter->fmt_out.i_codec;
+
+ in_buf.p_buffer = p_block->p_buffer;
+ in_buf.i_nb_bytes = p_block->i_buffer;
+ in_buf.i_nb_samples = p_block->i_samples;
+ out_buf.p_buffer = p_out->p_buffer;
+ out_buf.i_nb_bytes = p_out->i_buffer;
+ out_buf.i_nb_samples = p_out->i_samples;
+
+ DoWork( (aout_instance_t *)p_filter, &aout_filter, &in_buf, &out_buf );
+
+ return p_out;
+}