MediaStreamAPI: Difference between revisions

Jump to navigation Jump to search
Line 39: Line 39:
* Solution: if a (non-live) stream feeds into a blocking mixer, then it itself gets blocked. This has the same effect as the entire graph of (non-live) connected streams blocking as a unit.
* Solution: if a (non-live) stream feeds into a blocking mixer, then it itself gets blocked. This has the same effect as the entire graph of (non-live) connected streams blocking as a unit.


== <mediaresource> element ==
== &lt;mediaresource&gt; element ==


  interface HTMLMediaResourceElement {
  interface HTMLMediaResourceElement {
Line 73: Line 73:
  };
  };


<mediaresource> elements can have <source> children.
&lt;mediaresource&gt; elements can have &lt;source&gt; children.


Is this needed? Maybe to allow reliable synchronization/easy use of canned samples.
Is this needed? Maybe to allow reliable synchronization/easy use of canned samples.
Line 169: Line 169:


1) Play video with processing effect applied to the audio track
1) Play video with processing effect applied to the audio track
  <video src="foo.webm" id="v" controls streamaudio></video>
  &lt;video src="foo.webm" id="v" controls streamaudio&gt;&lt;/video&gt;
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   document.getElementById("out").src =
   document.getElementById("out").src =
     document.getElementById("v").getStream().createProcessor(new Worker("effect.js"));
     document.getElementById("v").getStream().createProcessor(new Worker("effect.js"));
  </script>
  &lt;/script&gt;


2) Play video with processing effects mixing in out-of-band audio tracks (in sync)
2) Play video with processing effects mixing in out-of-band audio tracks (in sync)
  <video src="foo.webm" id="v" streamaudio></video>
  &lt;video src="foo.webm" id="v" streamaudio&gt;&lt;/video&gt;
  <audio src="back.webm" id="back"></audio>
  &lt;audio src="back.webm" id="back"&gt;&lt;/audio&gt;
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   var mixer = document.getElementById("v").getStream().createProcessor(new Worker("audio-ducking.js"));
   var mixer = document.getElementById("v").getStream().createProcessor(new Worker("audio-ducking.js"));
   mixer.addStream(document.getElementById("back").getStream());
   mixer.addStream(document.getElementById("back").getStream());
Line 190: Line 190:
   // We probably need additional API to more conveniently tie together
   // We probably need additional API to more conveniently tie together
   // the controls for multiple media elements.
   // the controls for multiple media elements.
  </script>
  &lt;/script&gt;


3) Capture microphone input and stream it out to a peer with a processing effect applied to the audio
3) Capture microphone input and stream it out to a peer with a processing effect applied to the audio
  <script>
  &lt;script&gt;
   navigator.getUserMedia('audio', gotAudio);
   navigator.getUserMedia('audio', gotAudio);
   function gotAudio(stream) {
   function gotAudio(stream) {
     peerConnection.addStream(stream.createProcessor(new Worker("effect.js")));
     peerConnection.addStream(stream.createProcessor(new Worker("effect.js")));
   }
   }
  </script>
  &lt;/script&gt;


4) Capture microphone input and visualize it as it is being streamed out to a peer and recorded
4) Capture microphone input and visualize it as it is being streamed out to a peer and recorded
  <canvas id="c"></canvas>
  &lt;canvas id="c"&gt;&lt;/canvas&gt;
  <script>
  &lt;script&gt;
   navigator.getUserMedia('audio', gotAudio);
   navigator.getUserMedia('audio', gotAudio);
   var streamRecorder;
   var streamRecorder;
Line 214: Line 214:
     peerConnection.addStream(processed);
     peerConnection.addStream(processed);
   }
   }
  </script>
  &lt;/script&gt;


5) Capture microphone input, visualize it, mix in another audio track and stream the result to a peer and record
5) Capture microphone input, visualize it, mix in another audio track and stream the result to a peer and record
  <canvas id="c"></canvas>
  &lt;canvas id="c"&gt;&lt;/canvas&gt;
  <mediaresource src="back.webm" id="back"></mediaresource>
  &lt;mediaresource src="back.webm" id="back"&gt;&lt;/mediaresource&gt;
  <script>
  &lt;script&gt;
   navigator.getUserMedia('audio', gotAudio);
   navigator.getUserMedia('audio', gotAudio);
   var streamRecorder;
   var streamRecorder;
Line 233: Line 233:
     peerConnection.addStream(mixer);
     peerConnection.addStream(mixer);
   }
   }
  </script>
  &lt;/script&gt;


6) Receive audio streams from peers, mix them with spatialization effects, and play
6) Receive audio streams from peers, mix them with spatialization effects, and play
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   var worker = new Worker("spatializer.js");
   var worker = new Worker("spatializer.js");
   var spatialized = stream.createProcessor(worker);
   var spatialized = stream.createProcessor(worker);
Line 245: Line 245:
   };
   };
   document.getElementById("out").src = spatialized;   
   document.getElementById("out").src = spatialized;   
  </script>
  &lt;/script&gt;


7) Seamlessly chain from the end of one input stream to another
7) Seamlessly chain from the end of one input stream to another
  <mediaresource src="in1.webm" id="in1" preload></mediaresource>
  &lt;mediaresource src="in1.webm" id="in1" preload&gt;&lt;/mediaresource&gt;
  <mediaresource src="in2.webm" id="in2"></mediaresource>
  &lt;mediaresource src="in2.webm" id="in2"&gt;&lt;/mediaresource&gt;
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   var in1 = document.getElementById("in1");
   var in1 = document.getElementById("in1");
   in1.onloadeddata = function() {
   in1.onloadeddata = function() {
Line 260: Line 260:
     document.getElementById("out").src = mixer;
     document.getElementById("out").src = mixer;
   }
   }
  </script>
  &lt;/script&gt;


8) Seamlessly switch from one input stream to another, e.g. to implement adaptive streaming
8) Seamlessly switch from one input stream to another, e.g. to implement adaptive streaming
  <mediaresource src="in1.webm" id="in1" preload></mediaresource>
  &lt;mediaresource src="in1.webm" id="in1" preload&gt;&lt;/mediaresource&gt;
  <mediaresource src="in2.webm" id="in2"></mediaresource>
  &lt;mediaresource src="in2.webm" id="in2"&gt;&lt;/mediaresource&gt;
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   var stream1 = document.getElementById("in1").startStream();
   var stream1 = document.getElementById("in1").startStream();
   var mixer = stream1.createProcessor();
   var mixer = stream1.createProcessor();
Line 285: Line 285:
     }
     }
   }
   }
  </script>
  &lt;/script&gt;


9) Synthesize samples from JS data
9) Synthesize samples from JS data
  <audio id="out" autoplay></audio>
  &lt;audio id="out" autoplay&gt;&lt;/audio&gt;
  <script>
  &lt;script&gt;
   document.getElementById("out").src =
   document.getElementById("out").src =
     new StreamProcessor(new Worker("synthesizer.js"));
     new StreamProcessor(new Worker("synthesizer.js"));
  </script>
  &lt;/script&gt;


10) Trigger a sound sample to be played through the effects graph ASAP but without causing any blocking
10) Trigger a sound sample to be played through the effects graph ASAP but without causing any blocking
  <script>
  &lt;script&gt;
   var effectsMixer = ...;
   var effectsMixer = ...;
   function playSound(src) {
   function playSound(src) {
Line 306: Line 306:
     }
     }
   }
   }
  </script>
  &lt;/script&gt;
1,295

edits

Navigation menu