Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_input_debug_writer.cc |
| diff --git a/content/browser/renderer_host/media/audio_input_debug_writer.cc b/content/browser/renderer_host/media/audio_input_debug_writer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fb2d1f03f2399178552966318a16aa7c9e4a39b5 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/audio_input_debug_writer.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2015 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 "content/browser/renderer_host/media/audio_input_debug_writer.h" |
| + |
| +#include "content/public/browser/browser_thread.h" |
| +#include "media/base/audio_bus.h" |
| + |
| +namespace content { |
| + |
| +AudioInputDebugWriter::AudioInputDebugWriter(base::File file) |
| + : file_(file.Pass()), |
| + interleaved_data_size_(0), |
| + weak_factory_(this) { |
| +} |
| + |
| +AudioInputDebugWriter::~AudioInputDebugWriter() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| +} |
| + |
| +void AudioInputDebugWriter::Write(scoped_ptr<media::AudioBus> data) { |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&AudioInputDebugWriter::DoWrite, |
| + weak_factory_.GetWeakPtr(), |
| + base::Passed(&data))); |
| +} |
| + |
| +void AudioInputDebugWriter::DoWrite(scoped_ptr<media::AudioBus> data) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + |
| + int data_size_bytes = 2 * data->frames() * data->channels(); |
|
tommi (sloooow) - chröme
2015/08/07 12:09:51
Can you add a note here saying that we convert the
Henrik Grunell
2015/08/17 15:05:16
Done.
|
| + if (!interleaved_data_ || interleaved_data_size_ != data_size_bytes) { |
| + interleaved_data_.reset(new char[data_size_bytes]); |
| + interleaved_data_size_ = data_size_bytes; |
| + } |
| + |
| + data->ToInterleaved(data->frames(), 2, interleaved_data_.get()); |
| + file_.WriteAtCurrentPos(interleaved_data_.get(), interleaved_data_size_); |
|
tommi (sloooow) - chröme
2015/08/07 12:09:51
nit: should the second parameter be data_size_byte
Henrik Grunell
2015/08/17 15:05:16
Sure, agree it's slightly better. Done.
|
| +} |
| + |
| +} // namspace content |