Skip to content

Clear simulcast codec state on unpublish and full reconnect - #1159

Merged
hiroshihorie merged 4 commits into
mainfrom
hiroshi/simulcast-codecs-lifecycle
Aug 8, 2026
Merged

Clear simulcast codec state on unpublish and full reconnect#1159
hiroshihorie merged 4 commits into
mainfrom
hiroshi/simulcast-codecs-lifecycle

Conversation

@hiroshihorie

Copy link
Copy Markdown
Member

Stacked on #1155, review that first. Only the last commit (34aa23b) is new here.

Follow-up to the #1155 review. LocalVideoTrack.simulcastCodecs and encodingBackups were never cleared, so the backup codec senders they hold outlived the peer connection they belonged to:

The fix adds LocalVideoTrack.clearSimulcastState() and calls it from the two places senders become invalid: removePublishedTrack (after removing them from the peer connection, now awaited via a snapshot loop) and rePublishAllTracks (before republishing on the new connection).

Tests

test/track/simulcast_state_test.dart pins the invariant: re-adding a backup codec after clearing succeeds where it previously threw, and encoding backups are cleared too. Full suite passes (392 tests), analyze, format, and import sorter clean.

🤖 Generated with Claude Code

Base automatically changed from sxian/default-degradation-preference-by-source to main August 7, 2026 14:14
simulcastCodecs and encodingBackups were never cleared, so their senders
outlived the peer connection they belonged to. After a full reconnect,
republishing acted on those stale senders and addSimulcastTrack rejected
the backup codec as a duplicate when the server requested it again.
Unpublish also removed the simulcast senders with a fire and forget
forEach and force unwrapped a nullable sender, both fixed by iterating a
snapshot with awaits.
@hiroshihorie
hiroshihorie force-pushed the hiroshi/simulcast-codecs-lifecycle branch from 359c820 to 714ee4a Compare August 8, 2026 06:44
@hiroshihorie
hiroshihorie marked this pull request as ready for review August 8, 2026 06:44

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

One failed removeTrack no longer aborts removal of the remaining backup
senders. Matches how the JS SDK unpublishes, each sender removal is
caught on its own and the sender reference is dropped either way.
devin-ai-integration[bot]

This comment was marked as resolved.

The simulcast cleanup was gated on the primary sender existing, so a
track whose publish raced a disconnect kept stale backup codec state
through unpublish and a later republish rejected the backup codec as a
duplicate. Run the cleanup for every video track and negotiate only when
a sender was actually removed.
@hiroshihorie
hiroshihorie merged commit 7c232d9 into main Aug 8, 2026
15 checks passed
@hiroshihorie
hiroshihorie deleted the hiroshi/simulcast-codecs-lifecycle branch August 8, 2026 08:35
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.

1 participant