* ac3_spdif.c: ac3 pass-through to external decoder with enabled soundcard
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: ac3_spdif.c,v 1.8 2001/12/27 01:49:34 massiot Exp $
+ * $Id: ac3_spdif.c,v 1.12 2002/01/28 23:08:31 stef Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Juha Yrjola <jyrjola@cc.hut.fi>
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#define MODULE_NAME ac3_spdif
-#include "modules_inner.h"
-
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "defs.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* memcpy() */
#include <fcntl.h>
+#include <videolan/vlc.h>
+
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
-#include "common.h"
-#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
-#include "threads.h"
-#include "mtime.h"
-
#include "audio_output.h"
#include "stream_control.h"
#include "ac3_spdif.h"
#include "ac3_iec958.h"
-#include "modules.h"
-#include "modules_export.h"
-
#define FRAME_NB 8
/****************************************************************************
* Local Prototypes
****************************************************************************/
-static int ac3_spdif_Probe ( probedata_t * );
-static int ac3_spdif_Run ( decoder_config_t * );
-static int ac3_spdif_Init ( ac3_spdif_thread_t * );
-static void ac3_spdif_ErrorThread ( ac3_spdif_thread_t * );
-static void ac3_spdif_EndThread ( ac3_spdif_thread_t * );
-static void BitstreamCallback( bit_stream_t *, boolean_t );
+static int decoder_Probe ( probedata_t * );
+static int decoder_Run ( decoder_config_t * );
+static int InitThread ( ac3_spdif_thread_t * );
+static void EndThread ( ac3_spdif_thread_t * );
+static void BitstreamCallback ( bit_stream_t *, boolean_t );
/*****************************************************************************
* Capabilities
*****************************************************************************/
void _M( adec_getfunctions )( function_list_t * p_function_list )
{
- p_function_list->pf_probe = ac3_spdif_Probe;
- p_function_list->functions.dec.pf_run = ac3_spdif_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 spdif 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 SPDIF decoder for AC3 pass-through";
+ SET_DESCRIPTION( "SPDIF pass-through AC3 decoder" )
+ ADD_CAPABILITY( DECODER, 100 )
MODULE_INIT_STOP
MODULE_ACTIVATE_START
MODULE_DEACTIVATE_STOP
/*****************************************************************************
- * ac3_spdif_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_spdif_Probe( probedata_t *p_data )
+static int decoder_Probe( probedata_t *p_data )
{
- if( main_GetIntVariable( AOUT_SPDIF_VAR, 0 ) &&
- p_data->i_type == AC3_AUDIO_ES )
- return( 100 );
- else
- return( 0 );
+ return( ( main_GetIntVariable( AOUT_SPDIF_VAR, 0 )
+ && p_data->i_type == AC3_AUDIO_ES ) ? 100 : 0 );
}
/****************************************************************************
- * ac3_spdif_Run: the whole thing
+ * decoder_Run: the whole thing
****************************************************************************
* This function is called just after the thread is launched.
****************************************************************************/
-static int ac3_spdif_Run( decoder_config_t * p_config )
+static int decoder_Run( decoder_config_t * p_config )
{
ac3_spdif_thread_t * p_spdif;
mtime_t i_frame_time;
{
intf_ErrMsg ( "spdif error: not enough memory "
"for spdif_CreateThread() to create the new thread");
+ DecoderError( p_config->p_decoder_fifo );
return( -1 );
}
p_spdif->p_config = p_config;
- if (ac3_spdif_Init( p_spdif ) )
+ if (InitThread( p_spdif ) )
{
intf_ErrMsg( "spdif error: could not initialize thread" );
+ DecoderError( p_config->p_decoder_fifo );
+ free( p_spdif );
return( -1 );
}
/* If b_error is set, the ac3 spdif thread enters the error loop */
if( p_spdif->p_fifo->b_error )
{
- ac3_spdif_ErrorThread( p_spdif );
+ DecoderError( p_spdif->p_fifo );
}
/* End of the ac3 decoder thread */
- ac3_spdif_EndThread( p_spdif );
+ EndThread( p_spdif );
return( 0 );
}
/****************************************************************************
- * ac3_spdif_Init: initialize thread data and create output fifo
+ * InitThread: initialize thread data and create output fifo
****************************************************************************/
-static int ac3_spdif_Init( ac3_spdif_thread_t * p_spdif )
+static int InitThread( ac3_spdif_thread_t * p_spdif )
{
boolean_t b_sync = 0;
*/
p_spdif->p_fifo = p_spdif->p_config->p_decoder_fifo;
- p_spdif->p_config->pf_init_bit_stream(
- &p_spdif->bit_stream,
- p_spdif->p_config->p_decoder_fifo,
- BitstreamCallback, (void*)p_spdif );
-
- /* Creating the audio output fifo */
- p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_SPDIF_FIFO, 1, 48000, 0,
- SPDIF_FRAME_SIZE, NULL );
-
- if( p_spdif->p_aout_fifo == NULL )
- {
- return( -1 );
- }
-
- intf_WarnMsg( 3, "spdif: aout fifo #%d created",
- p_spdif->p_aout_fifo->i_fifo );
+ InitBitstream( &p_spdif->bit_stream, p_spdif->p_config->p_decoder_fifo,
+ BitstreamCallback, (void*)p_spdif );
/* Sync word */
p_spdif->p_ac3[0] = 0x0b;
* but all rates should be supported by the decoder (32, 44.1, 48) */
if( p_spdif->ac3_info.i_sample_rate != 48000 )
{
- intf_ErrMsg( "spdif error: Only 48000 Hz streams supported");
+ intf_ErrMsg( "spdif error: Only 48000 Hz streams tested"
+ "expect weird things !" );
+ //intf_ErrMsg( "spdif error: Only 48000 Hz streams supported");
- aout_DestroyFifo( p_spdif->p_aout_fifo );
- return -1;
+ //aout_DestroyFifo( p_spdif->p_aout_fifo );
+ //return -1;
+ }
+
+ /* Creating the audio output fifo */
+ p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_SPDIF_FIFO, 1,
+ p_spdif->ac3_info.i_sample_rate,
+ 0, SPDIF_FRAME_SIZE, NULL );
+
+ if( p_spdif->p_aout_fifo == NULL )
+ {
+ return( -1 );
}
- p_spdif->p_aout_fifo->l_rate = p_spdif->ac3_info.i_sample_rate;
+
+ intf_WarnMsg( 3, "spdif: aout fifo #%d created",
+ p_spdif->p_aout_fifo->i_fifo );
GetChunk( &p_spdif->bit_stream, p_spdif->p_ac3 + sizeof(sync_frame_t),
p_spdif->ac3_info.i_frame_size - sizeof(sync_frame_t) );
return( 0 );
}
-
-/*****************************************************************************
- * ac3_spdif_ErrorThread : ac3 spdif's RunThread() error loop
- *****************************************************************************/
-static void ac3_spdif_ErrorThread( ac3_spdif_thread_t * p_spdif )
-{
- /* We take the lock, because we are going to read/write the start/end
- * indexes of the decoder fifo */
- vlc_mutex_lock (&p_spdif->p_fifo->data_lock);
-
- /* Wait until a `die' order is sent */
- while( !p_spdif->p_fifo->b_die )
- {
- /* Trash all received PES packets */
- p_spdif->p_fifo->pf_delete_pes(
- p_spdif->p_fifo->p_packets_mgt,
- p_spdif->p_fifo->p_first );
-
- /* Waiting for the input thread to put new PES packets in the fifo */
- vlc_cond_wait( &p_spdif->p_fifo->data_wait,
- &p_spdif->p_fifo->data_lock );
- }
-
- /* We can release the lock before leaving */
- vlc_mutex_unlock( &p_spdif->p_fifo->data_lock );
-}
-
/*****************************************************************************
- * ac3_spdif_EndThread : ac3 spdif thread destruction
+ * EndThread : ac3 spdif thread destruction
*****************************************************************************/
-static void ac3_spdif_EndThread( ac3_spdif_thread_t * p_spdif )
+static void EndThread( ac3_spdif_thread_t * p_spdif )
{
intf_DbgMsg( "spdif debug: destroying thread %p", p_spdif );