Skip to content

Commit 926137e

Browse files
committed
Fix name + Add debug GetAudioRoute method + print current audio route in debug builds
1 parent b2c4b5a commit 926137e

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

Packages/StreamVideo/Runtime/Core/DeviceManagers/StreamAudioDeviceManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ protected override void OnUpdate()
159159
base.OnUpdate();
160160

161161
TrySyncMicrophoneAudioSourceReadPosWithMicrophoneWritePos();
162+
163+
// Check audio route every second on Android with native audio bindings
164+
#if UNITY_ANDROID && STREAM_DEBUG_ENABLED
165+
if (RtcSession.UseNativeAudioBindings)
166+
{
167+
var currentTime = Time.time;
168+
if (currentTime - _lastAudioRouteCheckTime >= AudioRouteCheckInterval)
169+
{
170+
_lastAudioRouteCheckTime = currentTime;
171+
NativeAudioDeviceManager.GetAudioRoute();
172+
}
173+
}
174+
#endif
162175
}
163176

164177
protected override void OnDisposing()
@@ -185,6 +198,9 @@ protected override void OnDisposing()
185198

186199
private NativeAudioDeviceManager.AudioDeviceInfo[] _inputDevicesBuffer
187200
= new NativeAudioDeviceManager.AudioDeviceInfo[128];
201+
202+
private float _lastAudioRouteCheckTime;
203+
private const float AudioRouteCheckInterval = 5.0f;
188204

189205
private AudioSource GetOrCreateTargetAudioSource()
190206
{

Packages/StreamVideo/Runtime/Core/StreamVideoClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public void SetAndroidAudioUsageMode(AndroidAudioUsageMode usageMode)
358358
{
359359
#if STREAM_NATIVE_AUDIO
360360
WebRTC.SetAndroidAudioUsageMode((Unity.WebRTC.AndroidAudioUsageMode)usageMode);
361-
_logs.Warning("Audio Playback is paused. This stops all audio coming from StreamVideo SDK on Android platform.");
361+
_logs.Warning("Set audio usage mode to " + Enum.GetName(typeof(AndroidAudioUsageMode), usageMode));
362362
#else
363363
throw new NotSupportedException(
364364
$"{nameof(SetAndroidAudioUsageMode)} is only supported on Android platform.");

Packages/StreamVideo/Runtime/Libs/DeviceManagers/AndroidAudioDeviceManager.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ public static void SetPreferredAudioRoute(NativeAudioDeviceManager.AudioRouting
2222
CallStatic("setAudioRoute", (int)audioRoute);
2323
}
2424

25+
/// <summary>
26+
/// Gets the current audio route and prints it to Unity console.
27+
/// </summary>
28+
public static void GetAudioRoute()
29+
{
30+
var routeId = CallStatic<int>("getAudioRoute");
31+
var routeName = GetRouteName(routeId);
32+
Debug.Log($"[AndroidAudioDeviceManager] Current audio route: {routeName} (ID: {routeId})");
33+
}
34+
35+
private static string GetRouteName(int routeId)
36+
{
37+
switch (routeId)
38+
{
39+
case 0: return "Earpiece";
40+
case 1: return "Speaker";
41+
case 2: return "Bluetooth";
42+
case 3: return "Wired Headset";
43+
case 4: return "USB Headset";
44+
default: return $"Unknown ({routeId})";
45+
}
46+
}
47+
2548
/// <summary>
2649
/// For Android, the devices represent available audio routing options instead of physical devices.
2750
/// </summary>

Packages/StreamVideo/Runtime/Libs/DeviceManagers/NativeAudioDeviceManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public static void GetAudioInputDevices(ref AudioDeviceInfo[] result)
7676
AndroidAudioDeviceManager.GetAudioInputDevices(ref result);
7777
#else
7878
UnityEngine.Debug.LogWarning($"{nameof(GetAudioInputDevices)} is not supported on this platform: " + UnityEngine.Application.platform);
79+
#endif
80+
}
81+
82+
/// <summary>
83+
/// Gets the current audio route and prints it to Unity console.
84+
/// </summary>
85+
public static void GetAudioRoute()
86+
{
87+
#if UNITY_ANDROID
88+
AndroidAudioDeviceManager.GetAudioRoute();
89+
#else
90+
UnityEngine.Debug.LogWarning($"{nameof(GetAudioRoute)} is not supported on this platform: " + UnityEngine.Application.platform);
7991
#endif
8092
}
8193
}

Packages/StreamVideo/Runtime/Libs/io.stream.unity.webrtc/Runtime/Scripts/Context.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public void UnmuteAndroidAudioPlayback()
424424

425425
public void SetAndroidAudioUsageMode(int usage)
426426
{
427-
NativeMethods.SetAndroidAudioUsageMode(self, usage);
427+
NativeMethods.SetAudioUsageMode(self, usage);
428428
}
429429
#endif
430430

Packages/StreamVideo/Runtime/Libs/io.stream.unity.webrtc/Runtime/Scripts/WebRTC.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ public static extern IntPtr CreateVideoRenderer(
18871887
public static extern void GetAudioProcessingModuleConfig(IntPtr context, out bool enabled, out bool echoCancellationEnabled, out bool autoGainEnabled, out bool noiseSuppressionEnabled, out int noiseSuppressionLevel);
18881888

18891889
[DllImport(WebRTC.Lib)]
1890-
public static extern void SetAndroidAudioUsageMode(IntPtr context, int usage);
1890+
public static extern void SetAudioUsageMode(IntPtr context, int usage);
18911891
#endif
18921892

18931893
}

0 commit comments

Comments
 (0)