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

Unified Diff: media/audio/audio_debug_recording_helper.cc

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Control through AudioManager. Compiles on Linux, works with PulseAudio. Created 3 years, 11 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: media/audio/audio_debug_recording_helper.cc
diff --git a/media/audio/audio_debug_recording_helper.cc b/media/audio/audio_debug_recording_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..71bbd4b4f75d2d4561f827bcc5a1bfa16c975b75
--- /dev/null
+++ b/media/audio/audio_debug_recording_helper.cc
@@ -0,0 +1,72 @@
+// 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.
+
+#include "media/audio/audio_debug_recording_helper.h"
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/single_thread_task_runner.h"
+#include "media/audio/audio_manager.h"
+
+namespace media {
+
+AudioDebugRecordingHelper::AudioDebugRecordingHelper(
+ AudioManager* audio_manager,
+ base::SingleThreadTaskRunner* task_runner)
+ : audio_manager_(audio_manager),
+ task_runner_(task_runner),
+ weak_factory_(this) {
+ DCHECK(audio_manager_);
+}
+
+AudioDebugRecordingHelper::~AudioDebugRecordingHelper() {}
+
+void AudioDebugRecordingHelper::EnableDebugRecording(
+ const AudioParameters& params,
+ const base::FilePath& file_name) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(!debug_writer_);
+
+ debug_writer_ = audio_manager_->CreateAudioFileWriter(params);
+
+ // The debug writer writes in wave format.
+ debug_writer_->Start(file_name.AddExtension("wav"));
+}
+
+void AudioDebugRecordingHelper::DisableDebugRecording() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (debug_writer_) {
+ debug_writer_->Stop();
+ debug_writer_.reset();
+ }
+}
+
+void AudioDebugRecordingHelper::MaybeWrite(const AudioBus* source) {
+ if (WillWrite()) {
DaleCurtis 2017/01/19 17:44:34 early return instead.
Henrik Grunell 2017/01/20 10:38:55 Done.
+ // TODO(grunell) Don't create a new AudioBus each time. Maybe a pool of
+ // AudioBuses. See also AudioInputController.
+ std::unique_ptr<AudioBus> audio_bus_copy =
+ AudioBus::Create(source->channels(), source->frames());
+ source->CopyTo(audio_bus_copy.get());
+
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&AudioDebugRecordingHelper::DoWrite,
+ weak_factory_.GetWeakPtr(), base::Passed(&audio_bus_copy)));
+ }
+}
+
+bool AudioDebugRecordingHelper::WillWrite() {
+ return debug_writer_ && debug_writer_->WillWrite();
+}
+
+void AudioDebugRecordingHelper::DoWrite(std::unique_ptr<media::AudioBus> data) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (debug_writer_)
+ debug_writer_->Write(std::move(data));
+}
+
+} // namspace media

Powered by Google App Engine
This is Rietveld 408576698