/*****************************************************************************
* ac3_adec.c: ac3 decoder module main file
*****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: ac3_adec.c,v 1.2 2001/11/13 18:10:38 sam Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: ac3_adec.c,v 1.12 2001/12/31 04:53:33 sam Exp $
*
* Authors: Michel Lespinasse <walken@zoy.org>
*
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-/*
- * TODO :
- *
- * - vérifier l'état de la fifo de sortie avant d'y stocker les samples
- * décodés ;
- * - vlc_cond_signal() / vlc_cond_wait()
- *
- */
-#define MODULE_NAME ac3_adec
-#include "modules_inner.h"
-
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "defs.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> /* getpid() */
-#endif
-
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* memset() */
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
+#include <videolan/vlc.h>
-#include "audio_output.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h> /* getpid() */
+#endif
-#include "modules.h"
-#include "modules_export.h"
+#include "audio_output.h"
#include "stream_control.h"
#include "input_ext-dec.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int ac3_adec_Probe ( probedata_t * );
-static int ac3_adec_Run ( decoder_config_t * );
-static int ac3_adec_Init (ac3dec_thread_t * p_adec);
-static void ac3_adec_ErrorThread (ac3dec_thread_t * p_adec);
-static void ac3_adec_EndThread (ac3dec_thread_t * p_adec);
-static void BitstreamCallback ( bit_stream_t *p_bit_stream,
- boolean_t b_new_pes );
+static int decoder_Probe ( probedata_t * );
+static int decoder_Run ( decoder_config_t * );
+static int InitThread ( ac3dec_thread_t * p_adec );
+static void EndThread ( ac3dec_thread_t * p_adec );
+static void BitstreamCallback ( bit_stream_t *p_bit_stream,
+ boolean_t b_new_pes );
/*****************************************************************************
* Capabilities
*****************************************************************************/
void _M( adec_getfunctions )( function_list_t * p_function_list )
{
- p_function_list->pf_probe = ac3_adec_Probe;
- p_function_list->functions.dec.pf_RunThread = ac3_adec_Run;
+ p_function_list->pf_probe = decoder_Probe;
+ p_function_list->functions.dec.pf_run = decoder_Run;
}
/*****************************************************************************
* Build configuration tree.
*****************************************************************************/
MODULE_CONFIG_START
-ADD_WINDOW( "Configuration for ac3 decoder module" )
- ADD_COMMENT( "Nothing to configure" )
MODULE_CONFIG_STOP
MODULE_INIT_START
- p_module->i_capabilities = MODULE_CAPABILITY_DEC;
- p_module->psz_longname = "Ac3 sofware decoder";
+ SET_DESCRIPTION( "software AC3 decoder" )
+ ADD_CAPABILITY( DECODER, 50 )
MODULE_INIT_STOP
MODULE_ACTIVATE_START
/*****************************************************************************
- * ac3_adec_Probe: probe the decoder and return score
+ * decoder_Probe: probe the decoder and return score
*****************************************************************************
* Tries to launch a decoder and return score so that the interface is able
* to chose.
*****************************************************************************/
-static int ac3_adec_Probe( probedata_t *p_data )
+static int decoder_Probe( probedata_t *p_data )
{
return ( p_data->i_type == AC3_AUDIO_ES ) ? 50 : 0;
}
/*****************************************************************************
- * ac3_adec_Run: this function is called just after the thread is created
+ * decoder_Run: this function is called just after the thread is created
*****************************************************************************/
-static int ac3_adec_Run ( decoder_config_t * p_config )
+static int decoder_Run ( decoder_config_t * p_config )
{
ac3dec_thread_t * p_ac3thread;
int sync;
if( p_ac3thread == NULL )
{
- intf_ErrMsg ( "ac3dec error: not enough memory "
- "for ac3_adec_Run() to allocate p_ac3thread" );
- free( p_ac3thread->p_config );
+ intf_ErrMsg ( "ac3_adec error: not enough memory "
+ "for decoder_Run() to allocate p_ac3thread" );
+ DecoderError( p_config->p_decoder_fifo );
return( -1 );
}
* Initialize the thread properties
*/
p_ac3thread->p_config = p_config;
- if( ac3_adec_Init( p_ac3thread ) )
+ if( InitThread( p_ac3thread ) )
{
- intf_ErrMsg( "ac3_adec error : could not initialize thread" );
- free( p_ac3thread->p_config );
+ intf_ErrMsg( "ac3_adec error: could not initialize thread" );
+ DecoderError( p_config->p_decoder_fifo );
free( p_ac3thread );
return( -1 );
}
sync = 1;
}
- if (DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts)
+ if (p_ac3thread->p_fifo->p_first->i_pts)
{
p_ac3thread->p_aout_fifo->date[
p_ac3thread->p_aout_fifo->l_end_frame] =
- DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts;
- DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts = 0;
+ p_ac3thread->p_fifo->p_first->i_pts;
+ p_ac3thread->p_fifo->p_first->i_pts = 0;
} else {
p_ac3thread->p_aout_fifo->date[
p_ac3thread->p_aout_fifo->l_end_frame] =
/* If b_error is set, the ac3 decoder thread enters the error loop */
if (p_ac3thread->p_fifo->b_error)
{
- ac3_adec_ErrorThread (p_ac3thread);
+ DecoderError( p_ac3thread->p_fifo );
}
/* End of the ac3 decoder thread */
- ac3_adec_EndThread (p_ac3thread);
+ EndThread (p_ac3thread);
- free( p_ac3thread->p_config );
free( p_ac3thread );
return( 0 );
/*****************************************************************************
- * ac3_adec_Init: initialize data before entering main loop
+ * InitThread: initialize data before entering main loop
*****************************************************************************/
-static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
+static int InitThread( ac3dec_thread_t * p_ac3thread )
{
/*
* Thread properties
*/
p_ac3thread->p_fifo = p_ac3thread->p_config->p_decoder_fifo;
- p_ac3thread->ac3_decoder = memalign(16, sizeof(ac3dec_t));
+ p_ac3thread->ac3_decoder = memalign( 16, sizeof(ac3dec_t) );
/*
* Choose the best downmix module
*/
#define DOWNMIX p_ac3thread->ac3_decoder->downmix
- DOWNMIX.p_module = module_Need( MODULE_CAPABILITY_DOWNMIX, NULL );
+ DOWNMIX.p_module = module_Need( MODULE_CAPABILITY_DOWNMIX,
+ main_GetPszVariable( DOWNMIX_METHOD_VAR, NULL ),
+ NULL );
if( DOWNMIX.p_module == NULL )
{
p_ac3thread->ac3_decoder->imdct = memalign(16, sizeof(imdct_t));
#define IMDCT p_ac3thread->ac3_decoder->imdct
- IMDCT->p_module = module_Need( MODULE_CAPABILITY_IMDCT, NULL );
+ IMDCT->p_module = module_Need( MODULE_CAPABILITY_IMDCT,
+ main_GetPszVariable( IMDCT_METHOD_VAR, NULL ),
+ NULL );
if( IMDCT->p_module == NULL )
{
intf_DbgMsg ( "ac3_adec debug: ac3_adec thread (%p) initialized",
p_ac3thread );
- /*
- * Bit stream
- */
- p_ac3thread->p_config->pf_init_bit_stream(
- &p_ac3thread->ac3_decoder->bit_stream,
- p_ac3thread->p_config->p_decoder_fifo,
- BitstreamCallback, (void *) p_ac3thread );
-
/* Creating the audio output fifo */
p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 2, 0, 0,
- AC3DEC_FRAME_SIZE, NULL );
+ AC3DEC_FRAME_SIZE, NULL );
if ( p_ac3thread->p_aout_fifo == NULL )
{
free( IMDCT->w_1 );
#else
free( p_ac3thread->ac3_decoder->samples );
#endif
+
+ module_Unneed( p_ac3thread->ac3_decoder->imdct->p_module );
+ module_Unneed( p_ac3thread->ac3_decoder->downmix.p_module );
+
free( p_ac3thread->ac3_decoder->imdct );
free( p_ac3thread->ac3_decoder );
+
return( -1 );
}
+ /*
+ * Bit stream
+ */
+ p_ac3thread->p_config->pf_init_bit_stream(
+ &p_ac3thread->ac3_decoder->bit_stream,
+ p_ac3thread->p_config->p_decoder_fifo,
+ BitstreamCallback, (void *) p_ac3thread );
+
intf_DbgMsg("ac3dec debug: ac3 decoder thread %p initialized", p_ac3thread);
return( 0 );
/*****************************************************************************
- * ac3_adec_ErrorThread : ac3 decoder's RunThread() error loop
- *****************************************************************************/
-static void ac3_adec_ErrorThread (ac3dec_thread_t * p_ac3thread)
-{
- /* We take the lock, because we are going to read/write the start/end
- * indexes of the decoder fifo */
- vlc_mutex_lock (&p_ac3thread->p_fifo->data_lock);
-
- /* Wait until a `die' order is sent */
- while (!p_ac3thread->p_fifo->b_die)
- {
- /* Trash all received PES packets */
- while (!DECODER_FIFO_ISEMPTY(*p_ac3thread->p_fifo))
- {
- p_ac3thread->p_fifo->pf_delete_pes(
- p_ac3thread->p_fifo->p_packets_mgt,
- DECODER_FIFO_START(*p_ac3thread->p_fifo));
- DECODER_FIFO_INCSTART (*p_ac3thread->p_fifo);
- }
-
- /* Waiting for the input thread to put new PES packets in the fifo */
- vlc_cond_wait (&p_ac3thread->p_fifo->data_wait,
- &p_ac3thread->p_fifo->data_lock);
- }
-
- /* We can release the lock before leaving */
- vlc_mutex_unlock (&p_ac3thread->p_fifo->data_lock);
-}
-
-/*****************************************************************************
- * ac3_adec_EndThread : ac3 decoder thread destruction
+ * EndThread : ac3 decoder thread destruction
*****************************************************************************/
-static void ac3_adec_EndThread (ac3dec_thread_t * p_ac3thread)
+static void EndThread (ac3dec_thread_t * p_ac3thread)
{
intf_DbgMsg ("ac3dec debug: destroying ac3 decoder thread %p", p_ac3thread);
vlc_mutex_unlock (&(p_ac3thread->p_aout_fifo->data_lock));
}
- /* Unlock the modules */
- module_Unneed( p_ac3thread->ac3_decoder->downmix.p_module );
- module_Unneed( p_ac3thread->ac3_decoder->imdct->p_module );
-
- /* Destroy descriptor */
+ /* Free allocated structures */
#define IMDCT p_ac3thread->ac3_decoder->imdct
free( IMDCT->w_1 );
free( IMDCT->w_64 );
#else
free( p_ac3thread->ac3_decoder->samples );
#endif
+
+ /* Unlock the modules */
+ module_Unneed( p_ac3thread->ac3_decoder->downmix.p_module );
+ module_Unneed( p_ac3thread->ac3_decoder->imdct->p_module );
+
+ /* Free what's left of the decoder */
free( p_ac3thread->ac3_decoder->imdct );
free( p_ac3thread->ac3_decoder );