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 AudioManager* audio_manager, | |
16 base::SingleThreadTaskRunner* task_runner) | |
17 : audio_manager_(audio_manager), | |
18 task_runner_(task_runner), | |
19 weak_factory_(this) { | |
20 DCHECK(audio_manager_); | |
21 } | |
22 | |
23 AudioDebugRecordingHelper::~AudioDebugRecordingHelper() {} | |
24 | |
25 void AudioDebugRecordingHelper::EnableDebugRecording( | |
26 const AudioParameters& params, | |
27 const base::FilePath& file_name) { | |
28 DCHECK(task_runner_->BelongsToCurrentThread()); | |
29 DCHECK(!debug_writer_); | |
30 | |
31 debug_writer_ = audio_manager_->CreateAudioFileWriter(params); | |
32 | |
33 // The debug writer writes in wave format. | |
34 debug_writer_->Start(file_name.AddExtension("wav")); | |
35 } | |
36 | |
37 void AudioDebugRecordingHelper::DisableDebugRecording() { | |
38 DCHECK(task_runner_->BelongsToCurrentThread()); | |
39 | |
40 if (debug_writer_) { | |
41 debug_writer_->Stop(); | |
42 debug_writer_.reset(); | |
43 } | |
44 } | |
45 | |
46 void AudioDebugRecordingHelper::MaybeWrite(const AudioBus* source) { | |
47 if (WillWrite()) { | |
DaleCurtis
2017/01/19 17:44:34
early return instead.
Henrik Grunell
2017/01/20 10:38:55
Done.
| |
48 // TODO(grunell) Don't create a new AudioBus each time. Maybe a pool of | |
49 // AudioBuses. See also AudioInputController. | |
50 std::unique_ptr<AudioBus> audio_bus_copy = | |
51 AudioBus::Create(source->channels(), source->frames()); | |
52 source->CopyTo(audio_bus_copy.get()); | |
53 | |
54 task_runner_->PostTask( | |
55 FROM_HERE, | |
56 base::Bind(&AudioDebugRecordingHelper::DoWrite, | |
57 weak_factory_.GetWeakPtr(), base::Passed(&audio_bus_copy))); | |
58 } | |
59 } | |
60 | |
61 bool AudioDebugRecordingHelper::WillWrite() { | |
62 return debug_writer_ && debug_writer_->WillWrite(); | |
63 } | |
64 | |
65 void AudioDebugRecordingHelper::DoWrite(std::unique_ptr<media::AudioBus> data) { | |
66 DCHECK(task_runner_->BelongsToCurrentThread()); | |
67 | |
68 if (debug_writer_) | |
69 debug_writer_->Write(std::move(data)); | |
70 } | |
71 | |
72 } // namspace media | |
OLD | NEW |