Skip to content

Add separate rendering starting and complete events - #991

Merged
sbooth merged 14 commits into
mainfrom
lifecycle-events
Sep 12, 2026
Merged

sbooth merged 14 commits into
mainfrom
lifecycle-events

Conversation

@sbooth

@sbooth sbooth commented Aug 28, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

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.

🟡 Changes recommended

DEBUG-only assertions can now fire on explicitly handled message-queue overruns (and a small render-path inefficiency was introduced), so the new event split needs minor tightening before it’s safe to land.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors rendering notifications in AudioPlayer by splitting the previous “frames rendered” event flags into dedicated “rendering started” and “rendering complete” events, allowing the event thread to process these lifecycle transitions separately from per-buffer frame accounting.

Changes:

  • Replaced FramesRenderedEventFlags with standalone renderingStarted and renderingComplete event commands.
  • Updated render-path event enqueueing to emit start / frames-rendered / complete events with appropriate host-time scheduling.
  • Added new event processing handlers to update decoder state and dispatch rendering lifecycle notifications.
File summaries
File Description
Sources/CSFBAudioEngine/Player/AudioPlayer.mm Splits rendering lifecycle notifications into separate events and adds dedicated processing functions.
Sources/CSFBAudioEngine/Player/AudioPlayer.h Extends EventCommand and declares new event-processing entry points.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/CSFBAudioEngine/Player/AudioPlayer.mm
Comment thread Sources/CSFBAudioEngine/Player/AudioPlayer.h
Comment thread Sources/CSFBAudioEngine/Player/AudioPlayer.mm
@sbooth sbooth closed this Sep 11, 2026
@sbooth
sbooth deleted the lifecycle-events branch September 11, 2026 13:36
@sbooth
sbooth restored the lifecycle-events branch September 11, 2026 13:36
@sbooth
sbooth deleted the lifecycle-events branch September 11, 2026 13:36
@sbooth
sbooth restored the lifecycle-events branch September 11, 2026 14:04
@sbooth sbooth reopened this Sep 11, 2026

Copilot AI left a comment

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.

🔵 Needs a closer look

Independently queued lifecycle events can be partially accepted, producing inconsistent rendering state.

Review details

Suppressed comments (2)

Sources/CSFBAudioEngine/Player/AudioPlayer.mm:1691

  • The start, frame, and completion records now fail independently. If the queue is full for renderingStarted but the consumer frees space before renderingComplete, completion is accepted without start; processRenderingCompleteEvent then asserts in debug and removes/notifies the decoder without a start in release. Preserve lifecycle atomicity by enqueueing one record or reserving and committing the required records as a batch.
            if (!events_.enqueue(EventCommand::renderingComplete, eventTime,
                                 renderingChunk_->descriptor_.sequenceNumber_,
                                 renderingChunk_->descriptor_.playbackGeneration_)) [[unlikely]] {
                setFlags(Flags::renderEventDropped);

Sources/CSFBAudioEngine/Player/AudioPlayer.mm:1734

  • The two lifecycle events for an empty decoder can be only partially queued. The event consumer may free capacity after renderingStarted fails, allowing this completion record through and violating the completion handler's required renderingStarted state. Queue both events atomically (or use one combined empty-render lifecycle record).
        if (!events_.enqueue(EventCommand::renderingComplete, eventTime, chunkDescriptor.sequenceNumber_,
                             chunkDescriptor.playbackGeneration_)) [[unlikely]] {
            setFlags(Flags::renderEventDropped);
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@sbooth
sbooth marked this pull request as ready for review September 12, 2026 13:43
@sbooth
sbooth merged commit 22c7f5a into main Sep 12, 2026
2 checks passed
@sbooth
sbooth deleted the lifecycle-events branch September 12, 2026 14:27
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.

2 participants