| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(const DecodeSamplesCallback& decode_callback) |
| 54 : stream_(NULL), | 54 : is_recording_(false), |
| 55 is_recording_(false), | 55 stream_(NULL), |
| 56 decode_callback_(decode_callback), | 56 decode_callback_(decode_callback), |
| 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() { |
| 62 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 62 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
| 63 FROM_HERE, | 63 FROM_HERE, |
| 64 base::Bind(&AudioRecorder::InitializeOnAudioThread, | 64 base::Bind(&AudioRecorder::InitializeOnAudioThread, |
| 65 base::Unretained(this))); | 65 base::Unretained(this))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 AudioRecorder::~AudioRecorder() { | 68 AudioRecorder::~AudioRecorder() { |
| 69 } | 69 } |
| 70 | 70 |
| 71 void AudioRecorder::Record() { | 71 void AudioRecorder::Record() { |
| 72 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 72 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
| 73 FROM_HERE, | 73 FROM_HERE, |
| 74 base::Bind(&AudioRecorder::RecordOnAudioThread, base::Unretained(this))); | 74 base::Bind(&AudioRecorder::RecordOnAudioThread, base::Unretained(this))); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void AudioRecorder::Stop() { | 77 void AudioRecorder::Stop() { |
| 78 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 78 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
| 79 FROM_HERE, | 79 FROM_HERE, |
| 80 base::Bind(&AudioRecorder::StopOnAudioThread, base::Unretained(this))); | 80 base::Bind(&AudioRecorder::StopOnAudioThread, base::Unretained(this))); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool AudioRecorder::IsRecording() { |
| 84 return is_recording_; |
| 85 } |
| 86 |
| 83 void AudioRecorder::Finalize() { | 87 void AudioRecorder::Finalize() { |
| 84 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 88 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
| 85 FROM_HERE, | 89 FROM_HERE, |
| 86 base::Bind(&AudioRecorder::FinalizeOnAudioThread, | 90 base::Bind(&AudioRecorder::FinalizeOnAudioThread, |
| 87 base::Unretained(this))); | 91 base::Unretained(this))); |
| 88 } | 92 } |
| 89 | 93 |
| 90 // Private methods. | 94 // Private methods. |
| 91 | 95 |
| 92 void AudioRecorder::InitializeOnAudioThread() { | 96 void AudioRecorder::InitializeOnAudioThread() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return; | 134 return; |
| 131 } | 135 } |
| 132 stream_->SetVolume(stream_->GetMaxVolume()); | 136 stream_->SetVolume(stream_->GetMaxVolume()); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void AudioRecorder::RecordOnAudioThread() { | 139 void AudioRecorder::RecordOnAudioThread() { |
| 136 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 140 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 137 if (!stream_ || is_recording_) | 141 if (!stream_ || is_recording_) |
| 138 return; | 142 return; |
| 139 | 143 |
| 140 DVLOG(2) << "Recording Audio."; | |
| 141 converter_->Reset(); | 144 converter_->Reset(); |
| 142 stream_->Start(this); | 145 stream_->Start(this); |
| 143 is_recording_ = true; | 146 is_recording_ = true; |
| 144 } | 147 } |
| 145 | 148 |
| 146 void AudioRecorder::StopOnAudioThread() { | 149 void AudioRecorder::StopOnAudioThread() { |
| 147 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 150 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 148 if (!stream_ || !is_recording_) | 151 if (!stream_ || !is_recording_) |
| 149 return; | 152 return; |
| 150 | 153 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 base::RunLoop rl; | 244 base::RunLoop rl; |
| 242 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( | 245 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
| 243 FROM_HERE, | 246 FROM_HERE, |
| 244 base::Bind(base::IgnoreResult(&AudioRecorder::FlushAudioLoopForTesting), | 247 base::Bind(base::IgnoreResult(&AudioRecorder::FlushAudioLoopForTesting), |
| 245 base::Unretained(this)), | 248 base::Unretained(this)), |
| 246 rl.QuitClosure()); | 249 rl.QuitClosure()); |
| 247 rl.Run(); | 250 rl.Run(); |
| 248 } | 251 } |
| 249 | 252 |
| 250 } // namespace copresence | 253 } // namespace copresence |
| OLD | NEW |