Skip to content

Allow to switch audio device module #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 3, 2025
Merged

Conversation

hiroshihorie
Copy link
Member

@hiroshihorie hiroshihorie commented Mar 27, 2025

Allow to use Legacy (WebRTC default) AudioDeviceModule instead of AVAudioEngine based AudioDeviceModule.

Currently when using legacy ADM, AVAudioSession category switching is not handled automatically, so switching to .playAndRecord is necessary when using the mic.

@hiroshihorie hiroshihorie changed the base branch from main to hiroshi/mic-mute-mode March 27, 2025 17:35
@hiroshihorie hiroshihorie changed the title Hiroshi/set audiomodule type Ability to switch adm Mar 27, 2025
@hiroshihorie hiroshihorie changed the title Ability to switch adm Allow to switch audio device module Mar 27, 2025
Base automatically changed from hiroshi/mic-mute-mode to main March 28, 2025 23:44
@hiroshihorie hiroshihorie marked this pull request as ready for review April 1, 2025 02:27
///
/// This method must be called before the peer connection is initialized. Changing the module type after
/// initialization is not supported and will result in an error.
static func set(audioDeviceModuleType: AudioDeviceModuleType) throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It effectively means you need to call this one before accessing AudioManager.shared, so somewhere in App.init() etc.

Copy link
Member Author

@hiroshihorie hiroshihorie Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it only works when called early at the moment. Even before AudioManager.shared, since peerConnection gets initialized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean e.g. in our example app even if you put it before .shared e.g. here:

        // here
        AudioManager.shared.onDeviceUpdate = { [weak self] _ in

it's not enough as SwiftUI may create .shared for you (e.g. in form of computed props).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it needs to be earlier at the moment. For our example app, it works here.
スクリーンショット 2025-04-03 14 36 10

RTC.audioDeviceModule.outputDevices.map { AudioDevice(ioDevice: $0) }
#else
[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, this is a no-op because of RTC limitations for iOS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a limitation at the moment.
I think we can simulate this to manipulate the AVAudioSession output port, but I'm not sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can comment it - just for the future generations.

var bypassVoiceProcessing: Bool = false
}

static let pcFactoryState = StateSync(PeerConnectionFactoryState())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: probably you can get rid of StateSync vs actor here if the mutations are local.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it require to be async ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

@pblazej pblazej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hiroshihorie hiroshihorie merged commit 586b475 into main Apr 3, 2025
16 of 20 checks passed
@hiroshihorie hiroshihorie deleted the hiroshi/set-audiomodule-type branch April 3, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants