Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/audio/audio_debug_recording_helper.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "media/audio/audio_manager.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 AudioDebugRecordingHelper::AudioDebugRecordingHelper( | |
| 15 const AudioParameters& params, | |
| 16 const CreateAudioFileWriterCallback& create_audio_file_writer_callback, | |
| 17 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 18 base::OnceClosure on_destruction_closure) | |
| 19 : params_(params), | |
| 20 create_audio_file_writer_callback_(create_audio_file_writer_callback), | |
| 21 task_runner_(std::move(task_runner)), | |
| 22 on_destruction_closure_(std::move(on_destruction_closure)), | |
| 23 weak_factory_(this) { | |
| 24 DCHECK(create_audio_file_writer_callback_); | |
| 25 } | |
| 26 | |
| 27 AudioDebugRecordingHelper::~AudioDebugRecordingHelper() { | |
| 28 if (on_destruction_closure_) | |
| 29 std::move(on_destruction_closure_).Run(); | |
| 30 } | |
| 31 | |
| 32 void AudioDebugRecordingHelper::EnableDebugRecording( | |
| 33 const base::FilePath& file_name) { | |
| 34 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 35 DCHECK(!debug_writer_); | |
| 36 | |
| 37 debug_writer_ = create_audio_file_writer_callback_.Run(params_); | |
| 38 | |
| 39 // The debug writer writes in wave format. | |
|
o1ka
2017/01/31 11:00:11
How do we know it here? It's just some audio file
Henrik Grunell
2017/02/08 11:29:37
Agree. Added AudioFileWriter::GetExtension(), and
| |
| 40 debug_writer_->Start(file_name.AddExtension("wav")); | |
| 41 } | |
| 42 | |
| 43 void AudioDebugRecordingHelper::DisableDebugRecording() { | |
| 44 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 45 | |
| 46 if (debug_writer_) { | |
| 47 debug_writer_->Stop(); | |
| 48 debug_writer_.reset(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 bool AudioDebugRecordingHelper::WillWrite() { | |
| 53 // AudioFileWriter::WillWrite() can be called on any thread. | |
|
o1ka
2017/01/31 11:00:11
Please explain why this method is ok to call from
Henrik Grunell
2017/02/08 11:29:37
Removed this function.
| |
| 54 return debug_writer_ && debug_writer_->WillWrite(); | |
| 55 } | |
| 56 | |
| 57 void AudioDebugRecordingHelper::OnData(const AudioBus* source) { | |
| 58 if (!WillWrite()) | |
|
o1ka
2017/01/31 11:00:11
Why is it safe to call it here?
Henrik Grunell
2017/02/08 11:29:37
WillWrite() has been removed, and I just check |de
| |
| 59 return; | |
| 60 | |
| 61 // TODO(grunell) Don't create a new AudioBus each time. Maybe a pool of | |
| 62 // AudioBuses. See also AudioInputController. | |
|
o1ka
2017/01/31 11:00:11
What exactly in AudioInputController?
Henrik Grunell
2017/02/08 11:29:37
Updated comment.
| |
| 63 std::unique_ptr<AudioBus> audio_bus_copy = | |
| 64 AudioBus::Create(source->channels(), source->frames()); | |
| 65 source->CopyTo(audio_bus_copy.get()); | |
| 66 | |
| 67 task_runner_->PostTask( | |
| 68 FROM_HERE, | |
| 69 base::Bind(&AudioDebugRecordingHelper::DoWrite, | |
| 70 weak_factory_.GetWeakPtr(), base::Passed(&audio_bus_copy))); | |
| 71 } | |
| 72 | |
| 73 void AudioDebugRecordingHelper::DoWrite(std::unique_ptr<media::AudioBus> data) { | |
| 74 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 75 | |
| 76 if (debug_writer_) | |
| 77 debug_writer_->Write(std::move(data)); | |
| 78 } | |
| 79 | |
| 80 } // namespace media | |
| OLD | NEW |