| 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/handlers/audio/audio_directive_handler.h" | 5 #include "components/copresence/handlers/audio/audio_directive_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // Private methods. | 115 // Private methods. |
| 116 | 116 |
| 117 void AudioDirectiveHandler::ProcessNextTransmit() { | 117 void AudioDirectiveHandler::ProcessNextTransmit() { |
| 118 // If we have an active directive for audible or inaudible audio, ensure that | 118 // If we have an active directive for audible or inaudible audio, ensure that |
| 119 // we are playing our respective token; if we do not have a directive, then | 119 // we are playing our respective token; if we do not have a directive, then |
| 120 // make sure we aren't playing. This is duplicate code, but for just two | 120 // make sure we aren't playing. This is duplicate code, but for just two |
| 121 // elements, it has hard to make a case for processing a loop instead. | 121 // elements, it has hard to make a case for processing a loop instead. |
| 122 | 122 |
| 123 scoped_ptr<AudioDirective> audible_transmit( | 123 scoped_ptr<AudioDirective> audible_transmit( |
| 124 transmits_list_audible_.GetActiveDirective()); | 124 transmits_list_audible_.GetActiveDirective()); |
| 125 if (audible_transmit && !player_audible_->IsPlaying()) { | 125 if (audible_transmit && !player_audible_->IsPlaying() && |
| 126 samples_cache_audible_.HasKey(current_token_audible_)) { |
| 126 DVLOG(3) << "Playing audible for op_id: " << audible_transmit->op_id; | 127 DVLOG(3) << "Playing audible for op_id: " << audible_transmit->op_id; |
| 127 player_audible_->Play( | 128 player_audible_->Play( |
| 128 samples_cache_audible_.GetValue(current_token_audible_)); | 129 samples_cache_audible_.GetValue(current_token_audible_)); |
| 129 stop_audible_playback_timer_.Start( | 130 stop_audible_playback_timer_.Start( |
| 130 FROM_HERE, | 131 FROM_HERE, |
| 131 audible_transmit->end_time - base::Time::Now(), | 132 audible_transmit->end_time - base::Time::Now(), |
| 132 this, | 133 this, |
| 133 &AudioDirectiveHandler::ProcessNextTransmit); | 134 &AudioDirectiveHandler::ProcessNextTransmit); |
| 134 } else if (!audible_transmit && player_audible_->IsPlaying()) { | 135 } else if (!audible_transmit && player_audible_->IsPlaying()) { |
| 135 DVLOG(3) << "Stopping audible playback."; | 136 DVLOG(3) << "Stopping audible playback."; |
| 136 current_token_audible_.clear(); | 137 current_token_audible_.clear(); |
| 137 stop_audible_playback_timer_.Stop(); | 138 stop_audible_playback_timer_.Stop(); |
| 138 player_audible_->Stop(); | 139 player_audible_->Stop(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 scoped_ptr<AudioDirective> inaudible_transmit( | 142 scoped_ptr<AudioDirective> inaudible_transmit( |
| 142 transmits_list_inaudible_.GetActiveDirective()); | 143 transmits_list_inaudible_.GetActiveDirective()); |
| 143 if (inaudible_transmit && !player_inaudible_->IsPlaying()) { | 144 if (inaudible_transmit && !player_inaudible_->IsPlaying() && |
| 145 samples_cache_inaudible_.HasKey(current_token_inaudible_)) { |
| 144 DVLOG(3) << "Playing inaudible for op_id: " << inaudible_transmit->op_id; | 146 DVLOG(3) << "Playing inaudible for op_id: " << inaudible_transmit->op_id; |
| 145 player_inaudible_->Play( | 147 player_inaudible_->Play( |
| 146 samples_cache_inaudible_.GetValue(current_token_inaudible_)); | 148 samples_cache_inaudible_.GetValue(current_token_inaudible_)); |
| 147 stop_inaudible_playback_timer_.Start( | 149 stop_inaudible_playback_timer_.Start( |
| 148 FROM_HERE, | 150 FROM_HERE, |
| 149 inaudible_transmit->end_time - base::Time::Now(), | 151 inaudible_transmit->end_time - base::Time::Now(), |
| 150 this, | 152 this, |
| 151 &AudioDirectiveHandler::ProcessNextTransmit); | 153 &AudioDirectiveHandler::ProcessNextTransmit); |
| 152 } else if (!inaudible_transmit && player_inaudible_->IsPlaying()) { | 154 } else if (!inaudible_transmit && player_inaudible_->IsPlaying()) { |
| 153 DVLOG(3) << "Stopping inaudible playback."; | 155 DVLOG(3) << "Stopping inaudible playback."; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 current_token_inaudible_ = token; | 211 current_token_inaudible_ = token; |
| 210 // Force process transmits to pick up the new token. | 212 // Force process transmits to pick up the new token. |
| 211 if (player_inaudible_->IsPlaying()) | 213 if (player_inaudible_->IsPlaying()) |
| 212 player_inaudible_->Stop(); | 214 player_inaudible_->Stop(); |
| 213 } | 215 } |
| 214 | 216 |
| 215 ProcessNextTransmit(); | 217 ProcessNextTransmit(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 } // namespace copresence | 220 } // namespace copresence |
| OLD | NEW |