Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions Runtime/Scripts/PlatformAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,7 @@ public struct AudioDevice
/// 2. Optionally enumerate and select devices
/// 3. Create audio tracks using PlatformAudioSource
/// 4. Remote audio automatically plays through speakers
/// </summary>
/// <example>
/// <code>
/// // Create PlatformAudio (enables ADM)
/// var platformAudio = new PlatformAudio();
///
/// // Enumerate devices
/// var (recording, playout) = platformAudio.GetDevices();
/// foreach (var device in recording)
/// Debug.Log($"Mic {device.Index}: {device.Name}");
///
/// // Select devices (no-op on Android/iOS; routing there is governed by the OS).
/// // Use the uint overload for quick index-based selection, or the string overload
/// // with a GUID from GetDevices() to persist a stable selection across hot-plug.
/// platformAudio.SetRecordingDevice(0);
/// platformAudio.SetPlayoutDevice(0);
///
/// // Create audio source and track
/// var source = new PlatformAudioSource(platformAudio);
/// var track = LocalAudioTrack.CreateAudioTrack("microphone", source, room);
///
/// // Publish track
/// await room.LocalParticipant.PublishTrack(track, options);
///
/// // Dispose when done
/// platformAudio.Dispose();
/// </code>
/// </example>

public sealed class PlatformAudio : IDisposable
{
internal readonly FfiHandle Handle;
Expand All @@ -111,6 +84,18 @@ public sealed class PlatformAudio : IDisposable
/// </summary>
public int PlayoutDeviceCount => _info.PlayoutDeviceCount;

/// <summary>
/// Whether per-device selection is honored on this platform.
///
/// True on desktop (Windows, macOS, Linux), where <see cref="SetRecordingDevice(string)"/>
/// and <see cref="SetPlayoutDevice(string)"/> select the device. False on iOS/Android,
/// where audio routing is controlled by the OS (AVAudioSession / AudioManager); the
/// selection methods are accepted but have no effect there.
///
/// Use this to decide whether to present a device-picker UI.
/// </summary>
public bool IsDeviceSelectionSupported => _info.DeviceSelectionSupported;

/// <summary>
/// Creates a new PlatformAudio instance, enabling the platform ADM.
///
Expand Down Expand Up @@ -149,6 +134,11 @@ public PlatformAudio()

/// <summary>
/// Gets the lists of available recording and playout devices.
///
/// On Android and iOS this typically reports a single "default" device, and
/// selecting a device has no effect (see <see cref="IsDeviceSelectionSupported"/>):
/// audio routing is governed by the OS. The list is informational there; prefer
/// gating any device-picker UI on <see cref="IsDeviceSelectionSupported"/>.
/// </summary>
/// <returns>
/// A tuple containing:
Expand Down Expand Up @@ -198,6 +188,9 @@ public PlatformAudio()
/// Convenience wrapper around <see cref="SetRecordingDevice(string)"/> that looks
/// up the GUID from <see cref="GetDevices"/>. Prefer the GUID overload for code
/// that persists a selection — indices can shift when devices are added/removed.
///
/// No-op on Android/iOS, same as <see cref="SetRecordingDevice(string)"/>
/// (see <see cref="IsDeviceSelectionSupported"/>).
/// </summary>
/// <param name="index">Device index from GetDevices().Recording</param>
/// <exception cref="InvalidOperationException">
Expand All @@ -215,10 +208,10 @@ public void SetRecordingDevice(uint index)
/// <summary>
/// Sets the recording device (microphone) by device ID (GUID).
///
/// On Android and iOS this is a no-op in the native ADM: input routing is
/// governed by the OS (AVAudioSession on iOS, AudioManager on Android) and
/// the call is acknowledged but ignored. The method is still safe to call,
/// and the response carries no error.
/// On Android and iOS this is a no-op (see <see cref="IsDeviceSelectionSupported"/>):
/// input routing is governed by the OS (AVAudioSession on iOS, AudioManager on
/// Android) and the call is acknowledged but ignored. The method is still safe to
/// call, and the response carries no error.
/// </summary>
/// <param name="deviceId">Device ID/GUID from GetDevices().Recording[i].Guid</param>
/// <exception cref="InvalidOperationException">
Expand All @@ -245,6 +238,9 @@ public void SetRecordingDevice(string deviceId)
/// Convenience wrapper around <see cref="SetPlayoutDevice(string)"/> that looks
/// up the GUID from <see cref="GetDevices"/>. Prefer the GUID overload for code
/// that persists a selection — indices can shift when devices are added/removed.
///
/// No-op on Android/iOS, same as <see cref="SetPlayoutDevice(string)"/>
/// (see <see cref="IsDeviceSelectionSupported"/>).
/// </summary>
/// <param name="index">Device index from GetDevices().Playout</param>
/// <exception cref="InvalidOperationException">
Expand All @@ -262,10 +258,10 @@ public void SetPlayoutDevice(uint index)
/// <summary>
/// Sets the playout device (speaker/headphones) by device ID (GUID).
///
/// On Android and iOS this is a no-op in the native ADM: output routing is
/// governed by the OS (AVAudioSession on iOS, AudioManager on Android) and
/// the call is acknowledged but ignored. The method is still safe to call,
/// and the response carries no error.
/// On Android and iOS this is a no-op (see <see cref="IsDeviceSelectionSupported"/>):
/// output routing is governed by the OS (AVAudioSession on iOS, AudioManager on
/// Android) and the call is acknowledged but ignored. The method is still safe to
/// call, and the response carries no error.
/// </summary>
/// <param name="deviceId">Device ID/GUID from GetDevices().Playout[i].Guid</param>
/// <exception cref="InvalidOperationException">
Expand Down
128 changes: 93 additions & 35 deletions Runtime/Scripts/Proto/AudioFrame.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading