1 // Copyright 2015 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.
5 #include "content/browser/renderer_host/media/audio_input_debug_writer.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "media/base/audio_bus.h"
12 AudioInputDebugWriter::AudioInputDebugWriter(base::File file
)
14 interleaved_data_size_(0),
18 AudioInputDebugWriter::~AudioInputDebugWriter() {
19 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
22 void AudioInputDebugWriter::Write(scoped_ptr
<media::AudioBus
> data
) {
23 BrowserThread::PostTask(
26 base::Bind(&AudioInputDebugWriter::DoWrite
,
27 weak_factory_
.GetWeakPtr(),
28 base::Passed(&data
)));
31 void AudioInputDebugWriter::DoWrite(scoped_ptr
<media::AudioBus
> data
) {
32 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
34 // Convert to 16 bit audio and write to file.
35 int data_size
= data
->frames() * data
->channels();
36 if (!interleaved_data_
|| interleaved_data_size_
< data_size
) {
37 interleaved_data_
.reset(new int16
[data_size
]);
38 interleaved_data_size_
= data_size
;
40 data
->ToInterleaved(data
->frames(), sizeof(interleaved_data_
[0]),
41 interleaved_data_
.get());
42 file_
.WriteAtCurrentPos(reinterpret_cast<char*>(interleaved_data_
.get()),
43 data_size
* sizeof(interleaved_data_
[0]));