/*****************************************************************************
* aout.c : QNX audio output
*****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
+ * Copyright (C) 2000, 2001 the VideoLAN team
*
* Authors: Henri Fallon <henri@videolan.org>
* Jon Lech Johansen <jon-vl@nanocrew.net>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <errno.h> /* ENOMEM */
-#include <string.h> /* strerror() */
-#include <stdlib.h> /* calloc(), malloc(), free() */
#include <vlc/vlc.h>
# include <alloca.h>
#endif
-#include <vlc/aout.h>
-#include "aout_internal.h"
+#include <vlc_aout.h>
#include <sys/asoundlib.h>
int i_device;
byte_t * p_silent_buffer;
- vlc_bool_t b_initialized;
};
#define DEFAULT_FRAME_SIZE 2048
int E_(OpenAudio) ( vlc_object_t *p_this );
void E_(CloseAudio) ( vlc_object_t *p_this );
static int GetBufInfo ( aout_instance_t * );
-static int SetFormat ( aout_instance_t * );
static void Play ( aout_instance_t * );
static int QNXaoutThread ( aout_instance_t * );
{
aout_instance_t *p_aout = (aout_instance_t *)p_this;
int i_ret;
+ int i_bytes_per_sample;
+ int i_nb_channels;
+ snd_pcm_channel_info_t pi;
+ snd_pcm_channel_params_t pp;
+ aout_instance_t *p_aout = (aout_instance_t *)p_this;
/* allocate structure */
p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );
return -1;
}
- /* Create audio thread and wait for its readiness. */
- p_aout->output.p_sys->b_initialized = VLC_FALSE;
- if( vlc_thread_create( p_aout, "aout", QNXaoutThread, VLC_FALSE ) )
- {
- msg_Err( p_aout, "cannot create QNX audio thread (%s)", strerror(errno) );
- E_(CloseAudio)( p_this );
- free( p_aout->output.p_sys );
- return -1;
- }
-
p_aout->output.p_sys->p_silent_buffer = malloc( DEFAULT_FRAME_SIZE * 4 );
-
- p_aout->output.pf_setformat = SetFormat;
p_aout->output.pf_play = Play;
-
- return( 0 );
-}
-
-/*****************************************************************************
- * SetFormat : set the audio output format
- *****************************************************************************
- * This function prepares the device, sets the rate, format, the mode
- * ("play as soon as you have data"), and buffer information.
- *****************************************************************************/
-static int SetFormat( aout_instance_t *p_this )
-{
- int i_ret;
- int i_bytes_per_sample;
- snd_pcm_channel_info_t pi;
- snd_pcm_channel_params_t pp;
- aout_instance_t *p_aout = (aout_instance_t *)p_this;
-
- p_aout->output.p_sys->b_initialized = VLC_FALSE;
+ aout_VolumeSoftInit( p_aout );
memset( &pi, 0, sizeof(pi) );
memset( &pp, 0, sizeof(pp) );
{
msg_Err( p_aout, "unable to get plugin info (%s)",
snd_strerror( i_ret ) );
+ E_(CloseAudio)( p_this );
+ free( p_aout->output.p_sys );
return -1;
}
pp.format.interleave = 1;
pp.format.rate = p_aout->output.output.i_rate;
- pp.format.voices = p_aout->output.output.i_channels;
- p_aout->output.output.i_format = AOUT_FMT_S16_NE;
- p_aout->output.i_nb_samples = DEFAULT_FRAME_SIZE;
-
- switch( p_aout->output.output.i_format )
+ i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
+ if ( i_nb_channels > 2 )
{
- case AOUT_FMT_S16_LE:
- pp.format.format = SND_PCM_SFMT_S16_LE;
- i_bytes_per_sample = 2;
- break;
-
- default:
- pp.format.format = SND_PCM_SFMT_S16_BE;
- i_bytes_per_sample = 2;
- break;
+ /* I don't know if QNX supports more than two channels. */
+ i_nb_channels = 2;
+ p_aout->output.output.i_channels = AOUT_CHAN_STEREO;
}
+ pp.format.voices = i_nb_channels;
+
+ p_aout->output.output.i_format = AOUT_FMT_S16_NE;
+ p_aout->output.i_nb_samples = DEFAULT_FRAME_SIZE;
+ pp.format.format = SND_PCM_SFMT_S16;
+ i_bytes_per_sample = 2;
pp.buf.block.frag_size = p_aout->output.i_nb_samples *
p_aout->output.output.i_channels *
&pp ) ) < 0 )
{
msg_Err( p_aout, "unable to set parameters (%s)", snd_strerror(i_ret) );
+ E_(CloseAudio)( p_this );
+ free( p_aout->output.p_sys );
return -1;
}
{
msg_Err( p_aout, "unable to prepare channel (%s)",
snd_strerror( i_ret ) );
+ E_(CloseAudio)( p_this );
+ free( p_aout->output.p_sys );
return -1;
}
- p_aout->output.p_sys->b_initialized = VLC_TRUE;
+ /* Create audio thread and wait for its readiness. */
+ if( vlc_thread_create( p_aout, "aout", QNXaoutThread,
+ VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
+ {
+ msg_Err( p_aout, "cannot create QNX audio thread (%m)" );
+ E_(CloseAudio)( p_this );
+ free( p_aout->output.p_sys );
+ return -1;
+ }
return( 0 );
}
aout_instance_t *p_aout = (aout_instance_t *)p_this;
int i_ret;
- p_aout->b_die = 1;
+ vlc_object_kill( p_aout );
vlc_thread_join( p_aout );
if( ( i_ret = snd_pcm_close( p_aout->output.p_sys->p_pcm_handle ) ) < 0 )
int i_tmp, i_size;
byte_t * p_bytes;
- if( !p_sys->b_initialized )
- {
- msleep( THREAD_SLEEP );
- continue;
- }
-
- if ( p_aout->output.output.i_format != AOUT_FMT_SPDIF )
+ if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') )
{
mtime_t next_date = 0;
if( i_tmp < 0 )
{
- msg_Err( p_aout, "write failed (%s)", strerror(errno) );
+ msg_Err( p_aout, "write failed (%m)" );
}
if ( p_buffer != NULL )