Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4289)

Unified Diff: chrome/test/data/webrtc/audio_extraction.js

Issue 2773083002: Reland of WebRTC: Use the MediaStream Recording API for the audio_quality_browsertest.
Patch Set: Fix issues with MOS score. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..db7536bbdae0baa9c20497eede27b5496628b79c
--- /dev/null
+++ b/chrome/test/data/webrtc/audio_extraction.js
@@ -0,0 +1,62 @@
+/**
+ * Copyright 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
+ */
+const AUDIO_BITS_PER_SECOND = 3000000;
+
+var doneCapturing = false;
+
+/**
+ * Starts the audio capturing.
+ *
+ * @param {Number} The duration of the capture in seconds.
+ */
+function startAudioCapture(capture_duration_in_seconds, output_file) {
+ console.log('Started capturing for ' + capture_duration_in_seconds + 's to '
+ + output_file);
+ var inputElement = document.getElementById('remote-view');
+
+ // |audioBitsPerSecond| must set to a large number to throw as little
+ // information away as possible.
+ var mediaRecorderOptions = {
+ audioBitsPerSecond: AUDIO_BITS_PER_SECOND,
+ mimeType: 'audio/webm',
+ };
+ var stream = inputElement.srcObject;
+ var mediaRecorder = new MediaRecorder(stream, mediaRecorderOptions);
+
+ var audio_chunks = [];
+
+ mediaRecorder.ondataavailable = function(recording) {
+ audio_chunks.push(recording.data);
+ }
+ mediaRecorder.onstop = function() {
+ var audioBlob = new Blob(audio_chunks, {type: 'audio/webm'});
+
+ var url = window.URL.createObjectURL(audioBlob);
+ var a = document.createElement('a');
+ document.body.appendChild(a);
+
+ a.href = url;
+ a.download = output_file;
+ a.click();
+
+ doneCapturing = true;
+ }
+
+ mediaRecorder.start();
+ setTimeout(function() { mediaRecorder.stop(); },
+ capture_duration_in_seconds * 1000);
+
+ returnToTest('ok-capturing');
+}
+
+function testIsDoneCapturing() {
+ returnToTest(doneCapturing.toString());
+}

Powered by Google App Engine
This is Rietveld 408576698