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

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

Issue 2753543010: WebRTC: Use the MediaStream Recording API for the audio_quality_browsertest. (Closed)
Patch Set: Download recording to file. 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..aa879563b5fc371f48ad2287c924ef9b110632e8
--- /dev/null
+++ b/chrome/test/data/webrtc/audio_extraction.js
@@ -0,0 +1,63 @@
+/**
+ * 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 CAPTURE_STATUS = 'not-started';
mcasas 2017/03/22 17:04:55 This is a true variable, so s/CAPTURE_STATUS/captu
+
+/**
+ * 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();
+
+ CAPTURE_STATUS = 'done-capturing';
+ }
+
+ mediaRecorder.start();
+ CAPTURE_STATUS = 'started';
+ setTimeout(function() { mediaRecorder.stop(); },
+ capture_duration_in_seconds * 1000);
+
+ returnToTest('ok-capturing');
+}
+
+function getCaptureStatus() {
+ returnToTest(CAPTURE_STATUS);
mcasas 2017/03/22 17:04:55 getCaptureStatus() uses only compare the returned
+}

Powered by Google App Engine
This is Rietveld 408576698