forked from fluffy/webrtc-w3c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getusermedia.html
2044 lines (1665 loc) · 76.7 KB
/
getusermedia.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 (experimental) for Linux https://github.com/w3c/tidy-html5/tree/68a9e74">
<link href="getusermedia.css" rel="stylesheet" type="text/css">
<title>Media Capture and Streams</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<!--
After making changes to this document in the github repo, run:
./publish.sh getusermedia.html
to publish a new editor's draft to the W3C CVS. This assumes your
CVS checkout is located at ../2011/webrtc, you can specify the location
as the second argument, for example:
./publish.sh getusermedia.html ~/path/to/w3/2011/webrtc
-->
<script class="remove" src="http://www.w3.org/Tools/respec/respec-w3c-common"
type="text/javascript">
<!-- keep this comment -->
</script>
<script class="remove" src="getusermedia.js" type="text/javascript">
<!-- keep this comment -->
</script>
</head>
<body>
<section id="abstract">
<p>This document defines a set of JavaScript APIs that allow local media,
including audio and video, to be requested from a platform.</p>
</section>
<section id="sotd">
<p>This document is not complete. It is subject to major changes and, while
early experimentations are encouraged, it is therefore not intended for
implementation. The API is based on preliminary work done in the WHATWG.
The Media Capture Task Force expects this specification to evolve
significantly based on:</p>
<ul>
<li>Privacy issues that arise when exposing local capabilities and local
streams.</li>
<li>Technical discussions within the task force.</li>
<li>Experience gained through early experimentations.</li>
<li>Feedback received from other groups and individuals.</li>
</ul>
</section>
<section class="informative" id="intro">
<h2>Introduction</h2>
<p>Access to multimedia streams (video, audio, or both) from local devices
(video cameras, microphones, Web cams) can have a number of uses, such as
real-time communication, recording, and surveillance.</p>
<p>This document defines the APIs used to get access to local devices that
can generate multimedia stream data. This document also defines the stream
API by which JavaScript is able to manipulate the stream data or otherwise
process it.</p>
</section>
<section id="conformance">
<p>
This specification defines conformance criteria that apply to a single
product: the <dfn>user agent</dfn> that implements the
interfaces that it contains.
</p>
<p>
Implementations that use ECMAScript to implement the APIs defined in
this specification must implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]],
as this specification uses that specification and terminology.
</p>
</section>
<section>
<h2>Terminology</h2>
<p>
The <code><a href="http://dev.w3.org/html5/spec/webappapis.html#eventhandler">
EventHandler</a></code> interface represents a callback used for event
handlers as defined in [[!HTML5]].
</p>
<p>
The concepts <dfn><a href="http://dev.w3.org/html5/spec/webappapis.html#queue-a-task">
queue a task</a></dfn> and
<dfn><a href="http://dev.w3.org/html5/spec/webappapis.html#fire-a-simple-event">
fires a simple event</a></dfn> are defined in [[!HTML5]].
</p>
<p>
The terms <dfn><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handlers">
event handlers</a></dfn> and
<dfn><a href="http://dev.w3.org/html5/spec/webappapis.html#event-handler-event-type">
event handler event types</a></dfn> are defined in [[!HTML5]].
</p>
</section>
<section id="stream-api">
<h2>Stream API</h2>
<section>
<h2>Introduction</h2>
<p>The <code><a>MediaStream</a></code> interface is used to represent
streams of media data, typically (but not necessarily) of audio and/or
video content, e.g. from a local camera. The data from a
<code><a>MediaStream</a></code> object does not necessarily have a
canonical binary form; for example, it could just be "the video currently
coming from the user’s video camera". This allows user agents to
manipulate media streams in whatever fashion is most suitable on the
user’s platform.</p>
<p>Each <code><a>MediaStream</a></code> object can contain zero or more
tracks, in particular audio and video tracks. All tracks in a MediaStream
are intended to be synchronized when rendered. Different MediaStreams do
not need to be synchronized.</p>
<p>Each track in a MediaStream object has a corresponding
<code><a>MediaStreamTrack</a></code> object.</p>
<p>A <code><a>MediaStreamTrack</a></code> represents content comprising
one or more channels, where the channels have a defined well known
relationship to each other (such as a stereo or 5.1 audio signal).</p>
<p>A channel is the smallest unit considered in this API
specification.</p>
<p>A <code><a>MediaStream</a></code> object has an input and an output.
The input depends on how the object was created: a
<code><a>LocalMediaStream</a></code> object generated by a <code><a href=
"#dom-navigator-getusermedia">getUserMedia()</a></code> call (which is
described later in this document), for instance, might take its input
from the user’s local camera. The output of the object controls how the
object is used, e.g., what is saved if the object is written to a file or
what is displayed if the object is used in a <code>video</code>
element.</p>
<p>Each track in a <code><a>MediaStream</a></code> object can be
disabled, meaning that it is muted in the object’s output. All tracks are
initially enabled.</p>
<p>A <code><a>MediaStream</a></code> can be <a>finished</a>, indicating
that its inputs have forever stopped providing data.</p>
<p>The output of a <code><a>MediaStream</a></code> object MUST correspond
to the tracks in its input. Muted audio tracks MUST be replaced with
silence. Muted video tracks MUST be replaced with blackness.</p>
<p>A new <code><a>MediaStream</a></code> object can be created from
existing <code><a>MediaStreamTrack</a></code> objects using the
<code><a href="#dom-mediastream">MediaStream()</a></code> constructor.
The constructor takes two lists of <code><a>MediaStreamTrack</a></code>
objects as arguments: one for audio tracks and one for video tracks. The
lists can either be the track lists of another stream, subsets of such
lists, or compositions of <code><a>MediaStreamTrack</a></code> objects
from different <code><a>MediaStream</a></code> objects.</p>
<p><img alt="A MediaStream" src="images/media-stream.png" width=
"40%"></p>
<p>The ability to duplicate a <code><a>MediaStream</a></code>, i.e.
create a new <code><a>MediaStream</a></code> object from the track lists
of an existing stream, allows for greater control since separate
<code><a>MediaStream</a></code> instances can be manipulated and
<a title="consumer">consumed</a> individually.</p>
<p>The <code><a>LocalMediaStream</a></code> interface is used when the
user agent is generating the stream’s data (e.g. from a camera or
streaming it from a local video file).</p>
<p>When a <code><a>LocalMediaStream</a></code> object is being generated
from a local file (as opposed to a live audio/video source), the user
agent SHOULD stream the data from the file in real time, not all at once.
The <code>MediaStream</code> object is also used in contexts outside
<code>getUserMedia</code>, such as [[!WEBRTC10]]. In both cases, ensuring
a realtime stream reduces the ease with which pages can distinguish live
video from pre-recorded video, which can help protect the user’s
privacy.</p>
</section>
<section>
<h2>MediaStream</h2>
<p>The <dfn id="dom-mediastream"> <code>MediaStream()</code></dfn>
constructor takes zero or one argument. If the argument,
<var>trackContainers</var>, is supplied, it specifies a list of <code>
<a>MediaStream</a></code>, <code><a>MediaStreamTrackList</a></code> and
<code><a>MediaStreamTrack</a></code> objects. The list objects specifies
existing tracks whose sources will be used to constuct the tracks in the
new <code><a>MediaStream</a></code> object. A <code>
<a>MediaStreamTrack</a></code> object specifies a track directly, while
<code><a>MediaStream</a></code> and <code><a>MediaStreamTrackList</a>
</code> objects specifiy all tracks contained within these objects. When
the constructor is invoked, the UA must run the following steps:</p>
<ol>
<li>
<p>Let <var>trackContainers</var> be the constructor’s argument, if
any, or null otherwise.</p>
</li>
<li>
<p>Let <var>stream</var> be a newly constructed <code>
<a>MediaStream</a></code> object.</p>
</li>
<li>
<p>Set <var>stream’s</var> label attribute to a newly generated
value.</p>
</li>
<li>
<p>If <var>trackContainers</var> is not null, then run the following
sub steps for every element, <var>trackContainer</var>, in
<var>trackContainers</var>:</p>
</li>
<ol>
<li>
<p>If <var>trackContainer</var> is null, then abort these steps
and continue with the next element.</p>
</li>
<li>
<p>If <var>trackContainer</var> is of type <code>
<a>MediaStreamTrack</a></code>, then run the following sub
steps:</p>
</li>
<ol>
<li>
<p><em>Add track</em>: Let <var>track</var> be the <code>
<a>MediaStreamTrack</a></code> about to be processed.</p>
</li>
<li>
<p>If <var>track’s</var> kind attribute is not
"<code>audio</code>" or "<code>video</code>", then throw a
<code>SyntaxError</code> exception.</p>
</li>
<li>
<p>If <var>track</var> has <a>ended</a> or if there is already
a <code><a>MediaStreamTrack</a></code> contained within
<var>stream</var> that has the same underlying source as
<var>track</var>, then abort these steps.
</p>
</li>
<li>
<p>Create a new <code><a>MediaStreamTrack</a></code> object
and let it inherit <var>track’s</var> underlying source,
<code><a href="#dom-mediastreamtrack-kind">kind</a></code> and
<code><a href="#dom-mediastreamtrack-label">label</a></code>
attributes. Append the new <code><a>MediaStreamTrack</a>
</code> to the corresponding track list
(<code><a href="#dom-mediastream-audiotracks">audioTracks</a>
</code> or <code>
<a href="#dom-mediastream-videotracks">videoTracks</a></code>)
in <var>stream</var> according to kind.</p>
</li>
</ol>
<li>
<p>If <var>trackContainer</var> is of type <code>
<a>MediaStreamTrackList</a></code>, then run the sub steps
labeled <em>Add track</em> (above) for every <code>
<a>MediaStreamTrack</a></code> in <var>trackContainer</var>.</p>
</li>
<li>
<p>If <var>trackContainer</var> is of type <code>
<a>MediaStream</a></code>, then run the sub steps labeled
<em>Add track</em> (above) for every <code>
<a>MediaStreamTrack</a></code> in <var>trackContainer’s</var>
two track lists
(<code><a href="#dom-mediastream-audiotracks">audioTracks</a>
</code> and <code>
<a href="#dom-mediastream-videotracks">videoTracks</a></code>).
</p>
</li>
</li>
</ol>
<li>
<p>Return <var>stream</var>.</p>
</li>
</ol>
<p>A <code><a>MediaStream</a></code> can have multiple audio and video
sources (e.g. because the user has multiple microphones, or because the
real source of the stream is a media resource with many media tracks).
The stream represented by a <code><a>MediaStream</a></code> thus has zero
or more tracks.</p>
<p>The tracks of a <code><a>MediaStream</a></code> are stored in two
track lists represented by <code><a>MediaStreamTrackList</a></code>
objects: one for audio tracks and one for video tracks. The two track
lists MUST contain the <code><a>MediaStreamTrack</a></code> objects that
correspond to the tracks of the stream. The relative order of all tracks
in a user agent MUST be stable. Tracks that come from a media resource
whose format defines an order MUST be in the order defined by the format;
tracks that come from a media resource whose format does not define an
order MUST be in the relative order in which the tracks are declared in
that media resource. Within these constraints, the order is user agent
defined.</p>
<p>An object that reads data from the output of a
<code><a>MediaStream</a></code> is referred to as a
<code><a>MediaStream</a></code> <dfn>consumer</dfn>. The list of
<code><a>MediaStream</a></code> consumers currently includes the media
elements and the <code><a>PeerConnection</a></code> API specified in
[[!WEBRTC10]].</p>
<p class="note"><code><a>MediaStream</a></code> consumers must be able to
handle tracks being added and removed. This behavior is specified per
consumer.</p>
<p>A <code><a>MediaStream</a></code> object is said to be
<dfn>finished</dfn> when all tracks belonging to the stream have
<a>ended</a>. When this happens for any reason other than the
<code><a href="#dom-mediastream-stop">stop()</a></code> method being
invoked, the user agent MUST queue a task that runs the following
steps:</p>
<ol>
<li>
<p>If the object’s <code><a href=
"#dom-mediastream-ended">ended</a></code> attribute has the value
true already, then abort these steps. (The <code><a href=
"#dom-mediastream-stop">stop()</a></code> method was probably called
just before the stream stopped for other reasons, e.g. the user
clicked an in-page stop button and then the user agent provided stop
button.)</p>
</li>
<li>
<p>Set the object’s <code><a href=
"#dom-mediastream-ended">ended</a></code> attribute to true.</p>
</li>
<li>
<p>Fire a simple event named <code title=
"event-MediaStream-ended"><a href=
"#event-mediastream-ended">ended</a></code> at the object.</p>
</li>
</ol>
<p>If the end of the stream was reached due to a user request, the task
source for this <span title="concept-task">task</span> is the user
interaction task source. Otherwise the task source for this <span title=
"concept-task">task</span> is the networking task source.</p>
<p class="note">The union type we want to express here is not supported
by ReSpec at the moment. Until it is supported, let
<code>TracksUnionType</code> be defined as <code>(MediaStream? or
MediaStreamTrackList or MediaStreamTrack)[]</code>.</p>
<dl class="idl"
title="[Constructor (TracksUnionType? trackContainers)] interface MediaStream">
<dt>readonly attribute DOMString label</dt>
<dd>
<p>When a <code><a>LocalMediaStream</a></code> object is created, the
user agent MUST generate a globally unique identifier string, and
MUST initialize the object’s <code><a href=
"#dom-mediastream-label">label</a></code> attribute to that string.
Such strings MUST only use characters in the ranges U+0021, U+0023 to
U+0027, U+002A to U+002B, U+002D to U+002E, U+0030 to U+0039, U+0041
to U+005A, U+005E to U+007E, and MUST be 36 characters long.</p>
<!-- UUIDs have 36 characters
including hyphens; the ranges above comes from RFC4574 (the a=label:
thing in SDP) -->
<!-- described below -->
<p>When a <code><a>MediaStream</a></code> is created from another
using the <code><a href="#dom-mediastream">MediaStream()</a></code>
constructor, the <code><a>label</a></code> attribute is initialized to
a newly generated value.</p><!-- described above -->
<p>The <dfn id="dom-mediastream-label"><code>label</code></dfn>
attribute MUST return the value to which it was initialized when the
object was created.</p>
</dd>
<dt>readonly attribute MediaStreamTrackList audioTracks</dt>
<dd>
<p>Returns a <code><a>MediaStreamTrackList</a></code> object
representing the audio tracks that can be enabled and disabled.</p>
<p>The <dfn id=
"dom-mediastream-audiotracks"><code>audioTracks</code></dfn>
attribute MUST return an <span title="array host objects">array host
object</span> for objects of type
<code><a>MediaStreamTrack</a></code> that is <em>fixed length</em>
and <em>read only</em>. The same object MUST be returned each time
the attribute is accessed.</p>
</dd>
<dt>readonly attribute MediaStreamTrackList videoTracks</dt>
<dd>
<p>Returns a <code><a>MediaStreamTrackList</a></code> object
representing the video tracks that can be enabled and disabled.</p>
<p>The <dfn id=
"dom-mediastream-videotracks"><code>videoTracks</code></dfn>
attribute MUST return an <span title="array host objects">array host
object</span> for objects of type
<code><a>MediaStreamTrack</a></code> that is <em>fixed length</em>
and <em>read only</em>. The same object MUST be returned each time
the attribute is accessed.</p>
</dd>
<dt>attribute boolean ended</dt>
<dd>
<p>The <dfn id=
"dom-mediastream-ended"><code>MediaStream.ended</code></dfn>
attribute MUST return true if the <code><a>MediaStream</a></code> has
<a>finished</a>, and false otherwise.</p>
<p>When a <code><a>MediaStream</a></code> object is created, its
<code><a href="#dom-mediastream-ended">ended</a></code> attribute
MUST be set to false, unless it is being created using the
<code><a href="#dom-mediastream">MediaStream()</a></code> constructor
whose arguments are lists of <code><a>MediaStreamTrack</a></code>
objects that are all <a>ended</a>, in which case the
<code><a>MediaStream</a></code> object MUST be created with its
<code><a href="#dom-mediastream-ended">ended</a></code> attribute set
to true.</p>
</dd>
<dt>attribute EventHandler onended</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastream-ended">ended</a></code>, MUST be supported by all
objects implementing the <code><a>MediaStream</a></code>
interface.</dd>
</dl>
<div class="idl" title="MediaStream implements EventTarget"></div>
</section>
<section>
<h2>LocalMediaStream</h2>
<p>Before the web application can access the user's media input devices
it must let <code><a href=
"#dom-navigator-getusermedia">getUserMedia()</a></code> create a
<code><a>LocalMediaStream</a></code> . Once the application is done
using, e.g., a webcam and a microphone, it may revoke its own access by
calling <code><a href="#dom-mediastream-stop">stop()</a></code> on the
<code><a>LocalMediaStream</a></code>.
<!--If the web application no longer has access to any media input devices, any
"on air" indicators in the browser UI MUST be turned off.--></p>
<p>A web application may, once it has access to a
<code><a>LocalMediaStream</a></code> , use the <code><a href=
"#dom-mediastream">MediaStream()</a></code> constructor to construct
additional <code><a>MediaStream</a></code> objects. Since a derived
<code><a>MediaStream</a></code> object is created from the tracks of an
existing stream, it cannot use any media input devices that have not been
approved by the user.</p>
<dl class="idl" title="interface LocalMediaStream : MediaStream">
<dt>void stop()</dt>
<dd>
<p>When a <code><a>LocalMediaStream</a></code> object’s <dfn id=
"dom-mediastream-stop"><code>stop()</code></dfn> method is invoked,
the user agent MUST queue a task that runs the following steps on
every track:</p>
<ol>
<li>
<p>Let <var>track</var> be the current
<code><a>MediaStreamTrack</a></code> object.</p>
</li>
<li>
<p><a title="ended">End</a> <var>track</var>. The track starts
outputting only silence and/or blackness, as appropriate.</p>
</li>
<li>
<p>Dereference <var>track’s</var> underlying media source.</p>
</li>
<li>
<p>If the reference count of <var>track’s</var> underlying media
source is greater than zero, then abort these steps.</p>
</li>
<li>
<p>Permanently stop the generation of data for <var>track’s</var>
source. If the data is being generated from a live source (e.g.,
a microphone or camera), then the user agent SHOULD remove any
active "on-air" indicator for that source. If the data is being
generated from a prerecorded source (e.g. a video file), any
remaining content in the file is ignored.</p>
</li>
</ol>
<p>The task source for the <span title="concept-task">tasks</span>
queued for the <code><a href=
"#dom-mediastream-stop">stop()</a></code> method is the DOM
manipulation task source.</p>
</dd>
</dl>
</section>
<section>
<h2>MediaStreamTrack</h2>
<p>A <code><a>MediaStreamTrack</a></code> object represents a media
source in the user agent. Several <code><a>MediaStreamTrack</a></code>
objects can represent the same media source, e.g., when the user chooses
the same camera in the UI shown by two consecutive calls to
<code><a href="#dom-navigator-getusermedia">getUserMedia()</a></code>
.</p>
<p>A <code><a>MediaStreamTrack</a></code> object can reference its media
source in two ways, either with a strong or a weak reference, depending
on how the track was created. For example, a track in a
<code><a>MediaStream</a></code>, derived from a
<code><a>LocalMediaStream</a></code> with the <code><a href=
"#dom-mediastream">MediaStream()</a></code> constructor, has a weak
reference to a local media source, while a track in a
<code><a>LocalMediaStream</a></code> has a strong reference. This means
that a track in a <code><a>MediaStream</a></code>, derived from a
<code><a>LocalMediaStream</a></code>, will end if there is no
non-<a>ended</a> track in a <code><a>LocalMediaStream</a></code> which
references the same local media source.</p>
<p class="note">The concept with strong and weak references to media
sources allows the web application to derive new
<code><a>MediaStream</a></code> objects from
<code><a>LocalMediaStream</a></code> objects (created via <code><a href=
"#dom-navigator-getusermedia">getUserMedia()</a></code>) and still be
able to revoke all given permissions with <code><a href=
"#dom-mediastream-stop">LocalMediaStream.stop()</a></code>.</p>
<p>A <code><a>MediaStreamTrack</a></code> object is said to <em>end</em>
when the user agent learns that no more data will ever be forthcoming for
this track.</p>
<p>When a <code><a>MediaStreamTrack</a></code> object ends for any reason
(e.g., because the user rescinds the permission for the page to use the
local camera, or because the data comes from a finite file and the file’s
end has been reached and the user has not requested that it be looped, or
because the UA has instructed the track to end for any reason, or because
the reference count of the track’s underlying media source has reached
zero, it is said to be <dfn>ended</dfn>. When track instance
<var>track</var> ends for any reason other than the <code><a href=
"#dom-mediastream-stop">stop()</a></code> method being invoked on the
<code><a>LocalMediaStream</a></code> object that represents
<var>track</var>, the user agent MUST queue a task that runs the
following steps:</p>
<ol>
<li>
<p>If the track’s <code><a href=
"#dom-mediastreamtrack-readystate">readyState</a></code> attribute
has the value <code><a href=
"#widl-MediaStreamTrack-ENDED">ENDED</a></code> (2) already, then
abort these steps.</p>
</li>
<li>
<p>Set <var>track’s</var> <code><a href=
"#dom-mediastreamtrack-readystate">readyState</a></code> attribute to
<code><a href="#widl-MediaStreamTrack-ENDED">ENDED</a></code>
(2).</p>
</li>
<li>
<p>Fire a simple event named <code><a href=
"#event-mediastreamtrack-ended">ended</a></code> at the object.</p>
</li>
</ol>
<p>If the end of the stream was reached due to a user request, the event
source for this event is the user interaction event source.</p>
<dl class="idl" title="interface MediaStreamTrack">
<dt>readonly attribute DOMString kind</dt>
<dd>
<p>The <dfn id=
"dom-mediastreamtrack-kind"><code>MediaStreamTrack.kind</code></dfn>
attribute MUST return the string "<code>audio</code>" if the object’s
corresponding track is or was an audio track, "<code>video</code>" if
the corresponding track is or was a video track, and a user agent
defined string otherwise.</p>
</dd>
<dt>readonly attribute DOMString label</dt>
<dd>
<p>User agents MAY label audio and video sources (e.g., "Internal
microphone" or "External USB Webcam"). The <dfn id=
"dom-mediastreamtrack-label"><code>MediaStreamTrack.label</code></dfn>
attribute MUST return the label of the object’s corresponding track,
if any. If the corresponding track has or had no label, the attribute
MUST instead return the empty string.</p>
<p class="note">Thus the <code><a href=
"#dom-mediastreamtrack-kind">kind</a></code> and <code title=
"dom-MediaStreamTrack-label"><a href=
"#dom-mediastreamtrack-label">label</a></code> attributes do not
change value, even if the <code><a>MediaStreamTrack</a></code> object
is disassociated from its corresponding track.</p>
</dd>
<dt>attribute boolean enabled</dt>
<dd>
<p>The <dfn id=
"dom-mediastreamtrack-enabled"><code>MediaStreamTrack.enabled</code></dfn>
attribute, on getting, MUST return the last value to which it was
set. On setting, it MUST be set to the new value, and then, if the
<code><a>MediaStreamTrack</a></code> object is still associated with
a track, MUST enable the track if the new value is true, and disable
it otherwise.</p>
<p class="note">Thus, after a <code><a>MediaStreamTrack</a></code> is
disassociated from its track, its <code><a href=
"#dom-mediastreamtrack-enabled">enabled</a></code> attribute still
changes value when set; it just doesn’t do anything with that new
value.</p>
</dd>
<dt>const unsigned short LIVE = 0</dt>
<dd>
<p>The track is active (the track’s underlying media source is making
a best-effort attempt to provide data in real time).</p>
<p>The output of a track in the <code><a href=
"#widl-MediaStreamTrack-LIVE">LIVE</a></code> state can be switched
on and off with the <code><a href=
"#dom-mediastreamtrack-enabled">enabled</a></code> attribute.</p>
</dd>
<dt>const unsigned short MUTED = 1</dt>
<dd>
<p>The track is muted (the track’s underlying media source is
temporarily unable to provide data).</p>
<p>A <code><a>MediaStreamTrack</a></code> in a
<code><a>LocalMediaStream</a></code> may be muted if the user
temporarily revokes the web application’s permission to use a media
input device.</p>
</dd>
<dt>const unsigned short ENDED = 2</dt>
<dd>
<p>The track has <a>ended</a> (the track’s underlying media source is
no longer providing data, and will never provide more data for this
track).</p>
<p>For example, a video track in a
<code><a>LocalMediaStream</a></code> finishes if the user unplugs the
USB web camera that acts as the track’s media source.</p>
</dd>
<dt>readonly attribute unsigned short readyState</dt>
<dd>
<p>The <dfn id=
"dom-mediastreamtrack-readystate"><code>readyState</code></dfn>
attribute represents the state of the track. It MUST return the value
to which the user agent last set it (as defined below). It can have
the following values: <dfn>LIVE</dfn>, <dfn>MUTED</dfn> or
<dfn>ENDED</dfn>.</p>
<p>When a <code><a>MediaStreamTrack</a></code> object is created, its
<code><a href=
"#dom-mediastreamtrack-readystate">readyState</a></code> is either
<code><a href="#widl-MediaStreamTrack-LIVE">LIVE</a></code> (0) or
<code><a href="#widl-MediaStreamTrack-MUTED">MUTED</a></code> (1),
depending on the state of the track’s underlying media source. For
example, a track in a <code><a>LocalMediaStream</a></code>, created
with <code><a href=
"#dom-navigator-getusermedia">getUserMedia()</a></code>, MUST
initially have its <code><a href=
"#dom-mediastreamtrack-readystate">readyState</a></code> attribute
set to <code><a href="#widl-MediaStreamTrack-LIVE">LIVE</a></code>
(1).</p>
</dd>
<dt>attribute EventHandler onmute</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastreamtrack-muted">muted</a></code>, MUST be supported by
all objects implementing the <code><a>MediaStreamTrack</a></code>
interface.</dd>
<dt>attribute EventHandler onunmute</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastreamtrack-unmuted">unmuted</a></code>, MUST be supported
by all objects implementing the <code><a>MediaStreamTrack</a></code>
interface.</dd>
<dt>attribute EventHandler onended</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastreamtrack-ended">ended</a></code>, MUST be supported by
all objects implementing the <code><a>MediaStreamTrack</a></code>
interface.</dd>
</dl>
</section>
<section>
<h2>URL</h2>
<dl class="idl" title="partial interface URL">
<dt>static DOMString createObjectURL (MediaStream stream)</dt>
<dd>
<p>Mints a <a href="#blob-url">Blob URL</a> to refer to the given
<code><a>MediaStream</a></code>.</p>
<p>When the <dfn id=
"dom-url-createobjecturl"><code>createObjectURL()</code></dfn> method
is called with a <code><a>MediaStream</a></code> argument, the user
agent MUST return a unique <a href="#blob-url">Blob URL</a> for the
given <code><a>MediaStream</a></code>. [[!FILE-API]]</p>
<p>For audio and video streams, the data exposed on that stream MUST
be in a format supported by the user agent for use in
<code>audio</code> and <code>video</code> elements.</p>
<p class="bookkeeping">A <dfn id="blob-url">Blob URL</dfn> is the
same as what the File API specification calls a Blob URI, except that
anything in the definition of that feature that refers to
<code>File</code> and <code>Blob</code> objects is hereby extended to
also apply to <code><a>MediaStream</a></code> and
<code><a>LocalMediaStream</a></code> objects.</p>
</dd>
</dl>
</section>
<section>
<h2>MediaStreamTrackList</h2>
<p>A <code><a>MediaStreamTrackList</a></code> object’s <dfn id=
"concept-track-list-corresponding-stream">corresponding</dfn>
<code><a>MediaStream</a></code> refers to the
<code><a>MediaStream</a></code> object which the current
<code><a>MediaStreamTrackList</a></code> object is a property of.</p>
<dl class="idl" title="interface MediaStreamTrackList">
<dt>readonly attribute unsigned long length</dt>
<dd>Returns the number of tracks in the list.</dd>
<!-- FIXME: getter syntax doesn't seem to be supported by respec -->
<dt>MediaStreamTrack item(unsigned long index)</dt>
<dd>Returns the <code><a>MediaStreamTrack</a></code> object at the
specified index.</dd>
<dt>void add(MediaStreamTrack track)</dt>
<dd>
<p>Adds the given <code><a>MediaStreamTrack</a></code> to this
<code><a>MediaStreamTrackList</a></code> according to the ordering
rules for tracks.</p>
<p>When the <dfn id=
"dom-mediastreamtracklist-add"><code>add()</code></dfn> method is
invoked, the user agent MUST run the following steps:</p>
<ol>
<li>
<p>Let <var>track</var> be the
<code><a>MediaStreamTrack</a></code> argument.</p>
</li>
<li>
<p>Let <var>stream</var> be the
<code><a>MediaStreamTrackList</a></code> object’s <a href=
"#concept-track-list-corresponding-stream" title=
"concept-track-list-corresponding-stream">corresponding</a>
<code><a>MediaStream</a></code> object.</p>
</li>
<li>
<p>If <var>stream</var> is <a>finished</a>, throw an
<code>INVALID_STATE_ERR</code> exception.</p>
</li>
<li>
<p>If <var>track</var> is already in the
<code><a>MediaStreamTrackList</a></code> object’s internal list,
then abort these steps.</p>
</li>
<li>
<p>Add <var>track</var> to the end of the
<code><a>MediaStreamTrackList</a></code> object’s internal
list.</p>
</li>
</ol>
</dd>
<dt>void remove(MediaStreamTrack track)</dt>
<dd>
<p>Removes the given <code><a>MediaStreamTrack</a></code> from this
<code><a>MediaStreamTrackList</a></code>.</p>
<p>When the <dfn id=
"dom-mediastreamtracklist-remove"><code>remove()</code></dfn> method
is invoked, the user agent MUST run the following steps:</p>
<ol>
<li>
<p>Let <var>track</var> be the
<code><a>MediaStreamTrack</a></code> argument.</p>
</li>
<li>
<p>Let <var>stream</var> be the
<code><a>MediaStreamTrackList</a></code> object’s <a href=
"#concept-track-list-corresponding-stream" title=
"concept-track-list-corresponding-stream">corresponding</a>
<code><a>MediaStream</a></code> object.</p>
</li>
<li>
<p>If <var>stream</var> is <a>finished</a>, throw an
<code>INVALID_STATE_ERR</code> exception.</p>
</li>
<li>
<p>If <var>track</var> is not in the
<code><a>MediaStreamTrackList</a></code> object’s internal list,
then abort these steps.</p>
</li>
<li>
<p>Remove <var>track</var> from the
<code><a>MediaStreamTrackList</a></code> object’s internal
list.</p>
</li>
</ol>
</dd>
<dt>attribute EventHandler onaddtrack</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastreamtracklist-addtrack">addtrack</a></code>, MUST be
supported by all objects implementing the
<code><a>MediaStreamTrackList</a></code> interface.</dd>
<dt>attribute EventHandler onremovetrack</dt>
<dd>This event handler, of type <code><a href=
"#event-mediastreamtracklist-removetrack">removetrack</a></code>, MUST
be supported by all objects implementing the
<code><a>MediaStreamTrackList</a></code> interface.</dd>
</dl>
</section>
<section>
<h2>MediaStreams as Media Elements</h2>
<p>A <code>MediaStream</code> may be assigned to media elements as defined in <a href=
"http://www.w3.org/TR/html5/media-elements.html#media-elements">HTML5</a> [[!HTML5]]
by calling <code><a>createObjectURL</a></code> to obtain a URL for the <code>MediaStream</code> and then
setting the media elements <code>src</code> attribute to that URL. A <code>MediaStream</code> is
not preloadable or seekable and represents a simple, potentially infinite,
linear media timeline. The timeline starts at 0 and increments linearly
in real time as long as the <code>MediaStream</code> is playing. The timeline does not
increment when the <code>MediaStream</code> is paused.</p>
<p class="issue">Do we also need to support direct assignment and access
of the underlying stream?</p>
<p>The nature of the <code>MediaStream</code> places certain restrictions on the
behavior and attribute values of the associated media element and on the
operations that can be performed on it, as shown below:</p>
<ul>
<li>Whenever the user agent runs the <a href=
"http://www.w3.org/TR/html5/media-elements.html#media-element-load-algorithm">
media element load algorithm</a>, reaches the <a href=
"http://www.w3.org/TR/html5/media-elements.html#concept-media-load-resource">
resource fetch phase</a> of this algorithm and determines that the
media resource in question is a MediaStream, it MUST immediately abort the <a href=
"http://www.w3.org/TR/html5/media-elements.html#concept-media-load-algorithm">
resource selection algorithm</a>, setting the <a href=
"http://www.w3.org/TR/html5/media-elements.html#dom-media-readystate">
<code>media.readystate</code></a> to HAVE_ENOUGH_DATA.
</li>
<li>The UA MUST NOT buffer data
from a MediaStream. When playing, the UA MUST always play the current data from the stream.</li>
</ul>
<table summary=
"Legal values for the properties of a media element bound to a MediaStream"
class="simple">
<thead>
<tr>
<th scope="col">Attribute Name</th>
<th scope="col">Attribute Type</th>
<th scope="col">Valid Values</th>
<th scope="col">Additional considerations</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#dom-media-src"
class="externalDFN"><code>src</code></a>
</td>
<td><code>DOMString</code></td>
<td>a local URI referencing a MediaStream</td>
<td>N.B. Revocation of the URI does not count as a change to this
field.</td>
</tr>
<tr>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#dom-media-currentsrc"
class="externalDFN"><code>currentSrc</code></a>
</td>
<td><code>DOMString</code></td>
<td>a local URI referencing a MediaStream</td>
<td>-</td>
</tr>
<tr>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#attr-media-preload"
class="externalDFN"><code>preload</code></a>
</td>
<td><code>DOMString</code></td>
<td><code>none</code></td>
<td>A MediaStream cannot be preloaded.</td>
</tr>
<tr>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#dom-media-buffered"
class="externalDFN"><code>buffered</code></a>
</td>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#timeranges"
class="externalDFN"><code>TimeRanges</code></a>
</td>
<td><code>buffered.length</code> MUST return <code>1</code>.<br>
<code>buffered.start(0)</code> MUST return <code>0</code>.<br>
<code>buffered.end(0)</code> MUST return <code>0</code>.<br></td>
<td>A MediaStream cannot be preloaded. Therefore, the amount
buffered is always an empty TimeRange.</td>
</tr>
<tr>
<td>
<a href=
"http://www.w3.org/TR/html5/media-elements.html#dom-media-currenttime"
class="externalDFN"><code>currentTime</code></a>
</td>
<td><code>double</code></td>