Index: chrome/test/data/webrtc/audio_extraction.js |
diff --git a/chrome/test/data/webrtc/audio_extraction.js b/chrome/test/data/webrtc/audio_extraction.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c22a22c216f1bb2b1da2ddace5aaa06bcc4cf9d |
--- /dev/null |
+++ b/chrome/test/data/webrtc/audio_extraction.js |
@@ -0,0 +1,103 @@ |
+/** |
+ * Copyright (c) 2017 The Chromium Authors. All rights reserved. |
mcasas
2017/03/21 16:54:22
No (c):
https://chromium.googlesource.com/chromiu
|
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+/** |
+ * Aggregate target bits per second for encoding of the Audio track. |
+ * @private |
+ */ |
+var gAudioBitsPerSecond = 3000000; |
mcasas
2017/03/21 16:54:22
gVarName for global variables is atypical in
javas
|
+ |
+/** |
+ * The duration of the audio recording in milliseconds. |
+ * @private |
+ */ |
+var gCaptureDuration = 0; |
mcasas
2017/03/21 16:54:22
s/gCaptureDuration/captureDurationMs/
but for its
|
+ |
+/** |
+ * The recorded audio encoded in Base64. |
+ * @private |
+ */ |
+var gAudioBase64 = ''; |
mcasas
2017/03/21 16:54:22
s/gAudioBase64/audio_as_base64/
This can be a hug
ehmaldonado_chromium
2017/03/21 16:59:55
Are there any examples of this already?
|
+ |
+/** |
+ * Chunks of the audio recorded by MediaRecorded as they become available. |
+ * @private |
+ */ |
+var gChunks = []; |
+ |
+/** |
+ * A string to be returned to the test about the current status of capture. |
+ */ |
+var gCapturingStatus = 'capturing-not-started'; |
+ |
+/** |
+ * Starts the audio capturing. |
+ * |
+ * @param {Number} The duration of the capture in seconds. |
+ */ |
+function startAudioCapture(duration) { |
mcasas
2017/03/21 16:54:22
s/duration/duration_seconds/ or similar?
|
+ console.log('started-capture'); |
+ var inputElement = document.getElementById('remote-view'); |
+ |
+ // |audioBitsPerSecond| must set to a large number to throw as little |
+ // information away as possible. |
+ var mediaRecorderOptions = { |
+ audioBitsPerSecond: gAudioBitsPerSecond, |
+ mimeType: 'audio/webm', |
+ }; |
+ var stream = getStreamFromElement_(inputElement); |
+ gCaptureDuration = 1000 * duration; |
+ |
+ var mediaRecorder = new MediaRecorder(stream, mediaRecorderOptions); |
+ |
+ mediaRecorder.ondataavailable = function(recording) { |
+ gChunks.push(recording.data); |
+ } |
+ mediaRecorder.onstop = function() { |
+ console.log(gChunks.length); |
+ var audioBlob = new Blob(gChunks, {type: "audio/webm"}); |
+ gChunks = []; |
+ var reader = new FileReader(); |
+ reader.onloadend = function() { |
+ gAudioBase64 = reader.result.substr(reader.result.indexOf(',') + 1); |
+ gCapturingStatus = 'done-capturing'; |
+ debug('done-capturing'); |
+ } |
+ reader.readAsDataURL(audioBlob); |
+ } |
+ |
+ mediaRecorder.start(); |
+ setTimeout(function() { mediaRecorder.stop(); }, gCaptureDuration); |
+ gCapturingStatus = 'still-capturing'; |
+} |
+ |
+/** |
+ * Returns the audio recorded by RecordMedia encoded in Base64. |
+ */ |
+function getRecordedAudioAsBase64() { |
+ silentReturnToTest(gAudioBase64); |
+} |
+ |
+/** |
+ * Queries if we're done with the capturing yet. |
+ */ |
+function doneCapturingAudio() { |
+ returnToTest(gCapturingStatus); |
+} |
+ |
+/** |
+ * Returns the stream from the input element to be attached to MediaRecorder. |
+ * @private |
+ */ |
+function getStreamFromElement_(element) { |
+ if (element.srcObject !== undefined) { |
+ return element.srcObject; |
+ } else if (element.src !== undefined) { |
+ return element.src; |
+ } else { |
+ failTest('Error extracting stream from element.'); |
+ } |
mcasas
2017/03/21 16:54:22
It's pervasive in Chromium to not have {}
when the
|
+} |