-
Notifications
You must be signed in to change notification settings - Fork 144
Add optional MediaStreamTrack integration points to encoders and decoders. #266
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
Comments
This proposal makes sense for realtime streams where the only goal is minimizing rendering latency. That's the case for many desktop-streaming cases, but in higher-latency case (including regular video conferencing) a jitter buffer may be preferable. Once you get to regular media playback it does not make sense to work this way. This is most similar to the let ctx = canvas.getContext("bitmaprenderer");
function output(frame) {
createImageBitmap(frame).then(bitmap => ctx.transferFromImageBitmap(bitmap));
frame.close();
} A let ctx = canvas.getContext("2d");
function output(frame) {
ctx.drawImage(frame, 0, 0);
frame.close();
} A |
@youennf mentioned using media stream tracks as well. This makes me a bit wary because media streams and video don’t have low latency guarantees, and may buffer the data, etc. |
This is accurate, the buffering properties of a MediaStreamTrack are not clear. It was designed to support WebRTC so it favors realtime use, though it does include the ability to jitter buffer. The Chrome implementation is realtime, except when used with MediaRecorder. There is difficulty inherent in integrating MediaStreamTrack with WebCodecs, since WebCodecs supports both realtime and non-realtime uses. MediaStreamTrackGenerator adds Streams to the mix, which is an extra layer where frames can be buffered. All that said, I would typically expect the buffers to be empty and the latency to be low. The goal is, after all, for MediaStreamTrackGenerator to be widely used by WebRTC apps. |
I do not think MediaStreamTracks do any buffering in general (it might be worth checking what browsers do by creating a canvas capture track, generating a frame on this track and then assigning the track to a video element without generating new frames). As of jitter buffer, this might be done on raw video frames, which might be memory intensive.
I am not really sure of that. Can you describe why that would be difficult? |
Is this just a convenient byproduct of the implementation or a guarantee by the spec? |
I think this is the spirit of the spec, especially given its first use is exposing realtime audio data like camera and microphone. There is not a lot of normative wording given this is not super observable by the web application. One example:
|
MediaStreamTrack is designed for realtime use, it will drop stale frames when new frames arrive. Apps are never guaranteed to receive all frames from a source, which is unsuitable for non-realtime uses. Adding Streams, as MediaStreamTrackProcessor does, adds a buffer that operates after stale frame dropping occurs. The result can be that a stale frame is kept alive inside the Stream for a long time while newer frames are dropped. In this case the drop behavior isn't even keeping the "next frame" fresh. |
Yeah MediaStreamTrack is always realtime AFAIK. Maybe you're confusing it with MSE?
Can you elaborate? My understanding of WHATWG streams is that they impose no buffering on their own. That is: streams can operate by passing (platform) objects around, and the default high-water mark is 1, which translates to no buffering. |
That is currently not observable to the web so it really depends on the source and sink internal behaviors. On another WebCodec threads, we are discussing the possibility to add a 'realtime' codec setting.
|
I don't think we could ever replace all the WebGL code in the first post. At best we could replace a canvas.drawImage() call, but the WebGL stuff has meaning. For these straight-to-canvas use cases, it seems like we instead want to use one of the proposed MediaStream creation mechanisms and pipe them into video:
We could accept either of those in the |
I do not see how MediaStreamTrackGenerator or MediaStreamTrackVideoController give benefits here over a MediaStreamTrack, can you clarify this? As a side bonus, if we design native MediaStreamTrack transforms, we could have WebCodecs -> MediaStreamTrack -> transform -> rendering without any JS interruption. |
MediaStreamTrack could also work; I just suggested the JS versions offhand. E.g., one possibility for optional interfaces like this:
Keep in mind MediaStreams run afoul of the same issues that streams do though, so we'll want to be careful here: In general though, we're supportive of optional MediaStreamTrack integration points. I agree they could be very useful for simplifying developers lives and improving performance by decoupling entirely from JS visible threads. |
For |
Thanks, I did mean |
In issue #211, koush@ raised the following idea for an option to send outputs directly to canvas (no callback). Splitting that off into its own issue for further consideration.
koush@ wrote:
The text was updated successfully, but these errors were encountered: