-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set BaseAudioContext::state by render thread to signal device readiness #419
Conversation
Fixes #410 Except for suspending/resuming, I don't have a solution for that yet. In summary: - A context is instantiated in Suspended state - Online context will change to Running at the first render quantum - Online context will change to Closed when the render thread is dropped after a `close` call - Online context suspend/resume state is still managed by the control thread - TODO - Offline context will change to Running after startRendering
@@ -333,14 +334,14 @@ impl ConcreteBaseAudioContext { | |||
/// Returns state of current context | |||
#[must_use] | |||
pub(super) fn state(&self) -> AudioContextState { | |||
self.inner.state.load(Ordering::SeqCst).into() | |||
self.inner.state.load(Ordering::Acquire).into() | |||
} | |||
|
|||
/// Updates state of current context | |||
pub(super) fn set_state(&self, state: AudioContextState) { | |||
let current_state = self.state(); | |||
if current_state != state { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A race condition may occur in concurrent calls to this method (e.g. making a massive amount of suspend calls) causing the statechange event to be sent too many times. This could be fixed with https://doc.rust-lang.org/std/sync/atomic/struct.AtomicU64.html#method.compare_exchange but this method will probably be refactored away once we solve how to make suspend_sync better
Cool! Looks all good to me This will be very simple to implement #411 from this point, I was unsure of the behaviour of await |
Ahah, that is what you think (and I thought), but this is especially tricky because we don't spawn an event loop in the case of the OfflineAudioContext. Something to reconsider maybe. In any case we can't use the existing methods to spawn the complete event. I tried but it does not emit the event properly. |
Ah damn I didn't realized that...
Indeed, and their will probably be another issue after that I just discovered yesterday... :) As we send the ended event for |
Indeed that will also be an issue. But to be fair, these events simply don't make sense on an OfflineAudioContext because there is not actionable thing you can do with them. |
Hehe yup you are right, I guess the most important use case is actually testing and, eventually, some kind of monitoring (I do my best here :)... |
Ready for merging |
src/context/online.rs
Outdated
// Then, ask to resume rendering via a control message | ||
let (sender, receiver) = oneshot::channel(); | ||
let notify = OneshotNotify::Async(sender); | ||
let suspend_msg = ControlMessage::Resume { notify }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspend_msg
is a bit misleading, should be resume_msg
?
src/context/online.rs
Outdated
// First, stop rendering via a control message | ||
let (sender, receiver) = oneshot::channel(); | ||
let notify = OneshotNotify::Async(sender); | ||
let suspend_msg = ControlMessage::Close { notify }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same close_msg
?
Nice! |
Released in v0.41 |
Fixes #410 #416 #101
It probably also fixes ircam-ismm/node-web-audio-api#61 (comment)
Todo