Commit 7ba99302 authored by Gildas Bazin's avatar Gildas Bazin

* modules/audio_output/portaudio.c: ported to portaudio v19 by Frederic Ruget...

* modules/audio_output/portaudio.c: ported to portaudio v19 by Frederic Ruget +  mostly rewritten by me.
parent d5237366
/***************************************************************************** /*****************************************************************************
* portaudio.c : portaudio audio output plugin * portaudio.c : portaudio (v19) audio output plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id$ * $Id$
* *
* Authors: Frederic Ruget <frederic.ruget@free.fr> * Authors: Frederic Ruget <frederic.ruget@free.fr>
* Gildas Bazin <gbazin@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -34,21 +35,31 @@ ...@@ -34,21 +35,31 @@
#include "aout_internal.h" #include "aout_internal.h"
#define FRAME_SIZE 1024 /* The size is in samples, not in bytes */ #define FRAME_SIZE 1024 /* The size is in samples, not in bytes */
#define FRAMES_NUM 8
/***************************************************************************** /*****************************************************************************
* aout_sys_t: portaudio audio output method descriptor * aout_sys_t: portaudio audio output method descriptor
*****************************************************************************/ *****************************************************************************/
typedef struct pa_thread_t
{
VLC_COMMON_MEMBERS
aout_instance_t * p_aout;
} pa_thread_t;
struct aout_sys_t struct aout_sys_t
{ {
aout_instance_t *p_aout; aout_instance_t *p_aout;
PortAudioStream *p_stream; PaStream *p_stream;
int i_numDevices;
int i_nbChannels; PaDeviceIndex i_devices;
PaSampleFormat sampleFormat; int i_sample_size;
int i_sampleSize; PaDeviceIndex i_device_id;
PaDeviceID i_deviceId; const PaDeviceInfo *deviceInfo;
PaDeviceInfo deviceInfo;
vlc_mutex_t lock;
vlc_cond_t wait;
pa_thread_t *pa_thread;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -57,7 +68,10 @@ struct aout_sys_t ...@@ -57,7 +68,10 @@ struct aout_sys_t
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static void Play ( aout_instance_t * ); static void Play ( aout_instance_t * );
static int i_once = 0; static void PORTAUDIOThread( pa_thread_t * );
static int PAOpenDevice( aout_instance_t * );
static int PAOpenStream( aout_instance_t * );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -69,36 +83,46 @@ vlc_module_begin(); ...@@ -69,36 +83,46 @@ vlc_module_begin();
set_description( N_("PORTAUDIO audio output") ); set_description( N_("PORTAUDIO audio output") );
add_integer( "portaudio-device", 0, NULL, add_integer( "portaudio-device", 0, NULL,
DEVICE_TEXT, DEVICE_LONGTEXT, VLC_FALSE ); DEVICE_TEXT, DEVICE_LONGTEXT, VLC_FALSE );
set_capability( "audio output", 40 ); set_capability( "audio output", 0 );
set_callbacks( Open, Close ); set_callbacks( Open, Close );
vlc_module_end(); vlc_module_end();
/* This routine will be called by the PortAudio engine when audio is needed. /* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything * It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free(). * that could mess up the system like calling malloc() or free().
*/ */
static int paCallback( void *inputBuffer, void *outputBuffer, static int paCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer, unsigned long framesPerBuffer,
PaTimestamp outTime, void *p_cookie ) const PaStreamCallbackTimeInfo *paDate,
PaStreamCallbackFlags statusFlags,
void *p_cookie )
{ {
struct aout_sys_t* p_sys = (struct aout_sys_t*) p_cookie; struct aout_sys_t *p_sys = (struct aout_sys_t*) p_cookie;
aout_instance_t * p_aout = p_sys->p_aout; aout_instance_t *p_aout = p_sys->p_aout;
aout_buffer_t * p_buffer; aout_buffer_t *p_buffer;
mtime_t out_date;
vlc_mutex_lock( &p_aout->output_fifo_lock ); out_date = mdate() + (mtime_t) ( 1000000 *
p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); ( paDate->outputBufferDacTime - paDate->currentTime ) );
vlc_mutex_unlock( &p_aout->output_fifo_lock ); p_buffer = aout_OutputNextBuffer( p_aout, out_date, VLC_TRUE );
if ( p_buffer != NULL ) if ( p_buffer != NULL )
{ {
p_aout->p_vlc->pf_memcpy( outputBuffer, p_buffer->p_buffer, p_aout->p_vlc->pf_memcpy( outputBuffer, p_buffer->p_buffer,
framesPerBuffer * p_sys->i_sampleSize ); framesPerBuffer * p_sys->i_sample_size );
/* aout_BufferFree may be dangereous here, but then so is
* aout_OutputNextBuffer (calls aout_BufferFree internally).
* one solution would be to link the no longer useful buffers
* in a second fifo (in aout_OutputNextBuffer too) and to
* wait until we are in Play to do the actual free.
*/
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
} }
else else
/* Audio output buffer shortage -> stop the fill process and wait */
{ {
p_aout->p_vlc->pf_memset( outputBuffer, 0, p_aout->p_vlc->pf_memset( outputBuffer, 0,
framesPerBuffer * p_sys->i_sampleSize ); framesPerBuffer * p_sys->i_sample_size );
} }
return 0; return 0;
} }
...@@ -106,270 +130,360 @@ static int paCallback( void *inputBuffer, void *outputBuffer, ...@@ -106,270 +130,360 @@ static int paCallback( void *inputBuffer, void *outputBuffer,
/***************************************************************************** /*****************************************************************************
* Open: open the audio device * Open: open the audio device
*****************************************************************************/ *****************************************************************************/
static int Open ( vlc_object_t * p_this ) static int Open( vlc_object_t * p_this )
{ {
aout_instance_t *p_aout = (aout_instance_t *)p_this; aout_instance_t *p_aout = (aout_instance_t *)p_this;
struct aout_sys_t * p_sys; struct aout_sys_t * p_sys;
PortAudioStream *p_stream;
vlc_value_t val; vlc_value_t val;
PaError i_err; int i_err;
int i_nb_channels;
const PaDeviceInfo *p_pdi;
int i, j;
msg_Dbg( p_aout, "Entering Open()"); msg_Dbg( p_aout, "Entering Open()");
/* Allocate p_sys structure */ /* Allocate p_sys structure */
p_sys = (struct aout_sys_t*) malloc( sizeof( aout_sys_t ) ); p_sys = (aout_sys_t *)malloc( sizeof(aout_sys_t) );
if( p_sys == NULL ) if( p_sys == NULL )
{ {
msg_Err( p_aout, "out of memory" ); msg_Err( p_aout, "out of memory" );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
p_sys->p_aout = p_aout; p_sys->p_aout = p_aout;
p_sys->p_stream = 0;
p_aout->output.p_sys = p_sys; p_aout->output.p_sys = p_sys;
p_aout->output.pf_play = Play;
/* Output device id */ /* Retrieve output device id from config */
var_Create( p_this, "portaudio-device", var_Create( p_aout, "portaudio-device", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); var_Get( p_aout, "portaudio-device", &val );
var_Get( p_this, "portaudio-device", &val ); p_sys->i_device_id = val.i_int;
p_sys->i_deviceId = val.i_int;
if (! i_once) if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
{ {
i_once = 1; msg_Err( p_aout, "cannot open portaudio device" );
i_err = Pa_Initialize(); free( p_sys );
if ( i_err != paNoError ) return VLC_EGENERIC;
{ }
msg_Err( p_aout, "Pa_Initialize returned %d : %s", i_err, Pa_GetErrorText( i_err ));
return VLC_EGENERIC; /* Close device for now. We'll re-open it later on */
} if( ( i_err = Pa_Terminate() ) != paNoError )
{
msg_Err( p_aout, "Pa_Terminate returned %d", i_err );
} }
p_sys->i_numDevices = Pa_CountDevices();
if( p_sys->i_numDevices < 0 ) /* Now we need to setup our DirectSound play notification structure */
p_sys->pa_thread = vlc_object_create( p_aout, sizeof(pa_thread_t) );
p_sys->pa_thread->p_aout = p_aout;
vlc_mutex_init( p_aout, &p_sys->lock );
vlc_cond_init( p_aout, &p_sys->wait );
/* Create PORTAUDIOThread */
if( vlc_thread_create( p_sys->pa_thread, "aout", PORTAUDIOThread,
VLC_THREAD_PRIORITY_OUTPUT, VLC_TRUE ) )
{ {
i_err = p_sys->i_numDevices; msg_Err( p_aout, "cannot create PORTAUDIO thread" );
msg_Err( p_aout, "Pa_CountDevices returned %d : %s", i_err, Pa_GetErrorText( i_err ));
(void) Pa_Terminate();
return VLC_EGENERIC; return VLC_EGENERIC;
} }
msg_Info( p_aout, "Number of devices = %d", p_sys->i_numDevices );
if ( p_sys->i_deviceId >= p_sys->i_numDevices ) if( p_sys->pa_thread->b_error )
{ {
msg_Err( p_aout, "Device %d does not exist", p_sys->i_deviceId ); msg_Err( p_aout, "PORTAUDIO thread failed" );
(void) Pa_Terminate(); Close( p_this );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
for( i = 0; i < p_sys->i_numDevices; i++ )
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: close the audio device
*****************************************************************************/
static void Close ( vlc_object_t *p_this )
{
aout_instance_t *p_aout = (aout_instance_t *)p_this;
aout_sys_t *p_sys = p_aout->output.p_sys;
msg_Dbg( p_aout, "closing portaudio");
vlc_mutex_lock( &p_sys->lock );
p_sys->pa_thread->b_die = VLC_TRUE;
vlc_cond_signal( &p_sys->wait );
vlc_mutex_unlock( &p_sys->lock );
vlc_thread_join( p_sys->pa_thread );
vlc_cond_destroy( &p_sys->wait );
vlc_mutex_destroy( &p_sys->lock );
msg_Dbg( p_aout, "portaudio closed");
free( p_sys );
}
/*****************************************************************************
* Play: play sound
*****************************************************************************/
static void Play( aout_instance_t * p_aout )
{
}
/*****************************************************************************
* PORTAUDIOThread: all interactions with libportaudio.a are handled
* in this single thread. Otherwise libportaudio.a is _not_ happy :-(
*****************************************************************************/
static void PORTAUDIOThread( pa_thread_t *pa_thread )
{
aout_instance_t *p_aout = pa_thread->p_aout;
aout_sys_t *p_sys = p_aout->output.p_sys;
int i_err;
if( PAOpenDevice( p_aout ) != VLC_SUCCESS )
{ {
p_pdi = Pa_GetDeviceInfo( i ); msg_Err( p_aout, "cannot open portaudio device" );
if ( i == p_sys->i_deviceId ) pa_thread->b_error = VLC_TRUE;
{ vlc_thread_ready( pa_thread );
p_sys->deviceInfo = *p_pdi; return;
} }
msg_Info( p_aout, "---------------------------------------------- #%d", i );
msg_Info( p_aout, "Name = %s", p_pdi->name ); if( PAOpenStream( p_aout ) != VLC_SUCCESS )
msg_Info( p_aout, "Max Inputs = %d, Max Outputs = %d", {
p_pdi->maxInputChannels, p_pdi->maxOutputChannels ); msg_Err( p_aout, "cannot open portaudio device" );
if( p_pdi->numSampleRates == -1 ) pa_thread->b_error = VLC_TRUE;
{ vlc_thread_ready( pa_thread );
msg_Info( p_aout, "Sample Rate Range = %f to %f", p_pdi->sampleRates[0], p_pdi->sampleRates[1] ); goto end;
}
else
{
msg_Info( p_aout, "Sample Rates =");
for( j = 0; j < p_pdi->numSampleRates; j++ )
{
msg_Info( p_aout, " %8.2f,", p_pdi->sampleRates[j] );
}
}
msg_Info( p_aout, "Native Sample Formats = ");
if( p_pdi->nativeSampleFormats & paInt8 ) msg_Info( p_aout, "paInt8");
if( p_pdi->nativeSampleFormats & paUInt8 ) msg_Info( p_aout, "paUInt8");
if( p_pdi->nativeSampleFormats & paInt16 ) msg_Info( p_aout, "paInt16");
if( p_pdi->nativeSampleFormats & paInt32 ) msg_Info( p_aout, "paInt32");
if( p_pdi->nativeSampleFormats & paFloat32 ) msg_Info( p_aout, "paFloat32");
if( p_pdi->nativeSampleFormats & paInt24 ) msg_Info( p_aout, "paInt24");
if( p_pdi->nativeSampleFormats & paPackedInt24 ) msg_Info( p_aout, "paPackedInt24");
} }
msg_Info( p_aout, "----------------------------------------------"); /* Tell the main thread that we are ready */
vlc_thread_ready( pa_thread );
/*
portaudio warning: Number of devices = 3
portaudio warning: ---------------------------------------------- #0 DefaultInput DefaultOutput
portaudio warning: Name = PORTAUDIO DirectX Full Duplex Driver
portaudio warning: Max Inputs = 2, Max Outputs = 2
portaudio warning: Sample Rates =
portaudio warning: 11025.00,
portaudio warning: 22050.00,
portaudio warning: 32000.00,
portaudio warning: 44100.00,
portaudio warning: 48000.00,
portaudio warning: 88200.00,
portaudio warning: 96000.00,
portaudio warning: Native Sample Formats =
portaudio warning: paInt16
portaudio warning: ---------------------------------------------- #1
portaudio warning: Name = PORTAUDIO Multimedia Driver
portaudio warning: Max Inputs = 2, Max Outputs = 2
portaudio warning: Sample Rates =
portaudio warning: 11025.00,
portaudio warning: 22050.00,
portaudio warning: 32000.00,
portaudio warning: 44100.00,
portaudio warning: 48000.00,
portaudio warning: 88200.00,
portaudio warning: 96000.00,
portaudio warning: Native Sample Formats =
portaudio warning: paInt16
portaudio warning: ---------------------------------------------- #2
portaudio warning: Name = E-MU PORTAUDIO
portaudio warning: Max Inputs = 0, Max Outputs = 4
portaudio warning: Sample Rates =
portaudio warning: 44100.00,
portaudio warning: 48000.00,
portaudio warning: 96000.00,
portaudio warning: Native Sample Formats =
portaudio warning: paInt16
portaudio warning: ----------------------------------------------
*/
p_aout->output.pf_play = Play; vlc_mutex_lock( &p_sys->lock );
aout_VolumeSoftInit( p_aout ); if( !pa_thread->b_die ) vlc_cond_wait( &p_sys->wait, &p_sys->lock );
vlc_mutex_unlock( &p_sys->lock );
/* select audio format */ i_err = Pa_StopStream( p_sys->p_stream );
if( p_sys->deviceInfo.nativeSampleFormats & paFloat32 ) if( i_err != paNoError )
{ {
p_sys->sampleFormat = paFloat32; msg_Err( p_aout, "Pa_StopStream: %d (%s)", i_err,
p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2'); Pa_GetErrorText( i_err ) );
p_sys->i_sampleSize = 4;
} }
else if( p_sys->deviceInfo.nativeSampleFormats & paInt16 ) i_err = Pa_CloseStream( p_sys->p_stream );
if( i_err != paNoError )
{ {
p_sys->sampleFormat = paInt16; msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err,
p_aout->output.output.i_format = AOUT_FMT_S16_NE; Pa_GetErrorText( i_err ) );
p_sys->i_sampleSize = 2;
} }
else
end:
i_err = Pa_Terminate();
if( i_err != paNoError )
{ {
msg_Err( p_aout, "Audio format not supported" ); msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err,
(void) Pa_Terminate(); Pa_GetErrorText( i_err ) );
}
}
static int PAOpenDevice( aout_instance_t *p_aout )
{
aout_sys_t *p_sys = p_aout->output.p_sys;
const PaDeviceInfo *p_pdi;
PaError i_err;
vlc_value_t val, text;
int i;
/* Initialize portaudio */
i_err = Pa_Initialize();
if( i_err != paNoError )
{
msg_Err( p_aout, "Pa_Initialize returned %d : %s",
i_err, Pa_GetErrorText( i_err ) );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
i_nb_channels = aout_FormatNbChannels( &p_aout->output.output ); p_sys->i_devices = Pa_GetDeviceCount();
msg_Info( p_aout, "nb_channels = %d", i_nb_channels ); if( p_sys->i_devices < 0 )
if ( i_nb_channels > p_sys->deviceInfo.maxOutputChannels ) {
i_err = p_sys->i_devices;
msg_Err( p_aout, "Pa_GetDeviceCount returned %d : %s", i_err,
Pa_GetErrorText( i_err ) );
goto error;
}
/* Display all devices info */
msg_Dbg( p_aout, "number of devices = %d", p_sys->i_devices );
for( i = 0; i < p_sys->i_devices; i++ )
{
p_pdi = Pa_GetDeviceInfo( i );
msg_Dbg( p_aout, "------------------------------------- #%d", i );
msg_Dbg( p_aout, "Name = %s", p_pdi->name );
msg_Dbg( p_aout, "Max Inputs = %d, Max Outputs = %d",
p_pdi->maxInputChannels, p_pdi->maxOutputChannels );
}
msg_Dbg( p_aout, "-------------------------------------" );
msg_Dbg( p_aout, "requested device is #%d", p_sys->i_device_id );
if( p_sys->i_device_id >= p_sys->i_devices )
{
msg_Err( p_aout, "device %d does not exist", p_sys->i_device_id );
goto error;
}
p_sys->deviceInfo = Pa_GetDeviceInfo( p_sys->i_device_id );
if( p_sys->deviceInfo->maxOutputChannels < 1 )
{ {
if ( p_sys->deviceInfo.maxOutputChannels < 1 ) msg_Err( p_aout, "no channel available" );
goto error;
}
if( var_Type( p_aout, "audio-device" ) == 0 )
{
var_Create( p_aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE);
text.psz_string = _("Audio Device");
var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL );
if( p_sys->deviceInfo->maxOutputChannels >= 1 )
{ {
msg_Err( p_aout, "No channel available" ); val.i_int = AOUT_VAR_MONO;
(void) Pa_Terminate(); text.psz_string = N_("Mono");
return VLC_EGENERIC; var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
&val, &text );
msg_Dbg( p_aout, "device supports 1 channel" );
} }
else if ( p_sys->deviceInfo.maxOutputChannels < 2 ) if( p_sys->deviceInfo->maxOutputChannels >= 2 )
{ {
p_sys->i_nbChannels = 1; val.i_int = AOUT_VAR_STEREO;
p_aout->output.output.i_physical_channels text.psz_string = N_("Stereo");
= AOUT_CHAN_CENTER; var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
&val, &text );
var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT,
&val, NULL );
msg_Dbg( p_aout, "device supports 2 channels" );
} }
else if ( p_sys->deviceInfo.maxOutputChannels < 4 ) if( p_sys->deviceInfo->maxOutputChannels >= 4 )
{ {
p_sys->i_nbChannels = 2; val.i_int = AOUT_VAR_2F2R;
p_aout->output.output.i_physical_channels text.psz_string = N_("2 Front 2 Rear");
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
&val, &text );
msg_Dbg( p_aout, "device supports 4 channels" );
} }
else if ( p_sys->deviceInfo.maxOutputChannels < 6 ) if( p_sys->deviceInfo->maxOutputChannels >= 5 )
{ {
p_sys->i_nbChannels = 4; val.i_int = AOUT_VAR_3F2R;
p_aout->output.output.i_physical_channels text.psz_string = N_("3 Front 2 Rear");
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT var_Change( p_aout, "audio-device",
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; VLC_VAR_ADDCHOICE, &val, &text );
msg_Dbg( p_aout, "device supports 5 channels" );
} }
else if( p_sys->deviceInfo->maxOutputChannels >= 6 )
{ {
p_sys->i_nbChannels = 6; val.i_int = AOUT_VAR_5_1;
p_aout->output.output.i_physical_channels text.psz_string = N_("5.1");
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE,
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT &val, &text );
| AOUT_CHAN_LFE; msg_Dbg( p_aout, "device supports 5.1 channels" );
} }
}
p_sys->i_sampleSize *= p_sys->i_nbChannels;
/* Open portaudio stream */ var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL );
p_aout->output.i_nb_samples = FRAME_SIZE;
msg_Info( p_aout, "rate = %d", p_aout->output.output.i_rate );
msg_Info( p_aout, "samples = %d", p_aout->output.i_nb_samples );
i_err = Pa_OpenStream(
&p_stream,
paNoDevice, 0, 0, 0, /* no input device */
p_sys->i_deviceId, /* output device */
p_sys->i_nbChannels,
p_sys->sampleFormat,
NULL,
(double) p_aout->output.output.i_rate,
(unsigned long) p_aout->output.i_nb_samples, /* FRAMES_PER_BUFFER */
FRAMES_NUM, /* number of buffers, if zero then use default minimum */
paClipOff, /* we won't output out of range samples so don't bother clipping them */
paCallback, p_sys );
if( i_err != paNoError )
{
msg_Err( p_aout, "Pa_OpenStream returns %d : %s", i_err,
Pa_GetErrorText( i_err ) );
(void) Pa_Terminate();
return VLC_EGENERIC;
}
p_sys->p_stream = p_stream; val.b_bool = VLC_TRUE;
i_err = Pa_StartStream( p_stream ); var_Set( p_aout, "intf-change", val );
if( i_err != paNoError )
{
(void) Pa_CloseStream( p_stream);
(void) Pa_Terminate();
return VLC_EGENERIC;
} }
msg_Dbg( p_aout, "Leaving Open()" ); /* Audio format is paFloat32 (always supported by portaudio v19) */
p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
return VLC_SUCCESS; return VLC_SUCCESS;
error:
if( ( i_err = Pa_Terminate() ) != paNoError )
{
msg_Err( p_aout, "Pa_Terminate returned %d", i_err );
}
return VLC_EGENERIC;
} }
/***************************************************************************** static int PAOpenStream( aout_instance_t *p_aout )
* Close: close the audio device
*****************************************************************************/
static void Close ( vlc_object_t *p_this )
{ {
aout_instance_t *p_aout = (aout_instance_t *)p_this; aout_sys_t *p_sys = p_aout->output.p_sys;
struct aout_sys_t * p_sys = p_aout->output.p_sys; const PaHostErrorInfo* paLastHostErrorInfo = Pa_GetLastHostErrorInfo();
PortAudioStream *p_stream = p_sys->p_stream; PaStreamParameters paStreamParameters;
PaError i_err; vlc_value_t val;
int i_channels, i_err;
msg_Dbg( p_aout, "Entering Close()"); if( var_Get( p_aout, "audio-device", &val ) < 0 )
{
return VLC_EGENERIC;
}
i_err = Pa_AbortStream( p_stream ); if( val.i_int == AOUT_VAR_5_1 )
if ( i_err != paNoError ) {
p_aout->output.output.i_physical_channels
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
| AOUT_CHAN_LFE;
}
else if( val.i_int == AOUT_VAR_3F2R )
{ {
msg_Err( p_aout, "Pa_AbortStream: %d (%s)", i_err, Pa_GetErrorText( i_err ) ); p_aout->output.output.i_physical_channels
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
} }
i_err = Pa_CloseStream( p_stream ); else if( val.i_int == AOUT_VAR_2F2R )
if ( i_err != paNoError )
{ {
msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err, Pa_GetErrorText( i_err ) ); p_aout->output.output.i_physical_channels
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
} }
i_err = Pa_Terminate(); else if( val.i_int == AOUT_VAR_MONO )
if ( i_err != paNoError )
{ {
msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err, Pa_GetErrorText( i_err ) ); p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
}
else
{
p_aout->output.output.i_physical_channels
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
} }
msg_Dbg( p_aout, "Leaving Close()");
}
/***************************************************************************** i_channels = aout_FormatNbChannels( &p_aout->output.output );
* Play: play sound msg_Dbg( p_aout, "nb_channels requested = %d", i_channels );
*****************************************************************************/
static void Play( aout_instance_t * p_aout ) /* Calculate the frame size in bytes */
{ p_sys->i_sample_size = 4 * i_channels;
p_aout->output.i_nb_samples = FRAME_SIZE;
aout_FormatPrepare( &p_aout->output.output );
aout_VolumeSoftInit( p_aout );
paStreamParameters.device = p_sys->i_device_id;
paStreamParameters.channelCount = i_channels;
paStreamParameters.sampleFormat = paFloat32;
paStreamParameters.suggestedLatency =
p_sys->deviceInfo->defaultLowOutputLatency;
paStreamParameters.hostApiSpecificStreamInfo = NULL;
i_err = Pa_OpenStream( &p_sys->p_stream, NULL /* no input */,
&paStreamParameters, (double)p_aout->output.output.i_rate,
FRAME_SIZE, paClipOff, paCallback, p_sys );
if( i_err != paNoError )
{
msg_Err( p_aout, "Pa_OpenStream returns %d : %s", i_err,
Pa_GetErrorText( i_err ) );
if( i_err == paUnanticipatedHostError )
{
msg_Err( p_aout, "type %d code %ld : %s",
paLastHostErrorInfo->hostApiType,
paLastHostErrorInfo->errorCode,
paLastHostErrorInfo->errorText );
}
p_sys->p_stream = 0;
return VLC_EGENERIC;
}
i_err = Pa_StartStream( p_sys->p_stream );
if( i_err != paNoError )
{
msg_Err( p_aout, "Pa_StartStream() failed" );
Pa_CloseStream( p_sys->p_stream );
return VLC_EGENERIC;
}
return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment