-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
1892 lines (1867 loc) · 84.1 KB
/
index.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>
<title>Media Capture and Streams Extensions</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script class='remove'>
"use strict";
// See https://github.com/w3c/respec/wiki/ for how to configure ReSpec
var respecConfig = {
group: "webrtc",
xref: ["geometry-1", "html", "infra", "permissions", "dom", "hr-time", "image-capture", "mediacapture-streams", "screen-capture", "webaudio", "webcodecs", "webidl"],
edDraftURI: "https://w3c.github.io/mediacapture-extensions/",
editors: [
{name: "Jan-Ivar Bruaroey", company: "Mozilla Corporation", w3cid: 79152},
{name: "Elad Alon", company: "Google", email: "[email protected]", w3cid: 118124},
],
shortName: "mediacapture-extensions",
specStatus: "ED",
subjectPrefix: "[mediacapture-extensions]",
github: "https://github.com/w3c/mediacapture-extensions",
};
</script>
</head>
<body>
<section id="abstract">
<p>This document defines a set of ECMAScript APIs in WebIDL to extend the [[mediacapture-streams]] specification.</p>
</section>
<section id="sotd">
<p>This is an unofficial proposal.</p>
</section>
<section id="introduction">
<h2>Introduction</h2>
<p>This document contains proposed extensions and modifications to the
[[mediacapture-streams]] specification.</p>
<p>New features and modifications to existing features proposed here may be
considered for addition into the main specification post Recommendation.
Deciding factors will include maturity of the extension or modification,
consensus on adding it, and implementation experience.</p>
<p>A concrete long-term goal is reducing the fingerprinting surface of
{{MediaDevices/enumerateDevices()}} by deprecating exposure of the device
{{MediaDeviceInfo/label}} in its results. This requires relieving
applications of the burden of building user interfaces to select cameras and
microphones in-content, by offering this in user agents as part of
{{MediaDevices/getUserMedia()}} instead.</p>
<p>Miscellaneous other smaller features are under consideration as well,
such as constraints to control multi-channel audio beyond stereo.</p>
</section>
<section>
<h2>Terminology</h2>
<p>
This document uses the definitions {{MediaDevices}}, {{MediaStreamTrack}},
{{MediaStreamConstraints}}, {{ConstrainablePattern}},
{{MediaTrackSupportedConstraints}}, {{MediaTrackCapabilities}},
{{MediaTrackConstraintSet}}, {{MediaTrackSettings}} and
{{ConstrainBoolean}} from [[!mediacapture-streams]].
<p>The terms [=permission state=], [=request permission to use=], and
<a data-cite="permissions">prompt the user to choose</a> are defined in
[[!permissions]].</p>
<p>
{{Performance.now()}} is defined in [[!hr-time]].
</p>
</section>
<section id="conformance">
</section>
<section id="camera_and_microphone_picker">
<h2>In-browser camera and microphone picker</h2>
<p>The existing {{MediaDevices/enumerateDevices()}} function exposes camera
and microphone {{MediaDeviceInfo/label}}s to let applications build
in-content user interfaces for camera and microphone selection. Applications
have had to do this because {{MediaDevices/getUserMedia()}} did not offer a
web compatible in-agent device picker. This specification aims to rectify
that.</p>
<p>Due to the significant fingerprinting vector caused by device
{{MediaDeviceInfo/label}}s, and the well-established nature of the existing
APIs, the scope of this particular effort is limited to removing
{{MediaDeviceInfo/label}}, leaving the overall constraints-based model
intact. This helps ensure a migration path more viable than to a
less-powerful API.</p>
<p>This specification augments the existing {{MediaDevices/getUserMedia()}}
function instead of introducing a new less-powerful API to compete with it,
for that reason as well.</p>
<section>
<h3>getUserMedia "user-chooses" semantics</h3>
<p>This specification introduces
slightly altered semantics to the {{MediaDevices/getUserMedia()}}
function called <code>"user-chooses"</code> that guarantee a picker will
be shown to the user in cases where the user agent would otherwise choose
for the user (that is: when application constraints do not narrow down
the choices to a single device). This is orthogonal to permission, and
offers a better and more consistent user experience across applications
and user agents.
</p>
<p>Unfortunately, since the <code>"user-chooses"</code> semantics may
produce user agent prompts at different times and in different situations
compared to the old semantics, they are somewhat incompatible with
expectations in some existing web applications that tend to call
{{MediaDevices/getUserMedia()}} repeatedly and lazily instead of using
e.g. <code>stream.clone()</code>.</p>
</section>
<section>
<h3>Web compatibility and migration</h3>
<p>User agents are encouraged to provide the new semantics as opt-in
initially for web compatibility. User agents MUST deprecate (remove)
{{MediaDeviceInfo/label}} from {{MediaDeviceInfo}} over time, though specific migration strategies
are left to user agents. User agents SHOULD migrate to offering the new
semantics by default (opt-out) over time.</p>
<p>Since the constraints-model remains intact, web compatibility problems
are expected to be limited to:</p>
<ul>
<li>
Sites that never migrated show e.g. "Camera 1", "Camera 2" etc.
instead of descriptive device labels
</li>
<li>
Sites with no device management strategy provoke a picker in the
user agent every visit for users with more than a singular choice
of camera or microphone (a feature of sorts)
</li>
</ul>
</section>
<section id="mediadevices-interface">
<h3>MediaDevices Interface Extensions</h3>
<div>
<pre class="idl"
>partial interface MediaDevices {
readonly attribute GetUserMediaSemantics defaultSemantics;
};</pre>
</div>
<section>
<h2>Attributes</h2>
<dl data-link-for="MediaDevices" data-dfn-for="MediaDevices"
class="attributes">
<dt id="def-mediadevices-defaultSemantics"><dfn><code>defaultSemantics</code></dfn>
of type <span class="idlAttrType"><a>GetUserMediaSemantics</a></span>, readonly</dt>
<dd>
<p>The default semantics of {{MediaDevices/getUserMedia()}} in this
user agent.</p>
<p>User agents SHOULD default to <code>"browser-chooses"</code>
for backwards compatibility, until a transition plan has been
enacted where a majority of user agents collectively switch their
defaults to <code>"user-chooses"</code> for improved user privacy,
and usage metrics suggest this transition is feasible without
major breakage.</p>
</dd>
</dl>
</section>
</section>
<section id="mediastreamconstraints-dictionary-extensions">
<h3>MediaStreamConstraints dictionary extensions</h3>
<div>
<pre class="idl"
>partial dictionary MediaStreamConstraints {
GetUserMediaSemantics semantics;
};</pre>
<section>
<h2>Dictionary {{MediaStreamConstraints}} Members</h2>
<dl data-link-for="MediaStreamConstraints" data-dfn-for=
"MediaStreamConstraints" class="dictionary-members">
<dt><dfn><code>semantics</code></dfn> of type <span class=
"idlMemberType">{{GetUserMediaSemantics}}</span></dt>
<dd>
<p>In cases where the specified constraints do not narrow
multiple choices between devices down to one per kind, specifies
how the final determination of which devices to pick from the
remaining choices MUST be made. If not specified, then the
<a data-link-for="MediaDevices">defaultSemantics</a> are used.
</p>
</dd>
</dl>
</section>
</div>
</section>
<section id="getusermediasemantics-enum">
<h3>GetUserMediaSemantics enum</h3>
<div>
<pre class="idl"
>enum GetUserMediaSemantics {
"browser-chooses",
"user-chooses"
};</pre>
<table data-link-for="GetUserMediaSemantics" data-dfn-for=
"GetUserMediaSemantics" class="simple">
<tbody>
<tr>
<th colspan="2"><dfn>GetUserMediaSemantics</dfn> Enumeration
description</th>
</tr>
<tr>
<td><dfn><code id=
"idl-def-GetUserMediaSemantics.browser-chooses">browser-chooses</code></dfn></td>
<td>
<p>When application-specified constraints do not narrow multiple
choices between devices down to one per kind, the user agent is
allowed to make the final determination between the remaining
choices.
</p>
</td>
</tr>
<tr>
<td><dfn><code id=
"idl-def-GetUserMediaSemantics.user-chooses">user-chooses</code></dfn></td>
<td>
<p>When application-specified constraints do not narrow
multiple choices between devices down to one per kind, the user
agent MUST
<a href="prompt-the-user-to-choose">prompt the user to choose</a>
between the remaining choices, even if the application already
has permission to some or all of them.</p>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3>Algorithms</h3>
<p>When the {{MediaDevices/getUserMedia()}} method is invoked, run the
following steps before invoking the {{MediaDevices/getUserMedia()}}
algorithm:</p>
<ol>
<li>
<p>Let <var>mediaDevices</var> be the object on which this method was
invoked.</p>
</li>
<li>
<p>Let <var>constraints</var> be the method's first argument.</p>
</li>
<li>
<p>Let <var>semanticsPresent</var> be <code>true</code> if
<var>constraints</var><code>.semantics</code> [= map/exists =],
otherwise <code>false</code>.</p>
</li>
<li>
<p>Let <var>semantics</var> be
<var>constraints</var><code>.semantics</code>
if it [= map/exists =],
or the value of <var>mediaDevices</var><code>.<a data-link-for="MediaDevices">defaultSemantics</a></code>
otherwise.</p>
</li>
<li>
<p>Replace step 6.5.1. of the {{MediaDevices/getUserMedia()}}
algorithm in its entirety with the following two steps:</p>
<ol>
<li>
<p>Let <var>descriptor</var> be a {{PermissionDescriptor}}
with its {{PermissionDescriptor/name}} member set to the permission name
associated with <var>kind</var> (e.g. [="camera"=] for
<code>"video"</code>, [="microphone"=] for <code>"audio"</code>).</p>
</li>
<li>
<p>If the number of unique devices sourcing tracks of
media type <var>kind</var> in <var>candidateSet</var>
is greater than <code>1</code> and
<var>semantics</var> is <code>"user-chooses"</code>,
then <a>prompt the user to choose</a> a device with
<var>descriptor</var>, resulting in provided media.
Otherwise, <a>request permission to use</a> a
device with <var>descriptor</var>, while considering
all devices being attached to a live and
<a>same-permission</a> MediaStreamTrack in the current
[=browsing
context=] to mean having permission status {{PermissionState/"granted"}},
resulting in provided media.</p>
<p><dfn>Same-permission</dfn> in this context means a
{{MediaStreamTrack}} that required the same level of
permission to obtain as what is being requested.</p>
<p>When asking the user’s permission, the user agent
MUST disclose whether permission will be granted only to
the device chosen, or to all devices of that
<var>kind</var>.</p>
<p>Let <var>track</var> be the provided media, which
MUST be precisely one track of type <var>kind</var> from
<var>finalSet</var>. If <var>semantics</var> is
<code>"browser-chooses"</code> then the decision of
which track to choose from <var>finalSet</var> is up
to the User Agent, which MAY use the value of the computed
"fitness distance" from the <a href=
"https://www.w3.org/TR/mediacapture-streams/#dfn-selectsettings">
SelectSettings</a>
algorithm, the value of <var>semanticsPresent</var>,
or any other internally-available information about
the devices, as inputs to its decision.
If <var>semantics</var> is <code>"user-chooses"</code>,
and the application has not narrowed down the choices
to one, then the user agent MUST ask the user to make
the final selection.</p>
<p>Once selected, the source of the
{{MediaStreamTrack}} MUST NOT change.</p>
<p>User Agents are encouraged to default to or present
a default choice based primarily on fitness distance,
and secondarily on the user's primary or system default
device for <var>kind</var> (when possible). User Agents
MAY allow users to use any media source, including
pre-recorded media files.</p>
</li>
</ol>
</li>
</ol>
</section>
<section>
<h3>Examples</h3>
<div>
<p>This example shows a setup with a start button and a camera selector
using the new semantics (microphone is not shown for brievity but is
equivalent).</p>
<pre class="example">
<button id="start">Start</button>
<button id="chosenCamera" disabled>Camera: none</button>
<script>
let cameraTrack = null;
start.onclick = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: {deviceId: localStorage.cameraId}
});
setCameraTrack(stream.getVideoTracks()[0]);
} catch (err) {
console.error(err);
}
}
chosenCamera.onclick = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
semantics: "user-chooses"
});
setCameraTrack(stream.getVideoTracks()[0]);
} catch (err) {
console.error(err);
}
}
function setCameraTrack(track) {
cameraTrack = track;
const {deviceId, label} = track.getSettings();
localStorage.cameraId = deviceId;
chosenCamera.innerText = `Camera: ${label}`;
chosenCamera.disabled = false;
}
</script>
</pre>
</div>
</section>
</section>
<section>
<h2>MediaStreamTrack extensions</h2>
<h3>Transferable MediaStreamTrack</h3>
<div>
<p>A {{MediaStreamTrack}} is a <a data-cite="!HTML/#transferable-objects">transferable object</a>.
This allows manipulating real-time media outside the context it was requested or created in,
for instance in workers or third-party iframes.</p>
<p>To preserve the existing privacy and security infrastructure, in particular for capture tracks,
the track source lifetime management remains tied to the context that created it.
The transfer algorithm MUST ensure the following behaviors:</p>
<p>
<ol>
<li><p>The context named <var>originalContext</var> that created a track named <var>originalTrack</var> remains in control
of the <var>originalTrack</var> source, named <var>trackSource</var>, even when <var>originalTrack</var> is transferred into <var>transferredTrack</var>.</p>
</li>
<li>
<p>In particular, <var>originalContext</var> remains the proxy to privacy indicators of <var>trackSource</var>.
<var>transferredTrack</var> or any of its clones are considered as tracks using <var>trackSource</var>
as if they were tracks created in and controlled by <var>originalContext</var>.</p>
</li>
<li><p>When <var>originalContext</var> goes away, <var>trackSource</var> gets ended, thus <var>transferredTrack</var> gets ended.</p></li>
<li><p>When <var>originalContext</var> would have muted/unmuted <var>originalTrack</var>, <var>transferredTrack</var> gets muted/unmuted.</p></li>
<li><p>If <var>transferredTrack</var> is cloned in <var>transferredTrackClone</var>, <var>transferredTrackClone</var> is tied to <var>trackSource</var>.
It is not tied to <var>originalTrack</var> in any way.</p></li>
<li><p>If <var>transferredTrack</var> is transferred into <var>transferredAgainTrack</var>, <var>transferredAgainTrack</var> is tied to <var>trackSource</var>.
It is not tied to <var>transferredTrack</var> or <var>originalTrack</var> in any way.</p></li>
</ol>
</p>
</div>
<div>
<p>The WebIDL changes to make the track transferable are the following:
<pre class="idl"
>[Exposed=(Window,Worker), Transferable]
partial interface MediaStreamTrack {
};</pre>
</div>
<div>
<p>At creation of a {{MediaStreamTrack}} object, called <var>track</var>, run the following steps:</p>
<ol>
<li><p>Initialize <var>track</var>.`[[IsDetached]]` to <code>false</code>.</p></li>
</ol>
</div>
<div>
<p>The {{MediaStreamTrack}} <a data-cite="!HTML/#transfer-steps">transfer steps</a>, given <var>value</var> and <var>dataHolder</var>, are:</p>
<ol>
<li><p>If <var>value</var>.`[[IsDetached]]` is <code>true</code>, throw a "DataCloneError" DOMException.</p></li>
<li><p>Set <var>dataHolder</var>.`[[id]]` to <var>value</var>.{{MediaStreamTrack/id}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[kind]]` to <var>value</var>.{{MediaStreamTrack/kind}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[label]]` to <var>value</var>.{{MediaStreamTrack/label}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[readyState]]` to <var>value</var>.{{MediaStreamTrack/readyState}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[enabled]]` to <var>value</var>.{{MediaStreamTrack/enabled}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[muted]]` to <var>value</var>.{{MediaStreamTrack/muted}}.</p></li>
<li><p>Set <var>dataHolder</var>.`[[source]]` to <var>value</var> underlying source.</p></li>
<li><p>Set <var>dataHolder</var>.`[[constraints]]` to <var>value</var> active constraints.</p></li>
<li><p>Set <var>dataHolder</var>.`[[contentHint]]` to <var>value</var> application-set content hint.</p></li>
<li><p>Set <var>value</var>.`[[IsDetached]]` to <code>true</code>.</p></li>
<li><p>Set <var>value</var>.<a data-cite="mediacapture-streams#dfn-readystate" data-link-type="attribute">[[\ReadyState]]</a> to {{MediaStreamTrackState/"ended"}} (without stopping the underlying source or firing an `ended` event).</p></li>
</ol>
</div>
<div><p>{{MediaStreamTrack}} <a data-cite="!HTML/#transfer-receiving-steps">transfer-receiving steps</a>, given <var>dataHolder</var> and <var>track</var>, are:</p>
<ol>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/id}} to <var>dataHolder</var>.`[[id]]`.</p></li>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/kind}} to <var>dataHolder</var>.`[[kind]]`.</p></li>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/label}} to <var>dataHolder</var>.`[[label]]`.</p></li>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/readyState}} to <var>dataHolder</var>.`[[readyState]]`.</p></li>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/enabled}} to <var>dataHolder</var>.`[[enabled]]`.</p></li>
<li><p>Initialize <var>track</var>.{{MediaStreamTrack/muted}} to <var>dataHolder</var>.`[[muted]]`.</p></li>
<li><p>Set <var>track</var> application-set content hint to <var>dataHolder</var>.`[[contentHint]]`.</p></li>
<li><p>[=Initialize the underlying source=] of <var>track</var> to <var>dataHolder</var>.`[[source]]`.</p></li>
<li><p>Set <var>track</var>'s constraints to <var>dataHolder</var>.`[[constraints]]`.</p></li>
</ol>
</div>
<div>
<p>The underlying source is supposed to be kept alive between the transfer and transfer-receiving steps, or as long as the data holder is alive.
In a sense, between these steps, the data holder is attached to the underlying source as if it was a track.</p>
</div>
<h3>MediaStreamTrack Statistics</h3>
<div>
<p>
On microphone audio tracks, frame counters allow the application to tell
the ratio of audio that is delivered as one quality indicator and the
latency metrics measure the input delay from capture to application.
</p>
<p>
On camera and screenshare video tracks, frame counters allow the
application to tell what the frame rate is, which may be lower than the
target {{MediaTrackSettings/frameRate}}. For example, if the track is
sourced from a camera then the production of frames could be slowed down
if it's dark or frames could be dropped if the system is CPU starved.
This could impact the total number of frames produced by the source and
impact how many frames are delivered, discarded or dropped for other
reasons.
</p>
</div>
<div>
<pre class="idl"
>partial interface MediaStreamTrack {
[SameObject] readonly attribute
(MediaStreamTrackAudioStats or MediaStreamTrackVideoStats)? stats;
};
</pre>
</div>
<div>
<p>Let the {{MediaStreamTrack}} have a
<dfn class=export data-dfn-for="MediaStreamTrack">[[\Stats]]</dfn>
internal slot initialized it to <code>null</code>, unless otherwise
specified below.</p>
<p>If the track's is of {{MediaStreamTrack/kind}} <code>"audio"</code>,
run the following steps:</p>
<ol>
<li>
<p>If the {{MediaStreamTrack}} is sourced from
<code>getUserMedia()</code>, initialize {{MediaStreamTrack/[[Stats]]}}
to a new instance of {{MediaStreamTrackAudioStats}} set up to expose
audio stats for this {{MediaStreamTrack}}.</p>
</li>
</ol>
<p>If the track's is of {{MediaStreamTrack/kind}} <code>"video"</code>,
run the following steps:</p>
<ol>
<li>
<p>If the {{MediaStreamTrack}} is sourced from
<code>getUserMedia()</code> or <code>getDisplayMedia()</code>,
initialize {{MediaStreamTrack/[[Stats]]}} to a new instance of
{{MediaStreamTrackVideoStats}} set up to expose video stats for this
{{MediaStreamTrack}}.</p>
</li>
</ol>
</div>
<section>
<h4>Attributes</h4>
<dl data-link-for="MediaStreamTrack" data-dfn-for="MediaStreamTrack"
class="attributes">
<dt>
<dfn data-idl="">stats</dfn> of type ({{MediaStreamTrackAudioStats}}
or {{MediaStreamTrackVideoStats}}), readonly
</dt>
<dd>
<p>
When this getter is called, the user agenst MUST run the following
steps:
</p>
<ol>
<li>
<p>
Let <var>track</var> be the {{MediaStreamTrack}} that this
getter is called on.
</p>
</li>
<li>
<p>Return <var>track</var>.{{MediaStreamTrack/[[Stats]]}}.</p>
</li>
</ol>
</dd>
</dl>
</section>
</section>
<section>
<h4>The MediaStreamTrackAudioStats interface</h4>
<div>
<pre class="idl" data-cite="HR-TIME">[Exposed=Window]
interface MediaStreamTrackAudioStats {
readonly attribute unsigned long long deliveredFrames;
readonly attribute DOMHighResTimeStamp deliveredFramesDuration;
readonly attribute unsigned long long totalFrames;
readonly attribute DOMHighResTimeStamp totalFramesDuration;
readonly attribute DOMHighResTimeStamp latency;
readonly attribute DOMHighResTimeStamp averageLatency;
readonly attribute DOMHighResTimeStamp minimumLatency;
readonly attribute DOMHighResTimeStamp maximumLatency;
undefined resetLatency();
[Default] object toJSON();
};
</pre>
<div class="note">
<p>The following metrics lack Working Group consensus:
{{MediaStreamTrackAudioStats/deliveredFrames}},
{{MediaStreamTrackAudioStats/deliveredFramesDuration}},
{{MediaStreamTrackAudioStats/totalFrames}} and
{{MediaStreamTrackAudioStats/totalFramesDuration}}. See <a
href="https://github.com/w3c/mediacapture-extensions/issues/129">Issue
#129</a>.</p>
</div>
<div>
<p>The {{MediaStreamTrackAudioStats}} expose frame counters for the
{{MediaStreamTrack}} that created it. For this track, the user agent
is required to count each audio frame from its source as follows:</p>
<ul>
<li>
<p>A frame is considered a <dfn data-lt="delivered audio frames">
delivered audio frame</dfn> if it either was delivered to a sink
or would have been delivered to a sink, if one was connected.</p>
</li>
<li>
<p>The <dfn data-lt="delivered audio frames duration">delivered
audio frames duration</dfn> is the total duration of all
[= delivered audio frames =]. This measurement is incremented at
the same time as [= delivered audio frames =] and is measured in
milliseconds.</p>
</li>
<li>
<p>An audio frame that is discarded because it cannot be delivered
on time, or it cannot be delivered for any other reason, is
considered <dfn data-lt="dropped audio frames">dropped</dfn>.</p>
</li>
<li>
<p>The <dfn data-lt="dropped audio frames duration">dropped audio
frames duration</dfn> is the total duration of all [= dropped
audio frames =]. This measurement is incremented at the same time
as [= dropped audio frames =] and is measured in milliseconds.</p>
<div class="note">
<p>If the track is unmuted and enabled, the counters increase as
audio is produced by the capture device. If no audio is flowing,
such as if the track is muted or disabled, then the counters do
not increase.</p>
</div>
</li>
<li>
<p><dfn data-lt="input latency">Input latency</dfn> is the time,
in milliseconds, between the point in time an audio input device
has acquired a signal and the time it is available for
consumption, which may include buffering by the user agent.</p>
<p>The <dfn data-lt="latest input latency">latest input
latency</dfn> is the latest available [= input latency =] as
estimated between the track's input device and delivery to any of
its sinks.</p>
<div class="note">
<p>The user agent updates its estimates at sufficient frequency
to allow monitoring. The latency is representative of the
experienced delay, but is not necessarily an exact measurement
of the last individual audio frame that was delivered.</p>
<p>A sink that consumes audio may add additional processing
latency not included in this measurement, such as playout delay
or encode time.</p>
</div>
<p>Every time the [= latest input latency =] measurement is
updated, the user agent also updates its
<dfn data-lt="average input latency">average input latency</dfn>,
<dfn data-lt="minimum input latency">minimum input latency</dfn>
and <dfn data-lt="maximum input latency">maximum input
latency</dfn> which are the average, minimum and maximum observed
measurements since the last <dfn data-lt="latency reset time">
latency reset time</dfn>.
</p>
</li>
</ul>
<p>Let the {{MediaStreamTrackAudioStats}} have internal slots
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\DeliveredFrames]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\DeliveredFramesDuration]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\DroppedFrames]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\DroppedFramesDuration]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\Latency]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\AverageLatency]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\MinimumLatency]]</dfn>
and
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\MaximumLatency]]</dfn>,
initialized to 0.</p>
<p>Let the {{MediaStreamTrackAudioStats}} also have internal slots
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\LastTask]]</dfn>
and
<dfn class=export data-dfn-for="MediaStreamTrackAudioStats">[[\LastExposureTime]]</dfn>,
initialized to <code>undefined</code>.</p>
<p>The <dfn data-lt="expose audio frame counters steps">expose audio
frame counters steps</dfn> are the following:</p>
<ul>
<li>
<p>Let <var>task</var> be the current [=task=].</p>
</li>
<li>
<p>If {{MediaStreamTrackAudioStats/[[LastTask]]}} is equal to
<var>task</var>, abort these steps.</p>
</li>
<li>
<p>Set {{MediaStreamTrackAudioStats/[[LastTask]]}} to
<var>task</var>.</p>
</li>
<li>
<p>Set {{MediaStreamTrackAudioStats/[[DeliveredFrames]]}} to
[= delivered audio frames =],
set {{MediaStreamTrackAudioStats/[[DeliveredFramesDuration]]}}
to [= delivered audio frames duration =],
set {{MediaStreamTrackAudioStats/[[DroppedFrames]]}} to
[= dropped audio frames =],
set {{MediaStreamTrackAudioStats/[[DroppedFramesDuration]]}} to
[= dropped audio frames duration =],
set {{MediaStreamTrackAudioStats/[[Latency]]}} to the
[= latest input latency =],
set {{MediaStreamTrackAudioStats/[[AverageLatency]]}} to the
[= average input latency =],
set {{MediaStreamTrackAudioStats/[[MinimumLatency]]}} to the
[= minimum input latency =] and
set {{MediaStreamTrackAudioStats/[[MaximumLatency]]}} to the
[= maximum input latency =].</p>
<p>Set {{MediaStreamTrackAudioStats/[[LastExposureTime]]}} to
reflect the time that these metrics were exposed.</p>
<div class="note">
<p>Only updating these counters once per [=task=] preserves the
<a href="https://w3ctag.github.io/design-principles/#js-rtc">
run-to-completion</a> semantics defined in
[[API-DESIGN-PRINCIPLES]].</p>
</div>
</li>
</ul>
</div>
<section>
<h4>Attributes</h4>
<dl data-link-for="MediaStreamTrackAudioStats"
data-dfn-for="MediaStreamTrackAudioStats" class="attributes">
<dt>
<dfn data-idl="">deliveredFrames</dfn> of type <span class=
"idlMemberType">unsigned long long, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return
{{MediaStreamTrackAudioStats/[[DeliveredFrames]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">deliveredFramesDuration</dfn> of type <span
class="idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return
{{MediaStreamTrackAudioStats/[[DeliveredFramesDuration]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">totalFrames</dfn> of type <span class=
"idlMemberType">unsigned long long, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return the sum of
{{MediaStreamTrackAudioStats/[[DeliveredFrames]]}} and
{{MediaStreamTrackAudioStats/[[DroppedFrames]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">totalFramesDuration</dfn> of type <span class=
"idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return the sum of
{{MediaStreamTrackAudioStats/[[DeliveredFramesDuration]]}} and
{{MediaStreamTrackAudioStats/[[DroppedFramesDuration]]}}.
</p>
<div class="note">
<p>Because audio capture devices produce audio in real-time,
audio frames may be dropped if not processed in a timely
manner.</p>
<p>The ratio of audio duration that was delivered, i.e. not
dropped, can be calculated as
{{MediaStreamTrackAudioStats/deliveredFramesDuration}} /
{{MediaStreamTrackAudioStats/totalFramesDuration}}.</p>
</div>
</dd>
<dt>
<dfn data-idl="">latency</dfn> of type <span
class="idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return {{MediaStreamTrackAudioStats/[[Latency]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">averageLatency</dfn> of type <span
class="idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return {{MediaStreamTrackAudioStats/[[AverageLatency]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">minimumLatency</dfn> of type <span
class="idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return {{MediaStreamTrackAudioStats/[[MinimumLatency]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">maximumLatency</dfn> of type <span
class="idlMemberType">DOMHighResTimeStamp, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose audio frame counters steps =]
and return {{MediaStreamTrackAudioStats/[[MaximumLatency]]}}.
</p>
</dd>
</dl>
</section>
<section>
<h4>Methods</h4>
<dl data-link-for="MediaStreamTrackAudioStats"
data-dfn-for="MediaStreamTrackAudioStats" class="methods">
<dt>
<dfn data-idl="">resetLatency</dfn>
</dt>
<dd>
<p>When called, run the following steps:</p>
<ul>
<li>
<p>Run the [= expose audio frame counters steps =].</p>
</li>
<li>
<p>Set {{MediaStreamTrackAudioStats/[[AverageLatency]]}},
{{MediaStreamTrackAudioStats/[[MinimumLatency]]}} and
{{MediaStreamTrackAudioStats/[[MaximumLatency]]}} to
{{MediaStreamTrackAudioStats/[[Latency]]}}.</p>
</li>
<li>
<p>Set the [= latency reset time =] to
{{MediaStreamTrackAudioStats/[[LastExposureTime]]}}.</p>
</li>
</ul>
</p>
</dd>
<dt>
<dfn data-idl="">toJSON</dfn>
</dt>
<dd>
<p>
When called, run [[!WEBIDL]]'s [= default toJSON steps =].
</p>
</dd>
</dl>
</section>
</div>
</section>
<section>
<h4>The MediaStreamTrackVideoStats interface</h4>
<div>
<pre class="idl">[Exposed=Window]
interface MediaStreamTrackVideoStats {
readonly attribute unsigned long long deliveredFrames;
readonly attribute unsigned long long discardedFrames;
readonly attribute unsigned long long totalFrames;
[Default] object toJSON();
};
</pre>
<div>
<p>The {{MediaStreamTrackVideoStats}} expose frame counters for the
{{MediaStreamTrack}} that created it. For this track, the user agent
is required to count each video frame from its source as follows:</p>
<ul>
<li>
<p>A frame is considered a <dfn data-lt="delivered video frames">
delivered video frame</dfn> if it either was delivered to a sink
or would have been delivered to a sink, if one was connected. This
is a subset of [= total video frames =] and it is incremented at
the same time as [= total video frames =].</p>
</li>
<li>
<p>A video frame is considered
<dfn data-lt="discarded video frames">discarded</dfn> if it was
discarded in order to achieve the target
{{MediaTrackSettings/frameRate}}. This is a subset of
[= total video frames =] and it is incremented at the same time as
[= total video frames =].</p>
</li>
<li>
<p>The <dfn data-lt="total video frames">total</dfn> number of
frames that have been processed by this source, meaning it is
known whether the frame was considered delivered, discarded or
dropped for any other reason. The number of dropped frames for
various unknown reasons can be calculated by subtracting
[= delivered video frames =] and [= discarded video frames =] from
[= total video frames =].</p>
<div class="note">
<p>If the track is unmuted and enabled and the source is backed
by a camera, total frames is incremented by frames produced by
the camera. If no frames are flowing, such as if the track is
muted or disabled, then total frames does not increment.</p>
</div>
</li>
</ul>
<p>Let the {{MediaStreamTrackVideoStats}} have internal slots
<dfn class=export data-dfn-for="MediaStreamTrackVideoStats">[[\DeliveredFrames]]</dfn>,
<dfn class=export data-dfn-for="MediaStreamTrackVideoStats">[[\DiscardedFrames]]</dfn>
and
<dfn class=export data-dfn-for="MediaStreamTrackVideoStats">[[\TotalFrames]]</dfn>,
initialized to 0.
</p>
<p>Let the {{MediaStreamTrackVideoStats}} also have an internal slot
<dfn class=export data-dfn-for="MediaStreamTrackVideoStats">[[\LastTask]]</dfn>
initialized to <code>null</code>.</p>
<p>The <dfn data-lt="expose video frame counters steps">expose video
frame counters steps</dfn> are the following:</p>
<ul>
<li>
<p>Let <var>task</var> be the current [=task=].</p>
</li>
<li>
<p>If {{MediaStreamTrackVideoStats/[[LastTask]]}} is equal to
<var>task</var>, abort these steps.</p>
</li>
<li>
<p>Set {{MediaStreamTrackVideoStats/[[LastTask]]}} to
<var>task</var>.</p>
</li>
<li>
<p>Set {{MediaStreamTrackVideoStats/[[DeliveredFrames]]}} to
[= delivered video frames =],
set {{MediaStreamTrackVideoStats/[[DiscardedFrames]]}} to
[= discarded video frames =] and
set {{MediaStreamTrackVideoStats/[[TotalFrames]]}} to
[= total video frames =].
</p>
<div class="note">
<p>Only updating these counters once per [=task=] preserves the
<a href="https://w3ctag.github.io/design-principles/#js-rtc">
run-to-completion</a> semantics defined in
[[API-DESIGN-PRINCIPLES]].</p>
</div>
</li>
</ul>
</div>
<section>
<h4>Attributes</h4>
<dl data-link-for="MediaStreamTrackVideoStats"
data-dfn-for="MediaStreamTrackVideoStats" class="attributes">
<dt>
<dfn data-idl="">deliveredFrames</dfn> of type <span class=
"idlMemberType">unsigned long long, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose video frame counters steps =]
and return {{MediaStreamTrackVideoStats/[[DeliveredFrames]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">discardedFrames</dfn> of type <span class=
"idlMemberType">unsigned long long, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose video frame counters steps =]
and return {{MediaStreamTrackVideoStats/[[DiscardedFrames]]}}.
</p>
</dd>
<dt>
<dfn data-idl="">totalFrames</dfn> of type <span class=
"idlMemberType">unsigned long long, readonly</span>
</dt>
<dd>
<p>
Upon getting, run the [= expose video frame counters steps =]
and return {{MediaStreamTrackVideoStats/[[TotalFrames]]}}.
</p>
</dd>
</dl>
</section>
<section>
<h4>Methods</h4>
<dl data-link-for="MediaStreamTrackVideoStats"
data-dfn-for="MediaStreamTrackVideoStats" class="methods">
<dt>
<dfn data-idl="">toJSON</dfn>
</dt>
<dd>
<p>
When called, run [[!WEBIDL]]'s [= default toJSON steps =].
</p>
</dd>
</dl>
</section>
</div>
</section>
</section>
<section>
<h2>The powerEfficient constraint</h2>
<section>
<h3>MediaTrackSupportedConstraints dictionary extensions</h3>
<div>
<pre class="idl"
>partial dictionary MediaTrackSupportedConstraints {
boolean powerEfficient = true;
};</pre>
<section>
<h2>Dictionary {{MediaTrackSupportedConstraints}} Members</h2>
<dl data-link-for="MediaTrackSupportedConstraints" data-dfn-for=
"MediaTrackSupportedConstraints" class="dictionary-members">
<dt><dfn>powerEfficient</dfn> of type
{{boolean}}, defaulting to <code>true</code></dt>
<dd>See <a href=
"#def-constraint-powerEfficient">
powerEfficient</a> for details.</dd>
</dl>
</section>
</div>
</section>
<section>
<h3>MediaTrackCapabilities dictionary extensions</h3>
<div>
<pre class="idl"
>partial dictionary MediaTrackCapabilities {
sequence<boolean> powerEfficient;
};</pre>
<section>
<h2>Dictionary {{MediaTrackCapabilities}} Members</h2>
<dl data-link-for="MediaTrackCapabilities" data-dfn-for=
"MediaTrackCapabilities" class="dictionary-members">
<dt><dfn>powerEfficient</dfn> of type
<code>sequence<{{boolean}}></code></dt>
<dd>
<p>The source may operate in different configurations.
If all configurations have the same power efficiency
impact, a single <code>false</code> is reported.
Otherwise, the source reports a list with
both <code>true</code> and <code>false</code>
as possible values. See <a href=
"#def-constraint-powerEfficient">
powerEfficient</a> for additional
details.</p>
</dd>
</dl>
</section>
</div>
</section>
<section>
<h3>MediaTrackSettings dictionary extensions</h3>
<div>
<pre class="idl"
>partial dictionary MediaTrackSettings {
boolean powerEfficient;
};</pre>
<section>
<h2>Dictionary {{MediaTrackSettings}} Members</h2>
<dl data-link-for="MediaTrackSettings" data-dfn-for=
"MediaTrackSettings" class="dictionary-members">
<dt><dfn>powerEfficient</dfn> of type
{{boolean}}</dt>
<dd>See <a href=
"#def-constraint-powerEfficient">
powerEfficient</a> for details.</dd>
</section>