Skip to content

fix: better callbacks handling#1092

Open
mdydek wants to merge 7 commits into
mainfrom
fix/better-callbacks-handling
Open

fix: better callbacks handling#1092
mdydek wants to merge 7 commits into
mainfrom
fix/better-callbacks-handling

Conversation

@mdydek

@mdydek mdydek commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Closes #

⚠️ Breaking changes ⚠️

Introduced changes

  • improved callback registering and unregistering between js and audio thread
  • setting callbacks objects are now done via atomic variables, not audio events which can be problematic when context is suspended

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

@mdydek mdydek added the fix label Jun 9, 2026
@mdydek mdydek changed the title fix: atomic in callbacks numbers, synchronized registers and unregisters fix: better callbacks handling Jun 9, 2026

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

Nice job reducing the scatter here!

Comment on lines -160 to +162
if (processor_->atBoundary()) {
if (processor_->shouldStop()) {
playbackState_ = PlaybackState::STOP_SCHEDULED;
}
if (processor_->didCrossLoopBoundary()) {
sendOnLoopEndedEvent();
}

if (processor_->atBoundary() && processor_->shouldStop()) {
playbackState_ = PlaybackState::STOP_SCHEDULED;
}

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 handling is inconsistent with AudioBufferQueueSourceNode.

Here the event dispatch is called outside of the processor while in AudioBufferQueueSourceNode a lambda is passed to be invoked.

It would be best to unify this.

Comment on lines +11 to +13
/// @brief Wrapper around EventCaller that dispatches position changed events
/// with interval throttling and optional flush-on-seek behavior.
class PositionChangedDispatcher {

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.

If we are planning to add more dispatchers it would be good to add a base class for them. Just a thought.

Comment on lines +32 to +35
void PositionChangedDispatcher::setIntervalMs(int intervalInMs, float sampleRate) {
//NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers)
setIntervalInFrames(static_cast<int>(sampleRate * static_cast<float>(intervalInMs) / 1000.0f));
}

@closetcaiman closetcaiman Jun 11, 2026

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.

I'm not a fan of ignoring the linter here. Don't we have any methods that handle calculation between frames and {m}s? I believe we have a unit conversion namespace somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants