-
Notifications
You must be signed in to change notification settings - Fork 167
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
AudioContext.decodeAudioData() from a SharedArrayBuffer source? #1850
Comments
This is something that would be very nice to have indeed, however it's not without problems. The main issue I see is that Having the possibility to mutate the bytes while the decoder is working probably cannot be proved safe in practice (due to the multiplicity of scenarios, a lot of which browser vendors don't have any control on). It used to be that the buffer wasn't detached, and this caused more than one security issue, iirc. I'm particularly concerned by codecs that try to keep the memory usage down and locality high by not copying information out of the container, and instead referencing bits of memory. Let's say you get a length out of the container, at a certain offset, validated initially, and then a malicious bit of code changes the length under the codec, that still references this memory, and this can potentially cause an OOB. I can't prove that this is something that is not done today in code that we don't control, and I can't prove that this is something that cannot be done in the future. In addition (and this is an implementation concern, not a spec concern), Firefox is now running the codecs in a separate process (because they are very complex piece of code, we're sandboxing them harder than the rest of the web content). This means that we would copy anyways (either to a SHMEM, or via a pipe, etc.), to decode. However this does it by block by block so the copies are smaller and the memory usage is not doubled. Is there a facility in Another thing that could be interesting would be to decode into a |
Not at this time. We're talking about adding mprotect-like features to wasm in the future but it's unknown how that would interact with the needs of the audio subsystem -- I would think it might just make things even more complicated. |
From an IDL perspective, you'll need to use That is, we want to enable Does that make sense? |
For the same reason, it would be great if we can use SAB for Audio Worklet's |
I don't really see that kind of mechanism being possible until wasm has something like mprotect and exception handling and we can phrase the semantics of the protection in those terms. In that case, we may be able to treat the audio subsystem simply as a concurrent agent that protects/unprotects parts of shared memory, and we'll have a model for what it means when other agents touch the protected area. |
I think it's best to wait until wasm/SAB has the facilities needed here. @lars-t-hansen, if discussions happens on something like mprotect/etc., can one of us be notified? I don't think we can do anything without it. |
@lars-t-hansen I really like that idea. This new design will help a lot of performance-critical audio use cases. We're punting this to v.next, but Audio WG might not be the right venue for discussion. Web Audio API or the other audio API will be a customer of such design. |
Solving this at a higher level, if #1305 happened, and a more efficient cursor-based decoding API was available, then that could be used as a replacement. In such scenario, many applications would be able to avoid having to stuff the compressed audio files inside the wasm heap in the first place, if the browser was able to decode audio for them. |
Closing this, it is not an area of the api that we will be working on in V2. However we hope that this |
(It's a requirement of the web-codec effort to work well with the web audio api). |
This comment was marked as off-topic.
This comment was marked as off-topic.
Probably it's better to get that in the WebCodec explainer. :) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Oh, I was merely quoting @padenot's comment - but "working well" means many things in many different layers; performance, API ergonomics, and ease of use. I won't try to clarify everything in this comment or this thread. |
This comment was marked as off-topic.
This comment was marked as off-topic.
The feature request template is being removed. We'll probably need to add some words somewhere that feature requests should go to the issues for the v2 repo. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Don't know how it will work, but having two apis that overlap a little is not a great pattern. It seems more beneficial for everyone if WebCodecs can solve this, rather than grafting some kind of partial solution to decodeAudioData but not be able to do other things that WebCodecs can do. It's up to you and us to do our best to make it happen. |
Multithreaded WebAssembly applications utilize a SharedArrayBuffer object as their heap type. These applications can contain encoded audio files inside their heaps, e.g. as part of a filesystem that they embed inside the heap.
However, these applications are unable to decode audio files from within their WebAssembly heaps. Calling
fails with
As a workaround, the applications need to create a temporary copy of the data from a SharedArrayBuffer to a regular ArrayBuffer, e.g.
If Web Audio spec allowed decodeAudioData directly from SABs, then the above deep copy of encoded .ogg files would be avoided in multithreaded WebAssembly applications.
CC @lars-t-hansen
The text was updated successfully, but these errors were encountered: