使用 WebRTC 和 HoloLens 2 上的 TURN 服务器收听远程音轨两次

问题描述 投票:0回答:1

我正在为 HoloLens 2 开发一个类似 TeamViewer 的应用程序,使用: https://github.com/microsoft/MixedReality-WebRTC

我正在通过信令服务器将 WebApp (Webcam) 与 HoloLens 2 (ArCam) 连接。

现在,只需使用点对点连接,本地一切就一直运行良好。但在我切换到 TURN 服务器进行通信后,我在 HoloLens 2 上听到两次远程音频(来自 WebApp),就像回声一样。感觉就像有两个音轨同时播放,最小延迟为 0.1 秒。发生这种情况时,仅存在一个音频源和一个远程音轨。奇怪的是,这只发生在 HoloLens 上。在 Unity 编辑器中运行相同的应用程序也可以正常工作。 有人有建议吗,为什么会发生这种情况?

使用:Unity 2022.3.7f1

MS-WebRTC:2.0.2

MRTK:2.8.3

PS:我知道 Microsoft WebRTC 已被弃用,但目前对我来说没问题。

unity-game-engine webrtc hololens turn
1个回答
0
投票

https://github.com/microsoft/MixedReality-WebRTC/issues/717

如果遇到此问题,请确保取消注释 AudioRenderer 类的“OnAudioFilterRead(...)”方法中的所有内容。我只是确保代码不会在统一编辑器之外编译,而不是特定于平台的代码

(#if UNITY_EDITOR ... #endif)

protected void OnAudioFilterRead(float[] data, int channels) { #if UNITY_EDITOR // Don't do this outside the editor becuase it causes AudioTack to render twice on HoloLens var behavior = PadWithSine ? AudioTrackReadBuffer.PadBehavior.PadWithSine : AudioTrackReadBuffer.PadBehavior.PadWithZero; bool hasRead = false; bool hasOverrun = false; bool hasUnderrun = false; lock (_readBufferLock) { // Read and use buffer under lock to prevent disposal while in use. if (_readBuffer != null) { _readBuffer.Read(_audioSampleRate, channels, data, out int numSamplesRead, out hasOverrun, behavior); hasRead = true; hasUnderrun = numSamplesRead < data.Length; } } if (hasRead) { // Uncomment for debugging. //if (hasOverrun) //{ // Debug.LogWarning($"Overrun in track {Track.Name}"); //} //if (hasUnderrun) //{ // Debug.LogWarning($"Underrun in track {Track.Name}"); //} return; } // If there is no track/buffer, fill array with 0s. for (int i = 0; i < data.Length; ++i) { data[i] = 0.0f; } #endif }

© www.soinside.com 2019 - 2024. All rights reserved.