I'm working on an application for tvOS platform for playing back audio using WebRTC (https://webrtc.org/). WebRTC uses AudioUnit for audio playout (https://chromium.googlesource.com/external/webrtc/+/7a82467d0db0d61f466a1da54b94f6a136726a3c/sdk/objc/native/src/audio/voice_processing_audio_unit.mm). It works perfectly on iOS, but produces errors on tvOS.
First of all I've disabled audio capturing at all. The first error happens when creating a Voice Processing IO audio unit:
// Create an audio component description to identify the Voice Processing
// I/O audio unit.
AudioComponentDescription vpio_unit_description;
vpio_unit_description.componentType = kAudioUnitType_Output;
vpio_unit_description.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
vpio_unit_description.componentManufacturer = kAudioUnitManufacturer_Apple;
vpio_unit_description.componentFlags = 0;
vpio_unit_description.componentFlagsMask = 0;
// Obtain an audio unit instance given the description.
AudioComponent found_vpio_unit_ref =
AudioComponentFindNext(nullptr, &vpio_unit_description);
// Create a Voice Processing IO audio unit.
OSStatus result = noErr;
result = AudioComponentInstanceNew(found_vpio_unit_ref, &vpio_unit_);
if (result != noErr) {
vpio_unit_ = nullptr;
RTCLogError(@"AudioComponentInstanceNew failed. Error=%ld.", (long)result);
return false;
}
AudioComponentInstanceNew returns -3000 OSStatus (I assume it means an invalid component ID). This issue can be fixed by replacing kAudioUnitSubType_VoiceProcessingIO → kAudioUnitSubType_GenericOutput (I'm not sure this is a correct replacement, but the error is gone).
After that WebRTC is trying to enable output
// Enable output on the output scope of the output element.
UInt32 enable_output = 1;
result = AudioUnitSetProperty(vpio_unit_, kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output, kOutputBus,
&enable_output, sizeof(enable_output));
if (result != noErr) {
DisposeAudioUnit();
RTCLogError(@"Failed to enable output on output scope of output element. "
"Error=%ld.",
(long)result);
return false;
}
and this doesn't work as well: it returns -10879 OSStatus (I assume it means an invalid property). I think the problem is in providing kAudioOutputUnitProperty_EnableIO property, but have no idea why should be utilized instead.
Any ideas pr advices are very much appreciated. Thanks in advance.