Skip to content

Commit e3641c1

Browse files
authored
Merge pull request #193 from GetStream/feature/uni-141-implement-audio-usage-mode-control-from-the-client
Feature/uni 141 implement audio usage mode control from the client
2 parents fedc8d6 + aea0781 commit e3641c1

File tree

7 files changed

+103
-15
lines changed

7 files changed

+103
-15
lines changed

Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ private void OnSfuConnectionQualityChanged(ConnectionQualityChanged connectionQu
14211421

14221422
private void OnSfuAudioLevelChanged(AudioLevelChanged audioLevelChanged)
14231423
{
1424-
_sfuTracer?.Trace("audioLevelChanged", audioLevelChanged);
1424+
14251425
// StreamTODO: Implement OnSfuAudioLevelChanged
14261426
}
14271427

Packages/StreamVideo/Runtime/Libs/AppInfo/UnityApplicationInfo.cs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,58 @@ namespace StreamVideo.Libs.AppInfo
55
public class UnityApplicationInfo : IApplicationInfo
66
{
77
public string Engine => "Unity";
8-
8+
99
public string EngineVersion => Application.unityVersion;
10-
10+
1111
public string Platform => Application.platform.ToString();
12-
12+
1313
public string OperatingSystem => SystemInfo.operatingSystem;
14-
public string OperatingSystemFamily => SystemInfo.operatingSystemFamily.ToString();
14+
15+
public string OperatingSystemFamily => GetOsFamily();
16+
1517
public string CpuArchitecture => SystemInfo.processorType;
1618

1719
public int MemorySize => SystemInfo.systemMemorySize;
18-
20+
1921
public int GraphicsMemorySize => SystemInfo.graphicsMemorySize;
2022

2123
public string ScreenSize => Screen.width + "x" + Screen.height;
22-
24+
2325
//StreamTodo: solve this, the deviceName is just a local name so perhaps not something we want
24-
public string DeviceName => SystemInfo.deviceName;
26+
public string DeviceName => SystemInfo.deviceName;
27+
2528
public string DeviceModel => SystemInfo.deviceModel;
29+
30+
private static string GetOsFamily()
31+
{
32+
switch (Application.platform)
33+
{
34+
case RuntimePlatform.Android:
35+
return "Android";
36+
37+
case RuntimePlatform.IPhonePlayer:
38+
return "iOS";
39+
40+
case RuntimePlatform.tvOS:
41+
return "tvOS";
42+
43+
case RuntimePlatform.OSXPlayer:
44+
case RuntimePlatform.OSXEditor:
45+
return "macOS";
46+
47+
case RuntimePlatform.WindowsPlayer:
48+
case RuntimePlatform.WindowsEditor:
49+
return "Windows";
50+
51+
case RuntimePlatform.LinuxPlayer:
52+
case RuntimePlatform.LinuxServer:
53+
case RuntimePlatform.LinuxEditor:
54+
return "Linux";
55+
56+
default:
57+
var family = SystemInfo.operatingSystemFamily;
58+
return family != UnityEngine.OperatingSystemFamily.Other ? family.ToString() : "Unknown";
59+
}
60+
}
2661
}
27-
}
62+
}
Binary file not shown.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ public void StopAudioPlayback()
411411
{
412412
NativeMethods.StopAudioPlayback(self);
413413
}
414+
415+
public void SetAndroidAudioUsageMode(int usage)
416+
{
417+
NativeMethods.SetAndroidAudioUsageMode(self, usage);
418+
}
414419
#endif
415420

416421
internal void BatchUpdate(IntPtr batchData)

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,26 @@ public enum NativeLoggingSeverity
715715
None,
716716
};
717717

718+
#if UNITY_ANDROID && !UNITY_EDITOR
719+
/// <summary>
720+
/// Android audio usage modes for Oboe audio streams.
721+
/// </summary>
722+
public enum AndroidAudioUsageMode
723+
{
724+
/// <summary>
725+
/// Media usage mode - suitable for media playback (e.g., music, video).
726+
/// Use this for viewers/consumers in livestream scenarios.
727+
/// </summary>
728+
Media = 1,
729+
730+
/// <summary>
731+
/// Voice communication usage mode - optimized for voice calls.
732+
/// Use this for broadcasters/hosts in livestream scenarios.
733+
/// </summary>
734+
VoiceCommunication = 2
735+
}
736+
#endif
737+
718738
/// <summary>
719739
/// Provides utilities and management functions for integrating WebRTC functionality.
720740
/// </summary>
@@ -1133,6 +1153,20 @@ public static void StopAudioPlayback()
11331153
Context.StopAudioPlayback();
11341154
}
11351155

