From 2ca2da67089d005b78feb6492040a3628ef09317 Mon Sep 17 00:00:00 2001 From: bnco Date: Fri, 26 Jan 2024 17:44:08 +0000 Subject: [PATCH] Add workaround for compatibility issue between Unity's WebRTC and Oculus/OpenXR SDK --- Unity/Assets/Editor/Packaging.meta | 8 +++ .../Editor/Packaging/AddPackageWebRTC.cs | 66 +++++++++++++++++++ .../Editor/Packaging/AddPackageWebRTC.cs.meta | 11 ++++ Unity/Assets/Editor/Ubiq.Editor.asmdef | 14 +++- .../Ubiq.Voip.Implementations.Null.asmdef | 3 +- ...ctionImpl.cs => NullPeerConnectionImpl.cs} | 12 ++-- ...cs.meta => NullPeerConnectionImpl.cs.meta} | 0 .../Implementations/Unity/AudioStatsFilter.cs | 4 +- .../Unity/PeerConnectionImpl.cs | 4 +- .../Unity/PeerConnectionImplFactory.cs | 4 ++ .../Unity/PeerConnectionMicrophone.cs | 4 +- .../Unity/SpatialisationCacheAudioFilter.cs | 4 +- .../Unity/SpatialisationRestoreAudioFilter.cs | 4 +- .../Ubiq.Voip.Implementations.Unity.asmdef | 13 +++- Unity/Assets/Samples/Demo (XRI)/Demo.unity | 24 +++---- Unity/Packages/manifest.json | 2 +- Unity/Packages/packages-lock.json | 8 +-- 17 files changed, 152 insertions(+), 33 deletions(-) create mode 100644 Unity/Assets/Editor/Packaging.meta create mode 100644 Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs create mode 100644 Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs.meta rename Unity/Assets/Runtime/Voip/Implementations/{Null/PeerConnectionImpl.cs => NullPeerConnectionImpl.cs} (57%) rename Unity/Assets/Runtime/Voip/Implementations/{Null/PeerConnectionImpl.cs.meta => NullPeerConnectionImpl.cs.meta} (100%) diff --git a/Unity/Assets/Editor/Packaging.meta b/Unity/Assets/Editor/Packaging.meta new file mode 100644 index 000000000..76b91d970 --- /dev/null +++ b/Unity/Assets/Editor/Packaging.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a7ed4fbec2f112c40af1a6f5cdabdcf0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs b/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs new file mode 100644 index 000000000..b88898b75 --- /dev/null +++ b/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs @@ -0,0 +1,66 @@ +#if !UNITY_WEBRTC_NO_VULKAN_HOOK && !UBIQ_SKIPCHECK_WEBRTCCOMPATIBILITY +using UnityEngine; +using UnityEditor; +using UnityEditor.PackageManager; +using UnityEditor.PackageManager.Requests; + +namespace Ubiq.Samples.Demo.Editor +{ + [InitializeOnLoad] + public class AddPackageWebRTC + { + private const string FORK_URL = "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git"; +#if UNITY_WEBRTC + AddAndRemoveRequest request; +#else + AddRequest request; +#endif + AddAndRemoveRequest foo; + + static AddPackageWebRTC() + { + Debug.Log("Ubiq attempting to add WebRTC to project requirements." + + " Please wait..."); + var instance = new AddPackageWebRTC(); +#if UNITY_WEBRTC + Debug.LogWarning("Ubiq has detected an existing com.unity.webrtc" + + " package. This package has compatibility issues with the" + + " Oculus/OpenXR SDK. Ubiq will remove this package and" + + " replace it with a modified fork which is compatible. If you" + + " would prefer to skip this check and prevent this behaviour," + + " add the string UBIQ_SKIPCHECK_WEBRTCCOMPATIBILITY to your" + + " scripting define symbols."); + instance.request = Client.AddAndRemove( + packagesToAdd : new string[] {FORK_URL}, + packagesToRemove : new string[] {"com.unity.webrtc"} + ); +#else + instance.request = Client.Add(FORK_URL); +#endif + EditorApplication.update += instance.Update; + } + + void Update() + { + if (request == null) + { + EditorApplication.update -= Update; + } + + if (request.Status == StatusCode.Failure) + { + var error = request.Error != null ? request.Error.message : "None specified"; + Debug.LogError($"Ubiq was unable to add WebRTC to project requirements. Error: {error}"); + EditorApplication.update -= Update; + } + + if (request.Status == StatusCode.Success) + { + EditorApplication.update -= Update; + Debug.Log("Ubiq added WebRTC to project requirements."); + AssetDatabase.Refresh(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs.meta b/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs.meta new file mode 100644 index 000000000..0df6ef8d3 --- /dev/null +++ b/Unity/Assets/Editor/Packaging/AddPackageWebRTC.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49066e1f294d47c44a6afe401e9661da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity/Assets/Editor/Ubiq.Editor.asmdef b/Unity/Assets/Editor/Ubiq.Editor.asmdef index 70d38d7c8..7ad45c395 100644 --- a/Unity/Assets/Editor/Ubiq.Editor.asmdef +++ b/Unity/Assets/Editor/Ubiq.Editor.asmdef @@ -1,5 +1,6 @@ { "name": "Ubiq.Editor", + "rootNamespace": "", "references": [ "GUID:ab979a98ba0be4546bceb48f770b11c8", "GUID:4be54a12296e0404db7080c914e17b05" @@ -13,6 +14,17 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.webrtc", + "expression": "0.0.0", + "define": "UNITY_WEBRTC" + }, + { + "name": "com.unity.webrtc-no-vulkan-hook", + "expression": "0.0.0", + "define": "UNITY_WEBRTC_NO_VULKAN_HOOK" + } + ], "noEngineReferences": false } \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Null/Ubiq.Voip.Implementations.Null.asmdef b/Unity/Assets/Runtime/Voip/Implementations/Null/Ubiq.Voip.Implementations.Null.asmdef index a3b7c7dd2..cdd9b2e2e 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Null/Ubiq.Voip.Implementations.Null.asmdef +++ b/Unity/Assets/Runtime/Voip/Implementations/Null/Ubiq.Voip.Implementations.Null.asmdef @@ -14,14 +14,15 @@ "iOS", "LinuxStandalone64", "CloudRendering", - "Lumin", "macOSStandalone", "PS4", "PS5", + "QNX", "Stadia", "Switch", "tvOS", "WSA", + "VisionOS", "WebGL", "WindowsStandalone32", "WindowsStandalone64", diff --git a/Unity/Assets/Runtime/Voip/Implementations/Null/PeerConnectionImpl.cs b/Unity/Assets/Runtime/Voip/Implementations/NullPeerConnectionImpl.cs similarity index 57% rename from Unity/Assets/Runtime/Voip/Implementations/Null/PeerConnectionImpl.cs rename to Unity/Assets/Runtime/Voip/Implementations/NullPeerConnectionImpl.cs index ddb13903e..caf20c102 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Null/PeerConnectionImpl.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/NullPeerConnectionImpl.cs @@ -1,18 +1,14 @@ +using System; using System.Collections.Generic; using UnityEngine; -namespace Ubiq.Voip.Implementations.Null +namespace Ubiq.Voip.Implementations { - public class PeerConnectionImpl : IPeerConnectionImpl + public class NullPeerConnectionImpl : IPeerConnectionImpl { -#pragma warning disable CS0067 - public event IceConnectionStateChangedDelegate iceConnectionStateChanged; - public event PeerConnectionStateChangedDelegate peerConnectionStateChanged; -#pragma warning restore CS0067 public void Dispose() {} - public PlaybackStats GetLastFramePlaybackStats() => new PlaybackStats(); public void ProcessSignalingMessage(string json) {} - public void Setup(IPeerConnectionContext context, bool polite, List iceServers) + public void Setup(IPeerConnectionContext context, bool polite, List iceServers, Action playbackStatsPushed, Action recordStatsPushed, Action iceConnectionStateChanged, Action peerConnectionStateChanged) { // Pretend we are connected to silence/hide warnings if (iceConnectionStateChanged != null) diff --git a/Unity/Assets/Runtime/Voip/Implementations/Null/PeerConnectionImpl.cs.meta b/Unity/Assets/Runtime/Voip/Implementations/NullPeerConnectionImpl.cs.meta similarity index 100% rename from Unity/Assets/Runtime/Voip/Implementations/Null/PeerConnectionImpl.cs.meta rename to Unity/Assets/Runtime/Voip/Implementations/NullPeerConnectionImpl.cs.meta diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/AudioStatsFilter.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/AudioStatsFilter.cs index 651759721..f4dcdd86f 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/AudioStatsFilter.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/AudioStatsFilter.cs @@ -1,3 +1,4 @@ +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK using System; using UnityEngine; using System.Collections.Concurrent; @@ -70,4 +71,5 @@ private void OnAudioFilterRead(float[] data, int channels) statsQueue.Enqueue(new AudioStats(length,volumeSum,0)); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImpl.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImpl.cs index b76546af7..f2560ff71 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImpl.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImpl.cs @@ -1,3 +1,4 @@ +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK using System; using System.Collections; using System.Collections.Generic; @@ -486,4 +487,5 @@ private static void Send(IPeerConnectionContext context, RTCIceCandidate ic) ))); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImplFactory.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImplFactory.cs index 56c0b4c60..8a739e9bf 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImplFactory.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionImplFactory.cs @@ -4,7 +4,11 @@ public static class PeerConnectionImplFactory { public static IPeerConnectionImpl Create() { +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK return new Ubiq.Voip.Implementations.Unity.PeerConnectionImpl(); +#else + return new Ubiq.Voip.Implementations.NullPeerConnectionImpl(); +#endif } } } diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionMicrophone.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionMicrophone.cs index 86397d05a..4eeabea91 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionMicrophone.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/PeerConnectionMicrophone.cs @@ -1,3 +1,4 @@ +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK using System; using System.Collections; using System.Collections.Generic; @@ -144,4 +145,5 @@ public void RemoveUser(GameObject user) users.Remove(user); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationCacheAudioFilter.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationCacheAudioFilter.cs index d7d737c84..d07e8916f 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationCacheAudioFilter.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationCacheAudioFilter.cs @@ -1,3 +1,4 @@ +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK using UnityEngine; namespace Ubiq.Voip.Implementations.Unity @@ -26,4 +27,5 @@ void OnAudioFilterRead(float[] data, int channels) } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationRestoreAudioFilter.cs b/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationRestoreAudioFilter.cs index 0f6591d35..b421fd2b1 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationRestoreAudioFilter.cs +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/SpatialisationRestoreAudioFilter.cs @@ -1,3 +1,4 @@ +#if UNITY_WEBRTC || UNITY_WEBRTC_NO_VULKAN_HOOK using UnityEngine; namespace Ubiq.Voip.Implementations.Unity @@ -31,4 +32,5 @@ void OnAudioFilterRead(float[] data, int channels) } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Unity/Assets/Runtime/Voip/Implementations/Unity/Ubiq.Voip.Implementations.Unity.asmdef b/Unity/Assets/Runtime/Voip/Implementations/Unity/Ubiq.Voip.Implementations.Unity.asmdef index ef5145f7e..76f1310ad 100644 --- a/Unity/Assets/Runtime/Voip/Implementations/Unity/Ubiq.Voip.Implementations.Unity.asmdef +++ b/Unity/Assets/Runtime/Voip/Implementations/Unity/Ubiq.Voip.Implementations.Unity.asmdef @@ -18,6 +18,17 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.webrtc", + "expression": "0.0.0", + "define": "UNITY_WEBRTC" + }, + { + "name": "com.unity.webrtc-no-vulkan-hook", + "expression": "0.0.0", + "define": "UNITY_WEBRTC_NO_VULKAN_HOOK" + } + ], "noEngineReferences": false } \ No newline at end of file diff --git a/Unity/Assets/Samples/Demo (XRI)/Demo.unity b/Unity/Assets/Samples/Demo (XRI)/Demo.unity index 61697e701..be2cd4754 100644 --- a/Unity/Assets/Samples/Demo (XRI)/Demo.unity +++ b/Unity/Assets/Samples/Demo (XRI)/Demo.unity @@ -677,32 +677,32 @@ PrefabInstance: - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_SizeDelta.x - value: 30 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_SizeDelta.y - value: 40 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchoredPosition.x - value: 53 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchoredPosition.y - value: -22.5 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2407431680527197411, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} @@ -982,32 +982,32 @@ PrefabInstance: - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_SizeDelta.x - value: 30 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_SizeDelta.y - value: 40 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchoredPosition.x - value: 21 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} propertyPath: m_AnchoredPosition.y - value: -22.5 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8225375711087241992, guid: 46c1f5d5a11cf5042886aabd56e7b9d7, type: 3} diff --git a/Unity/Packages/manifest.json b/Unity/Packages/manifest.json index f93d0a315..c3ad2a0ed 100644 --- a/Unity/Packages/manifest.json +++ b/Unity/Packages/manifest.json @@ -11,7 +11,7 @@ "com.unity.timeline": "1.7.6", "com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4", "com.unity.ugui": "1.0.0", - "com.unity.webrtc": "3.0.0-pre.7", + "com.unity.webrtc-no-vulkan-hook": "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git", "com.unity.xr.interaction.toolkit": "2.5.2", "com.unity.xr.management": "4.4.0", "com.unity.xr.oculus": "4.1.2", diff --git a/Unity/Packages/packages-lock.json b/Unity/Packages/packages-lock.json index 90a28a8e5..c2f57a387 100644 --- a/Unity/Packages/packages-lock.json +++ b/Unity/Packages/packages-lock.json @@ -145,16 +145,16 @@ "com.unity.modules.imgui": "1.0.0" } }, - "com.unity.webrtc": { - "version": "3.0.0-pre.7", + "com.unity.webrtc-no-vulkan-hook": { + "version": "https://github.com/UCL-VR/unity-webrtc-no-vulkan-hook.git", "depth": 0, - "source": "registry", + "source": "git", "dependencies": { "com.unity.modules.jsonserialize": "1.0.0", "com.unity.editorcoroutines": "1.0.0", "com.unity.modules.audio": "1.0.0" }, - "url": "https://packages.unity.com" + "hash": "deac61d7009e3d04bd7f8e1f8d33227bdddac153" }, "com.unity.xr.core-utils": { "version": "2.2.3",