| 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_player.h" | 5 #include "components/copresence/mediums/audio/audio_player.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" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 is_playing_ = false; | 134 is_playing_ = false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void AudioPlayer::FinalizeOnAudioThread() { | 137 void AudioPlayer::FinalizeOnAudioThread() { |
| 138 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 138 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 139 StopAndCloseOnAudioThread(); | 139 StopAndCloseOnAudioThread(); |
| 140 delete this; | 140 delete this; |
| 141 } | 141 } |
| 142 | 142 |
| 143 int AudioPlayer::OnMoreData(media::AudioBus* dest, | 143 int AudioPlayer::OnMoreData(media::AudioBus* dest, |
| 144 media::AudioBuffersState /* state */) { | 144 int /* total_bytes_delay */) { |
| 145 base::AutoLock al(state_lock_); | 145 base::AutoLock al(state_lock_); |
| 146 // Continuously play our samples till explicitly told to stop. | 146 // Continuously play our samples till explicitly told to stop. |
| 147 const int leftover_frames = samples_->frames() - frame_index_; | 147 const int leftover_frames = samples_->frames() - frame_index_; |
| 148 const int frames_to_copy = std::min(dest->frames(), leftover_frames); | 148 const int frames_to_copy = std::min(dest->frames(), leftover_frames); |
| 149 | 149 |
| 150 samples_->CopyPartialFramesTo(frame_index_, frames_to_copy, 0, dest); | 150 samples_->CopyPartialFramesTo(frame_index_, frames_to_copy, 0, dest); |
| 151 frame_index_ += frames_to_copy; | 151 frame_index_ += frames_to_copy; |
| 152 | 152 |
| 153 // If we didn't fill the destination audio bus, wrap around and fill the rest. | 153 // If we didn't fill the destination audio bus, wrap around and fill the rest. |
| 154 if (leftover_frames <= dest->frames()) { | 154 if (leftover_frames <= dest->frames()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 177 base::RunLoop rl; | 177 base::RunLoop rl; |
| 178 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( | 178 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
| 179 FROM_HERE, | 179 FROM_HERE, |
| 180 base::Bind(base::IgnoreResult(&AudioPlayer::FlushAudioLoopForTesting), | 180 base::Bind(base::IgnoreResult(&AudioPlayer::FlushAudioLoopForTesting), |
| 181 base::Unretained(this)), | 181 base::Unretained(this)), |
| 182 rl.QuitClosure()); | 182 rl.QuitClosure()); |
| 183 rl.Run(); | 183 rl.Run(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace copresence | 186 } // namespace copresence |
| OLD | NEW |