📄 auhal.c
字号:
/* Find the ID of the default Device */ i_param_size = sizeof( AudioDeviceID ); err = AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice, &i_param_size, (void *)&devid_def ); if( err != noErr ) { msg_Err( p_aout, "could not get default audio device: [%4.4s]", (char *)&err ); goto error; } p_sys->i_default_dev = devid_def; 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 ); for( i = 0; i < p_sys->i_devices; i++ ) { char psz_devuid[1024]; char psz_name[1024]; CFStringRef devUID; i_param_size = sizeof psz_name; err = AudioDeviceGetProperty( p_devices[i], 0, VLC_FALSE, kAudioDevicePropertyDeviceName, &i_param_size, psz_name); if( err ) goto error; i_param_size = sizeof(CFStringRef); err = AudioDeviceGetProperty( p_devices[i], 0, VLC_FALSE, kAudioDevicePropertyDeviceUID, &i_param_size, &devUID); if( err ) goto error; CFStringGetCString( devUID, psz_devuid, sizeof psz_devuid, CFStringGetSystemEncoding() ); msg_Dbg( p_aout, "DevID: %lu DevName: %s DevUID: %s", p_devices[i], psz_name, psz_devuid ); CFRelease( devUID ); if( !AudioDeviceHasOutput( p_devices[i]) ) { msg_Dbg( p_aout, "this device is INPUT only. skipping..." ); continue; } val.i_int = (int) p_devices[i]; text.psz_string = psz_name; var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text ); if( devid_def == p_devices[i] ) { var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL ); var_Set( p_aout, "audio-device", val ); } } var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart, NULL ); /* attach a Listener so that we are notified of a change in the Device setup */ /* err = AudioHardwareAddPropertyListener( kAudioHardwarePropertyDevices, HardwareListener, (void *)p_aout ); if( err ) goto error;*/ msg_Dbg( p_aout, "succesful finish of deviceslist" ); if( p_devices ) free( p_devices ); return (VLC_SUCCESS);error: var_Destroy( p_aout, "audio-device" ); if( p_devices ) free( p_devices ); return VLC_EGENERIC;}/***************************************************************************** * DeviceDigitalMode: Check i_dev_id for digital stream support. *****************************************************************************/static int DeviceDigitalMode( aout_instance_t *p_aout, AudioDeviceID i_dev_id ){ OSStatus err = noErr; UInt32 i_param_size; AudioStreamBasicDescription *p_format_list; int i, i_formats; struct aout_sys_t *p_sys = p_aout->output.p_sys; p_sys->b_supports_digital = VLC_FALSE; err = AudioDeviceGetPropertyInfo( i_dev_id, 0, FALSE, kAudioDevicePropertyStreamFormats, &i_param_size, NULL ); if( err != noErr ) { msg_Err( p_aout, "could not get number of streamsformats: [%4.4s]", (char *)&err ); return( VLC_EGENERIC ); } i_formats = i_param_size / sizeof( AudioStreamBasicDescription ); p_format_list = (AudioStreamBasicDescription *)malloc( i_param_size ); if( p_format_list == NULL ) { return( VLC_ENOMEM ); } err = AudioDeviceGetProperty( i_dev_id, 0, FALSE, kAudioDevicePropertyStreamFormats, &i_param_size, (void *)p_format_list ); if( err != noErr ) { msg_Err( p_aout, "could not get the list of formats: [%4.4s]", (char *)&err ); return( VLC_EGENERIC ); } for( i = 0; i < i_formats; i++ ) { msg_Dbg( p_aout, STREAM_FORMAT_MSG( "supported format", p_format_list[i] ) ); if( p_format_list[i].mFormatID == 'IAC3' || p_format_list[i].mFormatID == kAudioFormat60958AC3 ) { p_sys->b_supports_digital = VLC_TRUE; msg_Dbg( p_aout, "this device supports a digital stream" ); break; } } free( (void *)p_format_list ); return VLC_SUCCESS;}/***************************************************************************** * RenderCallbackAnalog: This function is called everytime the AudioUnit wants * us to provide some more audio data. * Don't print anything during normal playback, calling blocking function from * this callback is not allowed. *****************************************************************************/static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, unsigned int inBusNummer, unsigned int inNumberFrames, AudioBufferList *ioData ){ AudioTimeStamp host_time; mtime_t current_date = 0; uint32_t i_mData_bytes = 0; aout_instance_t * p_aout = (aout_instance_t *)_p_aout; struct aout_sys_t * p_sys = p_aout->output.p_sys; host_time.mFlags = kAudioTimeStampHostTimeValid; AudioDeviceTranslateTime( p_sys->i_selected_dev, inTimeStamp, &host_time ); p_sys->clock_diff = - (mtime_t) AudioConvertHostTimeToNanos( AudioGetCurrentHostTime() ) / 1000; p_sys->clock_diff += mdate(); current_date = p_sys->clock_diff + AudioConvertHostTimeToNanos( host_time.mHostTime ) / 1000; if( ioData == NULL && ioData->mNumberBuffers < 1 ) { msg_Err( p_aout, "no iodata or buffers"); return 0; } if( ioData->mNumberBuffers > 1 ) msg_Err( p_aout, "well this is weird. seems like there is more than one buffer..." ); if( p_sys->i_total_bytes > 0 ) { i_mData_bytes = __MIN( p_sys->i_total_bytes - p_sys->i_read_bytes, ioData->mBuffers[0].mDataByteSize ); p_aout->p_vlc->pf_memcpy( ioData->mBuffers[0].mData, &p_sys->p_remainder_buffer[p_sys->i_read_bytes], i_mData_bytes ); p_sys->i_read_bytes += i_mData_bytes; current_date += (mtime_t) ( (mtime_t) 1000000 / p_aout->output.output.i_rate ) * ( i_mData_bytes / 4 / aout_FormatNbChannels( &p_aout->output.output ) ); // 4 is fl32 specific if( p_sys->i_read_bytes >= p_sys->i_total_bytes ) p_sys->i_read_bytes = p_sys->i_total_bytes = 0; } while( i_mData_bytes < ioData->mBuffers[0].mDataByteSize ) { /* We don't have enough data yet */ aout_buffer_t * p_buffer; p_buffer = aout_OutputNextBuffer( p_aout, current_date , VLC_FALSE ); if( p_buffer != NULL ) { uint32_t i_second_mData_bytes = __MIN( p_buffer->i_nb_bytes, ioData->mBuffers[0].mDataByteSize - i_mData_bytes ); p_aout->p_vlc->pf_memcpy( (uint8_t *)ioData->mBuffers[0].mData + i_mData_bytes, p_buffer->p_buffer, i_second_mData_bytes ); i_mData_bytes += i_second_mData_bytes; if( i_mData_bytes >= ioData->mBuffers[0].mDataByteSize ) { p_sys->i_total_bytes = p_buffer->i_nb_bytes - i_second_mData_bytes; p_aout->p_vlc->pf_memcpy( p_sys->p_remainder_buffer, &p_buffer->p_buffer[i_second_mData_bytes], p_sys->i_total_bytes ); } else { // update current_date current_date += (mtime_t) ( (mtime_t) 1000000 / p_aout->output.output.i_rate ) * ( i_second_mData_bytes / 4 / aout_FormatNbChannels( &p_aout->output.output ) ); // 4 is fl32 specific } aout_BufferFree( p_buffer ); } else { p_aout->p_vlc->pf_memset( (uint8_t *)ioData->mBuffers[0].mData +i_mData_bytes, 0, ioData->mBuffers[0].mDataByteSize - i_mData_bytes ); i_mData_bytes += ioData->mBuffers[0].mDataByteSize - i_mData_bytes; } } return( noErr ); }/***************************************************************************** * Setup a digital stream *****************************************************************************/static int DigitalInit( aout_instance_t * p_aout ){ OSStatus err = noErr; UInt32 i, i_param_size; AudioDeviceID devid_def; AudioDeviceID *p_devices = NULL; vlc_value_t val, text; struct aout_sys_t *p_sys = p_aout->output.p_sys; return (VLC_SUCCESS);error: return VLC_EGENERIC;}int AudioDeviceHasOutput( AudioDeviceID i_dev_id ){ UInt32 dataSize; Boolean isWritable; verify_noerr( AudioDeviceGetPropertyInfo( i_dev_id, 0, FALSE, kAudioDevicePropertyStreams, &dataSize, &isWritable) ); if (dataSize == 0) return FALSE; return TRUE;}/***************************************************************************** * HardwareListener: Warns us of changes in the list of registered devices *****************************************************************************/static OSStatus HardwareListener( AudioHardwarePropertyID inPropertyID, void * inClientData ){ OSStatus err = noErr; aout_instance_t *p_aout = (aout_instance_t *)inClientData; /* struct aout_sys_t *p_sys = p_aout->output.p_sys; */ switch( inPropertyID ) { case kAudioHardwarePropertyDevices: { /* something changed in the list of devices */ /* We trigger the audio-device's aout_ChannelsRestart callback */ var_Change( p_aout, "audio-device", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL ); } break; } return( err );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -