-
Notifications
You must be signed in to change notification settings - Fork 191
PlatformAudio stability/shutdown #1193
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
Draft
alan-george-lk
wants to merge
3
commits into
main
Choose a base branch
from
feature/platform-audio-stability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| livekit: minor | ||
| libwebrtc: minor | ||
| livekit-ffi: patch | ||
| webrtc-sys: patch | ||
| --- | ||
|
|
||
| Fix platform ADM teardown races on macOS and release FFI handles on dispose. | ||
|
|
||
| - Clear remaining FFI handles during `FfiServer::dispose` so native resources are released across repeated initialize/shutdown cycles. | ||
| - Stop and detach platform/synthetic audio I/O before peer connection factory teardown, preventing `CaptureWorkerThread` from delivering into destroyed transports. | ||
| - Close rooms before dropping FFI track handles and stop platform capture when releasing the platform ADM reference. | ||
| - Add `LkRuntime::shutdown_audio_io()` and `PeerConnectionFactoryExt::shutdown_audio_io()` for explicit audio I/O shutdown during runtime teardown. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,9 @@ AdmProxy::AdmProxy(const webrtc::Environment& env, webrtc::Thread* worker_thread | |
| AdmProxy::~AdmProxy() { | ||
| RTC_LOG(LS_VERBOSE) << "AdmProxy::~AdmProxy()"; | ||
|
|
||
| StopAudioIO(); | ||
|
|
||
| webrtc::MutexLock lock(&mutex_); | ||
| if (synthetic_adm_) { | ||
| synthetic_adm_->Terminate(); | ||
| synthetic_adm_ = nullptr; | ||
|
|
@@ -180,6 +183,7 @@ void AdmProxy::ReleasePlatformAdm() { | |
| // Note: We do NOT terminate the Platform ADM - it stays alive until destructor. | ||
| // This avoids iOS KVO race conditions from re-creating the ADM. | ||
| if (platform_adm_ref_count_ == 0) { | ||
| StopPlatformAudioIO(); | ||
| SwitchPlayoutModeIfNeeded(); | ||
| SwitchRecordingAdmIfNeeded(); | ||
| } | ||
|
|
@@ -273,6 +277,42 @@ void AdmProxy::SwitchRecordingAdmIfNeeded() { | |
| } | ||
| } | ||
|
|
||
| void AdmProxy::StopPlatformAudioIO() { | ||
| recording_ = false; | ||
|
|
||
| if (platform_adm_) { | ||
| platform_adm_->RegisterAudioCallback(nullptr); | ||
| platform_adm_->StopRecording(); | ||
| platform_adm_->StopPlayout(); | ||
| // platform_adm_ is kept alive for re-acquire and iOS compatibility; see | ||
| // ReleasePlatformAdm(). | ||
| } | ||
| } | ||
|
|
||
| void AdmProxy::StopAudioIO() { | ||
| webrtc::MutexLock lock(&mutex_); | ||
|
|
||
| recording_ = false; | ||
| playing_ = false; | ||
| recording_initialized_ = false; | ||
| playout_initialized_ = false; | ||
|
|
||
| if (platform_adm_) { | ||
| platform_adm_->RegisterAudioCallback(nullptr); | ||
| platform_adm_->StopRecording(); | ||
| platform_adm_->StopPlayout(); | ||
| } | ||
|
|
||
| if (synthetic_adm_) { | ||
| synthetic_adm_->RegisterAudioCallback(nullptr); | ||
| synthetic_adm_->StopRecording(); | ||
| synthetic_adm_->StopPlayout(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| // synthetic_adm_ is kept alive until ~AdmProxy() / Terminate(). | ||
| } | ||
|
|
||
| audio_transport_ = nullptr; | ||
| } | ||
|
|
||
| // ============================================================================= | ||
| // AudioDeviceModule Interface Implementation | ||
| // ============================================================================= | ||
|
|
@@ -306,8 +346,9 @@ int32_t AdmProxy::Init() { | |
| } | ||
|
|
||
| int32_t AdmProxy::Terminate() { | ||
| webrtc::MutexLock lock(&mutex_); | ||
| StopAudioIO(); | ||
|
|
||
| webrtc::MutexLock lock(&mutex_); | ||
| int32_t result = 0; | ||
| if (synthetic_adm_) { | ||
| result = synthetic_adm_->Terminate(); | ||
|
|
@@ -554,11 +595,20 @@ int32_t AdmProxy::StopRecording() { | |
| webrtc::MutexLock lock(&mutex_); | ||
| recording_ = false; | ||
|
|
||
| auto* adm = recording_adm(); | ||
| if (adm) { | ||
| return adm->StopRecording(); | ||
| int32_t result = 0; | ||
| if (platform_adm_) { | ||
| const int32_t platform_result = platform_adm_->StopRecording(); | ||
| if (result == 0) { | ||
| result = platform_result; | ||
| } | ||
| } | ||
| return 0; | ||
| if (synthetic_adm_) { | ||
| const int32_t synthetic_result = synthetic_adm_->StopRecording(); | ||
| if (result == 0) { | ||
| result = synthetic_result; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| bool AdmProxy::Recording() const { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, curiously, why couldn't we set platform_adm_ = nullptr after calling StopXXX() function ?