📄 coreaudio.c
字号:
}/***************************************************************************** * InitDeviceInfo *****************************************************************************/static int InitDeviceInfo( UInt32 i_dev, aout_instance_t * p_aout ) { OSStatus err; UInt32 i, i_param_size; AudioBufferList * p_buffer_list; struct aout_sys_t * p_sys = p_aout->output.p_sys; struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev]; /* Get length of device name */ err = AudioDeviceGetPropertyInfo( p_dev->devid, 0, FALSE, kAudioDevicePropertyDeviceName, &i_param_size, NULL ); if( err != noErr ) { msg_Err( p_aout, "could not get size of devicename: [%4.4s]", (char *)&err ); return( VLC_EGENERIC ); } /* Allocate memory for device name */ p_dev->psz_device_name = (char *)malloc( i_param_size ); if( p_dev->psz_device_name == NULL ) { msg_Err( p_aout, "out of memory" ); return( VLC_ENOMEM ); } /* Get device name */ err = AudioDeviceGetProperty( p_dev->devid, 0, FALSE, kAudioDevicePropertyDeviceName, &i_param_size, p_dev->psz_device_name ); if( err != noErr ) { msg_Err( p_aout, "could not get devicename: [%4.4s]", (char *)&err ); free( (void *)p_dev->psz_device_name ); return( VLC_EGENERIC ); } msg_Dbg( p_aout, "device [%ld] has name [%s]", i_dev, p_dev->psz_device_name ); err = AudioDeviceGetPropertyInfo( p_dev->devid, 0, FALSE, kAudioDevicePropertyStreamConfiguration, &i_param_size, NULL ); if( err != noErr ) { msg_Err( p_aout, "could not get size of stream configuration: [%4.4s]", (char *)&err ); free( (void *)p_dev->psz_device_name ); return( VLC_EGENERIC ); } p_buffer_list = (AudioBufferList *)malloc( i_param_size ); if( p_buffer_list == NULL ) { msg_Err( p_aout, "out of memory" ); free( (void *)p_dev->psz_device_name ); return( VLC_ENOMEM ); } err = AudioDeviceGetProperty( p_dev->devid, 0, FALSE, kAudioDevicePropertyStreamConfiguration, &i_param_size, p_buffer_list ); if( err != noErr ) { msg_Err( p_aout, "could not get stream configuration: [%4.4s]", (char *)&err ); free( (void *)p_dev->psz_device_name ); free( (void *)p_buffer_list ); return( VLC_EGENERIC ); } p_dev->i_streams = p_buffer_list->mNumberBuffers; free( (void *)p_buffer_list ); msg_Dbg( p_aout, "device [%ld] has [%ld] streams", i_dev, p_dev->i_streams ); p_dev->pi_streams = (UInt32 *)malloc( p_dev->i_streams * sizeof( *p_dev->pi_streams ) ); if( p_dev->pi_streams == NULL ) { msg_Err( p_aout, "out of memory" ); free( (void *)p_dev->psz_device_name ); return( VLC_ENOMEM ); } p_dev->pp_streams = (AudioStreamBasicDescription **) malloc( p_dev->i_streams * sizeof( *p_dev->pp_streams ) ); if( p_dev->pp_streams == NULL ) { msg_Err( p_aout, "out of memory" ); free( (void *)p_dev->psz_device_name ); free( (void *)p_dev->pi_streams ); return( VLC_ENOMEM ); } for( i = 0; i < p_dev->i_streams; i++ ) { if( InitStreamInfo( i_dev, p_aout, i ) ) { UInt32 j; msg_Err( p_aout, "InitStreamInfo(%ld, %ld) failed", i_dev, i ); for( j = 0; j < i; j++ ) { FreeStreamInfo( i_dev, p_aout, j ); } free( (void *)p_dev->psz_device_name ); free( (void *)p_dev->pi_streams ); free( (void *)p_dev->pp_streams ); return( VLC_EGENERIC ); } } return( VLC_SUCCESS );}/***************************************************************************** * FreeDeviceInfo *****************************************************************************/static void FreeDeviceInfo( UInt32 i_dev, aout_instance_t * p_aout ){ UInt32 i; struct aout_sys_t * p_sys = p_aout->output.p_sys; struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev]; for( i = 0; i < p_dev->i_streams; i++ ) { FreeStreamInfo( i_dev, p_aout, i ); } free( (void *)p_dev->pp_streams ); free( (void *)p_dev->pi_streams ); free( (void *)p_dev->psz_device_name );}/***************************************************************************** * FreeHardwareInfo *****************************************************************************/static void FreeHardwareInfo( aout_instance_t * p_aout ){ UInt32 i; struct aout_sys_t * p_sys = p_aout->output.p_sys; vlc_mutex_lock( &p_sys->lock ); if( !p_sys->b_hwinfo ) { vlc_mutex_unlock( &p_sys->lock ); return; } for( i = 0; i < p_sys->i_devices; i++ ) { FreeDeviceInfo( i, p_aout ); } free( (void *)p_sys->p_options ); free( (void *)p_sys->p_devices ); p_sys->b_hwinfo = VLC_FALSE; vlc_mutex_unlock( &p_sys->lock );}/***************************************************************************** * GetStreamID *****************************************************************************/static int GetStreamID( AudioDeviceID devid, UInt32 i_idx, AudioStreamID * p_sid ){ OSStatus err; UInt32 i_param_size; AudioStreamID * p_stream_list; err = AudioDeviceGetPropertyInfo( devid, 0, FALSE, kAudioDevicePropertyStreams, &i_param_size, NULL ); if( err != noErr ) { return( VLC_EGENERIC ); } p_stream_list = (AudioStreamID *)malloc( i_param_size ); if( p_stream_list == NULL ) { return( VLC_ENOMEM ); } err = AudioDeviceGetProperty( devid, 0, FALSE, kAudioDevicePropertyStreams, &i_param_size, p_stream_list ); if( err != noErr ) { free( (void *)p_stream_list ); return( VLC_EGENERIC ); } *p_sid = p_stream_list[i_idx - 1]; free( (void *)p_stream_list ); return( VLC_SUCCESS );}/***************************************************************************** * InitStreamInfo *****************************************************************************/static int InitStreamInfo( UInt32 i_dev, aout_instance_t * p_aout, UInt32 i_idx ){ OSStatus err; AudioStreamID i_sid; UInt32 i, j, i_param_size; struct aout_sys_t * p_sys = p_aout->output.p_sys; struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev]; if( GetStreamID( p_dev->devid, i_idx + 1, &i_sid ) ) { msg_Err( p_aout, "GetStreamID(%ld, %ld) failed", i_dev, i_idx ); return( VLC_EGENERIC ); } err = AudioStreamGetPropertyInfo( i_sid, 0, kAudioStreamPropertyPhysicalFormats, &i_param_size, NULL ); if( err != noErr ) { msg_Err( p_aout, "could not retrieve the number of streams: [%4.4s]", (char *)&err ); return( VLC_EGENERIC ); }#define P_STREAMS p_dev->pp_streams[i_idx]#define I_STREAMS p_dev->pi_streams[i_idx] I_STREAMS = i_param_size / sizeof( AudioStreamBasicDescription ); P_STREAMS = (AudioStreamBasicDescription *)malloc( i_param_size ); if( P_STREAMS == NULL ) { msg_Err( p_aout, "out of memory" ); return( VLC_ENOMEM ); } memset( P_STREAMS, 0, i_param_size ); err = AudioStreamGetProperty( i_sid, 0, kAudioStreamPropertyPhysicalFormats, &i_param_size, P_STREAMS ); if( err != noErr ) { msg_Err( p_aout, "could no get the streams: [%4.4s]", (char *)&err ); free( (void *)P_STREAMS ); return( VLC_EGENERIC ); } for( j = 0; j < N_AOUT_CLASSES; j++ ) { vlc_bool_t b_found = 0; for( i = 0; i < I_STREAMS; i++ ) { if( j == 0 ) { msg_Dbg( p_aout, STREAM_FORMAT_MSG( "supported format", P_STREAMS[i] ) ); } if( ( P_STREAMS[i].mFormatID == 'IAC3' || P_STREAMS[i].mFormatID == kAudioFormat60958AC3 ) && !AOUT_FMT_NON_LINEAR( &p_aout->output.output ) ) { continue; } if( ( P_STREAMS[i].mFormatID != aout_classes[j].mFormatID ) || ( P_STREAMS[i].mChannelsPerFrame != aout_classes[j].mChannelsPerFrame ) ) { continue; } b_found = 1; break; } if( b_found ) { p_sys->p_options = (struct aout_option_t *) realloc( p_sys->p_options, ( p_sys->i_options + 1 ) * sizeof( struct aout_option_t ) ); if( p_sys->p_options == NULL ) { msg_Err( p_aout, "out of memory" ); free( (void *)P_STREAMS ); return( VLC_ENOMEM ); }#define AOUT_OPTION p_sys->p_options[p_sys->i_options] snprintf( AOUT_OPTION.sz_option, sizeof( AOUT_OPTION.sz_option ) / sizeof( AOUT_OPTION.sz_option[0] ) - 1, "%ld: %s (%s)", p_sys->i_options, p_dev->psz_device_name, aout_classes[j].psz_class ); AOUT_OPTION.i_sid = i_sid; AOUT_OPTION.i_dev = i_dev; AOUT_OPTION.i_idx = i_idx; AOUT_OPTION.i_sdx = i; AOUT_OPTION.i_cdx = j;#undef AOUT_OPTION p_sys->i_options++; } }#undef I_STREAMS#undef P_STREAMS return( VLC_SUCCESS );}/***************************************************************************** * FreeStreamInfo *****************************************************************************/static void FreeStreamInfo( UInt32 i_dev, aout_instance_t * p_aout, UInt32 i_idx ){ struct aout_sys_t * p_sys = p_aout->output.p_sys; struct aout_dev_t * p_dev = &p_sys->p_devices[i_dev]; free( (void *)p_dev->pp_streams[i_idx] );}/***************************************************************************** * InitDevice *****************************************************************************/static int InitDevice( aout_instance_t * p_aout ) { OSStatus err; vlc_value_t val; unsigned int i_option; vlc_bool_t b_found = VLC_FALSE; UInt32 i, i_stream, i_param_size, i_firstChannelNum; struct aout_dev_t * p_dev; struct aout_option_t * p_option; struct aout_sys_t * p_sys = p_aout->output.p_sys; if( var_Get( p_aout, "audio-device", &val ) < 0 ) { msg_Err( p_aout, "audio-device var does not exist" ); return( VLC_ENOVAR ); } i_option = val.i_int; p_option = &p_sys->p_options[i_option];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -