📄 auhal.c
字号:
p_aout->output.output.i_physical_channels |= AOUT_CHAN_LEFT; continue; case kAudioChannelLabel_Right: p_aout->output.output.i_physical_channels |= AOUT_CHAN_RIGHT; continue; case kAudioChannelLabel_Center: p_aout->output.output.i_physical_channels |= AOUT_CHAN_CENTER; continue; case kAudioChannelLabel_LFEScreen: p_aout->output.output.i_physical_channels |= AOUT_CHAN_LFE; continue; case kAudioChannelLabel_LeftSurround: p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARLEFT; continue; case kAudioChannelLabel_RightSurround: p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARRIGHT; continue; case kAudioChannelLabel_RearSurroundLeft: p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLELEFT; continue; case kAudioChannelLabel_RearSurroundRight: p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLERIGHT; continue; case kAudioChannelLabel_CenterSurround: p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARCENTER; continue; default: msg_Warn( p_aout, "Unrecognized channel form provided by driver: %d", (int)layout->mChannelDescriptions[i].mChannelLabel ); if( i == 0 ) { msg_Warn( p_aout, "Probably no channellayout is set. force based on channelcount" ); switch( layout->mNumberChannelDescriptions ) { /* We make assumptions based on number of channels here. * Unfortunatly Apple has provided no 100% method to retrieve the speaker configuration */ case 1: p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER; break; case 4: p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; break; case 6: p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; break; case 7: p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_REARCENTER; break; case 8: p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_LFE | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT; break; case 2: default: p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; } } break; } } free( layout ); msg_Dbg( p_aout, "defined %d physical channels for vlc core", aout_FormatNbChannels( &p_aout->output.output ) ); msg_Dbg( p_aout, "%s", aout_FormatPrintChannels( &p_aout->output.output )); AudioChannelLayout new_layout; memset (&new_layout, 0, sizeof(new_layout)); switch( aout_FormatNbChannels( &p_aout->output.output ) ) { case 1: new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono; break; case 2: new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo; break; case 3: if( p_aout->output.output.i_physical_channels & AOUT_CHAN_CENTER ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_7; // L R C } else if( p_aout->output.output.i_physical_channels & AOUT_CHAN_LFE ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_4; // L R LFE } break; case 4: if( p_aout->output.output.i_physical_channels & ( AOUT_CHAN_CENTER | AOUT_CHAN_LFE ) ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_10; // L R C LFE } else if( p_aout->output.output.i_physical_channels & ( AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT ) ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_3; // L R Ls Rs } else if( p_aout->output.output.i_physical_channels & ( AOUT_CHAN_CENTER | AOUT_CHAN_REARCENTER ) ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_3; // L R C Cs } break; case 5: if( p_aout->output.output.i_physical_channels & ( AOUT_CHAN_CENTER ) ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_19; // L R Ls Rs C } else if( p_aout->output.output.i_physical_channels & ( AOUT_CHAN_LFE ) ) { new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_18; // L R Ls Rs LFE } break; case 6: new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_20; // L R Ls Rs C LFE break; case 7: /* FIXME: This is incorrect. VLC uses the internal ordering: L R Lm Rm Lr Rr C LFE but this is wrong */ new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_6_1_A; // L R C LFE Ls Rs Cs break; case 8: /* FIXME: This is incorrect. VLC uses the internal ordering: L R Lm Rm Lr Rr C LFE but this is wrong */ new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_7_1_A; // L R C LFE Ls Rs Lc Rc break; } /* Set up the format to be used */ DeviceFormat.mSampleRate = p_aout->output.output.i_rate; DeviceFormat.mFormatID = kAudioFormatLinearPCM; /* We use float 32. It's the best supported format by both VLC and Coreaudio */ p_aout->output.output.i_format = VLC_FOURCC( 'f','l','3','2'); DeviceFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; DeviceFormat.mBitsPerChannel = 32; DeviceFormat.mChannelsPerFrame = aout_FormatNbChannels( &p_aout->output.output ); /* Calculate framesizes and stuff */ aout_FormatPrepare( &p_aout->output.output ); DeviceFormat.mFramesPerPacket = 1; DeviceFormat.mBytesPerFrame = DeviceFormat.mBitsPerChannel * DeviceFormat.mChannelsPerFrame / 8; DeviceFormat.mBytesPerPacket = DeviceFormat.mBytesPerFrame * DeviceFormat.mFramesPerPacket; i_param_size = sizeof(AudioStreamBasicDescription); /* Set desired format (Use CAStreamBasicDescription )*/ verify_noerr( AudioUnitSetProperty( p_sys->au_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &DeviceFormat, i_param_size )); msg_Dbg( p_aout, STREAM_FORMAT_MSG( "we set the AU format: " , DeviceFormat ) ); /* Retrieve actual format??? */ verify_noerr( AudioUnitGetProperty( p_sys->au_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &DeviceFormat, &i_param_size )); msg_Dbg( p_aout, STREAM_FORMAT_MSG( "the actual set AU format is " , DeviceFormat ) ); p_aout->output.i_nb_samples = 2048; aout_VolumeSoftInit( p_aout ); /* Let's pray for the following operation to be atomic... */ p_sys->clock_diff = - (mtime_t) AudioConvertHostTimeToNanos( AudioGetCurrentHostTime() ) / 1000; p_sys->clock_diff += mdate(); p_sys->i_read_bytes = 0; p_sys->i_total_bytes = 0; /* set the IOproc callback */ AURenderCallbackStruct input; input.inputProc = (AURenderCallback) RenderCallbackAnalog; input.inputProcRefCon = p_aout; verify_noerr( AudioUnitSetProperty( p_sys->au_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof( input ) ) ); input.inputProc = (AURenderCallback) RenderCallbackAnalog; input.inputProcRefCon = p_aout; /* Set the new_layout as the layout VLC feeds to the AU unit */ verify_noerr( AudioUnitSetProperty( p_sys->au_unit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &new_layout, sizeof(new_layout) ) ); /* AU initiliaze */ verify_noerr( AudioUnitInitialize(p_sys->au_unit) ); verify_noerr( AudioOutputUnitStart(p_sys->au_unit) ); return( VLC_SUCCESS );}/***************************************************************************** * Close: Close HAL AudioUnit *****************************************************************************/static void Close( vlc_object_t * p_this ){ aout_instance_t *p_aout = (aout_instance_t *)p_this; struct aout_sys_t *p_sys = p_aout->output.p_sys; if( p_sys->au_unit ) { verify_noerr( AudioOutputUnitStop( p_sys->au_unit ) ); verify_noerr( AudioUnitUninitialize( p_sys->au_unit ) ); verify_noerr( CloseComponent( p_sys->au_unit ) ); } free( p_sys );}/***************************************************************************** * Play: nothing to do *****************************************************************************/static void Play( aout_instance_t * p_aout ){}/***************************************************************************** * Probe *****************************************************************************/static int Probe( 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; /* Get number of devices */ err = AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices, &i_param_size, NULL ); if( err != noErr ) { msg_Err( p_aout, "could not get number of devices: [%4.4s]", (char *)&err ); goto error; } p_sys->i_devices = i_param_size / sizeof( AudioDeviceID ); if( p_sys->i_devices < 1 ) { msg_Err( p_aout, "no devices found" ); goto error; } msg_Dbg( p_aout, "system has [%ld] device(s)", p_sys->i_devices ); /* Allocate DeviceID array */ p_devices = (AudioDeviceID *)malloc( i_param_size ); if( p_devices == NULL ) { msg_Err( p_aout, "out of memory" ); goto error; } /* Populate DeviceID array */ err = AudioHardwareGetProperty( kAudioHardwarePropertyDevices, &i_param_size, (void *)p_devices ); if( err != noErr ) { msg_Err( p_aout, "could not get the device ID's: [%4.4s]", (char *)&err ); goto error; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -