| 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.
|
| + * 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;
|
| +
|
| +/**
|
| + * The duration of the audio recording in milliseconds.
|
| + * @private
|
| + */
|
| +var gCaptureDuration = 0;
|
| +
|
| +/**
|
| + * The recorded audio encoded in Base64.
|
| + * @private
|
| + */
|
| +var gAudioBase64 = '';
|
| +
|
| +/**
|
| + * 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) {
|
| + 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.');
|
| + }
|
| +}
|
|
|