1 /*****************************************************************************
2 * aout.m: CoreAudio output plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: aout.m,v 1.22 2003/01/21 00:47:43 jlj Exp $
7 * Authors: Colin Delacroix <colin@zoy.org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Heiko Panther <heiko.panther@web.de>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
36 #include "aout_internal.h"
38 #include <Carbon/Carbon.h>
39 #include <CoreAudio/HostTime.h>
40 #include <CoreAudio/AudioHardware.h>
42 #define A52_FRAME_NB 1536
44 #define STREAM_FORMAT_MSG( pre, sfm ) \
45 pre ": [%ld][%4.4s][%ld][%ld][%ld][%ld][%ld][%ld]", \
46 (UInt32)sfm.mSampleRate, (char *)&sfm.mFormatID, \
47 sfm.mFormatFlags, sfm.mBytesPerPacket, \
48 sfm.mFramesPerPacket, sfm.mBytesPerFrame, \
49 sfm.mChannelsPerFrame, sfm.mBitsPerChannel
51 /*****************************************************************************
53 ****************************************************************************/
56 AudioDeviceClassA52 = 1 << 0,
57 AudioDeviceClassPCM2 = 1 << 1,
58 AudioDeviceClassPCM4 = 1 << 2,
59 AudioDeviceClassPCM6 = 1 << 3
62 static struct aout_class_t
65 UInt32 mChannelsPerFrame;
66 enum AudioDeviceClass class;
67 const char *psz_class;
71 { /* old A/52 format type */
78 { /* new A/52 format type */
86 kAudioFormatLinearPCM,
93 kAudioFormatLinearPCM,
100 kAudioFormatLinearPCM,
102 AudioDeviceClassPCM6,
107 #define N_AOUT_CLASSES (sizeof(aout_classes)/sizeof(aout_classes[0]))
109 /*****************************************************************************
111 ****************************************************************************/
120 /*****************************************************************************
122 ****************************************************************************/
126 char *psz_device_name;
128 AudioStreamBasicDescription ** pp_streams;
131 /*****************************************************************************
132 * aout_sys_t: private audio output method descriptor
133 *****************************************************************************
134 * This structure is part of the audio output thread descriptor.
135 * It describes the CoreAudio specific properties of an output thread.
136 *****************************************************************************/
140 struct aout_dev_t * p_devices;
142 struct aout_option_t * p_options;
145 AudioStreamBasicDescription stream_format;
147 UInt32 i_buffer_size;
151 /*****************************************************************************
153 *****************************************************************************/
154 static int InitHardware ( aout_instance_t *p_aout );
155 static int InitDevice ( UInt32 i_dev, aout_instance_t *p_aout );
156 static void FreeDevice ( UInt32 i_dev, aout_instance_t *p_aout );
157 static void FreeHardware ( aout_instance_t *p_aout );
158 static int GetDevice ( aout_instance_t *p_aout,
159 AudioDeviceID *p_devid );
160 static int GetStreamID ( AudioDeviceID devid, UInt32 i_idx,
161 AudioStreamID * p_sid );
162 static int InitStream ( UInt32 i_dev, aout_instance_t *p_aout,
164 static void FreeStream ( UInt32 i_dev, aout_instance_t *p_aout,
167 static void Play ( aout_instance_t *p_aout );
169 static OSStatus IOCallback ( AudioDeviceID inDevice,
170 const AudioTimeStamp *inNow,
171 const void *inInputData,
172 const AudioTimeStamp *inInputTime,
173 AudioBufferList *outOutputData,
174 const AudioTimeStamp *inOutputTime,
175 void *threadGlobals );
177 /*****************************************************************************
178 * Open: open a CoreAudio HAL device
179 *****************************************************************************/
180 int E_(OpenAudio)( vlc_object_t * p_this )
184 UInt32 i, i_param_size;
185 struct aout_sys_t * p_sys;
186 aout_instance_t * p_aout = (aout_instance_t *)p_this;
188 /* Allocate structure */
189 p_sys = (struct aout_sys_t *)malloc( sizeof( struct aout_sys_t ) );
192 msg_Err( p_aout, "out of memory" );
193 return( VLC_ENOMEM );
196 memset( p_sys, 0, sizeof( struct aout_sys_t ) );
197 p_aout->output.p_sys = p_sys;
199 if( InitHardware( p_aout ) )
201 msg_Err( p_aout, "InitHardware failed" );
202 free( (void *)p_sys );
203 return( VLC_EGENERIC );
206 if( var_Type( p_aout, "audio-device" ) == 0 )
208 UInt32 i_option = config_GetInt( p_aout, "macosx-adev" );
210 var_Create( p_aout, "audio-device", VLC_VAR_STRING |
213 for( i = 0; i < p_sys->i_options; i++ )
215 val.psz_string = p_sys->p_options[i].sz_option;
216 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
220 var_Set( p_aout, "audio-device", val );
224 var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart,
227 val.b_bool = VLC_TRUE;
228 var_Set( p_aout, "intf-change", val );
231 /* Get requested device */
232 if( GetDevice( p_aout, &p_sys->devid ) )
234 msg_Err( p_aout, "GetDevice failed" );
235 FreeHardware( p_aout );
236 free( (void *)p_sys );
237 return( VLC_EGENERIC );
240 p_aout->output.pf_play = Play;
241 aout_VolumeSoftInit( p_aout );
243 /* Get a description of the stream format */
244 i_param_size = sizeof( AudioStreamBasicDescription );
245 err = AudioDeviceGetProperty( p_sys->devid, 0, false,
246 kAudioDevicePropertyStreamFormat,
247 &i_param_size, &p_sys->stream_format );
250 msg_Err( p_aout, "failed to get stream format: [%4.4s]",
252 FreeHardware( p_aout );
253 free( (void *)p_sys );
254 return( VLC_EGENERIC );
257 /* Set the output sample rate */
258 p_aout->output.output.i_rate =
259 (unsigned int)p_sys->stream_format.mSampleRate;
261 msg_Dbg( p_aout, STREAM_FORMAT_MSG( "using format",
262 p_sys->stream_format ) );
264 /* Get the buffer size */
265 i_param_size = sizeof( p_sys->i_buffer_size );
266 err = AudioDeviceGetProperty( p_sys->devid, 0, false,
267 kAudioDevicePropertyBufferSize,
268 &i_param_size, &p_sys->i_buffer_size );
271 msg_Err( p_aout, "failed to get buffer size: [%4.4s]",
273 FreeHardware( p_aout );
274 free( (void *)p_sys );
275 return( VLC_EGENERIC );
278 msg_Dbg( p_aout, "device buffer size: [%ld]", p_sys->i_buffer_size );
280 /* If we do AC3 over SPDIF, set buffer size to one AC3 frame */
281 if( ( p_sys->stream_format.mFormatID == kAudioFormat60958AC3 ||
282 p_sys->stream_format.mFormatID == 'IAC3' ) &&
283 p_sys->i_buffer_size != AOUT_SPDIF_SIZE )
285 p_sys->i_buffer_size = AOUT_SPDIF_SIZE;
286 i_param_size = sizeof( p_sys->i_buffer_size );
287 err = AudioDeviceSetProperty( p_sys->devid, 0, 0, false,
288 kAudioDevicePropertyBufferSize,
289 i_param_size, &p_sys->i_buffer_size );
292 msg_Err( p_aout, "failed to set buffer size: [%4.4s]",
294 FreeHardware( p_aout );
295 free( (void *)p_sys );
296 return( VLC_EGENERIC );
299 msg_Dbg( p_aout, "device buffer size set to: [%ld]",
300 p_sys->i_buffer_size );
303 switch( p_sys->stream_format.mFormatID )
305 case kAudioFormatLinearPCM:
306 p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
308 if( p_sys->stream_format.mChannelsPerFrame == 6 )
310 p_aout->output.output.i_physical_channels =
311 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
312 AOUT_CHAN_CENTER | AOUT_CHAN_REARRIGHT |
313 AOUT_CHAN_REARLEFT | AOUT_CHAN_LFE;
315 else if( p_sys->stream_format.mChannelsPerFrame == 4 )
317 p_aout->output.output.i_physical_channels =
318 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
319 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
323 p_aout->output.output.i_physical_channels =
324 AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
327 p_aout->output.i_nb_samples = (int)( p_sys->i_buffer_size /
328 p_sys->stream_format.mBytesPerFrame );
332 case kAudioFormat60958AC3:
333 p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
334 p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
335 p_aout->output.output.i_frame_length = A52_FRAME_NB;
336 p_aout->output.i_nb_samples = p_aout->output.output.i_frame_length;
340 msg_Err( p_aout, "unknown hardware format: [%4.4s]",
341 (char *)&p_sys->stream_format.mFormatID );
342 FreeHardware( p_aout );
343 free( (void *)p_sys );
344 return( VLC_EGENERIC );
347 /* Set buffer frame size */
348 i_param_size = sizeof( p_aout->output.i_nb_samples );
349 err = AudioDeviceSetProperty( p_sys->devid, 0, 0, false,
350 kAudioDevicePropertyBufferFrameSize,
352 &p_aout->output.i_nb_samples );
355 msg_Err( p_aout, "failed to set buffer frame size: [%4.4s]",
357 FreeHardware( p_aout );
358 free( (void *)p_sys );
359 return( VLC_EGENERIC );
362 msg_Dbg( p_aout, "device buffer frame size set to: [%d]",
363 p_aout->output.i_nb_samples );
366 err = AudioDeviceAddIOProc( p_sys->devid,
367 (AudioDeviceIOProc)IOCallback,
371 msg_Err( p_aout, "AudioDeviceAddIOProc failed: [%4.4s]",
373 FreeHardware( p_aout );
374 free( (void *)p_sys );
375 return( VLC_EGENERIC );
379 err = AudioDeviceStart( p_sys->devid, (AudioDeviceIOProc)IOCallback );
382 msg_Err( p_aout, "AudioDeviceStart failed: [%4.4s]",
384 FreeHardware( p_aout );
385 free( (void *)p_sys );
386 return( VLC_EGENERIC );
389 /* Let's pray for the following operation to be atomic... */
390 p_sys->clock_diff = - (mtime_t)
391 AudioConvertHostTimeToNanos( AudioGetCurrentHostTime() ) / 1000;
392 p_sys->clock_diff += mdate();
394 return( VLC_SUCCESS );
397 /*****************************************************************************
398 * Close: close the CoreAudio HAL device
399 *****************************************************************************/
400 void E_(CloseAudio)( aout_instance_t * p_aout )
403 struct aout_sys_t * p_sys = p_aout->output.p_sys;
406 err = AudioDeviceStop( p_sys->devid, (AudioDeviceIOProc)IOCallback );
409 msg_Err( p_aout, "AudioDeviceStop failed: [%4.4s]", (char *)&err );
412 /* Remove callback */
413 err = AudioDeviceRemoveIOProc( p_sys->devid,
414 (AudioDeviceIOProc)IOCallback );
417 msg_Err( p_aout, "AudioDeviceRemoveIOProc failed: [%4.4s]",
421 FreeHardware( p_aout );
426 /*****************************************************************************
427 * Play: nothing to do
428 *****************************************************************************/
429 static void Play( aout_instance_t * p_aout )
433 /*****************************************************************************
434 * IOCallback: callback for audio output
435 *****************************************************************************/
436 static OSStatus IOCallback( AudioDeviceID inDevice,
437 const AudioTimeStamp *inNow,
438 const void *inInputData,
439 const AudioTimeStamp *inInputTime,
440 AudioBufferList *outOutputData,
441 const AudioTimeStamp *inOutputTime,
442 void *threadGlobals )
444 aout_buffer_t * p_buffer;
445 AudioTimeStamp host_time;
446 mtime_t current_date;
448 aout_instance_t * p_aout = (aout_instance_t *)threadGlobals;
449 struct aout_sys_t * p_sys = p_aout->output.p_sys;
451 host_time.mFlags = kAudioTimeStampHostTimeValid;
452 AudioDeviceTranslateTime( inDevice, inOutputTime, &host_time );
453 current_date = p_sys->clock_diff +
454 AudioConvertHostTimeToNanos( host_time.mHostTime ) / 1000;
456 #define B_SPDI (p_aout->output.output.i_format == VLC_FOURCC('s','p','d','i'))
457 p_buffer = aout_OutputNextBuffer( p_aout, current_date, B_SPDI );
460 if( p_buffer != NULL )
462 /* move data into output data buffer */
463 BlockMoveData( p_buffer->p_buffer,
464 outOutputData->mBuffers[ 0 ].mData,
465 p_sys->i_buffer_size );
467 aout_BufferFree( p_buffer );
471 memset( outOutputData->mBuffers[ 0 ].mData,
472 0, p_sys->i_buffer_size );
478 /*****************************************************************************
480 *****************************************************************************/
481 static int InitHardware( aout_instance_t * p_aout )
484 UInt32 i, i_param_size;
485 AudioDeviceID * p_devices;
487 struct aout_sys_t * p_sys = p_aout->output.p_sys;
489 /* Get number of devices */
490 err = AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices,
491 &i_param_size, NULL );
494 msg_Err( p_aout, "AudioHardwareGetPropertyInfo failed: [%4.4s]",
496 return( VLC_EGENERIC );
499 p_sys->i_devices = i_param_size / sizeof( AudioDeviceID );
501 if( p_sys->i_devices < 1 )
503 msg_Err( p_aout, "no devices found" );
504 return( VLC_EGENERIC );
507 msg_Dbg( p_aout, "system has [%ld] device(s)", p_sys->i_devices );
509 /* Allocate DeviceID array */
510 p_devices = (AudioDeviceID *)malloc( i_param_size );
511 if( p_devices == NULL )
513 msg_Err( p_aout, "out of memory" );
514 return( VLC_ENOMEM );
517 /* Populate DeviceID array */
518 err = AudioHardwareGetProperty( kAudioHardwarePropertyDevices,
519 &i_param_size, (void *)p_devices );
522 msg_Err( p_aout, "AudioHardwareGetProperty failed: [%4.4s]",
524 free( (void *)p_devices );
525 return( VLC_EGENERIC );
528 p_sys->p_devices = (struct aout_dev_t *)
529 malloc( sizeof( struct aout_dev_t ) * p_sys->i_devices );
530 if( p_sys->p_devices == NULL )
532 msg_Err( p_aout, "out of memory" );
533 free( (void *)p_devices );
534 return( VLC_ENOMEM );
537 for( i = 0; i < p_sys->i_devices; i++ )
539 p_sys->p_devices[i].devid = p_devices[i];
541 if( InitDevice( i, p_aout ) )
545 msg_Err( p_aout, "InitDevice(%ld) failed", i );
547 for( j = 0; j < i; j++ )
549 FreeDevice( j, p_aout );
552 free( (void *)p_sys->p_devices );
553 free( (void *)p_devices );
555 return( VLC_EGENERIC );
559 free( (void *)p_devices );
561 return( VLC_SUCCESS );
564 /*****************************************************************************
566 *****************************************************************************/
567 static int InitDevice( UInt32 i_dev, aout_instance_t * p_aout )
570 UInt32 i, i_param_size;
571 AudioBufferList *p_buffer_list;
573 struct aout_sys_t * p_sys = p_aout->output.p_sys;
574 struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev];
576 /* Get length of device name */
577 err = AudioDeviceGetPropertyInfo( p_dev->devid, 0, FALSE,
578 kAudioDevicePropertyDeviceName,
579 &i_param_size, NULL );
582 msg_Err( p_aout, "AudioDeviceGetPropertyInfo failed: [%4.4s]",
584 return( VLC_EGENERIC );
587 /* Allocate memory for device name */
588 p_dev->psz_device_name = (char *)malloc( i_param_size );
589 if( p_dev->psz_device_name == NULL )
591 msg_Err( p_aout, "out of memory" );
592 return( VLC_ENOMEM );
595 /* Get device name */
596 err = AudioDeviceGetProperty( p_dev->devid, 0, FALSE,
597 kAudioDevicePropertyDeviceName,
598 &i_param_size, p_dev->psz_device_name );
601 msg_Err( p_aout, "AudioDeviceGetProperty failed: [%4.4s]",
603 free( (void *)p_dev->psz_device_name );
604 return( VLC_EGENERIC );
607 msg_Dbg( p_aout, "device [%ld] has name [%s]",
608 i_dev, p_dev->psz_device_name );
610 err = AudioDeviceGetPropertyInfo( p_dev->devid, 0, FALSE,
611 kAudioDevicePropertyStreamConfiguration,
612 &i_param_size, NULL );
615 msg_Err( p_aout, "AudioDeviceGetPropertyInfo failed: [%4.4s]",
617 free( (void *)p_dev->psz_device_name );
618 return( VLC_EGENERIC );
621 p_buffer_list = (AudioBufferList *)malloc( i_param_size );
622 if( p_buffer_list == NULL )
624 msg_Err( p_aout, "out of memory" );
625 free( (void *)p_dev->psz_device_name );
626 return( VLC_ENOMEM );
629 err = AudioDeviceGetProperty( p_dev->devid, 0, FALSE,
630 kAudioDevicePropertyStreamConfiguration,
631 &i_param_size, p_buffer_list );
634 msg_Err( p_aout, "AudioDeviceGetProperty failed: [%4.4s]",
636 free( (void *)p_dev->psz_device_name );
637 free( (void *)p_buffer_list );
638 return( VLC_EGENERIC );
641 p_dev->i_streams = p_buffer_list->mNumberBuffers;
642 free( (void *)p_buffer_list );
644 msg_Dbg( p_aout, "device [%ld] has [%ld] streams",
645 i_dev, p_dev->i_streams );
647 p_dev->pp_streams = (AudioStreamBasicDescription **)
648 malloc( p_dev->i_streams *
649 sizeof( *p_dev->pp_streams ) );
650 if( p_dev->pp_streams == NULL )
652 msg_Err( p_aout, "out of memory" );
653 free( (void *)p_dev->psz_device_name );
654 return( VLC_ENOMEM );
657 for( i = 0; i < p_dev->i_streams; i++ )
659 if( InitStream( i_dev, p_aout, i ) )
663 msg_Err( p_aout, "InitStream(%ld, %ld) failed", i_dev, i );
665 for( j = 0; j < i; j++ )
667 FreeStream( i_dev, p_aout, j );
670 free( (void *)p_dev->psz_device_name );
671 free( (void *)p_dev->pp_streams );
673 return( VLC_EGENERIC );
677 return( VLC_SUCCESS );
680 /*****************************************************************************
682 *****************************************************************************/
683 static void FreeDevice( UInt32 i_dev, aout_instance_t * p_aout )
687 struct aout_sys_t * p_sys = p_aout->output.p_sys;
688 struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev];
690 for( i = 0; i < p_dev->i_streams; i++ )
692 FreeStream( i_dev, p_aout, i );
695 free( (void *)p_dev->pp_streams );
696 free( (void *)p_dev->psz_device_name );
699 /*****************************************************************************
701 *****************************************************************************/
702 static void FreeHardware( aout_instance_t * p_aout )
706 struct aout_sys_t * p_sys = p_aout->output.p_sys;
708 for( i = 0; i < p_sys->i_devices; i++ )
710 FreeDevice( i, p_aout );
713 free( (void *)p_sys->p_options );
714 free( (void *)p_sys->p_devices );
717 /*****************************************************************************
719 *****************************************************************************/
720 static int GetStreamID( AudioDeviceID devid, UInt32 i_idx,
721 AudioStreamID * p_sid )
725 AudioStreamID * p_stream_list;
727 err = AudioDeviceGetPropertyInfo( devid, 0, FALSE,
728 kAudioDevicePropertyStreams,
729 &i_param_size, NULL );
732 return( VLC_EGENERIC );
735 p_stream_list = (AudioStreamID *)malloc( i_param_size );
736 if( p_stream_list == NULL )
738 return( VLC_ENOMEM );
741 err = AudioDeviceGetProperty( devid, 0, FALSE,
742 kAudioDevicePropertyStreams,
743 &i_param_size, p_stream_list );
746 free( (void *)p_stream_list );
747 return( VLC_EGENERIC );
750 *p_sid = p_stream_list[i_idx - 1];
752 free( (void *)p_stream_list );
754 return( VLC_SUCCESS );
757 /*****************************************************************************
759 *****************************************************************************/
760 static int InitStream( UInt32 i_dev, aout_instance_t *p_aout,
766 UInt32 j, i_param_size;
768 struct aout_sys_t * p_sys = p_aout->output.p_sys;
769 struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev];
771 if( GetStreamID( p_dev->devid, i_idx + 1, &i_sid ) )
773 msg_Err( p_aout, "GetStreamID(%ld, %ld) failed", i_dev, i_idx );
774 return( VLC_EGENERIC );
777 err = AudioStreamGetPropertyInfo( i_sid, 0,
778 kAudioStreamPropertyPhysicalFormats,
779 &i_param_size, NULL );
782 msg_Err( p_aout, "AudioStreamGetPropertyInfo failed: [%4.4s]",
784 return( VLC_EGENERIC );
787 i_streams = i_param_size / sizeof( AudioStreamBasicDescription );
789 #define P_STREAMS p_dev->pp_streams[i_idx]
791 P_STREAMS = (AudioStreamBasicDescription *)malloc( i_param_size );
792 if( P_STREAMS == NULL )
794 msg_Err( p_aout, "out of memory" );
795 return( VLC_ENOMEM );
798 err = AudioStreamGetProperty( i_sid, 0,
799 kAudioStreamPropertyPhysicalFormats,
800 &i_param_size, P_STREAMS );
803 msg_Err( p_aout, "AudioStreamGetProperty failed: [%4.4s]",
805 free( (void *)P_STREAMS );
806 return( VLC_EGENERIC );
809 for( j = 0; j < N_AOUT_CLASSES; j++ )
811 vlc_bool_t b_found = 0;
812 UInt32 i_channels = 0xFFFFFFFF;
815 for( i = 0; i < i_streams; i++ )
819 msg_Dbg( p_aout, STREAM_FORMAT_MSG( "supported format",
823 if( ( P_STREAMS[i].mFormatID != aout_classes[j].mFormatID ) ||
824 ( P_STREAMS[i].mChannelsPerFrame <
825 aout_classes[j].mChannelsPerFrame ) )
830 if( P_STREAMS[i].mChannelsPerFrame < i_channels )
832 i_channels = P_STREAMS[i].mChannelsPerFrame;
840 p_sys->p_options = (struct aout_option_t *)
841 realloc( p_sys->p_options,
842 ( p_sys->i_options + 1 ) *
843 sizeof( struct aout_option_t ) );
844 if( p_sys->p_options == NULL )
846 msg_Err( p_aout, "out of memory" );
847 free( (void *)P_STREAMS );
848 return( VLC_ENOMEM );
851 #define AOUT_OPTION p_sys->p_options[p_sys->i_options]
853 snprintf( AOUT_OPTION.sz_option,
854 sizeof( AOUT_OPTION.sz_option ) /
855 sizeof( AOUT_OPTION.sz_option[0] ) - 1,
858 p_dev->psz_device_name,
859 aout_classes[j].psz_class );
861 AOUT_OPTION.i_sid = i_sid;
862 AOUT_OPTION.i_dev = i_dev;
863 AOUT_OPTION.i_idx = i_idx;
864 AOUT_OPTION.i_sdx = i_sdx;
865 AOUT_OPTION.i_cdx = j;
875 return( VLC_SUCCESS );
878 /*****************************************************************************
880 *****************************************************************************/
881 static void FreeStream( UInt32 i_dev, aout_instance_t *p_aout,
884 struct aout_sys_t * p_sys = p_aout->output.p_sys;
885 struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev];
887 free( (void *)p_dev->pp_streams[i_idx] );
890 /*****************************************************************************
892 *****************************************************************************/
893 static int GetDevice( aout_instance_t *p_aout, AudioDeviceID *p_devid )
897 unsigned int i_option;
899 struct aout_dev_t * p_dev;
900 struct aout_option_t * p_option;
901 struct aout_sys_t * p_sys = p_aout->output.p_sys;
903 if( var_Get( p_aout, "audio-device", &val ) < 0 )
905 msg_Err( p_aout, "audio-device var does not exist" );
906 return( VLC_ENOVAR );
909 if( !sscanf( val.psz_string, "%d:", &i_option ) ||
910 p_sys->i_options <= i_option )
915 free( (void *)val.psz_string );
917 p_option = &p_sys->p_options[i_option];
918 p_dev = &p_sys->p_devices[p_option->i_dev];
920 #define P_STREAMS p_dev->pp_streams[p_option->i_idx]
922 err = AudioStreamSetProperty( p_option->i_sid, 0, 0,
923 kAudioStreamPropertyPhysicalFormat,
924 sizeof( P_STREAMS[p_option->i_sdx] ),
925 &P_STREAMS[p_option->i_sdx] );
928 msg_Err( p_aout, "AudioStreamSetProperty failed: [%4.4s]",
930 return( VLC_EGENERIC );
935 msg_Dbg( p_aout, "getting device [%ld]", p_option->i_dev );
937 config_PutInt( p_aout, "macosx-adev", i_option );
939 *p_devid = p_dev->devid;
941 return( VLC_SUCCESS );