Skip to content

fix(source): wait for the broadcast announcement instead of racing it#49

Open
appkanamiru wants to merge 1 commit into
moq-dev:mainfrom
appkanamiru:fix/consume-announced-race
Open

fix(source): wait for the broadcast announcement instead of racing it#49
appkanamiru wants to merge 1 commit into
moq-dev:mainfrom
appkanamiru:fix/consume-announced-race

Conversation

@appkanamiru

Copy link
Copy Markdown

AI Icon Warning, AI generated ⚠️

Problem

moq_source_start_consume calls the synchronous moq_origin_consume
immediately after the session connects (first on_session_status). At that
moment the announcement usually hasn't propagated, so the lookup loses the
race and returns BroadcastNotFound (-24), and the source blanks without
retrying. A MoQ Source pointed at a live broadcast just stays black:

[obs-moq] MoQ session connected (generation N, epoch 1)
[obs-moq] Failed to consume broadcast 'live/...': -24

The web player works against the same broadcast because it waits for the
announcement.

Fix

Use moq_origin_consume_announced, which waits for the announcement and
delivers the broadcast handle via a callback (on_broadcast_ready), then
sets up the catalog subscription exactly as before. libmoq's own docs
recommend this call "right after moq_session_connect to avoid racing
announcement gossip." The wait handle is stored so disconnect can cancel
it; the ref-counting and generation/shutting-down guards mirror the existing
paths.

Requires libmoq exporting moq_origin_consume_announced /
moq_origin_consume_announced_close (present in 0.3.10; builds cleanly with
--libmoq-release 0.3.10).

Test

  • Add a MoQ Source to an already-live broadcast → video appears (was black).
  • Add it before the broadcast starts → waits, then appears on announce.
  • Log shows Waiting for broadcast announcement then Consuming announced broadcast.

@sourcery-ai sourcery-ai 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.

Sorry @appkanamiru, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

src/moq-source.cpp is modified to consume announced broadcasts asynchronously via moq_origin_consume_announced instead of the synchronous moq_origin_consume. A new consume_announced_task field tracks the pending task handle for cancellation and cleanup. A new on_broadcast_ready callback manages the announced-consume lifetime, handles success/error/terminal cases, sets the consume handle, and initiates catalog subscription via moq_consume_catalog. Disconnect logic and related log/comment text are updated to reflect the new asynchronous flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: waiting for the broadcast announcement instead of racing it.
Description check ✅ Passed The description matches the code changes and explains the announced-consume flow, cancellation, and test behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/moq-source.cpp`:
- Around line 668-669: Thread the per-task consume-announced state through
on_broadcast_ready so stale callbacks cannot overwrite newer context. Capture
the task token and expected generation when calling
moq_origin_consume_announced, pass them via the callback state, and update
on_broadcast_ready to verify the callback still matches ctx before clearing
consume_announced_task or attaching the broadcast. Ignore late callbacks from
older reconnecting/closed tasks instead of using ctx->generation at callback
time.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 57b4abc2-fd54-4ca8-9e90-e56aceaf4f21

📥 Commits

Reviewing files that changed from the base of the PR and between 323d597 and 0774bd0.

📒 Files selected for processing (1)
  • src/moq-source.cpp

Comment thread src/moq-source.cpp
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