- From: Jan-Ivar Bruaroey via GitHub <sysbot+gh@w3.org>
- Date: Wed, 27 Nov 2024 00:03:15 +0000
- To: public-webrtc-logs@w3.org
> Forcing track transferability requires cloning the camera track and a communication protocol between Worker and Window to keep the state consistent between them, all of which is unnecessary if the tracks can be kept on Window. Transfer does not require cloning. It's the before/after use case showing the original camera track that needs it. Without that, no clone is needed (and one less track to stop). > How does it relate to https://github.com/w3c/mediacapture-transform/issues/113? This issue focuses on the web developer aspect only, phrased as a problem with the existing spec. Thanks @guidou! > - The difference in code complexity is not that big in these two examples. Agree. 25 vs 40 lines doesn't seem enough to justify a bespoke API. > - For stopping track, I would think the first example to be easier to handle: stopping the post transform track will stop the writable, which the worker is notified and would stop the original track. @youennf's tip in https://github.com/w3c/mediacapture-transform/issues/117#issuecomment-2502034790 lets us simplify further (32 lines): ```js // main.html function setUpWorker() { const worker = new Worker("worker.js"); worker.onmessage = async ({data}) => { processedVideo.srcObject = new MediaStream([data.track]); await processedVideo.play(); } } async function startCapture() { const stream = await navigator.mediaDevices.getUserMedia({video:true}); originalVideo.srcObject = stream.clone(); await originalVideo.play(); const [track] = stream.getVideoTracks(); worker.postMessage({track}, [track]); } function stopCapture() { [originalVideo, processedVideo].forEach(v => v.srcObject.getTracks()[0].stop()); } // worker.js onmessage = async ({data: {track}}) => { const processor = new MediaStreamTrackProcessor({track}); const generator = new VideoTrackGenerator(); postMessage({track: generator.track}, [generator.track]); try { await processor.readable.pipeThrough(GetTransform()).pipeTo(generator.writable); } finally { track.stop(); } } ``` -- GitHub Notification of comment by jan-ivar Please view or discuss this issue at https://github.com/w3c/mediacapture-transform/issues/116#issuecomment-2502224631 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Wednesday, 27 November 2024 00:03:16 UTC