2016-10-27 17 views
3

私はVOIPアプリの基礎としてSpeakerBoxアプリを使用しています。私はすべてのものを動作させることができましたが、マイクからデバイスのスピーカーへのオーディオの「短絡」を取り除くことはできません。CallKitを使用したVOIPアプリでのオーディオの短絡

つまり、私が電話をすると、スピーカーと相手の声で自分の声を聞くことができます。これをどうやって変更できますか?

AVAudioSessionセットアップ:IOユニットの

AVAudioSession *sessionInstance = [AVAudioSession sharedInstance]; 

    NSError *error = nil; 
    [sessionInstance setCategory:AVAudioSessionCategoryPlayAndRecord error:&error]; 
    XThrowIfError((OSStatus)error.code, "couldn't set session's audio category"); 

    [sessionInstance setMode:AVAudioSessionModeVoiceChat error:&error]; 
    XThrowIfError((OSStatus)error.code, "couldn't set session's audio mode"); 

    NSTimeInterval bufferDuration = .005; 
    [sessionInstance setPreferredIOBufferDuration:bufferDuration error:&error]; 
    XThrowIfError((OSStatus)error.code, "couldn't set session's I/O buffer duration"); 

    [sessionInstance setPreferredSampleRate:44100 error:&error]; 
    XThrowIfError((OSStatus)error.code, "couldn't set session's preferred sample rate"); 

セットアップ:

- (void)setupIOUnit 
{ 
try { 
    // Create a new instance of Apple Voice Processing IO 

    AudioComponentDescription desc; 
    desc.componentType = kAudioUnitType_Output; 
    desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO; 
    desc.componentManufacturer = kAudioUnitManufacturer_Apple; 
    desc.componentFlags = 0; 
    desc.componentFlagsMask = 0; 

    AudioComponent comp = AudioComponentFindNext(NULL, &desc); 
    XThrowIfError(AudioComponentInstanceNew(comp, &_rioUnit), "couldn't create a new instance of Apple Voice Processing IO"); 

    // Enable input and output on Apple Voice Processing IO 
    // Input is enabled on the input scope of the input element 
    // Output is enabled on the output scope of the output element 

    UInt32 one = 1; 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one)), "could not enable input on Apple Voice Processing IO"); 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &one, sizeof(one)), "could not enable output on Apple Voice Processing IO"); 

    // Explicitly set the input and output client formats 
    // sample rate = 44100, num channels = 1, format = 32 bit floating point 

    CAStreamBasicDescription ioFormat = CAStreamBasicDescription(44100, 1, CAStreamBasicDescription::kPCMFormatFloat32, false); 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &ioFormat, sizeof(ioFormat)), "couldn't set the input client format on Apple Voice Processing IO"); 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &ioFormat, sizeof(ioFormat)), "couldn't set the output client format on Apple Voice Processing IO"); 

    // Set the MaximumFramesPerSlice property. This property is used to describe to an audio unit the maximum number 
    // of samples it will be asked to produce on any single given call to AudioUnitRender 
    UInt32 maxFramesPerSlice = 4096; 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFramesPerSlice, sizeof(UInt32)), "couldn't set max frames per slice on Apple Voice Processing IO"); 

    // Get the property value back from Apple Voice Processing IO. We are going to use this value to allocate buffers accordingly 
    UInt32 propSize = sizeof(UInt32); 
    XThrowIfError(AudioUnitGetProperty(_rioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFramesPerSlice, &propSize), "couldn't get max frames per slice on Apple Voice Processing IO"); 

    // We need references to certain data in the render callback 
    // This simple struct is used to hold that information 

    cd.rioUnit = _rioUnit; 
    cd.muteAudio = &_muteAudio; 
    cd.audioChainIsBeingReconstructed = &_audioChainIsBeingReconstructed; 

    // Set the render callback on Apple Voice Processing IO 
    AURenderCallbackStruct renderCallback; 
    renderCallback.inputProc = performRender; 
    renderCallback.inputProcRefCon = NULL; 
    XThrowIfError(AudioUnitSetProperty(_rioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(renderCallback)), "couldn't set render callback on Apple Voice Processing IO"); 

    // Initialize the Apple Voice Processing IO instance 
    XThrowIfError(AudioUnitInitialize(_rioUnit), "couldn't initialize Apple Voice Processing IO instance"); 
} 

catch (CAXException &e) { 
    NSLog(@"Error returned from setupIOUnit: %d: %s", (int)e.mError, e.mOperation); 
} 
catch (...) { 
    NSLog(@"Unknown error returned from setupIOUnit"); 
} 

return; 
} 

はIOUnitを開始するには:

NSError *error = nil; 
[[AVAudioSession sharedInstance] setActive:YES error:&error]; 
if (nil != error) NSLog(@"AVAudioSession set active (TRUE) failed with error: %@", error); 

OSStatus err = AudioOutputUnitStart(_rioUnit); 
if (err) NSLog(@"couldn't start Apple Voice Processing IO: %d", (int)err); 
return err; 

をIOUnit

NSError *error = nil; 
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error]; 
if (nil != error) NSLog(@"AVAudioSession set active (FALSE) failed with error: %@", error); 

OSStatus err = AudioOutputUnitStop(_rioUnit); 
if (err) NSLog(@"couldn't stop Apple Voice Processing IO: %d", (int)err); 
return err; 
を停止するには

私はSIPスタックとしてPJSIPを使用しており、Asteriskサーバーを持っています。この問題は、Android側のPJSIPの実装にも問題がないため、問題はクライアント側でなければなりません。

+0

私のアプリでもほぼ同じ問題が調査されています。私がスピーカーボックスの設定を正しく理解していれば、スピーカーボックスのコードはスピーカーへの入力をストリームします。私はそのサンプルコードを使用していません。私はpjsua_set_no_snd_dev()とpjsua_set_snd_dev()を使用しています。私の場合、もう片側がこの短絡問題の影響を受けます。ちなみに、CallKitを使用しないと、移植がうまくいきます。 –

+0

[OK]私の問題は古いiOSバージョンにも存在し、相手側が自分の声を聞くことができます。この問題の原因と原因はわかりません。あなたの場合、私は、pjsip関数を使用すると言うでしょう。 pjsipとCallKitの詳細については、https://trac.pjsip.org/repos/ticket/1941を参照してください。 –

答えて

2

WebRTCを使用して同じ問題が発生しました。私は結局のところ、AudioController.mmにIOUnitを設定するのではなく、PJSIP(私の場合はWebRTC)に任せるべきだという結論に達しました。 AudioController.mmのsetupAudioChainでコメントアウト[self setupIOUnit];などProviderDelegate.swiftdidActivate audioSessionstartAudio()

簡単な修正は次のとおりです。

関連する問題