You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: explainer.md
+29-3Lines changed: 29 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,10 +36,36 @@ The encoder is an object that takes a Stream(raw frames) and emits a Stream(enco
36
36
37
37
## Code examples
38
38
39
-
We can pass a factory function to the PeerConnection that does the building whenever an encoder is needed (and similar for the decoder):
39
+
In order to insert your own processing in the media pipeline, do the following:
40
40
41
+
1. Declare a function that does what you want to a single frame.
41
42
<pre>
42
-
pc = new PeerConnection( {
43
+
function mungeFunction(frame) { … }
44
+
</pre>
45
+
2. Set up a transform stream that will apply this function to all frames passed to it.
46
+
<pre>
47
+
var munger = new TransformStream({transformer: mungeFunction});
48
+
</pre>
49
+
3. Create a function that will take the original encoder, connect it to the transformStream in an appropriate way, and return an object that can be treated by the rest of the system as if it is an encoder:
50
+
<pre>
51
+
function installMunger(encoder, context) {
52
+
encoder.readable.pipeTo(munger.writable);
53
+
var wrappedEncoder = { readable: munger.readable,
54
+
writable: encoder.writable };
55
+
return wrappedEncoder;
56
+
}
57
+
</pre>
58
+
4. Tell the PeerConnection to call this function whenever an encoder is created:
59
+
<pre>
60
+
pc = new RTCPeerConnection ({
61
+
encoderFactory: installMunger;
62
+
});
63
+
</pre>
64
+
65
+
Or do it all using a deeply nested set of parentheses:
66
+
67
+
<pre>
68
+
pc = new RTCPeerConnection( {
43
69
encoderFactory: (encoder) => {
44
70
var munger = new TransformStream({
45
71
transformer: munge
@@ -56,7 +82,7 @@ The PC will then connect the returned object’s “writable” to the media inp
56
82
57
83
When the processing is to be done in a worker, we let the factory method pass the pipes to the worker:
58
84
<pre>
59
-
pc = new PeerConnection({
85
+
pc = new RTCPeerConnection({
60
86
encoderFactory: (encoder) => {
61
87
var munger = new TransformStream({ transformer: munge });
0 commit comments