Serialize mixer output frame ordering via AsyncStream.#1890
Merged
shogo4405 merged 1 commit intoHaishinKit:mainfrom Mar 22, 2026
Merged
Conversation
Replace unstructured Task {} in MediaMixerOutput and StreamOutput
conformances with AsyncStream channels that preserve FIFO ordering.
The previous pattern created a new Task for each audio/video callback,
which provides no ordering guarantee when entering an actor's serial
executor. This caused adjacent frames to arrive out of order, resulting
in RTMPTimestamp.invalidSequence errors (silent frame drops) and
AVAssetWriter failures in StreamRecorder.
ad4e94e to
ea4d6b2
Compare
CricHeroesiOS
added a commit
to CricHeroesiOS/HaishinKit.swift
that referenced
this pull request
Mar 19, 2026
Replace unstructured Task {} in MediaMixerOutput and StreamOutput
conformances with AsyncStream channels that preserve FIFO ordering.
The previous pattern created a new Task for each audio/video callback,
which provides no ordering guarantee when entering an actor's serial
executor. This caused adjacent frames to arrive out of order, resulting
in RTMPTimestamp.invalidSequence errors (silent frame drops) and
AVAssetWriter failures in StreamRecorder.
Collaborator
|
Thank you for your patience. I haven’t been able to come up with a solid design yet, so I’d like to merge this PR and proceed with testing. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1889
Replace unstructured Task {} in MediaMixerOutput and StreamOutput conformances with AsyncStream channels that preserve FIFO ordering.
Problem
The nonisolated mixer delegate methods in RTMPStream, SRTStream, and StreamRecorder each create a new Task {} per callback to hop into the actor. Swift provides no ordering guarantee for unstructured tasks entering an actor's serial executor, so adjacent frames can arrive out of order.
This causes:
Changes
Continuations are declared nonisolated(unsafe) since AsyncStream.Continuation.yield is thread-safe and mutations only occur from within the actor.