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

Side by Side Diff: media/audio/audio_debug_recording_helper.cc

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Using callbacks instead. Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(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 : params_(params),
19 create_audio_file_writer_callback_(create_audio_file_writer_callback),
20 task_runner_(std::move(task_runner)),
21 weak_factory_(this) {
22 DCHECK(create_audio_file_writer_callback_);
23 }
24
25 AudioDebugRecordingHelper::~AudioDebugRecordingHelper() {}
26
27 void AudioDebugRecordingHelper::EnableDebugRecording(
28 const base::FilePath& file_name) {
29 DCHECK(task_runner_->BelongsToCurrentThread());
30 DCHECK(!debug_writer_);
31
32 debug_writer_ = create_audio_file_writer_callback_.Run(params_);
33
34 // The debug writer writes in wave format.
35 debug_writer_->Start(file_name.AddExtension("wav"));
36 }
37
38 void AudioDebugRecordingHelper::DisableDebugRecording() {
39 DCHECK(task_runner_->BelongsToCurrentThread());
40
41 if (debug_writer_) {
42 debug_writer_->Stop();
43 debug_writer_.reset();
44 }
45 }
46
47 void AudioDebugRecordingHelper::MaybeWrite(const AudioBus* source) {
48 if (!WillWrite())
49 return;
50
51 // TODO(grunell) Don't create a new AudioBus each time. Maybe a pool of
52 // AudioBuses. See also AudioInputController.
53 std::unique_ptr<AudioBus> audio_bus_copy =
54 AudioBus::Create(source->channels(), source->frames());
55 source->CopyTo(audio_bus_copy.get());
56
57 task_runner_->PostTask(
58 FROM_HERE,
59 base::Bind(&AudioDebugRecordingHelper::DoWrite,
60 weak_factory_.GetWeakPtr(), base::Passed(&audio_bus_copy)));
61 }
62
63 bool AudioDebugRecordingHelper::WillWrite() {
64 return debug_writer_ && debug_writer_->WillWrite();
65 }
66
67 void AudioDebugRecordingHelper::DoWrite(std::unique_ptr<media::AudioBus> data) {
68 DCHECK(task_runner_->BelongsToCurrentThread());
69
70 if (debug_writer_)
71 debug_writer_->Write(std::move(data));
72 }
73
74 } // namspace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698