Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/idempotent-add-simulcast-track.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Fix crash when a duplicate SubscribedQualityUpdate requests a backup codec that is already added. addSimulcastTrack now skips the duplicate instead of throwing IllegalStateException ("VP8 already added!"), matching the JS SDK behavior.
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,10 @@ internal constructor(
return
}
val (newOptions, newEncodings) = result
val simulcastTrack = track.addSimulcastTrack(codec, newEncodings)
// A duplicate SubscribedQualityUpdate can request a codec that is already being
// published (or mid-publish, before the sender is attached). Treat it as a no-op
// instead of throwing, so a repeated update doesn't crash the session.
val simulcastTrack = track.addSimulcastTrack(codec, newEncodings) ?: return

val transceiverInit = RtpTransceiverInit(
RtpTransceiver.RtpTransceiverDirection.SEND_ONLY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,10 @@ constructor(
return newCodecs
}

internal fun addSimulcastTrack(codec: VideoCodec, encodings: List<RtpParameters.Encoding>): SimulcastTrackInfo {
internal fun addSimulcastTrack(codec: VideoCodec, encodings: List<RtpParameters.Encoding>): SimulcastTrackInfo? {
if (this.simulcastCodecs.containsKey(codec)) {
throw IllegalStateException("$codec already added!")
LKLog.w { "$codec already added, skipping." }
return null
}
val simulcastTrackInfo = SimulcastTrackInfo(
codec = codec.codecName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
assertEquals(4, getPublisherPeerConnection().transceivers.size)
}

@Test
fun addSimulcastTrackForAlreadyAddedCodecIsNoOp() = runTest {
val videoTrack = createLocalTrack()

val first = videoTrack.addSimulcastTrack(VideoCodec.VP8, emptyList())
val second = videoTrack.addSimulcastTrack(VideoCodec.VP8, emptyList())

assertNotNull(first)
assertNull(second)
}

@Test
fun duplicateSubscribedQualityUpdateDoesNotRepublishBackupCodec() = runTest {
room.videoTrackPublishDefaults = room.videoTrackPublishDefaults.copy(
videoCodec = VideoCodec.VP9.codecName,
scalabilityMode = "L3T3",
backupCodec = BackupVideoCodec(codec = VideoCodec.VP8.codecName),
)

connect()
val videoTrack = createLocalTrack()
room.localParticipant.publishVideoTrack(videoTrack)

val trackSid = room.localParticipant.videoTrackPublications.first().first.sid
receiveSubscribedQualityUpdate(trackSid)
receiveSubscribedQualityUpdate(trackSid)

assertEquals(2, getPublisherPeerConnection().transceivers.size)
}
Comment on lines +355 to +371

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test already passes on main today, so it is not testing the fix of your issue. Can you please remove it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like there's a pretty specific hard to test window to get the original situation to pass, and the test is a reasonable guard to have overall anyways, so I'm going to keep this one and merge.


@Test
fun disposeDisposesVideoSource() {
val source = mock(VideoSource::class.java)
Expand Down
Loading