-
Notifications
You must be signed in to change notification settings - Fork 58
Isolate per-track mute RPCs and atomic mute map #1796
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
Open
PratimMallick
wants to merge
4
commits into
develop
Choose a base branch
from
fix/mute-state-sync-cancels-other-tracks
base: develop
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.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
502ebdc
fix(core): stop mute sync from cancelling other tracks' RPCs
PratimMallick fa2cf2a
fix(core): update muteState map atomically across tracks
PratimMallick 616ec1c
fix(core): pause mute SFU sync during reconnect and migration
PratimMallick 268830e
Merge branch 'develop' into fix/mute-state-sync-cancels-other-tracks
PratimMallick 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
Some comments aren't visible on the classic Files Changed page.
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
47 changes: 47 additions & 0 deletions
47
...video-android-core/src/main/kotlin/io/getstream/video/android/core/call/TrackKeyedJobs.kt
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,47 @@ | ||
| /* | ||
| * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.core.call | ||
|
|
||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.CoroutineStart | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.launch | ||
| import stream.video.sfu.models.TrackType | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| /** | ||
| * One job per [TrackType]. Replacing a job cancels only that track's previous work, so an | ||
| * in-flight audio mute RPC is not dropped when video or screen-share sync starts. | ||
| */ | ||
| internal class TrackKeyedJobs { | ||
| private val jobs = ConcurrentHashMap<TrackType, Job>() | ||
|
|
||
| fun launch( | ||
| scope: CoroutineScope, | ||
| trackType: TrackType, | ||
| block: suspend CoroutineScope.() -> Unit, | ||
| ) { | ||
| val job = scope.launch(start = CoroutineStart.LAZY, block = block) | ||
| jobs.put(trackType, job)?.cancel() | ||
| job.start() | ||
| } | ||
|
|
||
| fun cancelAll() { | ||
| jobs.values.forEach { it.cancel() } | ||
| jobs.clear() | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
...o-android-core/src/test/kotlin/io/getstream/video/android/core/call/TrackKeyedJobsTest.kt
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,82 @@ | ||
| /* | ||
| * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.core.call | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
| import kotlinx.coroutines.test.runTest | ||
| import org.junit.Test | ||
| import stream.video.sfu.models.TrackType | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| class TrackKeyedJobsTest { | ||
|
|
||
| @Test | ||
| fun `launching a second track does not cancel the first track's job`() = runTest { | ||
| val scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler) + Job()) | ||
| val jobs = TrackKeyedJobs() | ||
| val release = CompletableDeferred<Unit>() | ||
| val audioDone = AtomicBoolean(false) | ||
| val videoDone = AtomicBoolean(false) | ||
|
|
||
| try { | ||
| jobs.launch(scope, TrackType.TRACK_TYPE_AUDIO) { | ||
| release.await() | ||
| audioDone.set(true) | ||
| } | ||
| jobs.launch(scope, TrackType.TRACK_TYPE_VIDEO) { | ||
| release.await() | ||
| videoDone.set(true) | ||
| } | ||
|
|
||
| release.complete(Unit) | ||
|
|
||
| assertThat(audioDone.get()).isTrue() | ||
| assertThat(videoDone.get()).isTrue() | ||
| } finally { | ||
| scope.coroutineContext[Job]?.cancel() | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `launching the same track cancels the previous job`() = runTest { | ||
| val scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler) + Job()) | ||
| val jobs = TrackKeyedJobs() | ||
| val firstHold = CompletableDeferred<Unit>() | ||
| val firstDone = AtomicBoolean(false) | ||
| val secondDone = AtomicBoolean(false) | ||
|
|
||
| try { | ||
| jobs.launch(scope, TrackType.TRACK_TYPE_AUDIO) { | ||
| firstHold.await() | ||
| firstDone.set(true) | ||
| } | ||
| jobs.launch(scope, TrackType.TRACK_TYPE_AUDIO) { | ||
| secondDone.set(true) | ||
| } | ||
| firstHold.complete(Unit) | ||
|
|
||
| assertThat(firstDone.get()).isFalse() | ||
| assertThat(secondDone.get()).isTrue() | ||
| } finally { | ||
| scope.coroutineContext[Job]?.cancel() | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.