- From: Jan-Ivar Bruaroey via GitHub <sysbot+gh@w3.org>
- Date: Tue, 26 Nov 2024 21:49:01 +0000
- To: public-webrtc@w3.org
jan-ivar has just created a new issue for https://github.com/w3c/mediacapture-transform: == Fire a stopped event on VideoTrackGenerator if all downstream tracks are stopped == My example code in a [recent blog](https://blog.mozilla.org/webrtc/unbundling-mediastreamtrackprocessor-and-videotrackgenerator/) was missing a `Stop!` button to keep things simple. Here's why: ```js start.onclick = async () => { const stream = await navigator.mediaDevices.getUserMedia({video: true}); const [track] = stream.getVideoTracks(); const worker = new Worker(`data:text/javascript,(${work.toString()})()`); worker.postMessage({track}, [track]); const {data} = await new Promise(r => worker.onmessage = r); video.srcObject = new MediaStream([data.track]); }; stop.onclick = async () => video.srcObject.getTracks()[0].stop(); // <--- click Stop! function work() { onmessage = async ({data: {track}}) => { const vtg = new VideoTrackGenerator(); self.postMessage({track: vtg.track}, [vtg.track]); const mstp = new MediaStreamTrackProcessor({track}); await mstp.readable.pipeThrough(new TransformStream({transform})).pipeTo(vtg.writable); }; } ``` Stopping left the hardware light on, because only the generator track was stopped, not the gUM track in the worker. I'd need to postMessage to the worker to stop the latter. This adds cruft, but also feels redundant, because of this line: _"When all tracks using a source have been stopped or ended by some other means, the source is [stopped](https://w3c.github.io/mediacapture-main/#source-stopped). "_ **Proposal:** Fire a `stopped` event on the generator when all downstream tracks have stopped. Then it becomes simple: ```js vtg.onstopped = () => track.stop(); // <--- add this line ``` Please view or discuss this issue at https://github.com/w3c/mediacapture-transform/issues/117 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Tuesday, 26 November 2024 21:49:02 UTC