OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>MediaStream Recoder Browser Test (w/ MediaSource)</title> | 4 <title>MediaStream Recoder Browser Test (w/ MediaSource)</title> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <div> Record Real-Time video content browser test.</div> | 7 <div> Record Real-Time video content browser test.</div> |
8 <video id="video" autoplay></video> | 8 <video id="video" autoplay></video> |
9 <video id="remoteVideo" autoplay></video> | 9 <video id="remoteVideo" autoplay></video> |
10 </body> | 10 </body> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 }); | 158 }); |
159 }) | 159 }) |
160 .catch(function(err) { | 160 .catch(function(err) { |
161 return failTest(err.toString()); | 161 return failTest(err.toString()); |
162 }) | 162 }) |
163 .then(function() { | 163 .then(function() { |
164 reportTestSuccess(); | 164 reportTestSuccess(); |
165 }); | 165 }); |
166 } | 166 } |
167 | 167 |
| 168 function getConstraintsForDevice(deviceLabel) { |
| 169 return new Promise(function(resolve, reject) { |
| 170 navigator.mediaDevices.enumerateDevices() |
| 171 .then(function(devices) { |
| 172 for (var i = 0; i < devices.length; ++i) { |
| 173 if (deviceLabel == devices[i].label) { |
| 174 return resolve({video:{deviceId: {exact: devices[i].deviceId}}}); |
| 175 } |
| 176 } |
| 177 console.error("Expected to have a device with label:" + deviceLabel); |
| 178 resolve(null); |
| 179 }); |
| 180 }); |
| 181 } |
| 182 |
168 // Tests that when MediaRecorder's start() function is called, some data is | 183 // Tests that when MediaRecorder's start() function is called, some data is |
169 // made available by media recorder via dataavailable events, containing non | 184 // made available by media recorder via dataavailable events, containing non |
170 // empty blob data. | 185 // empty blob data. |
171 function testStartAndDataAvailable(codec) { | 186 function testStartAndDataAvailable(codec, deviceLabel) { |
172 var videoSize = 0; | 187 var videoSize = 0; |
173 var emptyBlobs = 0; | 188 var emptyBlobs = 0; |
174 var timeStamps = []; | 189 var timeStamps = []; |
175 const mimeType = codec ? "video/webm;codecs=" + String(codec) : ""; | 190 var mediaConstrains = deviceLabel ? getConstraintsForDevice(deviceLabel) : |
176 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) | 191 Promise.resolve(DEFAULT_CONSTRAINTS); |
| 192 |
| 193 mediaConstrains.then(function(constraints) { |
| 194 return navigator.mediaDevices.getUserMedia(constraints); |
| 195 }) |
177 .then(function(stream) { | 196 .then(function(stream) { |
| 197 const mimeType = codec ? "video/webm;codecs=" + String(codec) : ""; |
178 return createAndStartMediaRecorder(stream, mimeType); | 198 return createAndStartMediaRecorder(stream, mimeType); |
179 }) | 199 }) |
180 .then(function(recorder) { | 200 .then(function(recorder) { |
181 // Save history of Blobs received via dataavailable. | 201 // Save history of Blobs received via dataavailable. |
182 recorder.ondataavailable = function(event) { | 202 recorder.ondataavailable = function(event) { |
183 timeStamps.push(event.timeStamp); | 203 timeStamps.push(event.timeStamp); |
184 if (event.data.size > 0) | 204 if (event.data.size > 0) |
185 videoSize += event.data.size; | 205 videoSize += event.data.size; |
186 else | 206 else |
187 emptyBlobs += 1; | 207 emptyBlobs += 1; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 return failTest(err.toString()); | 611 return failTest(err.toString()); |
592 }) | 612 }) |
593 .then(function() { | 613 .then(function() { |
594 reportTestSuccess(); | 614 reportTestSuccess(); |
595 }); | 615 }); |
596 } | 616 } |
597 | 617 |
598 </script> | 618 </script> |
599 </body> | 619 </body> |
600 </html> | 620 </html> |
OLD | NEW |