Comments (10)
Don't use SharedArrayBuffer. We want to avoid the possibility of races. Instead make mapDataInto neuter buffer
so that it can no longer be written into.
from mediacapture-worker.
Like the post => http://robert.ocallahan.org/2013/07/avoiding-copies-in-web-apis.html
from mediacapture-worker.
Neutering indeed prevents data racing but how will the caller get the buffer
back?
The neutering operation defined in the HTML spec is a non-reversible operation:
Transferring is an irreversible and non-idempotent operation. Once an object has been transferred, it cannot be transferred, or indeed used, again.
And, It seems that there is no definition of "un-neutering". (Correct me if I was wrong.)
Moreover, the buffer
argument might be the asm.js application's run-time heap and if the mapDataInto()
neuters it, the application will then lose its heap...?
from mediacapture-worker.
Why would you want to get the buffer back? It's an output buffer.
This is indeed a problem for asm.js. I don't know what the current thinking is about how to make this fit with asm.js.
from mediacapture-worker.
Why would you want to get the buffer back? It's an output buffer.
Just because it's an output buffer, so the caller need to access it later. For example:
var bitmap = createImageBitmap(......);
var format = bitmap.findOptimalFormat();
var length = bitmap.mappedDataLength(format);
var buffer = new ArrayBuffer(length);
var p = bitmap.mapDataInto(format, buffer, 0, length); // If the _buffer_ is neutered here.
p.then(function() {
var view = new Int32TypedArray(buffer); // This will be a bad operation since the length of _buffer_ now is 0.
// No way to access the data in the _buffer_.
});
Do I misunderstand anything?
from mediacapture-worker.
Is the application going to read from it later, or write to it later as well?
If the application wants to write into it later, then mapDataInto needs to have the semantics of making a copy.
from mediacapture-worker.
Is the application going to read from it later, or write to it later as well?
Both read and write are possible.
If the application wants to write into it later, then mapDataInto needs to have the semantics of making a copy.
My implementation now does coping the ImageBitmap's data into the given buffer. (Maybe the bugzilla discussion is related to this topic.)
But, my point is that if the buffer is already neutered by the mapDataInto()
, then, no matter the buffer is mapping or coping the ImageBitmap's data, it is never accessible again in the latter JavaScript code. Isn't it?
from mediacapture-worker.
Right.
Actually I was a bit confused above, sorry. mapDataInto is defined to copy the ImageBitmap contents into the array buffer. Therefore, changes to the array buffer must not affect the ImageBitmap. There is no race.
from mediacapture-worker.
But the racing happens at another point. It happens if developers call the mapDataInto()
with a buffer and then write the buffer immediately after the mapDataInto()
function call, in stead of waiting for the promise to be resolved/rejected. In this situation, both the mapDataInto()
native implementation and the JavaScript code might write into the buffer at the same time. (Please refer to the sample code in the top post of this issue.)
Looks like neutering (without un-neutering mechanism) is not a solution?
from mediacapture-worker.
Then the mapping part of mapDataInto would have to be synchronous. It could happen either during the mapDataInto call or at the moment the promise resolves. The latter would give you more optimization opportunities (e.g. do format conversion async and then map or copy the changed data into place at the end).
from mediacapture-worker.
Related Issues (20)
- ImageBitmapFactory::createImageBitmap(FromBufferSource) should throw if the given format is not supported.
- Add constructors to both ChannelPixelLayout and ImageFormatPixelLayout HOT 6
- Decouple VideoProcessor from Workers HOT 16
- Consider leveraging `Canvas::captureMedia` for generating content HOT 5
- Consider leveraging Worklet to decouple monitor/processor from WebWorker.
- Processing offline context. HOT 9
- Elaborate the backpressure handling
- Security Considerations
- [UseCases] Re-sample the video frame rate.
- Support asynchronous processing in the VideoProcessor case? HOT 3
- Change the VideoProcessorEvent.outputImageBitmap to VideoProcessorEvent.setOutputImageBitmap() HOT 1
- The name of enum DataType is too generic HOT 1
- Simplify the ChannelPixelLayout and ImageFormatPixelLayout HOT 1
- The ImageBitmap::FindOptimalFormat() should not return empty string HOT 1
- Call mapDataInto() on an ImageBitmap which was created with a cropping area that is outside of the source image. HOT 3
- Crop YUV422/YUV420 data? HOT 1
- The data type of HSV and Lab should be floating point
- Drop the cropping variant of creating ImageBitmap from an ArrayBuffer. HOT 1
- Publish First Public Working Draft HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediacapture-worker.