aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mediatrackconstraints/index.html
blob: 4b0a07a102bbbe6d408dbb83131e2b1a3bbfa8f9 (plain)
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
---
title: 媒体追踪约束
slug: Web/API/MediaTrackConstraints
translation_of: Web/API/MediaTrackConstraints
---
<div>{{APIRef("媒体捕获与媒体流")}}</div>

<p>The <strong><code>MediaTrackConstraints</code></strong> dictionary is used to describe a set of capabilities and the value or values each can take on. A constraints dictionary is passed into {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.</p>

<p>For each constraint, you can typically specify an exact value you need, an ideal value you want, a range of acceptable values, and/or a value which you'd like to be as close to as possible. The specifics vary somewhat depending on the type of the constrainable property.</p>

<p>To learn more about how constraints work, see <a href="/en-US/docs/Web/API/Media_Streams_API/Constraints">Capabilities, constraints, and settings</a>.</p>

<h2 id="Properties">Properties</h2>

<p>Some combination—but not necessarily all—of the following properties will exist on the object.</p>

<h3 id="Properties_of_all_media_tracks">Properties of all media tracks</h3>

<dl>
 <dt>{{domxref("MediaTrackConstraints.deviceId", "deviceId")}}</dt>
 <dd>A {{domxref("ConstrainDOMString")}} object specifying a device ID or an array of device IDs which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.groupId", "groupId")}}</dt>
 <dd>A {{domxref("ConstrainDOMString")}} object specifying a group ID or an array of group IDs which are acceptable and/or required.</dd>
</dl>

<h3 id="Properties_of_audio_tracks">Properties of audio tracks</h3>

<dl>
 <dt>{{domxref("MediaTrackConstraints.autoGainControl", "autoGainControl")}}</dt>
 <dd>A {{domxref("ConstrainBoolean")}} object which specifies whether automatic gain control is preferred and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.channelCount", "channelCount")}}</dt>
 <dd>A {{domxref("ConstrainLong")}} specifying the channel count or range of channel counts which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.echoCancellation", "echoCancellation")}}</dt>
 <dd>A {{domxref("ConstrainBoolean")}} object specifying whether or not echo cancellation is preferred and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.latency", "latency")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} specifying the latency or range of latencies which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.noiseSuppression", "noiseSuppression")}}</dt>
 <dd>A {{domxref("ConstrainBoolean")}} which specifies whether noise suppression is preferred and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.sampleRate", "sampleRate")}}</dt>
 <dd>A {{domxref("ConstrainLong")}} specifying the sample rate or range of sample rates which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.sampleSize", "sampleSize")}}</dt>
 <dd>A {{domxref("ConstrainLong")}} specifying the sample size or range of sample sizes which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.volume", "volume")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} specifying the volume or range of volumes which are acceptable and/or required.</dd>
</dl>

<h3 id="Properties_of_image_tracks">Properties of image tracks</h3>

<dl>
 <dt>{{domxref("MediaTrackConstraints.whiteBalanceMode","whiteBalanceMode")}}</dt>
 <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd>
 <dt>{{domxref("MediaTrackConstraints.exposureMode","exposureMode")}}</dt>
 <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd>
 <dt>{{domxref("MediaTrackConstraints.focusMode","focusMode")}}</dt>
 <dd>A {{jsxref("String")}} specifying one of <code>"none"</code>, <code>"manual"</code>, <code>"sigle-shot"</code>, or <code>"continuous"</code>.</dd>
 <dt>{{domxref("MediaTrackConstraints.pointsOfInterest","pointsOfInterest")}}</dt>
 <dd>The pixel coordinates on the sensor of one or more points of interest. This is either an object in the form { x:<em>value</em>, y:<em>value</em> } or an array of such objects, where <em>value </em> is a double-precision integer.</dd>
 <dt>{{domxref("MediaTrackConstraints.expsureCompensation","exposureCompensation")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying f-stop adjustment by up to ±3. </dd>
 <dt>{{domxref("MediaTrackConstraints.colorTemperature","colorTemperature")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired color temperature in degrees kelvin.</dd>
 <dt>{{domxref("MediaTrackConstraints.iso","iso")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired iso setting.</dd>
 <dt>{{domxref("MediaTrackConstraints.brightness","brightness")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying a desired brightness setting.</dd>
 <dt>{{domxref("MediaTrackConstraints.contrast","contrast")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the degree of difference between light and dark.</dd>
 <dt>{{domxref("MediaTrackConstraints.saturation","saturation")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the degree of color intensity.</dd>
 <dt>{{domxref("MediaTrackConstraints.sharpness","sharpness")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the intensity of edges.</dd>
 <dt>{{domxref("MediaTrackConstraints.focusDistance","focusDistance")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying distance to a focused object.</dd>
 <dt>{{domxref("MediaTrackConstraints.zoom","zoom")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} (a double-precision integer) specifying the desired focal length.</dd>
 <dt>{{domxref("MediaTrackConstraints.torch","torch")}}</dt>
 <dd>A {{jsxref("Boolean")}} whter the fill light continuously connected, meaning it stays on as long as the track is active.</dd>
</dl>

<h3 id="Properties_of_video_tracks">Properties of video tracks</h3>

<dl>
 <dt>{{domxref("MediaTrackConstraints.aspectRatio", "aspectRatio")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.facingMode", "facingMode")}}</dt>
 <dd>A {{domxref("ConstrainDOMString")}} object specifying a facing or an array of facings which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.frameRate", "frameRate")}}</dt>
 <dd>A {{domxref("ConstrainDouble")}} specifying the frame rate or range of frame rates which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.height", "height")}}</dt>
 <dd>A {{domxref("ConstrainLong")}} specifying the video height or range of heights which are acceptable and/or required.</dd>
 <dt>{{domxref("MediaTrackConstraints.width", "width")}}</dt>
 <dd>A {{domxref("ConstrainLong")}} specifying the video width or range of widths which are acceptable and/or required.</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Media Capture', '#dom-mediatrackconstraints', 'applyConstraints()')}}</td>
   <td>{{Spec2('Media Capture')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('MediaStream Image', '#mediatrackconstraintset-section','applyConstraints()')}}</td>
   <td>{{Spec2('MediaStream Image')}}</td>
   <td>Adds image constraints.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{ CompatibilityTable }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOpera(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td><code>deviceId</code></td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOpera(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td><code>groupId</code></td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOpera(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Audio track properties</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Image track properties</td>
   <td>{{CompatChrome(63)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOpera(50)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Video track properties</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOpera(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOperaMobile(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td><code>deviceId</code></td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOperaMobile(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td><code>groupId</code></td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOperaMobile(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Audio track properties</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Image track properties</td>
   <td>{{CompatChrome(63)}}</td>
   <td>{{CompatChrome(63)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOperaMobile(50)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
  <tr>
   <td>Video track properties</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{CompatChrome(59)}}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{ CompatUnknown }}</td>
   <td>{{CompatOperaMobile(46)}}</td>
   <td>{{ CompatUnknown }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("MediaDevices.getUserMedia()")}}</li>
 <li>{{domxref("MediaStreamTrack.getConstraints()")}}</li>
 <li>{{domxref("MediaStreamTrack.applyConstraints()")}}</li>
 <li>{{domxref("MediaDevices.getSupportedConstraints()")}}</li>
 <li>{{domxref("MediaTrackSupportedConstraints")}}</li>
 <li>{{domxref("MediaStreamTrack.getSettings()")}}</li>
</ul>