| 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" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 stream_->Close(); | 124 stream_->Close(); |
| 125 stream_ = nullptr; | 125 stream_ = nullptr; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void AudioPlayerImpl::FinalizeOnAudioThread() { | 128 void AudioPlayerImpl::FinalizeOnAudioThread() { |
| 129 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 129 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| 130 StopAndCloseOnAudioThread(); | 130 StopAndCloseOnAudioThread(); |
| 131 delete this; | 131 delete this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 int AudioPlayerImpl::OnMoreData(media::AudioBus* dest, | 134 int AudioPlayerImpl::OnMoreData( |
| 135 uint32_t /* total_bytes_delay */, | 135 media::AudioBus* dest, |
| 136 uint32_t /* frames_skipped */) { | 136 uint32_t /* total_bytes_delay */, |
| 137 uint32_t /* frames_skipped */, |
| 138 const media::AudioTimestamp& /* output_timestamp */) { |
| 137 base::AutoLock al(state_lock_); | 139 base::AutoLock al(state_lock_); |
| 138 // Continuously play our samples till explicitly told to stop. | 140 // Continuously play our samples till explicitly told to stop. |
| 139 const int leftover_frames = samples_->frames() - frame_index_; | 141 const int leftover_frames = samples_->frames() - frame_index_; |
| 140 const int frames_to_copy = std::min(dest->frames(), leftover_frames); | 142 const int frames_to_copy = std::min(dest->frames(), leftover_frames); |
| 141 | 143 |
| 142 samples_->CopyPartialFramesTo(frame_index_, frames_to_copy, 0, dest); | 144 samples_->CopyPartialFramesTo(frame_index_, frames_to_copy, 0, dest); |
| 143 frame_index_ += frames_to_copy; | 145 frame_index_ += frames_to_copy; |
| 144 | 146 |
| 145 // If we didn't fill the destination audio bus, wrap around and fill the rest. | 147 // If we didn't fill the destination audio bus, wrap around and fill the rest. |
| 146 if (leftover_frames <= dest->frames()) { | 148 if (leftover_frames <= dest->frames()) { |
| 147 samples_->CopyPartialFramesTo( | 149 samples_->CopyPartialFramesTo( |
| 148 0, dest->frames() - frames_to_copy, frames_to_copy, dest); | 150 0, dest->frames() - frames_to_copy, frames_to_copy, dest); |
| 149 frame_index_ = dest->frames() - frames_to_copy; | 151 frame_index_ = dest->frames() - frames_to_copy; |
| 150 } | 152 } |
| 151 | 153 |
| 152 return dest->frames(); | 154 return dest->frames(); |
| 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 |
| 163 } // namespace audio_modem | 165 } // namespace audio_modem |
| OLD | NEW |