You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@annevk We don't support Transfer in AudioWorklet's comm channel anyway, so changing the term from 'structured cloning' to 'serializing'. (and perhaps with a link to the reference) Does it makes sense?
Yeah, I think you want to invoke StructuredSerialize and StructuredDeserialize, referenced and with their proper names, but you also need to define the processing model of some of this in more detail.
E.g., step 4 of "The instantiation of AudioWorkletNode and AudioWorkletProcessor" currently says structured cloning is involved, but I can't find where that actually happens. (That algorithm also weirdly seems to cross threads without any kind of message passing or acknowledment that it's doing so. Is there an issue on that?)
I think ideally this would be an opportunity to make the actual usage more rigorous in "The instantiation of AudioWorkletNode and AudioWorkletProcessor". In particular, you'd have steps like:
Let serializedOptions be StructuredSerialize(options).
Let optionsInWorklet be StructuredDeserialize(serializedOptions, the AudioWorkletGlobalScope's Realm).
Now you can use optionsInWorklet in the Construct() step.
I'm not sure exactly how to phrase the prose references that currently say "structured clone". Maybe something like replacing
This may be any value or JavaScript object handled by the structured clone algorithm.
That algorithm also weirdly seems to cross threads without any kind of message passing or acknowledment that it's doing so. Is there an issue on that?
@annevk How do you describe cross-thread operation in terms of EcmaScript? The algorithm is largely based on the PaintWorklet, except that it has several cross-thread tasks. Any example for this pattern?
We have several examples of cross-thread messaging in the Web Audio API. When talking to the rendering thread, use a control message. We don't have a traditional event loop, but we have our own mechanism that is compatible with our processing based on rendering quantum. When talking to the main thread, queue a task on the main thread as usual, quoting the current spec:
Communication from the control thread to the rendering thread is done using control message
passing. Communication in the other direction is done using regular event loop tasks.
@hoch in ECMAScript you'd have to use a worker and postMessage(). In a specification that translates to serializing objects and queuing tasks to deserialize them.
@annevk Thanks for the clarification. We don't use either worker of postMessage, so I will try to capture the cross-thread task in a prose, as @padenot suggested above.
@hoch for the record, you can't describe anything in terms of ECMAScript in the specification. You'll always need to use some abstract concepts. There will be way too many gotchas otherwise.
This we can synchronously throw an exception, abort the construction (i.e. return null so it can't be connected to anything)
This we should make the Worklet invalid and make it output silence as you note. The other option would be to make it pass-through, but I don't like that, it makes it harder to debug, in a way.
is normal, it should not be an error. You create it, you connect it, etc., but it's not ready so it outputs silence like the other nodes.
For the notification, onstatechange or onerror would work. Semantically speaking, I don't think we should overload onmessage on the port, which is used for normal (author-initiated) messages.
This we can synchronously throw an exception, abort the construction (i.e. return null so it can't be connected to anything)
Hmm. I thought you wanted to make the instantiation process non-atomic, asynchronous. Then how can we throw an exception synchronously from the async process?
This we should make the Worklet invalid and make it output silence as you note. The other option would be to make it pass-through, but I don't like that, it makes it harder to debug, in a way.
Agreed. I like it to be silent for the same reason.
isn't really controversial. :)
For the notification, onstatechange or onerror would work. Semantically speaking, I don't think we should overload onmessage on the port, which is used for normal (author-initiated) messages.
Exactly. Having onstatechange also means we need state read-only attribute in the node. Plus, onerror can be used for two purposes: 1) when the AWP construction fails and 2) when the execution of process() throws and it becomes silent.
Hmm. I thought you wanted to make the instantiation process non-atomic, asynchronous. Then how can we throw an exception synchronously from the async process?
Oops sorry I misread AWP for AWN, you're right that it would put the node in error.
From F2F: We'll adopt @hoch's state enumeration proposal. We need language explaining that the running and stopped states are distinguished only by the value of the AWN's active source flag.
We also need to revise the description of how the active source flag is propagated from the rendering thread to the main thread to explicitly state that a message is queued. There are two copies of this flag: one on the AWP (to gate whether process() gets called again) and another on the AWN (to drive the internal reference that affects GC).
The instantiation of AWN/AWP requires some thread-specific information for each object. For this purpose, we need some synchronization steps when addModule() call resolves. So I filed an issue for the worklet spec: w3c/css-houdini-drafts#418.
Activity
hoch commentedon Apr 5, 2017
@annevk We don't support
Transferin AudioWorklet's comm channel anyway, so changing the term from 'structured cloning' to 'serializing'. (and perhaps with a link to the reference) Does it makes sense?annevk commentedon Apr 6, 2017
Yeah, I think you want to invoke StructuredSerialize and StructuredDeserialize, referenced and with their proper names, but you also need to define the processing model of some of this in more detail.
E.g., step 4 of "The instantiation of AudioWorkletNode and AudioWorkletProcessor" currently says structured cloning is involved, but I can't find where that actually happens. (That algorithm also weirdly seems to cross threads without any kind of message passing or acknowledment that it's doing so. Is there an issue on that?)
domenic commentedon Apr 6, 2017
I think ideally this would be an opportunity to make the actual usage more rigorous in "The instantiation of AudioWorkletNode and AudioWorkletProcessor". In particular, you'd have steps like:
I'm not sure exactly how to phrase the prose references that currently say "structured clone". Maybe something like replacing
by
domenic commentedon Apr 6, 2017
Oh, I see I left my tab open for too long and @annevk said what I was going to say, basically.
hoch commentedon Apr 6, 2017
Thanks @annevk, @domenic - I will try to capture this change in our text.
hoch commentedon Apr 6, 2017
One more question:
@annevk How do you describe cross-thread operation in terms of EcmaScript? The algorithm is largely based on the PaintWorklet, except that it has several cross-thread tasks. Any example for this pattern?
annevk commentedon Apr 7, 2017
Well, each thread has an event loop. So what you end up doing is queuing tasks back and forth (message passing through tasks).
padenot commentedon Apr 7, 2017
We have several examples of cross-thread messaging in the Web Audio API. When talking to the rendering thread, use a control message. We don't have a traditional event loop, but we have our own mechanism that is compatible with our processing based on rendering quantum. When talking to the main thread, queue a task on the main thread as usual, quoting the current spec:
annevk commentedon Apr 7, 2017
The way worklets are defined they have an event loop, so you'll have to reconcile that somehow I suppose.
padenot commentedon Apr 7, 2017
Yes, this is not hard to do.
hoch commentedon Apr 7, 2017
I was hoping to find some examples that describe cross-thread operation in terms of ES, but I guess a well-written prose is good enough for this case.
annevk commentedon Apr 7, 2017
@hoch in ECMAScript you'd have to use a worker and
postMessage(). In a specification that translates to serializing objects and queuing tasks to deserialize them.hoch commentedon Apr 7, 2017
@annevk Thanks for the clarification. We don't use either worker of postMessage, so I will try to capture the cross-thread task in a prose, as @padenot suggested above.
annevk commentedon Apr 7, 2017
@hoch for the record, you can't describe anything in terms of ECMAScript in the specification. You'll always need to use some abstract concepts. There will be way too many gotchas otherwise.
17 remaining items
hoch commentedon Jun 8, 2017
We can make AWN output silence when it's in a weird state:
process()method throws the exception.Then asynchronously notify the user with:
@padenot WDYT?
padenot commentedon Jun 9, 2017
nullso it can't be connected to anything)For the notification,
onstatechangeoronerrorwould work. Semantically speaking, I don't think we should overloadonmessageon theport, which is used for normal (author-initiated) messages.hoch commentedon Jun 9, 2017
Hmm. I thought you wanted to make the instantiation process non-atomic, asynchronous. Then how can we throw an exception synchronously from the async process?
Agreed. I like it to be silent for the same reason.
Exactly. Having
onstatechangealso means we needstateread-only attribute in the node. Plus,onerrorcan be used for two purposes: 1) when the AWP construction fails and 2) when the execution ofprocess()throws and it becomes silent.padenot commentedon Jun 12, 2017
Oops sorry I misread AWP for AWN, you're right that it would put the node in error.
Fix WebAudio#1193: Revise AWN/AWP instantiation algorithm (WIP)
Fix WebAudio#1193: Revise AWN/AWP instantiation algorithm (WIP)
Fix WebAudio#1193: Revise AWN/AWP instantiation algorithm (WIP)
hoch commentedon Jun 15, 2017
Here's the work-in-progress PR, so we can discuss in F2F: Preview
joeberkovitz commentedon Jun 20, 2017
From F2F: We'll adopt @hoch's state enumeration proposal. We need language explaining that the
runningandstoppedstates are distinguished only by the value of the AWN's active source flag.We also need to revise the description of how the active source flag is propagated from the rendering thread to the main thread to explicitly state that a message is queued. There are two copies of this flag: one on the AWP (to gate whether process() gets called again) and another on the AWN (to drive the internal reference that affects GC).
Fix WebAudio#1193: Revise AWN/AWP instantiation algorithm (WIP)
hoch commentedon Jun 23, 2017
The instantiation of AWN/AWP requires some thread-specific information for each object. For this purpose, we need some synchronization steps when
addModule()call resolves. So I filed an issue for the worklet spec: w3c/css-houdini-drafts#418.Fix WebAudio#1193: Revise AWN/AWP instantiation algorithm (WIP)
joeberkovitz commentedon Sep 7, 2017
Fixed by #1265