OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/copresence/mediums/audio/audio_recorder.h" | 5 #include "components/copresence/mediums/audio/audio_recorder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 for (int ch = 0; ch < channels; ++ch) { | 32 for (int ch = 0; ch < channels; ++ch) { |
33 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels) | 33 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels) |
34 buffer_view[di] = source->channel(ch)[si]; | 34 buffer_view[di] = source->channel(ch)[si]; |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 // Called every kProcessIntervalMs to process the recorded audio. This | 38 // Called every kProcessIntervalMs to process the recorded audio. This |
39 // converts our samples to the required sample rate, interleaves the samples | 39 // converts our samples to the required sample rate, interleaves the samples |
40 // and sends them to the whispernet decoder to process. | 40 // and sends them to the whispernet decoder to process. |
41 void ProcessSamples(scoped_ptr<media::AudioBus> bus, | 41 void ProcessSamples(scoped_ptr<media::AudioBus> bus, |
42 const AudioRecorder::DecodeSamplesCallback& callback) { | 42 const AudioRecorder::RecordedSamplesCallback& callback) { |
43 std::string samples; | 43 std::string samples; |
44 AudioBusToString(bus.Pass(), &samples); | 44 AudioBusToString(bus.Pass(), &samples); |
45 content::BrowserThread::PostTask( | 45 content::BrowserThread::PostTask( |
46 content::BrowserThread::UI, FROM_HERE, base::Bind(callback, samples)); | 46 content::BrowserThread::UI, FROM_HERE, base::Bind(callback, samples)); |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // Public methods. | 51 // Public methods. |
52 | 52 |
53 AudioRecorder::AudioRecorder(const DecodeSamplesCallback& decode_callback) | 53 AudioRecorder::AudioRecorder() |
54 : is_recording_(false), | 54 : is_recording_(false), |
55 stream_(NULL), | 55 stream_(NULL), |
56 decode_callback_(decode_callback), | 56 temp_conversion_buffer_(NULL), |
57 total_buffer_frames_(0), | 57 total_buffer_frames_(0), |
58 buffer_frame_index_(0) { | 58 buffer_frame_index_(0) { |
59 } | 59 } |
60 | 60 |
61 void AudioRecorder::Initialize() { | 61 void AudioRecorder::Initialize(const RecordedSamplesCallback& decode_callback) { |
| 62 decode_callback_ = decode_callback; |
62 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 63 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
63 FROM_HERE, | 64 FROM_HERE, |
64 base::Bind(&AudioRecorder::InitializeOnAudioThread, | 65 base::Bind(&AudioRecorder::InitializeOnAudioThread, |
65 base::Unretained(this))); | 66 base::Unretained(this))); |
66 } | 67 } |
67 | 68 |
68 AudioRecorder::~AudioRecorder() { | 69 AudioRecorder::~AudioRecorder() { |
69 } | 70 } |
70 | 71 |
71 void AudioRecorder::Record() { | 72 void AudioRecorder::Record() { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 base::RunLoop rl; | 243 base::RunLoop rl; |
243 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( | 244 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
244 FROM_HERE, | 245 FROM_HERE, |
245 base::Bind(base::IgnoreResult(&AudioRecorder::FlushAudioLoopForTesting), | 246 base::Bind(base::IgnoreResult(&AudioRecorder::FlushAudioLoopForTesting), |
246 base::Unretained(this)), | 247 base::Unretained(this)), |
247 rl.QuitClosure()); | 248 rl.QuitClosure()); |
248 rl.Run(); | 249 rl.Run(); |
249 } | 250 } |
250 | 251 |
251 } // namespace copresence | 252 } // namespace copresence |
OLD | NEW |