Skip to content
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

Expose MSTP and MSTG on DedicatedWorker #61

Merged
merged 2 commits into from Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions index.bs
Expand Up @@ -178,6 +178,7 @@ does not give the UA enough flexibility to choose the buffering policy.
### Interface definition ### {#track-processor-interface}

<pre class="idl">
[Exposed=Window,DedicatedWorker]
interface MediaStreamTrackProcessor {
constructor(MediaStreamTrackProcessorInit init);
attribute ReadableStream readable;
Expand Down Expand Up @@ -307,6 +308,7 @@ resources are no longer accessible from JavaScript.

### Interface definition ### {#generator-interface}
<pre class="idl">
[Exposed=Window,DedicatedWorker]
interface MediaStreamTrackGenerator : MediaStreamTrack {
constructor(MediaStreamTrackGeneratorInit init);
attribute WritableStream writable; // VideoFrame or AudioFrame
Expand Down Expand Up @@ -741,7 +743,52 @@ self.onmessage = async function(e) {
await Promise.all([audioPromise, videoPromise]);
cleanupNetworkSinks();
}

</pre>
Example using transfer of the MediaStreamTrack:
<pre class="example">
// main.js
const stream = await getUserMedia({audio:true, video:true});
const audioTrack = stream.getAudioTracks()[0];
const videoTrack = stream.getVideoTracks()[0];
const worker = new Worker('worker.js');
worker.postMessage({
audioTrack: audioTrack,
videoTrack: videoTrack,
}, [
audioTrack, videoTrack
]);

// worker.js
function writeToSink(readable, sinkFunction) {
return new Promise(async resolve => {
while (true) {
const result = await readable.read();
if (result.done) {
break;
} else {
sinkFunction(result.value);
result.value.close();
}
}
resolve();
});
}

self.onmessage = async function(e) {
setupNetworkSinks();
const audioProcessor = new MediaStreamTrackProcessor({track: e.data.audioTrack});
const videoProcessor = new MediaStreamTrackProcessor({track: e.data.videoTrack});
const audioReader = audioProcessor.readable.getReader();
const videoReader = videoProcessor.readable.getReader();
const audioPromise = writeToSink(audioReader, sendAudioToNetwork);
const videoPromise = writeToSink(videoReader, sendVideoToNetwork);
await Promise.all([audioPromise, videoPromise]);
cleanupNetworkSinks();
}

</pre>


# Implementation advice # {#implementation-advice}

Expand Down