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_player_impl.h" | 5 #include "components/audio_modem/audio_player_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/run_loop.h" |
13 #include "components/audio_modem/public/audio_modem_types.h" | 14 #include "components/audio_modem/public/audio_modem_types.h" |
| 15 #include "content/public/browser/browser_thread.h" |
14 #include "media/audio/audio_manager.h" | 16 #include "media/audio/audio_manager.h" |
15 #include "media/audio/audio_parameters.h" | 17 #include "media/audio/audio_parameters.h" |
16 #include "media/base/audio_bus.h" | 18 #include "media/base/audio_bus.h" |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 const int kDefaultFrameCount = 1024; | 22 const int kDefaultFrameCount = 1024; |
21 const double kOutputVolumePercent = 1.0f; | 23 const double kOutputVolumePercent = 1.0f; |
22 | 24 |
23 } // namespace | 25 } // namespace |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 155 } |
154 | 156 |
155 void AudioPlayerImpl::OnError(media::AudioOutputStream* /* stream */) { | 157 void AudioPlayerImpl::OnError(media::AudioOutputStream* /* stream */) { |
156 LOG(ERROR) << "Error during system sound reproduction."; | 158 LOG(ERROR) << "Error during system sound reproduction."; |
157 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 159 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
158 FROM_HERE, | 160 FROM_HERE, |
159 base::Bind(&AudioPlayerImpl::StopAndCloseOnAudioThread, | 161 base::Bind(&AudioPlayerImpl::StopAndCloseOnAudioThread, |
160 base::Unretained(this))); | 162 base::Unretained(this))); |
161 } | 163 } |
162 | 164 |
| 165 void AudioPlayerImpl::FlushAudioLoopForTesting() { |
| 166 if (media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()) |
| 167 return; |
| 168 |
| 169 // Queue task on the audio thread, when it is executed, that means we've |
| 170 // successfully executed all the tasks before us. |
| 171 base::RunLoop rl; |
| 172 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
| 173 FROM_HERE, |
| 174 base::Bind(base::IgnoreResult(&AudioPlayerImpl::FlushAudioLoopForTesting), |
| 175 base::Unretained(this)), |
| 176 rl.QuitClosure()); |
| 177 rl.Run(); |
| 178 } |
| 179 |
163 } // namespace audio_modem | 180 } // namespace audio_modem |
OLD | NEW |