forked from w3c/media-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media-source-cr.html
3362 lines (3067 loc) · 330 KB
/
media-source-cr.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" dir="ltr" typeof="bibo:Document w3p:CR" about="" property="dcterms:language" content="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Source Extensions</title>
<!-- script to register bugs -->
<script src="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/assets/scripts/bug-assist.js"></script>
<meta name="bug.short_desc" content="[MSE] ">
<meta name="bug.product" content="HTML WG">
<meta name="bug.component" content="Media Source Extensions">
<style>/* --- ISSUES/NOTES --- */
div.issue-title, div.note-title {
padding-right: 1em;
min-width: 7.5em;
color: #b9ab2d;
}
div.issue-title { color: #e05252; }
div.note-title { color: #2b2; }
div.issue-title span, div.note-title span {
text-transform: uppercase;
}
div.note, div.issue {
margin-top: 1em;
margin-bottom: 1em;
}
.note > p:first-child, .issue > p:first-child { margin-top: 0 }
.issue, .note {
padding: .5em;
border-left-width: .5em;
border-left-style: solid;
}
div.issue, div.note {
padding: 1em 1.2em 0.5em;
margin: 1em 0;
position: relative;
clear: both;
}
span.note, span.issue { padding: .1em .5em .15em; }
.issue {
border-color: #e05252;
background: #fbe9e9;
}
.note {
border-color: #52e052;
background: #e9fbe9;
}
</style><style>/* --- WEB IDL --- */
pre.idl {
border-top: 1px solid #90b8de;
border-bottom: 1px solid #90b8de;
padding: 1em;
line-height: 120%;
}
pre.idl::before {
content: "WebIDL";
display: block;
width: 150px;
background: #90b8de;
color: #fff;
font-family: initial;
padding: 3px;
font-weight: bold;
margin: -1em 0 1em -1em;
}
.idlType {
color: #ff4500;
font-weight: bold;
text-decoration: none;
}
/*.idlModule*/
/*.idlModuleID*/
/*.idlInterface*/
.idlInterfaceID, .idlDictionaryID, .idlCallbackID, .idlEnumID {
font-weight: bold;
color: #005a9c;
}
a.idlEnumItem {
color: #000;
border-bottom: 1px dotted #ccc;
text-decoration: none;
}
.idlSuperclass {
font-style: italic;
color: #005a9c;
}
/*.idlAttribute*/
.idlAttrType, .idlFieldType, .idlMemberType {
color: #005a9c;
}
.idlAttrName, .idlFieldName, .idlMemberName {
color: #ff4500;
}
.idlAttrName a, .idlFieldName a, .idlMemberName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlMethod*/
.idlMethType, .idlCallbackType {
color: #005a9c;
}
.idlMethName {
color: #ff4500;
}
.idlMethName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlCtor*/
.idlCtorName {
color: #ff4500;
}
.idlCtorName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlParam*/
.idlParamType {
color: #005a9c;
}
.idlParamName, .idlDefaultValue {
font-style: italic;
}
.extAttr {
color: #666;
}
/*.idlSectionComment*/
.idlSectionComment {
color: gray;
}
/*.idlConst*/
.idlConstType {
color: #005a9c;
}
.idlConstName {
color: #ff4500;
}
.idlConstName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlException*/
.idlExceptionID {
font-weight: bold;
color: #c00;
}
.idlTypedefID, .idlTypedefType {
color: #005a9c;
}
.idlRaises, .idlRaises a.idlType, .idlRaises a.idlType code, .excName a, .excName a code {
color: #c00;
font-weight: normal;
}
.excName a {
font-family: monospace;
}
.idlRaises a.idlType, .excName a.idlType {
border-bottom: 1px dotted #c00;
}
.excGetSetTrue, .excGetSetFalse, .prmNullTrue, .prmNullFalse, .prmOptTrue, .prmOptFalse {
width: 45px;
text-align: center;
}
.excGetSetTrue, .prmNullTrue, .prmOptTrue { color: #0c0; }
.excGetSetFalse, .prmNullFalse, .prmOptFalse { color: #c00; }
.idlImplements a {
font-weight: bold;
}
dl.attributes, dl.methods, dl.constants, dl.constructors, dl.fields, dl.dictionary-members {
margin-left: 2em;
}
.attributes dt, .methods dt, .constants dt, .constructors dt, .fields dt, .dictionary-members dt {
font-weight: normal;
}
.attributes dt code, .methods dt code, .constants dt code, .constructors dt code, .fields dt code, .dictionary-members dt code {
font-weight: bold;
color: #000;
font-family: monospace;
}
.attributes dt code, .fields dt code, .dictionary-members dt code {
background: #ffffd2;
}
.attributes dt .idlAttrType code, .fields dt .idlFieldType code, .dictionary-members dt .idlMemberType code {
color: #005a9c;
background: transparent;
font-family: inherit;
font-weight: normal;
font-style: italic;
}
.methods dt code {
background: #d9e6f8;
}
.constants dt code {
background: #ddffd2;
}
.constructors dt code {
background: #cfc;
}
.attributes dd, .methods dd, .constants dd, .constructors dd, .fields dd, .dictionary-members dd {
margin-bottom: 1em;
}
table.parameters, table.exceptions {
border-spacing: 0;
border-collapse: collapse;
margin: 0.5em 0;
width: 100%;
}
table.parameters { border-bottom: 1px solid #90b8de; }
table.exceptions { border-bottom: 1px solid #deb890; }
.parameters th, .exceptions th {
color: #fff;
padding: 3px 5px;
text-align: left;
font-family: initial;
font-weight: normal;
text-shadow: #666 1px 1px 0;
}
.parameters th { background: #90b8de; }
.exceptions th { background: #deb890; }
.parameters td, .exceptions td {
padding: 3px 10px;
border-top: 1px solid #ddd;
vertical-align: top;
}
.parameters tr:first-child td, .exceptions tr:first-child td {
border-top: none;
}
.parameters td.prmName, .exceptions td.excName, .exceptions td.excCodeName {
width: 100px;
}
.parameters td.prmType {
width: 120px;
}
table.exceptions table {
border-spacing: 0;
border-collapse: collapse;
width: 100%;
}
</style><link href="mse.css" rel="stylesheet">
<style>/*****************************************************************
* ReSpec 3 CSS
* Robin Berjon - http://berjon.com/
*****************************************************************/
/* --- INLINES --- */
em.rfc2119 {
text-transform: lowercase;
font-variant: small-caps;
font-style: normal;
color: #900;
}
h1 acronym, h2 acronym, h3 acronym, h4 acronym, h5 acronym, h6 acronym, a acronym,
h1 abbr, h2 abbr, h3 abbr, h4 abbr, h5 abbr, h6 abbr, a abbr {
border: none;
}
dfn {
font-weight: bold;
}
a.internalDFN {
color: inherit;
border-bottom: 1px solid #99c;
text-decoration: none;
}
a.externalDFN {
color: inherit;
border-bottom: 1px dotted #ccc;
text-decoration: none;
}
a.bibref {
text-decoration: none;
}
cite .bibref {
font-style: normal;
}
code {
color: #ff4500;
}
/* --- TOC --- */
.toc a, .tof a {
text-decoration: none;
}
a .secno, a .figno {
color: #000;
}
ul.tof, ol.tof {
list-style: none outside none;
}
.caption {
margin-top: 0.5em;
font-style: italic;
}
/* --- TABLE --- */
table.simple {
border-spacing: 0;
border-collapse: collapse;
border-bottom: 3px solid #005a9c;
}
.simple th {
background: #005a9c;
color: #fff;
padding: 3px 5px;
text-align: left;
}
.simple th[scope="row"] {
background: inherit;
color: inherit;
border-top: 1px solid #ddd;
}
.simple td {
padding: 3px 10px;
border-top: 1px solid #ddd;
}
.simple tr:nth-child(even) {
background: #f0f6ff;
}
/* --- DL --- */
.section dd > p:first-child {
margin-top: 0;
}
.section dd > p:last-child {
margin-bottom: 0;
}
.section dd {
margin-bottom: 1em;
}
.section dl.attrs dd, .section dl.eldef dd {
margin-bottom: 0;
}
@media print {
.removeOnSave {
display: none;
}
}
</style><link href="https://www.w3.org/StyleSheets/TR/W3C-CR" rel="stylesheet"><!--[if lt IE 9]><script src='https://www.w3.org/2008/site/js/html5shiv.js'></script><![endif]--></head>
<body class="h-entry" id="respecDocument" role="document"><div class="head" id="respecHeader" role="contentinfo">
<p>
<a href="http://www.w3.org/"><img width="72" height="48" alt="W3C" src="https://www.w3.org/Icons/w3c_home"></a>
</p>
<h1 class="title p-name" id="title" property="dcterms:title">Media Source Extensions</h1>
<h2 id="w3c-candidate-recommendation-17-july-2014" property="dcterms:issued" content="2014-07-17T07:00:00.000Z" datatype="xsd:dateTime"><abbr title="World Wide Web Consortium">W3C</abbr> Candidate Recommendation <time class="dt-published" datetime="2014-07-17">17 July 2014</time></h2>
<dl>
<dt>This version:</dt>
<dd><a class="u-url" href="http://www.w3.org/TR/2014/CR-media-source-20140717/">http://www.w3.org/TR/2014/CR-media-source-20140717/</a></dd>
<dt>Latest published version:</dt>
<dd><a href="http://www.w3.org/TR/media-source/">http://www.w3.org/TR/media-source/</a></dd>
<dt>Latest editor's draft:</dt>
<dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html">http://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2014/CR-media-source-20140109/" rel="dcterms:replaces">http://www.w3.org/TR/2014/CR-media-source-20140109/</a></dd>
<dt>Editors:</dt>
<dd class="p-author h-card vcard" inlist="" rel="bibo:editor"><span typeof="foaf:Person"><span class="p-name fn" property="foaf:name">Aaron Colwell</span>, <a class="p-org org h-org h-card" href="http://www.google.com/" rel="foaf:workplaceHomepage">Google Inc.</a></span>
</dd>
<dd class="p-author h-card vcard" inlist="" rel="bibo:editor"><span typeof="foaf:Person"><span class="p-name fn" property="foaf:name">Adrian Bateman</span>, <a class="p-org org h-org h-card" href="http://www.microsoft.com/" rel="foaf:workplaceHomepage">Microsoft Corporation</a></span>
</dd>
<dd class="p-author h-card vcard" inlist="" rel="bibo:editor"><span typeof="foaf:Person"><span class="p-name fn" property="foaf:name">Mark Watson</span>, <a class="p-org org h-org h-card" href="http://www.netflix.com/" rel="foaf:workplaceHomepage">Netflix Inc.</a></span>
</dd>
</dl>
<p class="copyright">
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> ©
2014
<a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup>
(<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>,
<a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>),
All Rights Reserved.
<abbr title="World Wide Web Consortium">W3C</abbr> <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and
<a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a>
rules apply.
</p>
<hr>
</div>
<section class="introductory" id="abstract" typeof="bibo:Chapter" property="dcterms:abstract" datatype="" rel="bibo:Chapter" resource="#abstract"><h2 id="h2_abstract" role="heading" aria-level="1">Abstract</h2>
This specification extends HTMLMediaElement to allow
JavaScript to generate media streams for playback.
Allowing JavaScript to generate streams facilitates a variety of use
cases like adaptive streaming and time shifting live streams.
<p>If you wish to make comments or file bugs regarding this document in a manner that is tracked by the <abbr title="World Wide Web Consortium">W3C</abbr>, please submit them via
<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=HTML%20WG&component=Media%20Source%20Extensions&short_desc=%5BMSE%5D%20">our public bug database</a>.
</p>
</section><section class="introductory" id="sotd" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#sotd"><h2 id="h2_sotd" role="heading" aria-level="1">Status of This Document</h2>
<p>
<em>This section describes the status of this document at the time of its publication.
Other documents may supersede this document. A list of current <abbr title="World Wide Web Consortium">W3C</abbr> publications and the
latest revision of this technical report can be found in the <a href="http://www.w3.org/TR/"><abbr title="World Wide Web Consortium">W3C</abbr> technical reports index</a> at
http://www.w3.org/TR/.</em>
</p>
<p>
This document was published by the <a href="http://www.w3.org/html/wg/">HTML Working Group</a> as a revised Candidate Recommendation. Revisions to the original Candidate Recommendation can be found in the <a href="#revision-history">Revision History</a>.
This document is intended to become a <abbr title="World Wide Web Consortium">W3C</abbr> Recommendation.
If you wish to make comments regarding this document, please send them to
<a href="mailto:public-html-media@w3.org">public-html-media@w3.org</a>
(<a href="mailto:public-html-media-request@w3.org?subject=subscribe">subscribe</a>,
<a href="http://lists.w3.org/Archives/Public/public-html-media/">archives</a>).
<abbr title="World Wide Web Consortium">W3C</abbr> publishes a Candidate Recommendation to indicate that the document is believed to be
stable and to encourage implementation by the developer community. This Candidate
Recommendation is expected to advance to Proposed Recommendation no earlier than
09 April 2014.
All comments are welcome.
</p>
<p>
Publication as a Candidate Recommendation does not imply endorsement by the <abbr title="World Wide Web Consortium">W3C</abbr>
Membership. This is a draft document and may be updated, replaced or obsoleted by other
documents at any time. It is inappropriate to cite this document as other than work in
progress.
</p>
<p>For this specification to exit the Candidate Recommendation stage, two independent implementations as detailed in the <a href="http://dev.w3.org/html5/decision-policy/public-permissive-exit-criteria.html">CR Exit Criteria (Public Permissive version 3)</a> document will be required to pass each test in the MSE test suite to be developed by the HTML WG.</p>
<p>No <a href="http://www.w3.org/wiki/ImplementationReport">implementation report</a> yet exists for this specification.</p>
<p>Implementors should be aware that this specification is not stable. <strong>Implementors who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways.</strong> Vendors interested in implementing this specification before it eventually reaches the Candidate Recommendation stage should join the mailing list mentioned above and take part in the discussions.</p>
<p>The following features are <strong>at risk</strong> and may be removed due to lack of implementation.
</p>
<ul>
<li><code><a href="#widl-VideoPlaybackQuality-totalFrameDelay">totalFrameDelay</a></code></li>
</ul>
<p>Note that this specification has a normative dependency on the name of a readable <code><a href="http://www.w3.org/TR/2013/WD-streams-api-20131105/#idl-def-Stream" class="idlType">Stream</a></code> object from the Streams API specification [<cite><a class="bibref" href="#bib-STREAMS-API">STREAMS-API</a></cite>].</p>
<p>
This document was produced by a group operating under the
<a id="sotd_patent" href="http://www.w3.org/Consortium/Patent-Policy-20040205/" rel="w3p:patentRules" about="">5 February 2004 <abbr title="World Wide Web Consortium">W3C</abbr> Patent
Policy</a>.
<abbr title="World Wide Web Consortium">W3C</abbr> maintains a <a href="http://www.w3.org/2004/01/pp-impl/40318/status" rel="disclosure">public list of any patent
disclosures</a>
made in connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual knowledge of a patent
which the individual believes contains
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the <abbr title="World Wide Web Consortium">W3C</abbr> Patent Policy</a>.
</p>
</section><section id="toc"><h2 class="introductory" id="h2_toc" role="heading" aria-level="1">Table of Contents</h2><ul class="toc" id="respecContents" role="directory"><li class="tocline"><a class="tocxref" href="#introduction"><span class="secno">1. </span>Introduction</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#goals"><span class="secno">1.1 </span>Goals</a></li><li class="tocline"><a class="tocxref" href="#definitions"><span class="secno">1.2 </span>Definitions</a></li></ul></li><li class="tocline"><a class="tocxref" href="#mediasource"><span class="secno">2. </span>MediaSource Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes"><span class="secno">2.1 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods"><span class="secno">2.2 </span>Methods</a></li><li class="tocline"><a class="tocxref" href="#mediasource-events"><span class="secno">2.3 </span>Event Summary</a></li><li class="tocline"><a class="tocxref" href="#mediasource-algorithms"><span class="secno">2.4 </span>Algorithms</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#mediasource-attach"><span class="secno">2.4.1 </span>Attaching to a media element</a></li><li class="tocline"><a class="tocxref" href="#mediasource-detach"><span class="secno">2.4.2 </span>Detaching from a media element</a></li><li class="tocline"><a class="tocxref" href="#mediasource-seeking"><span class="secno">2.4.3 </span>Seeking</a></li><li class="tocline"><a class="tocxref" href="#buffer-monitoring"><span class="secno">2.4.4 </span>SourceBuffer Monitoring</a></li><li class="tocline"><a class="tocxref" href="#active-source-buffer-changes"><span class="secno">2.4.5 </span>Changes to selected/enabled track state</a></li><li class="tocline"><a class="tocxref" href="#duration-change-algorithm"><span class="secno">2.4.6 </span>Duration change</a></li><li class="tocline"><a class="tocxref" href="#end-of-stream-algorithm"><span class="secno">2.4.7 </span>End of stream algorithm</a></li></ul></li></ul></li><li class="tocline"><a class="tocxref" href="#sourcebuffer"><span class="secno">3. </span>SourceBuffer Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-1"><span class="secno">3.1 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods-1"><span class="secno">3.2 </span>Methods</a></li><li class="tocline"><a class="tocxref" href="#track-buffers"><span class="secno">3.3 </span>Track Buffers</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-events"><span class="secno">3.4 </span>Event Summary</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-algorithms"><span class="secno">3.5 </span>Algorithms</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#sourcebuffer-segment-parser-loop"><span class="secno">3.5.1 </span>Segment Parser Loop</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-reset-parser-state"><span class="secno">3.5.2 </span>Reset Parser State</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-append-error"><span class="secno">3.5.3 </span>Append Error Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-prepare-append"><span class="secno">3.5.4 </span>Prepare Append Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-buffer-append"><span class="secno">3.5.5 </span>Buffer Append Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-stream-append-loop"><span class="secno">3.5.6 </span>Stream Append Loop</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-init-segment-received"><span class="secno">3.5.7 </span>Initialization Segment Received</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-default-track-language"><span class="secno">3.5.8 </span>Default track language</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-default-track-kinds"><span class="secno">3.5.9 </span>Default track kinds</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-coded-frame-processing"><span class="secno">3.5.10 </span>Coded Frame Processing</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-coded-frame-removal"><span class="secno">3.5.11 </span>Coded Frame Removal Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-coded-frame-eviction"><span class="secno">3.5.12 </span>Coded Frame Eviction Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-audio-splice-frame-algorithm"><span class="secno">3.5.13 </span>Audio Splice Frame Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-audio-splice-rendering-algorithm"><span class="secno">3.5.14 </span>Audio Splice Rendering Algorithm</a></li><li class="tocline"><a class="tocxref" href="#sourcebuffer-text-splice-frame-algorithm"><span class="secno">3.5.15 </span>Text Splice Frame Algorithm</a></li></ul></li></ul></li><li class="tocline"><a class="tocxref" href="#sourcebufferlist"><span class="secno">4. </span>SourceBufferList Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-2"><span class="secno">4.1 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods-2"><span class="secno">4.2 </span>Methods</a></li><li class="tocline"><a class="tocxref" href="#sourcebufferlist-events"><span class="secno">4.3 </span>Event Summary</a></li></ul></li><li class="tocline"><a class="tocxref" href="#videoplaybackquality"><span class="secno">5. </span>VideoPlaybackQuality Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-3"><span class="secno">5.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#trackdefault"><span class="secno">6. </span>TrackDefault Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#constructors"><span class="secno">6.1 </span>Constructors</a></li><li class="tocline"><a class="tocxref" href="#attributes-4"><span class="secno">6.2 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#trackdefaultlist"><span class="secno">7. </span>TrackDefaultList Object</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#constructors-1"><span class="secno">7.1 </span>Constructors</a></li><li class="tocline"><a class="tocxref" href="#attributes-5"><span class="secno">7.2 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods-3"><span class="secno">7.3 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#url"><span class="secno">8. </span>URL Object Extensions</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-4"><span class="secno">8.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#htmlmediaelement-extensions"><span class="secno">9. </span>HTMLMediaElement Extensions</a></li><li class="tocline"><a class="tocxref" href="#htmlvideoelement-extensions"><span class="secno">10. </span>HTMLVideoElement Extensions</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-5"><span class="secno">10.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#audio-track-extensions"><span class="secno">11. </span>AudioTrack Extensions</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-6"><span class="secno">11.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#video-track-extensions"><span class="secno">12. </span>VideoTrack Extensions</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-7"><span class="secno">12.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#text-track-extensions"><span class="secno">13. </span>TextTrack Extensions</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-8"><span class="secno">13.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#byte-stream-formats"><span class="secno">14. </span>Byte Stream Formats</a></li><li class="tocline"><a class="tocxref" href="#examples"><span class="secno">15. </span>Examples</a></li><li class="tocline"><a class="tocxref" href="#acknowledgements"><span class="secno">16. </span>Acknowledgments</a></li><li class="tocline"><a class="tocxref" href="#revision-history"><span class="secno">17. </span>Revision History</a></li><li class="tocline"><a class="tocxref" href="#references"><span class="secno">A. </span>References</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#normative-references"><span class="secno">A.1 </span>Normative references</a></li><li class="tocline"><a class="tocxref" href="#informative-references"><span class="secno">A.2 </span>Informative references</a></li></ul></li></ul></section>
<section id="introduction" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#introduction">
<!--OddPage--><h2 id="h2_introduction" role="heading" aria-level="1"><span class="secno">1. </span>Introduction</h2>
<p>This specification allows JavaScript to dynamically construct media streams for <audio> and <video>.
It defines objects that allow JavaScript to pass media segments to an <a href="http://www.w3.org/TR/html5/embedded-content-0.html#htmlmediaelement">HTMLMediaElement</a> [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>].
A buffering model is also included to describe how the user agent acts when different media segments are
appended at different times. Byte stream specifications used with these extensions are available in the byte stream format registry [<cite><a class="bibref" href="#bib-MSE-REGISTRY">MSE-REGISTRY</a></cite>].</p>
<img alt="Media Source Pipeline Model Diagram" src="pipeline_model.png">
<section id="goals" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#goals">
<h3 id="h3_goals" role="heading" aria-level="2"><span class="secno">1.1 </span>Goals</h3>
<p>This specification was designed with the following goals in mind:</p>
<ul>
<li>Allow JavaScript to construct media streams independent of how the media is fetched.</li>
<li>Define a splicing and buffering model that facilitates use cases like adaptive streaming, ad-insertion, time-shifting, and video editing.</li>
<li>Minimize the need for media parsing in JavaScript.</li>
<li>Leverage the browser cache as much as possible.</li>
<li>Provide requirements for byte stream format specifications.</li>
<li>Not require support for any particular media format or codec.</li>
</ul>
<p>This specification defines:</p>
<ul>
<li>Normative behavior for user agents to enable interoperability between user agents and web applications when processing media data.</li>
<li>Normative requirements to enable other specifications to define media formats to be used within this specification.</li>
</ul>
</section>
<section id="definitions" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#definitions">
<h3 id="h3_definitions" role="heading" aria-level="2"><span class="secno">1.2 </span>Definitions</h3>
<dl>
<dt id="active-track-buffers">Active Track Buffers</dt>
<dd><p>The <a href="#track-buffer">track buffers</a> that provide <a href="#coded-frame">coded frames</a> for the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-audiotrack-enabled">enabled</a></code>
<code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-audiotracks">audioTracks</a></code>, the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-videotrack-selected">selected</a></code> <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-videotracks">videoTracks</a></code>, and the
<code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-showing">"showing"</a></code> or <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-hidden">"hidden"</a></code> <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-texttracks">textTracks</a></code>. All these tracks are associated with
<a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects in the <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code> list.</p>
</dd>
<dt id="append-window">Append Window</dt>
<dd><p>A <a href="#presentation-timestamp">presentation timestamp</a> range used to filter out <a href="#coded-frame">coded frames</a> while appending. The append window represents a single
continuous time range with a single start time and end time. Coded frames with <a href="#presentation-timestamp">presentation timestamp</a> within this range are allowed to be appended
to the <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> while coded frames outside this range are filtered out. The append window start and end times are controlled by
the <code><a href="#widl-SourceBuffer-appendWindowStart">appendWindowStart</a></code> and <code><a href="#widl-SourceBuffer-appendWindowEnd">appendWindowEnd</a></code> attributes respectively.</p></dd>
<dt id="coded-frame">Coded Frame</dt>
<dd><p>A unit of media data that has a <a href="#presentation-timestamp">presentation timestamp</a>, a <a href="#decode-timestamp">decode timestamp</a>, and a <a href="#coded-frame-duration">coded frame duration</a>.</p></dd>
<dt id="coded-frame-duration">Coded Frame Duration</dt>
<dd>
<p>The duration of a <a href="#coded-frame">coded frame</a>. For video and text, the duration indicates how long the video frame or text should be displayed. For audio, the duration represents the sum of all the samples contained within the coded frame. For example, if an audio frame contained 441 samples @44100Hz the frame duration would be 10 milliseconds.</p>
</dd>
<dt id="coded-frame-end-timestamp">Coded Frame End Timestamp</dt>
<dd>
<p>The sum of a <a href="#coded-frame">coded frame</a> <a href="#presentation-timestamp">presentation timestamp</a> and its
<a href="#coded-frame-duration">coded frame duration</a>. It represents the <a href="#presentation-timestamp">presentation timestamp</a> that immediately follows the coded frame.</p>
</dd>
<dt id="coded-frame-group">Coded Frame Group</dt>
<dd><p>A group of <a href="#coded-frame">coded frames</a> that are adjacent and have monotonically increasing <a href="#decode-timestamp">decode timestamps</a> without any gaps. Discontinuities detected by the
<a href="#sourcebuffer-coded-frame-processing">coded frame processing algorithm</a> and <code><a href="#widl-SourceBuffer-abort-void">abort()</a></code> calls trigger the start of a new coded frame group.</p>
</dd>
<dt id="decode-timestamp">Decode Timestamp</dt>
<dd>
<p> The decode timestamp indicates the latest time at which the frame needs to be decoded assuming instantaneous decoding and rendering of this and any dependant frames (this is equal to the <a href="#presentation-timestamp">presentation timestamp</a> of the earliest frame, in <a href="#presentation-order">presentation order</a>, that is dependant on this frame). If frames can be decoded out of <a href="#presentation-order">presentation order</a>, then the decode timestamp must be present in or derivable from the byte stream. The user agent must run the <a href="#end-of-stream-algorithm">end of stream algorithm</a> with the <var>error</var> parameter set to <code><a href="#idl-def-EndOfStreamError.decode">"decode"</a></code> if this is not the case. If frames cannot be decoded out of <a href="#presentation-order">presentation order</a> and a decode timestamp is not present in the byte stream, then the decode timestamp is equal to the <a href="#presentation-timestamp">presentation timestamp</a>.
</p></dd>
<dt id="displayed-frame-delay">Displayed Frame Delay</dt>
<dd>
<p>The delay between a frame's presentation time and the actual time it was displayed, in a double-precision value in seconds & rounded to the nearest display refresh interval. This
delay is always greater than or equal to zero since frames must never be displayed before their presentation time. Non-zero delays are a sign of playback jitter
and possible loss of A/V sync.</p>
</dd>
<dt id="init-segment">Initialization Segment</dt>
<dd>
<p>A sequence of bytes that contain all of the initialization information required to decode a sequence of <a href="#media-segment">media segments</a>. This includes codec initialization data, <a href="#track-id">Track ID</a> mappings for multiplexed segments, and timestamp offsets (e.g. edit lists).</p>
<div class="note"><div class="note-title" id="h_note_1" role="heading" aria-level="3"><span>Note</span></div><p>The <a href="#byte-stream-format-specs">byte stream format specifications</a> in the byte stream format registry [<cite><a class="bibref" href="#bib-MSE-REGISTRY">MSE-REGISTRY</a></cite>] contain format specific examples.</p></div>
<dt id="media-segment">Media Segment</dt>
<dd>
<p>A sequence of bytes that contain packetized & timestamped media data for a portion of the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#media-timeline">media timeline</a>. Media segments are always associated with the most recently appended <a href="#init-segment">initialization segment</a>.</p>
<div class="note"><div class="note-title" id="h_note_2" role="heading" aria-level="3"><span>Note</span></div><p>The <a href="#byte-stream-format-specs">byte stream format specifications</a> in the byte stream format registry [<cite><a class="bibref" href="#bib-MSE-REGISTRY">MSE-REGISTRY</a></cite>] contain format specific examples.</p></div>
</dd>
<dt id="mediasource-object-url">MediaSource object URL</dt>
<dd>
<p>A MediaSource object URL is a unique <a href="http://www.w3.org/TR/FileAPI/#url">Blob URI</a> [<cite><a class="bibref" href="#bib-FILE-API">FILE-API</a></cite>] created by <code><a href="#widl-URL-createObjectURL-DOMString-MediaSource-mediaSource">createObjectURL()</a></code>. It is used to attach a <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object to an HTMLMediaElement.</p>
<p>These URLs are the same as a <a href="http://www.w3.org/TR/FileAPI/#url">Blob URI</a>, except that anything in the definition of that feature that refers to <a href="http://www.w3.org/TR/FileAPI/#dfn-file">File</a> and <a href="http://www.w3.org/TR/FileAPI/#dfn-Blob">Blob</a> objects is hereby extended to also apply to <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> objects.</p>
<p>The <a href="http://www.w3.org/TR/html5/browsers.html#origin-0">origin</a> of the MediaSource object URL is the <a href="http://www.w3.org/TR/html5/browsers.html#effective-script-origin">effective script origin</a> of the document that called <code><a href="#widl-URL-createObjectURL-DOMString-MediaSource-mediaSource">createObjectURL()</a></code>.</p>
<div class="note"><div class="note-title" id="h_note_3" role="heading" aria-level="3"><span>Note</span></div><p>For example, the <a href="http://www.w3.org/TR/html5/browsers.html#origin-0">origin</a> of the MediaSource object URL affects the way that the media element is <a href="http://www.w3.org/TR/html5/embedded-content-0.html#security-with-canvas-elements">consumed by canvas</a>.</p></div>
</dd>
<dt id="parent-media-source">Parent Media Source</dt>
<dd><p>The parent media source of a <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> object is the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object that created it.</p></dd>
<dt id="presentation-start-time">Presentation Start Time</dt>
<dd><p>The presentation start time is the earliest time point in the presentation and specifies the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#initial-playback-position">initial playback position</a> and <a href="http://www.w3.org/TR/html5/embedded-content-0.html#earliest-possible-position">earliest possible position</a>. All presentations created using this specification have a presentation start time of 0.</p></dd>
<dt id="presentation-interval">Presentation Interval</dt>
<dd>
<p>The presentation interval of a <a href="#coded-frame">coded frame</a> is the time interval from its <a href="#presentation-timestamp">presentation timestamp</a> to the <a href="#presentation-timestamp">presentation timestamp</a> plus the <a href="#coded-frame-duration">coded frame's duration</a>. For example, if a coded frame has a presentation timestamp of 10 seconds and a <a href="#coded-frame-duration">coded frame duration</a> of 100 milliseconds, then the presentation interval would be [10-10.1). Note that the start of the range is inclusive, but the end of the range is exclusive.</p>
</dd>
<dt id="presentation-order">Presentation Order</dt>
<dd>
<p>The order that <a href="#coded-frame">coded frames</a> are rendered in the presentation. The presentation order is achieved by ordering <a href="#coded-frame">coded frames</a> in monotonically increasing order by their <a href="#presentation-timestamp">presentation timestamps</a>.</p>
</dd>
<dt id="presentation-timestamp">Presentation Timestamp</dt>
<dd>
<p>A reference to a specific time in the presentation. The presentation timestamp in a <a href="#coded-frame">coded frame</a> indicates when the frame must be rendered.</p>
</dd>
<dt id="random-access-point">Random Access Point</dt>
<dd><p>A position in a <a href="#media-segment">media segment</a> where decoding and continuous playback can begin without relying on any previous data in the segment. For video this tends to be the location of I-frames. In the case of audio, most audio frames can be treated as a random access point. Since video tracks tend to have a more sparse distribution of random access points, the location of these points are usually considered the random access points for multiplexed streams.</p></dd>
<dt id="sourcebuffer-byte-stream-format-spec">SourceBuffer byte stream format specification</dt>
<dd><p>The specific <a href="#byte-stream-format-specs">byte stream format specification</a> that describes the format of the byte stream accepted by a <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> instance. The
<a href="#byte-stream-format-specs">byte stream format specification</a>, for a <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> object, is selected based on the <var>type</var> passed to the
<code><a href="#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type">addSourceBuffer()</a></code> call that created the object.</p></dd>
<dt id="track-description">Track Description</dt>
<dd><p>A byte stream format specific structure that provides the <a href="#track-id">Track ID</a>, codec configuration, and other metadata for a single track. Each track description inside a single <a href="#init-segment">initialization segment</a> has a unique <a href="#track-id">Track ID</a>. The user agent must run the <a href="#end-of-stream-algorithm">end of stream algorithm</a> with the <var>error</var> parameter set to <code><a href="#idl-def-EndOfStreamError.decode">"decode"</a></code> if the <a href="#track-id">Track ID</a> is not unique within the <a href="#init-segment">initialization segment</a> .</p></dd>
<dt id="track-id">Track ID</dt>
<dd><p>A Track ID is a byte stream format specific identifier that marks sections of the byte stream as being part of a specific track. The Track ID in a <a href="#track-description">track description</a> identifies which sections of a <a href="#media-segment">media segment</a> belong to that track.</p></dd>
</dl>
</section>
</section>
<section id="mediasource" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource">
<!--OddPage--><h2 id="h2_mediasource" role="heading" aria-level="1"><span class="secno">2. </span>MediaSource Object</h2>
<p>The MediaSource object represents a source of media data for an HTMLMediaElement. It keeps track of the <code><a href="#widl-MediaSource-readyState">readyState</a></code> for this source as well as a list of <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects that can be used to add media data to the presentation. MediaSource objects are created by the web application and then attached to an HTMLMediaElement. The application uses the <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code> to add media data to this source. The HTMLMediaElement fetches this media data from the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object when it is needed during playback.</p>
<pre class="idl"><span class="idlEnum" id="idl-def-ReadyState">enum <span class="idlEnumID">ReadyState</span> {
"<a class="idlEnumItem" href="#idl-def-ReadyState.closed">closed</a>",
"<a class="idlEnumItem" href="#idl-def-ReadyState.open">open</a>",
"<a class="idlEnumItem" href="#idl-def-ReadyState.ended">ended</a>"
};</span></pre><table class="simple"><tbody><tr><th colspan="2">Enumeration description</th></tr><tr><td><code id="idl-def-ReadyState.closed">closed</code></td><td>
Indicates the source is not currently attached to a media element.
</td></tr><tr><td><code id="idl-def-ReadyState.open">open</code></td><td>
The source has been opened by a media element and is ready for data to be appended to the <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.
</td></tr><tr><td><code id="idl-def-ReadyState.ended">ended</code></td><td>
The source is still attached to a media element, but <code><a href="#widl-MediaSource-endOfStream-void-EndOfStreamError-error">endOfStream()</a></code> has been called.
</td></tr></tbody></table>
<pre class="idl"><span class="idlEnum" id="idl-def-EndOfStreamError">enum <span class="idlEnumID">EndOfStreamError</span> {
"<a class="idlEnumItem" href="#idl-def-EndOfStreamError.network">network</a>",
"<a class="idlEnumItem" href="#idl-def-EndOfStreamError.decode">decode</a>"
};</span></pre><table class="simple"><tbody><tr><th colspan="2">Enumeration description</th></tr><tr><td><code id="idl-def-EndOfStreamError.network">network</code></td><td>
<p>Terminates playback and signals that a network error has occured.</p>
<div class="note"><div class="note-title" id="h_note_4" role="heading" aria-level="2"><span>Note</span></div><p>JavaScript applications should use this status code to terminate playback with a network error. For example, if a network error occurs while fetching media data.</p></div>
</td></tr><tr><td><code id="idl-def-EndOfStreamError.decode">decode</code></td><td>
<p>Terminates playback and signals that a decoding error has occured.</p>
<div class="note"><div class="note-title" id="h_note_5" role="heading" aria-level="2"><span>Note</span></div><p>JavaScript applications should use this status code to terminate playback with a decode error. For example, if a parsing error occurs while processing out-of-band media data.</p></div>
</td></tr></tbody></table>
<pre class="idl"><span class="idlInterface" id="idl-def-MediaSource">[<span class="extAttr">Constructor</span>]
interface <span class="idlInterfaceID">MediaSource</span> : <span class="idlSuperclass">EventTarget</span> {
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a></span> <span class="idlAttrName"><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></span>;</span>
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a></span> <span class="idlAttrName"><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></span>;</span>
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a class="idlType" href="#idl-def-ReadyState"><code>ReadyState</code></a></span> <span class="idlAttrName"><a href="#widl-MediaSource-readyState">readyState</a></span>;</span>
<span class="idlAttribute"> attribute <span class="idlAttrType">unrestricted double</span> <span class="idlAttrName"><a href="#widl-MediaSource-duration">duration</a></span>;</span>
<span class="idlMethod"> <span class="idlMethType"><a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a></span> <span class="idlMethName"><a href="#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type">addSourceBuffer</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">type</span></span>);</span>
<span class="idlMethod"> <span class="idlMethType">void</span> <span class="idlMethName"><a href="#widl-MediaSource-removeSourceBuffer-void-SourceBuffer-sourceBuffer">removeSourceBuffer</a></span> (<span class="idlParam"><span class="idlParamType"><a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a></span> <span class="idlParamName">sourceBuffer</span></span>);</span>
<span class="idlMethod"> <span class="idlMethType">void</span> <span class="idlMethName"><a href="#widl-MediaSource-endOfStream-void-EndOfStreamError-error">endOfStream</a></span> (<span class="idlParam">optional <span class="idlParamType"><a class="idlType" href="#idl-def-EndOfStreamError"><code>EndOfStreamError</code></a></span> <span class="idlParamName">error</span></span>);</span>
<span class="idlMethod"> static <span class="idlMethType">boolean</span> <span class="idlMethName"><a href="#widl-MediaSource-isTypeSupported-boolean-DOMString-type">isTypeSupported</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">type</span></span>);</span>
};</span></pre><section id="attributes"><h3 id="h3_attributes" role="heading" aria-level="2"><span class="secno">2.1 </span>Attributes</h3><dl class="attributes"><dt id="widl-MediaSource-activeSourceBuffers"><code>activeSourceBuffers</code> of type <span class="idlAttrType"><a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a></span>, readonly </dt><dd>
<p>Contains the subset of <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code> that are providing the
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-videotrack-selected">selected video track</a>, the
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-audiotrack-enabled">enabled audio track(s)</a>, and the
<a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-showing">"showing"</a> or <a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-hidden">"hidden"</a> text track(s).
</p>
<div class="note"><div class="note-title" id="h_note_6" role="heading" aria-level="3"><span>Note</span></div><p>The <a href="#active-source-buffer-changes">Changes to selected/enabled track state</a> section describes how this attribute gets
updated.</p></div>
</dd><dt id="widl-MediaSource-duration"><code>duration</code> of type <span class="idlAttrType">unrestricted double</span>, </dt><dd>
<p>Allows the web application to set the presentation duration. The duration is initially set to NaN when the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object is created.</p>
<p>On getting, run the following steps:</p>
<ol>
<li>If the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute is <code><a href="#idl-def-ReadyState.closed">"closed"</a></code> then return NaN and abort these steps.</li>
<li>Return the current value of the attribute.</li>
</ol>
<p>On setting, run the following steps:</p>
<ol>
<li>If the value being set is negative or NaN then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
<li>If the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute is not <code><a href="#idl-def-ReadyState.open">"open"</a></code> then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>If the <code><a href="#widl-SourceBuffer-updating">updating</a></code> attribute equals true on any <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>, then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>Run the <a href="#duration-change-algorithm">duration change algorithm</a> with <var>new duration</var> set to the value being assigned to this attribute.
<div class="note"><div class="note-title" id="h_note_7" role="heading" aria-level="3"><span>Note</span></div><p><code><a href="#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data">appendBuffer()</a></code>, <code><a href="#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-maxSize">appendStream()</a></code> and <code><a href="#widl-MediaSource-endOfStream-void-EndOfStreamError-error">endOfStream()</a></code> can update the duration under certain circumstances.</p></div>
</li>
</ol>
</dd><dt id="widl-MediaSource-readyState"><code>readyState</code> of type <span class="idlAttrType"><a class="idlType" href="#idl-def-ReadyState"><code>ReadyState</code></a></span>, readonly </dt><dd>
<p>Indicates the current state of the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object. When the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> is created <code><a href="#widl-MediaSource-readyState">readyState</a></code> must be set to <code><a href="#idl-def-ReadyState.closed">"closed"</a></code>.
</p></dd><dt id="widl-MediaSource-sourceBuffers"><code>sourceBuffers</code> of type <span class="idlAttrType"><a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a></span>, readonly </dt><dd>
Contains the list of <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects associated with this <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a>. When <code><a href="#widl-MediaSource-readyState">readyState</a></code> equals <code><a href="#idl-def-ReadyState.closed">"closed"</a></code> this list will be empty. Once <code><a href="#widl-MediaSource-readyState">readyState</a></code> transitions to <code><a href="#idl-def-ReadyState.open">"open"</a></code> SourceBuffer objects can be added to this list by using <code><a href="#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type">addSourceBuffer()</a></code>.
</dd></dl></section><section id="methods"><h3 id="h3_methods" role="heading" aria-level="2"><span class="secno">2.2 </span>Methods</h3><dl class="methods"><dt id="widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type"><code>addSourceBuffer</code></dt><dd>
<p>Adds a new <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> to <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</p>
<p>Implementations must support at least 1 MediaSource object with the following <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> configurations. MediaSource objects must
support each of the configurations below, but they are only required to support one configuration at a time.
Supporting multiple configurations at once or additional configurations is a quality of implementation issue.
<ul>
<li>A single SourceBuffer with 1 audio track and/or 1 video track.</li>
<li>Two SourceBuffers with one handling a single audio track and the other handling a single video track.</li>
</ul>
<p></p>
<table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">type</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code><a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a></code></div><p>When this method is invoked, the user agent must run the following steps:</p><ol class="method-algorithm">
<li>If <var>type</var> is an empty string then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and abort these steps.</li>
<li>If <var>type</var> contains a MIME type that is not supported or contains a MIME type that is not supported with the types specified for the other <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>, then throw a <code><a href="http://dom.spec.whatwg.org/#dom-domexception-not_supported_err">NOT_SUPPORTED_ERR</a></code> exception and abort these steps.</li>
<li>If the user agent can't handle any more SourceBuffer objects then throw a <code><a href="http://dom.spec.whatwg.org/#dom-domexception-quota_exceeded_err">QUOTA_EXCEEDED_ERR</a></code> exception and abort these steps.
<div class="note"><div class="note-title" id="h_note_8" role="heading" aria-level="3"><span>Note</span></div><p>For example, a user agent may throw a <code><a href="http://dom.spec.whatwg.org/#dom-domexception-quota_exceeded_err">QUOTA_EXCEEDED_ERR</a></code> exception if the media element has reached the
<code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-have_metadata">HAVE_METADATA</a></code> readyState. This can occur if the user agent's media engine does not support adding more tracks during
playback.
</p></div>
</li>
<li>If the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute is not in the <code><a href="#idl-def-ReadyState.open">"open"</a></code> state then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>Create a new <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> object and associated resources.</li>
<li>Set the <var><a href="#sourcebuffer-generate-timestamps-flag">generate timestamps flag</a></var> on the new object to the value in the
"Generate Timestamps Flag" column of the byte stream format registry [<cite><a class="bibref" href="#bib-MSE-REGISTRY">MSE-REGISTRY</a></cite>] entry
that is associated with <var>type</var>.
<li>
<dl class="switch">
<dt>If the <var><a href="#sourcebuffer-generate-timestamps-flag">generate timestamps flag</a></var> equals true:</dt>
<dd>
Set the <code><a href="#widl-SourceBuffer-mode">mode</a></code> attribute on the new object to
<code><a href="#idl-def-AppendMode.sequence">"sequence"</a></code>.
</dd>
<dt>Otherwise:</dt>
<dd>
Set the <code><a href="#widl-SourceBuffer-mode">mode</a></code> attribute on the new object to
<code><a href="#idl-def-AppendMode.segments">"segments"</a></code>.
</dd>
</dl></li>
<li>Add the new object to <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code> and <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-addsourcebuffer">addsourcebuffer</a></code> at <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</li>
<li>Return the new object.</li>
</ol></dd><dt id="widl-MediaSource-endOfStream-void-EndOfStreamError-error"><code>endOfStream</code></dt><dd>
<p>Signals the end of the stream.</p>
<table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">error</td><td class="prmType"><code><a class="idlType" href="#idl-def-EndOfStreamError"><code>EndOfStreamError</code></a></code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptTrue"><span role="img" aria-label="True">✔</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>void</code></div><p>When this method is invoked, the user agent must run the following steps:</p><ol class="method-algorithm">
<li>If the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute is not in the <code><a href="#idl-def-ReadyState.open">"open"</a></code> state then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>If the <code><a href="#widl-SourceBuffer-updating">updating</a></code> attribute equals true on any <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>, then throw an <code><a href="http://dom.spec.whatwg.org/#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and abort these steps.</li>
<li>Run the <a href="#end-of-stream-algorithm">end of stream algorithm</a> with the <var>error</var> parameter set to <var>error</var>.</li>
</ol></dd><dt id="widl-MediaSource-isTypeSupported-boolean-DOMString-type"><code>isTypeSupported</code>, static</dt><dd>
<p>Check to see whether the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> is capable of creating <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects for the specified MIME type.</p>
<div class="note"><div class="note-title" id="h_note_9" role="heading" aria-level="3"><span>Note</span></div><p>
If true is returned from this method, it only indicates that the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> implementation is capable of creating <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects for the specified MIME type. An <code><a href="#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type">addSourceBuffer()</a></code> call may still fail if sufficient resources are not available to support the addition of a new <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a>.
</p></div>
<div class="note"><div class="note-title" id="h_note_10" role="heading" aria-level="3"><span>Note</span></div><p>
This method returning true implies that HTMLMediaElement.canPlayType() will return "maybe" or "probably" since it does not make sense for a <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> to support a type the HTMLMediaElement knows it cannot play.
</p></div>
<table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">type</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>boolean</code></div><p>When this method is invoked, the user agent must run the following steps:</p><ol class="method-algorithm">
<li>If <var>type</var> is an empty string, then return false.</li>
<li>If <var>type</var> does not contain a valid MIME type string, then return false.</li>
<li>If <var>type</var> contains a media type or media subtype that the MediaSource does not support, then return false.</li>
<li>If <var>type</var> contains a codec that the MediaSource does not support, then return false.</li>
<li>If the MediaSource does not support the specified combination of media type, media subtype, and codecs then return false.</li>
<li>Return true.</li>
</ol></dd><dt id="widl-MediaSource-removeSourceBuffer-void-SourceBuffer-sourceBuffer"><code>removeSourceBuffer</code></dt><dd>
<p>Removes a <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> from <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</p>
<table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">sourceBuffer</td><td class="prmType"><code><a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a></code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>void</code></div><p>When this method is invoked, the user agent must run the following steps:</p><ol class="method-algorithm">
<li>If <var>sourceBuffer</var> specifies an object that is not in <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code> then throw a <code><a href="http://dom.spec.whatwg.org/#dom-domexception-not_found_err">NOT_FOUND_ERR</a></code> exception and abort these steps.</li>
<li>If the <var>sourceBuffer</var>.<code><a href="#widl-SourceBuffer-updating">updating</a></code> attribute equals true, then run the following steps:
<ol>
<li>Abort the <a href="#sourcebuffer-buffer-append">buffer append</a> and <a href="#sourcebuffer-stream-append-loop">stream append loop</a> algorithms if they are running.</li>
<li>Set the <var>sourceBuffer</var>.<code><a href="#widl-SourceBuffer-updating">updating</a></code> attribute to false.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-abort">abort</a></code> at <var>sourceBuffer</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-updateend">updateend</a></code> at <var>sourceBuffer</var>.</li>
</ol>
</li>
<li>Let <var>SourceBuffer audioTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotracklist">AudioTrackList</a></code> object returned by <var>sourceBuffer</var>.<code><a href="#widl-SourceBuffer-audioTracks">audioTracks</a></code>.</li>
<li>If the <var>SourceBuffer audioTracks list</var> is not empty, then run the following steps:
<ol>
<li>Let <var>HTMLMediaElement audioTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotracklist">AudioTrackList</a></code> object returned by the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-audiotracks">audioTracks</a></code> attribute on the HTMLMediaElement.</li>
<li>Let the <var>removed enabled audio track flag</var> equal false.</li>
<li>For each <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotrack">AudioTrack</a></code> object in the <var>SourceBuffer audioTracks list</var>, run the following steps:
<ol>
<li>Set the <code><a href="#widl-AudioTrack-sourceBuffer">sourceBuffer</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotrack">AudioTrack</a></code> object to null.</li>
<li>If the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-audiotrack-enabled">enabled</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotrack">AudioTrack</a></code> object is true, then
set the <var>removed enabled audio track flag</var> to true.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotrack">AudioTrack</a></code> object from the <var>HTMLMediaElement audioTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>HTMLMediaElement audioTracks list</var>.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#audiotrack">AudioTrack</a></code> object from the <var>SourceBuffer audioTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>SourceBuffer audioTracks list</var>.</li>
</ol>
</li>
<li>If the <var>removed enabled audio track flag</var> equals true, then <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onchange">change</a></code> at the
<var>HTMLMediaElement audioTracks list</var>.</li>
</ol>
</li>
<li>Let <var>SourceBuffer videoTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotracklist">VideoTrackList</a></code> object returned by <var>sourceBuffer</var>.<code><a href="#widl-SourceBuffer-videoTracks">videoTracks</a></code>.</li>
<li>If the <var>SourceBuffer videoTracks list</var> is not empty, then run the following steps:
<ol>
<li>Let <var>HTMLMediaElement videoTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotracklist">VideoTrackList</a></code> object returned by the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-videotracks">videoTracks</a></code> attribute on the HTMLMediaElement.</li>
<li>Let the <var>removed selected video track flag</var> equal false.</li>
<li>For each <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotrack">VideoTrack</a></code> object in the <var>SourceBuffer videoTracks list</var>, run the following steps:
<ol>
<li>Set the <code><a href="#widl-VideoTrack-sourceBuffer">sourceBuffer</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotrack">VideoTrack</a></code> object to null.</li>
<li>If the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-videotrack-selected">selected</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotrack">VideoTrack</a></code> object is true, then
set the <var>removed selected video track flag</var> to true.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotrack">VideoTrack</a></code> object from the <var>HTMLMediaElement videoTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>HTMLMediaElement videoTracks list</var>.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#videotrack">VideoTrack</a></code> object from the <var>SourceBuffer videoTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>SourceBuffer videoTracks list</var>.</li>
</ol>
</li>
<li>If the <var>removed selected video track flag</var> equals true, then <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onchange">change</a></code> at the
<var>HTMLMediaElement videoTracks list</var>.</li>
</ol>
</li>
<li>Let <var>SourceBuffer textTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttracklist">TextTrackList</a></code> object returned by <var>sourceBuffer</var>.<code><a href="#widl-SourceBuffer-textTracks">textTracks</a></code>.</li>
<li>If the <var>SourceBuffer textTracks list</var> is not empty, then run the following steps:
<ol>
<li>Let <var>HTMLMediaElement textTracks list</var> equal the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttracklist">TextTrackList</a></code> object returned by the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-texttracks">textTracks</a></code> attribute on the HTMLMediaElement.</li>
<li>Let the <var>removed enabled text track flag</var> equal false.</li>
<li>For each <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttrack">TextTrack</a></code> object in the <var>SourceBuffer textTracks list</var>, run the following steps:
<ol>
<li>Set the <code><a href="#widl-TextTrack-sourceBuffer">sourceBuffer</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttrack">TextTrack</a></code> object to null.</li>
<li>If the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-mode">mode</a></code> attribute on the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttrack">TextTrack</a></code> object is set to <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-showing">"showing"</a></code> or
<code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-texttrack-hidden">"hidden"</a></code> , then set the <var>removed enabled text track flag</var> to true.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttrack">TextTrack</a></code> object from the <var>HTMLMediaElement textTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>HTMLMediaElement textTracks list</var>.</li>
<li>Remove the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#texttrack">TextTrack</a></code> object from the <var>SourceBuffer textTracks list</var>.</li>
<li><a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to fire a <a href="http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">trusted event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onremovetrack">removetrack</a></code>, that does not bubble and is not cancelable, and that uses the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#trackevent">TrackEvent</a></code> interface, at the <var>SourceBuffer textTracks list</var>.</li>
</ol>
</li>
<li>If the <var>removed enabled text track flag</var> equals true, then <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#handler-tracklist-onchange">change</a></code> at the
<var>HTMLMediaElement textTracks list</var>.</li>
</ol>
</li>
<li>If <var>sourceBuffer</var> is in <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code>, then remove <var>sourceBuffer</var> from <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code> and
<a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at the <a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a> returned by <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code>.</li>
<li>Remove <var>sourceBuffer</var> from <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code> and <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at
the <a class="idlType" href="#idl-def-SourceBufferList"><code>SourceBufferList</code></a> returned by <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</li>
<li>Destroy all resources for <var>sourceBuffer</var>.</li>
</ol></dd></dl></section>
<section id="mediasource-events" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource-events">
<h3 id="h3_mediasource-events" role="heading" aria-level="2"><span class="secno">2.3 </span>Event Summary</h3>
<table class="old-table">
<thead>
<tr>
<th>Event name</th>
<th>Interface</th>
<th>Dispatched when...</th>
</tr>
</thead>
<tbody>
<tr>
<td><dfn id="dom-evt-sourceopen"><code>sourceopen</code></dfn></td>
<td><code>Event</code></td>
<td><code><a href="#widl-MediaSource-readyState">readyState</a></code> transitions from <code><a href="#idl-def-ReadyState.closed">"closed"</a></code> to <code><a href="#idl-def-ReadyState.open">"open"</a></code> or from <code><a href="#idl-def-ReadyState.ended">"ended"</a></code> to <code><a href="#idl-def-ReadyState.open">"open"</a></code>.</td>
</tr>
<tr>
<td><dfn id="dom-evt-sourceended"><code>sourceended</code></dfn></td>
<td><code>Event</code></td>
<td><code><a href="#widl-MediaSource-readyState">readyState</a></code> transitions from <code><a href="#idl-def-ReadyState.open">"open"</a></code> to <code><a href="#idl-def-ReadyState.ended">"ended"</a></code>.</td>
</tr>
<tr>
<td><dfn id="dom-evt-sourceclose"><code>sourceclose</code></dfn></td>
<td><code>Event</code></td>
<td><code><a href="#widl-MediaSource-readyState">readyState</a></code> transitions from <code><a href="#idl-def-ReadyState.open">"open"</a></code> to <code><a href="#idl-def-ReadyState.closed">"closed"</a></code> or <code><a href="#idl-def-ReadyState.ended">"ended"</a></code> to <code><a href="#idl-def-ReadyState.closed">"closed"</a></code>.</td>
</tr>
</tbody>
</table>
</section>
<section id="mediasource-algorithms" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource-algorithms">
<h3 id="h3_mediasource-algorithms" role="heading" aria-level="2"><span class="secno">2.4 </span>Algorithms</h3>
<section id="mediasource-attach" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource-attach">
<h4 id="h4_mediasource-attach" role="heading" aria-level="3"><span class="secno">2.4.1 </span>Attaching to a media element</h4>
<p> A <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> object can be attached to a media element by assigning a <a href="#mediasource-object-url">MediaSource object URL</a> to the media element <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#attr-media-src">src</a></code> attribute or the src attribute of a <source> inside a media element. A <a href="#mediasource-object-url">MediaSource object URL</a> is created by passing a MediaSource object to <code><a href="#widl-URL-createObjectURL-DOMString-MediaSource-mediaSource">createObjectURL()</a></code>.</p>
<p>If the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a> absolute URL matches the MediaSource object URL, run the following steps right before the <span>"<i>Perform a potentially CORS-enabled fetch</i>"</span>
step in the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a>.</p>
<dl class="switch">
<dt>If <code><a href="#widl-MediaSource-readyState">readyState</a></code> is NOT set to <code><a href="#idl-def-ReadyState.closed">"closed"</a></code></dt>
<dd>Run the <span>"<i>If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource</i>"</span> steps of the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a>.</dd>
<dt>Otherwise</dt>
<dd>
<ol>
<li>Set the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute to <code><a href="#idl-def-ReadyState.open">"open"</a></code>.</li>
<li>
<a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-sourceopen">sourceopen</a></code> at the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a>.</li>
<li>Continue the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a> by running the <span>"<i>Perform a potentially CORS-enabled fetch</i>"</span> step. Text in the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a>
that refers to "the download" or "bytes received" refer to data passed in via <code><a href="#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data">appendBuffer()</a></code> and <code><a href="#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-maxSize">appendStream()</a></code>. References to
HTTP in the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#concept-media-load-resource">resource fetch algorithm</a> do not apply because the HTMLMediaElement does not fetch media data via HTTP when a <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a> is attached.</li>
</ol>
</dd>
</dl>
</section>
<section id="mediasource-detach" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource-detach">
<h4 id="h4_mediasource-detach" role="heading" aria-level="3"><span class="secno">2.4.2 </span>Detaching from a media element</h4>
<p>The following steps are run in any case where the media element is going to transition to <a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-network_empty">NETWORK_EMPTY</a> and <a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <a href="http://www.w3.org/TR/html5/embedded-content-0.html#event-mediacontroller-emptied">emptied</a> at the media element. These steps must be run right before the transition.</p>
<ol>
<li>Set the <code><a href="#widl-MediaSource-readyState">readyState</a></code> attribute to <code><a href="#idl-def-ReadyState.closed">"closed"</a></code>.</li>
<li>Set the <code><a href="#widl-MediaSource-duration">duration</a></code> attribute to NaN.</li>
<li>Remove all the <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects from <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code>.</li>
<li>
<a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code>.</li>
<li>Remove all the <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> objects from <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</li>
<li>
<a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-removesourcebuffer">removesourcebuffer</a></code> at <code><a href="#widl-MediaSource-sourceBuffers">sourceBuffers</a></code>.</li>
<li>
<a href="http://www.w3.org/TR/html5/webappapis.html#queue-a-task">Queue a task</a> to <a href="http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">fire a simple event</a> named <code><a href="#dom-evt-sourceclose">sourceclose</a></code> at the <a class="idlType" href="#idl-def-MediaSource"><code>MediaSource</code></a>.</li>
</ol>
</section>
<section id="mediasource-seeking" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#mediasource-seeking">
<h4 id="h4_mediasource-seeking" role="heading" aria-level="3"><span class="secno">2.4.3 </span>Seeking</h4>
<p>Run the following steps as part of the "<i>Wait until the user agent has established whether or not the media data for the new playback position is available, and, if it is, until it has decoded enough data to play back that position"</i> step of the <a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seek">seek algorithm</a>:</p>
<ol>
<li>The media element looks for <a href="#media-segment">media segments</a> containing the <var>new playback position</var> in each <a class="idlType" href="#idl-def-SourceBuffer"><code>SourceBuffer</code></a> object in <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code>.
<dl class="switch">
<dt>If one or more of the objects in <code><a href="#widl-MediaSource-activeSourceBuffers">activeSourceBuffers</a></code> is missing <a href="#media-segment">media segments</a> for the <var>new playback position</var>
</dt>
<dd>
<ol>
<li>Set the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-have_metadata">HAVE_METADATA</a></code>.</li>
<li>The media element waits until an <code><a href="#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data">appendBuffer()</a></code> or an <code><a href="#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-maxSize">appendStream()</a></code> call causes the <a href="#sourcebuffer-coded-frame-processing">coded frame processing algorithm</a> to set
the <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-readystate">HTMLMediaElement.readyState</a></code> attribute to a value greater than <code><a href="http://www.w3.org/TR/html5/embedded-content-0.html#dom-media-have_metadata">HAVE_METADATA</a></code>.