AudioUnit无法在tvOS上播放音频

时间:2020-08-06 14:59:33

标签: ios audio webrtc tvos audiounit

我正在为tvOS平台开发应用程序,以使用WebRTC(https://webrtc.org/)播放音频。 WebRTC使用AudioUnit进行音频播放(https://chromium.googlesource.com/external/webrtc/+/7a82467d0db0d61f466a1da54b94f6a136726a3c/sdk/objc/native/src/audio/voice_processing_audio_unit.mm)。它可以在iOS上完美运行,但在tvOS上会产生错误。

首先,我完全禁用了音频捕获。创建语音处理IO音频单元时发生第一个错误:

// 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返回-3000 OSStatus(我认为这意味着无效的组件ID)。可以通过替换kAudioUnitSubType_VoiceProcessingIO→kAudioUnitSubType_GenericOutput来解决此问题(我不确定这是否是正确的替代方法,但是错误消失了。)

之后,WebRTC尝试启用输出

// 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;
  }   

,它也不能正常工作:它返回-10879 OSStatus(我认为它表示无效的属性)。我认为问题出在提供kAudioOutputUnitProperty_EnableIO属性,但不知道为什么应该使用它。

任何想法公关建议都非常感谢。预先感谢。

0 个答案:

没有答案