| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/audio_modem/audio_recorder_impl.h" | 5 #include "components/audio_modem/audio_recorder_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "components/audio_modem/public/audio_modem_types.h" | 16 #include "components/audio_modem/public/audio_modem_types.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "media/audio/audio_device_description.h" |
| 18 #include "media/audio/audio_manager.h" | 19 #include "media/audio/audio_manager.h" |
| 19 #include "media/audio/audio_manager_base.h" | |
| 20 #include "media/base/audio_bus.h" | 20 #include "media/base/audio_bus.h" |
| 21 | 21 |
| 22 namespace audio_modem { | 22 namespace audio_modem { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const float kProcessIntervalMs = 500.0f; // milliseconds. | 26 const float kProcessIntervalMs = 500.0f; // milliseconds. |
| 27 | 27 |
| 28 void AudioBusToString(std::unique_ptr<media::AudioBus> source, | 28 void AudioBusToString(std::unique_ptr<media::AudioBus> source, |
| 29 std::string* buffer) { | 29 std::string* buffer) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Private methods. | 96 // Private methods. |
| 97 | 97 |
| 98 void AudioRecorderImpl::InitializeOnAudioThread() { | 98 void AudioRecorderImpl::InitializeOnAudioThread() { |
| 99 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 99 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 100 | 100 |
| 101 media::AudioParameters params; | 101 media::AudioParameters params; |
| 102 if (params_for_testing_) { | 102 if (params_for_testing_) { |
| 103 params = *params_for_testing_; | 103 params = *params_for_testing_; |
| 104 } else { | 104 } else { |
| 105 params = media::AudioManager::Get()->GetInputStreamParameters( | 105 params = media::AudioManager::Get()->GetInputStreamParameters( |
| 106 media::AudioManagerBase::kDefaultDeviceId); | 106 media::AudioDeviceDescription::kDefaultDeviceId); |
| 107 params.set_effects(media::AudioParameters::NO_EFFECTS); | 107 params.set_effects(media::AudioParameters::NO_EFFECTS); |
| 108 } | 108 } |
| 109 | 109 |
| 110 total_buffer_frames_ = kProcessIntervalMs * params.sample_rate() / 1000; | 110 total_buffer_frames_ = kProcessIntervalMs * params.sample_rate() / 1000; |
| 111 buffer_ = media::AudioBus::Create(params.channels(), total_buffer_frames_); | 111 buffer_ = media::AudioBus::Create(params.channels(), total_buffer_frames_); |
| 112 buffer_frame_index_ = 0; | 112 buffer_frame_index_ = 0; |
| 113 | 113 |
| 114 stream_ = input_stream_for_testing_ | 114 stream_ = input_stream_for_testing_ |
| 115 ? input_stream_for_testing_.get() | 115 ? input_stream_for_testing_.get() |
| 116 : media::AudioManager::Get()->MakeAudioInputStream( | 116 : media::AudioManager::Get()->MakeAudioInputStream( |
| 117 params, media::AudioManagerBase::kDefaultDeviceId); | 117 params, media::AudioDeviceDescription::kDefaultDeviceId); |
| 118 | 118 |
| 119 if (!stream_ || !stream_->Open()) { | 119 if (!stream_ || !stream_->Open()) { |
| 120 LOG(ERROR) << "Failed to open an input stream."; | 120 LOG(ERROR) << "Failed to open an input stream."; |
| 121 if (stream_) { | 121 if (stream_) { |
| 122 stream_->Close(); | 122 stream_->Close(); |
| 123 stream_ = nullptr; | 123 stream_ = nullptr; |
| 124 } | 124 } |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 stream_->SetVolume(stream_->GetMaxVolume()); | 127 stream_->SetVolume(stream_->GetMaxVolume()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 void AudioRecorderImpl::OnError(media::AudioInputStream* /* stream */) { | 194 void AudioRecorderImpl::OnError(media::AudioInputStream* /* stream */) { |
| 195 LOG(ERROR) << "Error during sound recording."; | 195 LOG(ERROR) << "Error during sound recording."; |
| 196 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 196 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
| 197 FROM_HERE, | 197 FROM_HERE, |
| 198 base::Bind(&AudioRecorderImpl::StopAndCloseOnAudioThread, | 198 base::Bind(&AudioRecorderImpl::StopAndCloseOnAudioThread, |
| 199 base::Unretained(this))); | 199 base::Unretained(this))); |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace audio_modem | 202 } // namespace audio_modem |
| OLD | NEW |