| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
#ifdef HAVE_CONFIG_H |
|---|
| 30 |
# include "config.h" |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
#include <vlc_common.h> |
|---|
| 34 |
#include <vlc_plugin.h> |
|---|
| 35 |
#include <vlc_aout.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
#include <portaudio.h> |
|---|
| 39 |
|
|---|
| 40 |
#define FRAME_SIZE 1024 |
|---|
| 41 |
|
|---|
| 42 |
#ifdef WIN32 |
|---|
| 43 |
# define PORTAUDIO_IS_SERIOUSLY_BROKEN 1 |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
typedef struct pa_thread_t |
|---|
| 50 |
{ |
|---|
| 51 |
VLC_COMMON_MEMBERS |
|---|
| 52 |
aout_instance_t *p_aout; |
|---|
| 53 |
|
|---|
| 54 |
vlc_cond_t wait; |
|---|
| 55 |
vlc_mutex_t lock_wait; |
|---|
| 56 |
bool b_wait; |
|---|
| 57 |
vlc_cond_t signal; |
|---|
| 58 |
vlc_mutex_t lock_signal; |
|---|
| 59 |
bool b_signal; |
|---|
| 60 |
|
|---|
| 61 |
} pa_thread_t; |
|---|
| 62 |
|
|---|
| 63 |
struct aout_sys_t |
|---|
| 64 |
{ |
|---|
| 65 |
aout_instance_t *p_aout; |
|---|
| 66 |
PaStream *p_stream; |
|---|
| 67 |
|
|---|
| 68 |
PaDeviceIndex i_devices; |
|---|
| 69 |
int i_sample_size; |
|---|
| 70 |
PaDeviceIndex i_device_id; |
|---|
| 71 |
const PaDeviceInfo *deviceInfo; |
|---|
| 72 |
|
|---|
| 73 |
bool b_chan_reorder; |
|---|
| 74 |
int pi_chan_table[AOUT_CHAN_MAX]; |
|---|
| 75 |
uint32_t i_channel_mask; |
|---|
| 76 |
uint32_t i_bits_per_sample; |
|---|
| 77 |
uint32_t i_channels; |
|---|
| 78 |
}; |
|---|
| 79 |
|
|---|
| 80 |
static const uint32_t pi_channels_out[] = |
|---|
| 81 |
{ AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, |
|---|
| 82 |
AOUT_CHAN_CENTER, AOUT_CHAN_LFE, |
|---|
| 83 |
AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER, |
|---|
| 84 |
AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, 0 }; |
|---|
| 85 |
|
|---|
| 86 |
#ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN |
|---|
| 87 |
static bool b_init = 0; |
|---|
| 88 |
static pa_thread_t *pa_thread; |
|---|
| 89 |
static void* PORTAUDIOThread( vlc_object_t * ); |
|---|
| 90 |
#endif |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
static int Open ( vlc_object_t * ); |
|---|
| 96 |
static void Close ( vlc_object_t * ); |
|---|
| 97 |
static void Play ( aout_instance_t * ); |
|---|
| 98 |
|
|---|
| 99 |
static int PAOpenDevice( aout_instance_t * ); |
|---|
| 100 |
static int PAOpenStream( aout_instance_t * ); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
#define DEVICE_TEXT N_("Output device") |
|---|
| 106 |
#define DEVICE_LONGTEXT N_("Portaudio identifier for the output device") |
|---|
| 107 |
|
|---|
| 108 |
vlc_module_begin(); |
|---|
| 109 |
set_shortname( "PortAudio" ); |
|---|
| 110 |
set_description( N_("PORTAUDIO audio output") ); |
|---|
| 111 |
set_category( CAT_AUDIO ); |
|---|
| 112 |
set_subcategory( SUBCAT_AUDIO_AOUT ); |
|---|
| 113 |
add_integer( "portaudio-audio-device", 0, NULL, |
|---|
| 114 |
DEVICE_TEXT, DEVICE_LONGTEXT, false ); |
|---|
| 115 |
add_deprecated_alias( "portaudio-device" ); |
|---|
| 116 |
set_capability( "audio output", 0 ); |
|---|
| 117 |
set_callbacks( Open, Close ); |
|---|
| 118 |
vlc_module_end(); |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
static int paCallback( const void *inputBuffer, void *outputBuffer, |
|---|
| 125 |
unsigned long framesPerBuffer, |
|---|
| 126 |
const PaStreamCallbackTimeInfo *paDate, |
|---|
| 127 |
PaStreamCallbackFlags statusFlags, void *p_cookie ) |
|---|
| 128 |
{ |
|---|
| 129 |
struct aout_sys_t *p_sys = (struct aout_sys_t*) p_cookie; |
|---|
| 130 |
aout_instance_t *p_aout = p_sys->p_aout; |
|---|
| 131 |
aout_buffer_t *p_buffer; |
|---|
| 132 |
mtime_t out_date; |
|---|
| 133 |
|
|---|
| 134 |
out_date = mdate() + (mtime_t) ( 1000000 * |
|---|
| 135 |
( paDate->outputBufferDacTime - paDate->currentTime ) ); |
|---|
| 136 |
p_buffer = aout_OutputNextBuffer( p_aout, out_date, true ); |
|---|
| 137 |
|
|---|
| 138 |
if ( p_buffer != NULL ) |
|---|
| 139 |
{ |
|---|
| 140 |
if( p_sys->b_chan_reorder ) |
|---|
| 141 |
{ |
|---|
| 142 |
|
|---|
| 143 |
aout_ChannelReorder( p_buffer->p_buffer, p_buffer->i_nb_bytes, |
|---|
| 144 |
p_sys->i_channels, p_sys->pi_chan_table, |
|---|
| 145 |
p_sys->i_bits_per_sample ); |
|---|
| 146 |
} |
|---|
| 147 |
vlc_memcpy( outputBuffer, p_buffer->p_buffer, |
|---|
| 148 |
framesPerBuffer * p_sys->i_sample_size ); |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
aout_BufferFree( p_buffer ); |
|---|
| 156 |
} |
|---|
| 157 |
else |
|---|
| 158 |
|
|---|
| 159 |
{ |
|---|
| 160 |
vlc_memset( outputBuffer, 0, framesPerBuffer * p_sys->i_sample_size ); |
|---|
| 161 |
} |
|---|
| 162 |
return 0; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
static int Open( vlc_object_t * p_this ) |
|---|
| 169 |
{ |
|---|
| 170 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 171 |
struct aout_sys_t * p_sys; |
|---|
| 172 |
vlc_value_t val; |
|---|
| 173 |
int i_err; |
|---|
| 174 |
|
|---|
| 175 |
msg_Dbg( p_aout, "entering Open()"); |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
p_sys = (aout_sys_t *)malloc( sizeof(aout_sys_t) ); |
|---|
| 179 |
if( p_sys == NULL ) |
|---|
| 180 |
return VLC_ENOMEM; |
|---|
| 181 |
p_sys->p_aout = p_aout; |
|---|
| 182 |
p_sys->p_stream = 0; |
|---|
| 183 |
p_aout->output.p_sys = p_sys; |
|---|
| 184 |
p_aout->output.pf_play = Play; |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
var_Create( p_aout, "portaudio-audio-device", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT); |
|---|
| 188 |
var_Get( p_aout, "portaudio-audio-device", &val ); |
|---|
| 189 |
p_sys->i_device_id = val.i_int; |
|---|
| 190 |
|
|---|
| 191 |
#ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN |
|---|
| 192 |
if( !b_init ) |
|---|
| 193 |
{ |
|---|
| 194 |
|
|---|
| 195 |
if( PAOpenDevice( p_aout ) != VLC_SUCCESS ) |
|---|
| 196 |
{ |
|---|
| 197 |
msg_Err( p_aout, "cannot open portaudio device" ); |
|---|
| 198 |
free( p_sys ); |
|---|
| 199 |
return VLC_EGENERIC; |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
if( ( i_err = Pa_Terminate() ) != paNoError ) |
|---|
| 204 |
{ |
|---|
| 205 |
msg_Err( p_aout, "closing the device returned %d", i_err ); |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
b_init = true; |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
pa_thread = vlc_object_create( p_aout, sizeof(pa_thread_t) ); |
|---|
| 212 |
pa_thread->p_aout = p_aout; |
|---|
| 213 |
pa_thread->b_error = false; |
|---|
| 214 |
vlc_mutex_init( &pa_thread->lock_wait ); |
|---|
| 215 |
vlc_cond_init( &pa_thread->wait ); |
|---|
| 216 |
pa_thread->b_wait = false; |
|---|
| 217 |
vlc_mutex_init( &pa_thread->lock_signal ); |
|---|
| 218 |
vlc_cond_init( &pa_thread->signal ); |
|---|
| 219 |
pa_thread->b_signal = false; |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
if( vlc_thread_create( pa_thread, "aout", PORTAUDIOThread, |
|---|
| 223 |
VLC_THREAD_PRIORITY_OUTPUT, false ) ) |
|---|
| 224 |
{ |
|---|
| 225 |
msg_Err( p_aout, "cannot create PORTAUDIO thread" ); |
|---|
| 226 |
return VLC_EGENERIC; |
|---|
| 227 |
} |
|---|
| 228 |
} |
|---|
| 229 |
else |
|---|
| 230 |
{ |
|---|
| 231 |
pa_thread->p_aout = p_aout; |
|---|
| 232 |
pa_thread->b_wait = false; |
|---|
| 233 |
pa_thread->b_signal = false; |
|---|
| 234 |
pa_thread->b_error = false; |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
vlc_mutex_lock( &pa_thread->lock_signal ); |
|---|
| 239 |
pa_thread->b_signal = true; |
|---|
| 240 |
vlc_cond_signal( &pa_thread->signal ); |
|---|
| 241 |
vlc_mutex_unlock( &pa_thread->lock_signal ); |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
vlc_mutex_lock( &pa_thread->lock_wait ); |
|---|
| 245 |
if( !pa_thread->b_wait ) |
|---|
| 246 |
vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait ); |
|---|
| 247 |
vlc_mutex_unlock( &pa_thread->lock_wait ); |
|---|
| 248 |
pa_thread->b_wait = false; |
|---|
| 249 |
|
|---|
| 250 |
if( pa_thread->b_error ) |
|---|
| 251 |
{ |
|---|
| 252 |
msg_Err( p_aout, "PORTAUDIO thread failed" ); |
|---|
| 253 |
Close( p_this ); |
|---|
| 254 |
return VLC_EGENERIC; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
return VLC_SUCCESS; |
|---|
| 258 |
|
|---|
| 259 |
#else |
|---|
| 260 |
|
|---|
| 261 |
if( PAOpenDevice( p_aout ) != VLC_SUCCESS ) |
|---|
| 262 |
{ |
|---|
| 263 |
msg_Err( p_aout, "cannot open portaudio device" ); |
|---|
| 264 |
free( p_sys ); |
|---|
| 265 |
return VLC_EGENERIC; |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
if( PAOpenStream( p_aout ) != VLC_SUCCESS ) |
|---|
| 269 |
{ |
|---|
| 270 |
msg_Err( p_aout, "cannot open portaudio device" ); |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
return VLC_SUCCESS; |
|---|
| 274 |
|
|---|
| 275 |
#endif |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
static void Close ( vlc_object_t *p_this ) |
|---|
| 282 |
{ |
|---|
| 283 |
aout_instance_t *p_aout = (aout_instance_t *)p_this; |
|---|
| 284 |
aout_sys_t *p_sys = p_aout->output.p_sys; |
|---|
| 285 |
int i_err; |
|---|
| 286 |
|
|---|
| 287 |
msg_Dbg( p_aout, "closing portaudio"); |
|---|
| 288 |
|
|---|
| 289 |
#ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
vlc_mutex_lock( &pa_thread->lock_signal ); |
|---|
| 293 |
pa_thread->b_signal = true; |
|---|
| 294 |
vlc_cond_signal( &pa_thread->signal ); |
|---|
| 295 |
vlc_mutex_unlock( &pa_thread->lock_signal ); |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
vlc_mutex_lock( &pa_thread->lock_wait ); |
|---|
| 299 |
if( !pa_thread->b_wait ) |
|---|
| 300 |
vlc_cond_wait( &pa_thread->wait, &pa_thread->lock_wait ); |
|---|
| 301 |
vlc_mutex_unlock( &pa_thread->lock_wait ); |
|---|
| 302 |
pa_thread->b_wait = false; |
|---|
| 303 |
|
|---|
| 304 |
#else |
|---|
| 305 |
|
|---|
| 306 |
i_err = Pa_StopStream( p_sys->p_stream ); |
|---|
| 307 |
if( i_err != paNoError ) |
|---|
| 308 |
{ |
|---|
| 309 |
msg_Err( p_aout, "Pa_StopStream: %d (%s)", i_err, |
|---|
| 310 |
Pa_GetErrorText( i_err ) ); |
|---|
| 311 |
} |
|---|
| 312 |
i_err = Pa_CloseStream( p_sys->p_stream ); |
|---|
| 313 |
if( i_err != paNoError ) |
|---|
| 314 |
{ |
|---|
| 315 |
msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err, |
|---|
| 316 |
Pa_GetErrorText( i_err ) ); |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
i_err = Pa_Terminate(); |
|---|
| 320 |
if( i_err != paNoError ) |
|---|
| 321 |
{ |
|---|
| 322 |
msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err, |
|---|
| 323 |
Pa_GetErrorText( i_err ) ); |
|---|
| 324 |
} |
|---|
| 325 |
|
|---|
| 326 |
#endif |
|---|
| 327 |
|
|---|
| 328 |
msg_Dbg( p_aout, "portaudio closed"); |
|---|
| 329 |
free( p_sys ); |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
static int PAOpenDevice( aout_instance_t *p_aout ) |
|---|
| 333 |
{ |
|---|
| 334 |
aout_sys_t *p_sys = p_aout->output.p_sys; |
|---|
| 335 |
const PaDeviceInfo *p_pdi; |
|---|
| 336 |
PaError i_err; |
|---|
| 337 |
vlc_value_t val, text; |
|---|
| 338 |
int i; |
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
i_err = Pa_Initialize(); |
|---|
| 342 |
if( i_err != paNoError ) |
|---|
| 343 |
{ |
|---|
| 344 |
msg_Err( p_aout, "Pa_Initialize returned %d : %s", |
|---|
| 345 |
i_err, Pa_GetErrorText( i_err ) ); |
|---|
| 346 |
|
|---|
| 347 |
return VLC_EGENERIC; |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
p_sys->i_devices = Pa_GetDeviceCount(); |
|---|
| 351 |
if( p_sys->i_devices < 0 ) |
|---|
| 352 |
{ |
|---|
| 353 |
i_err = p_sys->i_devices; |
|---|
| 354 |
msg_Err( p_aout, "Pa_GetDeviceCount returned %d : %s", i_err, |
|---|
| 355 |
Pa_GetErrorText( i_err ) ); |
|---|
| 356 |
|
|---|
| 357 |
goto error; |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
msg_Dbg( p_aout, "number of devices = %d", p_sys->i_devices ); |
|---|
| 362 |
for( i = 0; i < p_sys->i_devices; i++ ) |
|---|
| 363 |
{ |
|---|
| 364 |
p_pdi = Pa_GetDeviceInfo( i ); |
|---|
| 365 |
msg_Dbg( p_aout, "------------------------------------- #%d", i ); |
|---|
| 366 |
msg_Dbg( p_aout, "Name = %s", p_pdi->name ); |
|---|
| 367 |
msg_Dbg( p_aout, "Max Inputs = %d, Max Outputs = %d", |
|---|
| 368 |
p_pdi->maxInputChannels, p_pdi->maxOutputChannels ); |
|---|
| 369 |
} |
|---|
| 370 |
msg_Dbg( p_aout, "-------------------------------------" ); |
|---|
| 371 |
|
|---|
| 372 |
msg_Dbg( p_aout, "requested device is #%d", p_sys->i_device_id ); |
|---|
| 373 |
if( p_sys->i_device_id >= p_sys->i_devices ) |
|---|
| 374 |
{ |
|---|
| 375 |
msg_Err( p_aout, "device %d does not exist", p_sys->i_device_id ); |
|---|
| 376 |
goto error; |
|---|
| 377 |
} |
|---|
| 378 |
p_sys->deviceInfo = Pa_GetDeviceInfo( p_sys->i_device_id ); |
|---|
| 379 |
|
|---|
| 380 |
if( p_sys->deviceInfo->maxOutputChannels < 1 ) |
|---|
| 381 |
{ |
|---|
| 382 |
msg_Err( p_aout, "no channel available" ); |
|---|
| 383 |
goto error; |
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
if( var_Type( p_aout, "audio-device" ) == 0 ) |
|---|
| 387 |
{ |
|---|
| 388 |
var_Create( p_aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE); |
|---|
| 389 |
text.psz_string = _("Audio Device"); |
|---|
| 390 |
var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL ); |
|---|
| 391 |
|
|---|
| 392 |
if( p_sys->deviceInfo->maxOutputChannels >= 1 ) |
|---|
| 393 |
{ |
|---|
| 394 |
val.i_int = AOUT_VAR_MONO; |
|---|
| 395 |
text.psz_string = N_("Mono"); |
|---|
| 396 |
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, |
|---|
| 397 |
&val, &text ); |
|---|
| 398 |
msg_Dbg( p_aout, "device supports 1 channel" ); |
|---|
| 399 |
} |
|---|
| 400 |
if( p_sys->deviceInfo->maxOutputChannels >= 2 ) |
|---|
| 401 |
{ |
|---|
| 402 |
val.i_int = AOUT_VAR_STEREO; |
|---|
| 403 |
text.psz_string = N_("Stereo"); |
|---|
| 404 |
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, |
|---|
| 405 |
&val, &text ); |
|---|
| 406 |
var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, |
|---|
| 407 |
&val, NULL ); |
|---|
| 408 |
var_Set( p_aout, "audio-device", val ); |
|---|
| 409 |
msg_Dbg( p_aout, "device supports 2 channels" ); |
|---|
| 410 |
} |
|---|
| 411 |
if( p_sys->deviceInfo->maxOutputChannels >= 4 ) |
|---|
| 412 |
{ |
|---|
| 413 |
val.i_int = AOUT_VAR_2F2R; |
|---|
| 414 |
text.psz_string = N_("2 Front 2 Rear"); |
|---|
| 415 |
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, |
|---|
| 416 |
&val, &text ); |
|---|
| 417 |
msg_Dbg( p_aout, "device supports 4 channels" ); |
|---|
| 418 |
} |
|---|
| 419 |
if( p_sys->deviceInfo->maxOutputChannels >= 5 ) |
|---|
| 420 |
{ |
|---|
| 421 |
val.i_int = AOUT_VAR_3F2R; |
|---|
| 422 |
text.psz_string = N_("3 Front 2 Rear"); |
|---|
| 423 |
var_Change( p_aout, "audio-device", |
|---|
| 424 |
VLC_VAR_ADDCHOICE, &val, &text ); |
|---|
| 425 |
msg_Dbg( p_aout, "device supports 5 channels" ); |
|---|
| 426 |
} |
|---|
| 427 |
if( p_sys->deviceInfo->maxOutputChannels >= 6 ) |
|---|
| 428 |
{ |
|---|
| 429 |
val.i_int = AOUT_VAR_5_1; |
|---|
| 430 |
text.psz_string = "5.1"; |
|---|
| 431 |
var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, |
|---|
| 432 |
&val, &text ); |
|---|
| 433 |
msg_Dbg( p_aout, "device supports 5.1 channels" ); |
|---|
| 434 |
} |
|---|
| 435 |
|
|---|
| 436 |
var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL ); |
|---|
| 437 |
|
|---|
| 438 |
val.b_bool = true; |
|---|
| 439 |
var_Set( p_aout, "intf-change", val ); |
|---|
| 440 |
} |
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2'); |
|---|
| 444 |
|
|---|
| 445 |
return VLC_SUCCESS; |
|---|
| 446 |
|
|---|
| 447 |
error: |
|---|
| 448 |
if( ( i_err = Pa_Terminate() ) != paNoError ) |
|---|
| 449 |
{ |
|---|
| 450 |
msg_Err( p_aout, "Pa_Terminate returned %d", i_err ); |
|---|
| 451 |
} |
|---|
| 452 |
return VLC_EGENERIC; |
|---|
| 453 |
} |
|---|
| 454 |
|
|---|
| 455 |
static int PAOpenStream( aout_instance_t *p_aout ) |
|---|
| 456 |
{ |
|---|
| 457 |
aout_sys_t *p_sys = p_aout->output.p_sys; |
|---|
| 458 |
const PaHostErrorInfo* paLastHostErrorInfo = Pa_GetLastHostErrorInfo(); |
|---|
| 459 |
PaStreamParameters paStreamParameters; |
|---|
| 460 |
vlc_value_t val; |
|---|
| 461 |
int i_channels, i_err; |
|---|
| 462 |
uint32_t i_channel_mask; |
|---|
| 463 |
|
|---|
| 464 |
if( var_Get( p_aout, "audio-device", &val ) < 0 ) |
|---|
| 465 |
{ |
|---|
| 466 |
return VLC_EGENERIC; |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
if( val.i_int == AOUT_VAR_5_1 ) |
|---|
| 470 |
{ |
|---|
| 471 |
p_aout->output.output.i_physical_channels |
|---|
| 472 |
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
|---|
| 473 |
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
|---|
| 474 |
| AOUT_CHAN_LFE; |
|---|
| 475 |
} |
|---|
| 476 |
else if( val.i_int == AOUT_VAR_3F2R ) |
|---|
| 477 |
{ |
|---|
| 478 |
p_aout->output.output.i_physical_channels |
|---|
| 479 |
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
|---|
| 480 |
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; |
|---|
| 481 |
} |
|---|
| 482 |
else if( val.i_int == AOUT_VAR_2F2R ) |
|---|
| 483 |
{ |
|---|
| 484 |
p_aout->output.output.i_physical_channels |
|---|
| 485 |
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
|---|
| 486 |
| AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; |
|---|
| 487 |
} |
|---|
| 488 |
else if( val.i_int == AOUT_VAR_MONO ) |
|---|
| 489 |
{ |
|---|
| 490 |
p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER; |
|---|
| 491 |
} |
|---|
| 492 |
else |
|---|
| 493 |
{ |
|---|
| 494 |
p_aout->output.output.i_physical_channels |
|---|
| 495 |
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; |
|---|
| 496 |
} |
|---|
| 497 |
|
|---|
| 498 |
i_channels = aout_FormatNbChannels( &p_aout->output.output ); |
|---|
| 499 |
msg_Dbg( p_aout, "nb_channels requested = %d", i_channels ); |
|---|
| 500 |
i_channel_mask = p_aout->output.output.i_physical_channels; |
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
p_sys->i_sample_size = 4 * i_channels; |
|---|
| 504 |
p_aout->output.i_nb_samples = FRAME_SIZE; |
|---|
| 505 |
aout_FormatPrepare( &p_aout->output.output ); |
|---|
| 506 |
aout_VolumeSoftInit( p_aout ); |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
p_aout->output.p_sys->i_channel_mask = i_channel_mask; |
|---|
| 510 |
p_aout->output.p_sys->i_bits_per_sample = 32; |
|---|
| 511 |
p_aout->output.p_sys->i_channels = i_channels; |
|---|
| 512 |
|
|---|
| 513 |
p_aout->output.p_sys->b_chan_reorder = |
|---|
| 514 |
aout_CheckChannelReorder( NULL, pi_channels_out, |
|---|
| 515 |
i_channel_mask, i_channels, |
|---|
| 516 |
p_aout->output.p_sys->pi_chan_table ); |
|---|
| 517 |
|
|---|
| 518 |
if( p_aout->output.p_sys->b_chan_reorder ) |
|---|
| 519 |
{ |
|---|
| 520 |
msg_Dbg( p_aout, "channel reordering needed" ); |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
paStreamParameters.device = p_sys->i_device_id; |
|---|
| 524 |
paStreamParameters.channelCount = i_channels; |
|---|
| 525 |
paStreamParameters.sampleFormat = paFloat32; |
|---|
| 526 |
paStreamParameters.suggestedLatency = |
|---|
| 527 |
p_sys->deviceInfo->defaultLowOutputLatency; |
|---|
| 528 |
paStreamParameters.hostApiSpecificStreamInfo = NULL; |
|---|
| 529 |
|
|---|
| 530 |
i_err = Pa_OpenStream( &p_sys->p_stream, NULL , |
|---|
| 531 |
&paStreamParameters, (double)p_aout->output.output.i_rate, |
|---|
| 532 |
FRAME_SIZE, paClipOff, paCallback, p_sys ); |
|---|
| 533 |
if( i_err != paNoError ) |
|---|
| 534 |
{ |
|---|
| 535 |
msg_Err( p_aout, "Pa_OpenStream returns %d : %s", i_err, |
|---|
| 536 |
Pa_GetErrorText( i_err ) ); |
|---|
| 537 |
if( i_err == paUnanticipatedHostError ) |
|---|
| 538 |
{ |
|---|
| 539 |
msg_Err( p_aout, "type %d code %ld : %s", |
|---|
| 540 |
paLastHostErrorInfo->hostApiType, |
|---|
| 541 |
paLastHostErrorInfo->errorCode, |
|---|
| 542 |
paLastHostErrorInfo->errorText ); |
|---|
| 543 |
} |
|---|
| 544 |
p_sys->p_stream = 0; |
|---|
| 545 |
return VLC_EGENERIC; |
|---|
| 546 |
} |
|---|
| 547 |
|
|---|
| 548 |
i_err = Pa_StartStream( p_sys->p_stream ); |
|---|
| 549 |
if( i_err != paNoError ) |
|---|
| 550 |
{ |
|---|
| 551 |
msg_Err( p_aout, "Pa_StartStream() failed" ); |
|---|
| 552 |
Pa_CloseStream( p_sys->p_stream ); |
|---|
| 553 |
return VLC_EGENERIC; |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
return VLC_SUCCESS; |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
static void Play( aout_instance_t * p_aout ) |
|---|
| 563 |
{ |
|---|
| 564 |
} |
|---|
| 565 |
|
|---|
| 566 |
#ifdef PORTAUDIO_IS_SERIOUSLY_BROKEN |
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
static void* PORTAUDIOThread( vlc_object_t *p_this ) |
|---|
| 572 |
{ |
|---|
| 573 |
pa_thread_t *pa_thread = (pa_thread_t*)p_this; |
|---|
| 574 |
aout_instance_t *p_aout; |
|---|
| 575 |
aout_sys_t *p_sys; |
|---|
| 576 |
int i_err; |
|---|
| 577 |
int canc = vlc_savecancel (); |
|---|
| 578 |
|
|---|
| 579 |
while( vlc_object_alive (pa_thread) ) |
|---|
| 580 |
{ |
|---|
| 581 |
|
|---|
| 582 |
vlc_mutex_lock( &pa_thread->lock_signal ); |
|---|
| 583 |
if( !pa_thread->b_signal ) |
|---|
| 584 |
vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal ); |
|---|
| 585 |
vlc_mutex_unlock( &pa_thread->lock_signal ); |
|---|
| 586 |
pa_thread->b_signal = false; |
|---|
| 587 |
|
|---|
| 588 |
p_aout = pa_thread->p_aout; |
|---|
| 589 |
p_sys = p_aout->output.p_sys; |
|---|
| 590 |
|
|---|
| 591 |
if( PAOpenDevice( p_aout ) != VLC_SUCCESS ) |
|---|
| 592 |
{ |
|---|
| 593 |
msg_Err( p_aout, "cannot open portaudio device" ); |
|---|
| 594 |
pa_thread->b_error = true; |
|---|
| 595 |
} |
|---|
| 596 |
|
|---|
| 597 |
if( !pa_thread->b_error && PAOpenStream( p_aout ) != VLC_SUCCESS ) |
|---|
| 598 |
{ |
|---|
| 599 |
msg_Err( p_aout, "cannot open portaudio device" ); |
|---|
| 600 |
pa_thread->b_error = true; |
|---|
| 601 |
|
|---|
| 602 |
i_err = Pa_Terminate(); |
|---|
| 603 |
if( i_err != paNoError ) |
|---|
| 604 |
{ |
|---|
| 605 |
msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err, |
|---|
| 606 |
Pa_GetErrorText( i_err ) ); |
|---|
| 607 |
} |
|---|
| 608 |
} |
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
vlc_mutex_lock( &pa_thread->lock_wait ); |
|---|
| 612 |
pa_thread->b_wait = true; |
|---|
| 613 |
vlc_cond_signal( &pa_thread->wait ); |
|---|
| 614 |
vlc_mutex_unlock( &pa_thread->lock_wait ); |
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
vlc_mutex_lock( &pa_thread->lock_signal ); |
|---|
| 618 |
if( !pa_thread->b_signal ) |
|---|
| 619 |
vlc_cond_wait( &pa_thread->signal, &pa_thread->lock_signal ); |
|---|
| 620 |
vlc_mutex_unlock( &pa_thread->lock_signal ); |
|---|
| 621 |
pa_thread->b_signal = false; |
|---|
| 622 |
|
|---|
| 623 |
if( pa_thread->b_error ) continue; |
|---|
| 624 |
|
|---|
| 625 |
i_err = Pa_StopStream( p_sys->p_stream ); |
|---|
| 626 |
if( i_err != paNoError ) |
|---|
| 627 |
{ |
|---|
| 628 |
msg_Err( p_aout, "Pa_StopStream: %d (%s)", i_err, |
|---|
| 629 |
Pa_GetErrorText( i_err ) ); |
|---|
| 630 |
} |
|---|
| 631 |
i_err = Pa_CloseStream( p_sys->p_stream ); |
|---|
| 632 |
if( i_err != paNoError ) |
|---|
| 633 |
{ |
|---|
| 634 |
msg_Err( p_aout, "Pa_CloseStream: %d (%s)", i_err, |
|---|
| 635 |
Pa_GetErrorText( i_err ) ); |
|---|
| 636 |
} |
|---|
| 637 |
i_err = Pa_Terminate(); |
|---|
| 638 |
if( i_err != paNoError ) |
|---|
| 639 |
{ |
|---|
| 640 |
msg_Err( p_aout, "Pa_Terminate: %d (%s)", i_err, |
|---|
| 641 |
Pa_GetErrorText( i_err ) ); |
|---|
| 642 |
} |
|---|
| 643 |
|
|---|
| 644 |
|
|---|
| 645 |
vlc_mutex_lock( &pa_thread->lock_wait ); |
|---|
| 646 |
pa_thread->b_wait = true; |
|---|
| 647 |
vlc_cond_signal( &pa_thread->wait ); |
|---|
| 648 |
vlc_mutex_unlock( &pa_thread->lock_wait ); |
|---|
| 649 |
} |
|---|
| 650 |
vlc_restorecancel (canc); |
|---|
| 651 |
return NULL; |
|---|
| 652 |
} |
|---|
| 653 |
#endif |
|---|