Chromium Code Reviews| 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 </body> | 9 </body> |
| 10 <script type="text/javascript" src="mediarecorder_test_utils.js"></script> | 10 <script type="text/javascript" src="mediarecorder_test_utils.js"></script> |
| 11 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 11 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
| 12 <script> | 12 <script> |
| 13 | 13 |
| 14 'use strict'; | 14 'use strict'; |
| 15 | 15 |
| 16 const DEFAULT_CONSTRAINTS= {audio:true, video:true}; | 16 const DEFAULT_CONSTRAINTS = {audio: true, video: true}; |
| 17 const DEFAULT_RECORDER_MIME_TYPE = ''; | 17 const DEFAULT_RECORDER_MIME_TYPE = ''; |
| 18 const DEFAULT_TIME_SLICE = 100; | 18 const DEFAULT_TIME_SLICE = 100; |
| 19 const FREQUENCY = 880; | 19 const FREQUENCY = 880; |
| 20 // Note that not all audio sampling rates are supported by the underlying | 20 // Note that not all audio sampling rates are supported by the underlying |
| 21 // Opus audio codec: the valid rates are 8kHz, 12kHz, 16kHz, 24kHz, 48kHz. | 21 // Opus audio codec: the valid rates are 8kHz, 12kHz, 16kHz, 24kHz, 48kHz. |
| 22 // See crbug/569089 for details. | 22 // See crbug/569089 for details. |
| 23 const SAMPLING_RATE = 48000; | 23 const SAMPLING_RATE = 48000; |
| 24 const NUM_SAMPLES = 2 * SAMPLING_RATE; | 24 const NUM_SAMPLES = 2 * SAMPLING_RATE; |
| 25 | 25 |
| 26 // Function assert_throws inspired from Blink's | 26 // Function assert_throws inspired from Blink's |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 var timeStamps = []; | 131 var timeStamps = []; |
| 132 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) | 132 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) |
| 133 .then(function(stream) { | 133 .then(function(stream) { |
| 134 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); | 134 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); |
| 135 }) | 135 }) |
| 136 .then(function(recorder) { | 136 .then(function(recorder) { |
| 137 // Save history of Blobs received via dataavailable. | 137 // Save history of Blobs received via dataavailable. |
| 138 recorder.ondataavailable = function(event) { | 138 recorder.ondataavailable = function(event) { |
| 139 timeStamps.push(event.timeStamp); | 139 timeStamps.push(event.timeStamp); |
| 140 if (event.data.size > 0) | 140 if (event.data.size > 0) |
| 141 videoSize += event.data.size; | 141 videoSize += event.data.size; |
| 142 else | 142 else |
| 143 emptyBlobs += 1; | 143 emptyBlobs += 1; |
| 144 }; | 144 }; |
| 145 }) | 145 }) |
| 146 .then(function() { | 146 .then(function() { |
| 147 return waitFor('Make sure the recording has data', | 147 return waitFor('Make sure the recording has data', |
| 148 function() { | 148 function() { |
| 149 return videoSize > 0; | 149 return videoSize > 0; |
| 150 }); | 150 }); |
| 151 }) | 151 }) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 169 var timeStamps = []; | 169 var timeStamps = []; |
| 170 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) | 170 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) |
| 171 .then(function(stream) { | 171 .then(function(stream) { |
| 172 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE, | 172 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE, |
| 173 DEFAULT_TIME_SLICE); | 173 DEFAULT_TIME_SLICE); |
| 174 }) | 174 }) |
| 175 .then(function(recorder) { | 175 .then(function(recorder) { |
| 176 recorder.ondataavailable = function(event) { | 176 recorder.ondataavailable = function(event) { |
| 177 timeStamps.push(event.timeStamp); | 177 timeStamps.push(event.timeStamp); |
| 178 if (event.data.size > 0) | 178 if (event.data.size > 0) |
| 179 videoSize += event.data.size; | 179 videoSize += event.data.size; |
| 180 else | 180 else |
| 181 emptyBlobs += 1; | 181 emptyBlobs += 1; |
| 182 }; | 182 }; |
| 183 }) | 183 }) |
| 184 .then(function() { | 184 .then(function() { |
| 185 return waitFor('Making sure the recording has data', | 185 return waitFor('Making sure the recording has data', |
| 186 function() { | 186 function() { |
| 187 return videoSize > 0 && timeStamps.length > 10; | 187 return videoSize > 0 && timeStamps.length > 10; |
| 188 }); | 188 }); |
| 189 }) | 189 }) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 210 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); | 210 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); |
| 211 }) | 211 }) |
| 212 .then(function(recorder) { | 212 .then(function(recorder) { |
| 213 theRecorder = recorder; | 213 theRecorder = recorder; |
| 214 theRecorder.pause(); | 214 theRecorder.pause(); |
| 215 }) | 215 }) |
| 216 .then(function() { | 216 .then(function() { |
| 217 theRecorder.onresume = function(event) { | 217 theRecorder.onresume = function(event) { |
| 218 resumeEventReceived = true; | 218 resumeEventReceived = true; |
| 219 assertEquals('recording', theRecorder.state); | 219 assertEquals('recording', theRecorder.state); |
| 220 } | 220 }; |
| 221 theRecorder.resume(); | 221 theRecorder.resume(); |
| 222 }) | 222 }) |
| 223 .then(function() { | 223 .then(function() { |
| 224 return waitFor('Making sure the resume event has been received', | 224 return waitFor('Making sure the resume event has been received', |
| 225 function() { | 225 function() { |
| 226 return resumeEventReceived == true; | 226 return resumeEventReceived == true; |
| 227 }); | 227 }); |
| 228 }) | 228 }) |
| 229 .catch(function(err) { | 229 .catch(function(err) { |
| 230 return failTest(err.toString()); | 230 return failTest(err.toString()); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 260 .then(function(stream) { | 260 .then(function(stream) { |
| 261 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); | 261 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); |
| 262 }) | 262 }) |
| 263 .then(function(recorder) { | 263 .then(function(recorder) { |
| 264 theRecorder = recorder; | 264 theRecorder = recorder; |
| 265 theRecorder.pause(); | 265 theRecorder.pause(); |
| 266 }) | 266 }) |
| 267 .then(function() { | 267 .then(function() { |
| 268 theRecorder.ondataavailable = function(event) { | 268 theRecorder.ondataavailable = function(event) { |
| 269 if (event.data.size > 0) { | 269 if (event.data.size > 0) { |
| 270 videoSize += event.data.size; | 270 videoSize += event.data.size; |
| 271 } else { | 271 } else { |
| 272 console.log('This dataavailable event is empty', event); | 272 console.log('This dataavailable event is empty', event); |
| 273 emptyBlobs += 1; | 273 emptyBlobs += 1; |
| 274 } | 274 } |
| 275 }; | 275 }; |
| 276 }) | 276 }) |
| 277 .then(function() { | 277 .then(function() { |
| 278 theRecorder.resume(); | 278 theRecorder.resume(); |
| 279 }) | 279 }) |
| 280 .then(function() { | 280 .then(function() { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 303 var pauseEventReceived = false; | 303 var pauseEventReceived = false; |
| 304 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) | 304 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) |
| 305 .then(function(stream) { | 305 .then(function(stream) { |
| 306 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); | 306 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); |
| 307 }) | 307 }) |
| 308 .then(function(recorder) { | 308 .then(function(recorder) { |
| 309 theRecorder = recorder; | 309 theRecorder = recorder; |
| 310 theRecorder.onpause = function(event) { | 310 theRecorder.onpause = function(event) { |
| 311 pauseEventReceived = true; | 311 pauseEventReceived = true; |
| 312 assertEquals('paused', theRecorder.state); | 312 assertEquals('paused', theRecorder.state); |
| 313 } | 313 }; |
| 314 theRecorder.pause(); | 314 theRecorder.pause(); |
| 315 }) | 315 }) |
| 316 .then(function() { | 316 .then(function() { |
| 317 return waitFor('Making sure the pause event has been received', | 317 return waitFor('Making sure the pause event has been received', |
| 318 function() { | 318 function() { |
| 319 return pauseEventReceived == true; | 319 return pauseEventReceived == true; |
| 320 }); | 320 }); |
| 321 }) | 321 }) |
| 322 .catch(function(err) { | 322 .catch(function(err) { |
| 323 return failTest(err.toString()); | 323 return failTest(err.toString()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 350 }) | 350 }) |
| 351 .then(function() { | 351 .then(function() { |
| 352 reportTestSuccess(); | 352 reportTestSuccess(); |
| 353 }); | 353 }); |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Tests that no dataavailable event is fired after MediaRecorder's pause() | 356 // Tests that no dataavailable event is fired after MediaRecorder's pause() |
| 357 // function is called. | 357 // function is called. |
| 358 function testPausePreventsDataavailableFromBeingFired() { | 358 function testPausePreventsDataavailableFromBeingFired() { |
| 359 var theRecorder; | 359 var theRecorder; |
| 360 var videoSize = 0; | 360 var videoSize = 0; |
|
mcasas
2016/01/07 23:04:11
Unused as well, as I wrote in the bug.
cpaulin (no longer in chrome)
2016/01/07 23:14:06
That one got away.
| |
| 361 var emptyBlobs = 0; | |
| 362 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) | 361 navigator.mediaDevices.getUserMedia(DEFAULT_CONSTRAINTS) |
| 363 .then(function(stream) { | 362 .then(function(stream) { |
| 364 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); | 363 return createAndStartMediaRecorder(stream, DEFAULT_RECORDER_MIME_TYPE); |
| 365 }) | 364 }) |
| 366 .then(function(recorder) { | 365 .then(function(recorder) { |
| 367 theRecorder = recorder; | 366 theRecorder = recorder; |
| 368 theRecorder.pause(); | 367 theRecorder.pause(); |
| 369 }) | 368 }) |
| 370 .then(function() { | 369 .then(function() { |
| 371 theRecorder.ondataavailable = function(event) { | 370 theRecorder.ondataavailable = function(event) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 assertThrows(function() {recorder.start()}, 'Calling start() in' + | 433 assertThrows(function() {recorder.start()}, 'Calling start() in' + |
| 435 ' paused state should cause a DOM error'); | 434 ' paused state should cause a DOM error'); |
| 436 }); | 435 }); |
| 437 } | 436 } |
| 438 | 437 |
| 439 // Tests that MediaRecorder can record a 2 Channel audio stream. | 438 // Tests that MediaRecorder can record a 2 Channel audio stream. |
| 440 function testTwoChannelAudio() { | 439 function testTwoChannelAudio() { |
| 441 var audioSize = 0; | 440 var audioSize = 0; |
| 442 var context = new OfflineAudioContext(2, NUM_SAMPLES, SAMPLING_RATE); | 441 var context = new OfflineAudioContext(2, NUM_SAMPLES, SAMPLING_RATE); |
| 443 var oscillator = context.createOscillator(); | 442 var oscillator = context.createOscillator(); |
| 444 oscillator.type = "sine"; | 443 oscillator.type = 'sine'; |
| 445 oscillator.frequency.value = FREQUENCY; | 444 oscillator.frequency.value = FREQUENCY; |
| 446 var dest = context.createMediaStreamDestination(); | 445 var dest = context.createMediaStreamDestination(); |
| 447 dest.channelCount = 2; | 446 dest.channelCount = 2; |
| 448 oscillator.connect(dest); | 447 oscillator.connect(dest); |
| 449 createMediaRecorder(dest.stream, DEFAULT_RECORDER_MIME_TYPE) | 448 createMediaRecorder(dest.stream, DEFAULT_RECORDER_MIME_TYPE) |
| 450 .then(function(recorder) { | 449 .then(function(recorder) { |
| 451 recorder.ondataavailable = function(event) { | 450 recorder.ondataavailable = function(event) { |
| 452 audioSize += event.data.size; | 451 audioSize += event.data.size; |
| 453 }; | 452 }; |
| 454 recorder.start(); | 453 recorder.start(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 480 .then(function(recorder) { | 479 .then(function(recorder) { |
| 481 assertThrows(function() {recorder.requestData()}, | 480 assertThrows(function() {recorder.requestData()}, |
| 482 'Calling requestdata() in inactive state should throw a DOM ' + | 481 'Calling requestdata() in inactive state should throw a DOM ' + |
| 483 'Exception'); | 482 'Exception'); |
| 484 }); | 483 }); |
| 485 } | 484 } |
| 486 | 485 |
| 487 </script> | 486 </script> |
| 488 </body> | 487 </body> |
| 489 </html> | 488 </html> |
| OLD | NEW |