1156+
/// <summary>
1157+
/// Sets the Android audio usage mode for audio playback.
1158+
/// Changing the usage mode during an active call will restart the audio stream.
1159+
/// </summary>
1160+
/// <param name="usage">The audio usage mode to set (Media or VoiceCommunication)</param>
1161+
/// <remarks>
1162+
/// - Use VoiceCommunication for broadcasters/hosts in livestream scenarios
1163+
/// - Use Media for viewers/consumers in livestream scenarios
1164+
/// </remarks>
1165+
public static void SetAndroidAudioUsageMode(AndroidAudioUsageMode usage)
1166+
{
1167+
Context.SetAndroidAudioUsageMode((int)usage);
1168+
}
1169+
11361170
#endif
11371171
class CallbackObject
11381172
{
@@ -1837,6 +1871,9 @@ public static extern IntPtr CreateVideoRenderer(
18371871

18381872
[DllImport(WebRTC.Lib)]
18391873
public static extern void GetAudioProcessingModuleConfig(IntPtr context, out bool enabled, out bool echoCancellationEnabled, out bool autoGainEnabled, out bool noiseSuppressionEnabled, out int noiseSuppressionLevel);
1874+
1875+
[DllImport(WebRTC.Lib)]
1876+
public static extern void SetAndroidAudioUsageMode(IntPtr context, int usage);
18401877
#endif
18411878

18421879
}

Packages/StreamVideo/Tests/Runtime/CallsTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using NUnit.Framework;
6+
using StreamVideo.Core;
67
using StreamVideo.Core.StatefulModels.Tracks;
78
using StreamVideo.Tests.Shared;
89
using UnityEngine;
@@ -35,27 +36,32 @@ public IEnumerator When_client_joins_call_with_video_expect_receiving_video_trac
3536
private async Task When_client_joins_call_with_video_expect_receiving_video_track_Async(
3637
ITestClient clientA, ITestClient clientB)
3738
{
38-
var streamCall = await clientA.JoinRandomCallAsync();
39+
var clientACall = await clientA.JoinRandomCallAsync();
3940

4041
var cameraDevice = await TestUtils.TryGetFirstWorkingCameraDeviceAsync(clientA.Client);
4142
Debug.Log("Selected camera device: " + cameraDevice);
4243
clientA.Client.VideoDeviceManager.SelectDevice(cameraDevice, enable: true);
4344

44-
var call = await clientB.Client.JoinCallAsync(streamCall.Type, streamCall.Id, create: false,
45+
var clientBCall = await clientB.Client.JoinCallAsync(clientACall.Type, clientACall.Id, create: false,
4546
ring: false,
4647
notify: false);
4748

48-
var otherParticipant = call.Participants.First(p => !p.IsLocalParticipant);
49+
// Wait for client B to get client A participant
50+
await WaitForConditionAsync(()
51+
=> clientBCall.Participants.Any(p => p.SessionId == clientACall.GetLocalParticipant().SessionId));
52+
53+
var clientAParticipant = clientBCall.Participants.First(p => p.SessionId == clientACall.GetLocalParticipant().SessionId);
54+
clientAParticipant.UpdateRequestedVideoResolution(VideoResolution.Res_720p);
4955

5056
StreamVideoTrack streamTrack = null;
5157

52-
if (otherParticipant.VideoTrack != null)
58+
if (clientAParticipant.VideoTrack != null)
5359
{
54-
streamTrack = (StreamVideoTrack)otherParticipant.VideoTrack;
60+
streamTrack = (StreamVideoTrack)clientAParticipant.VideoTrack;
5561
}
5662
else
5763
{
58-
otherParticipant.TrackAdded += (_, track) => { streamTrack = (StreamVideoTrack)track; };
64+
clientAParticipant.TrackAdded += (_, track) => { streamTrack = (StreamVideoTrack)track; };
5965

6066
await WaitForConditionAsync(() => streamTrack != null);
6167
}

Packages/StreamVideo/Tests/Shared/TestClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public TestClient(IStreamVideoClient client)
2323

2424
public async Task<IStreamCall> JoinRandomCallAsync()
2525
{
26+
if (Client.ActiveCall != null)
27+
{
28+
await Client.ActiveCall.LeaveAsync();
29+
}
30+
2631
var callId = Guid.NewGuid().ToString();
2732
return await Client.JoinCallAsync(StreamCallType.Default, callId, create: true, ring: false,
2833
notify: false);

0 commit comments

Comments
 (0)