| 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_manager_impl.h" | 5 #include "components/copresence/mediums/audio/audio_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void AudioManagerImpl::StopPlaying(AudioType type) { | 123 void AudioManagerImpl::StopPlaying(AudioType type) { |
| 124 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 124 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 125 should_be_playing_[type] = false; | 125 should_be_playing_[type] = false; |
| 126 player_[type]->Stop(); | 126 player_[type]->Stop(); |
| 127 // If we were only recording to hear our own played tokens, stop. | 127 // If we were only recording to hear our own played tokens, stop. |
| 128 if (!should_be_recording_[AUDIBLE] && !should_be_recording_[INAUDIBLE]) | 128 if (!should_be_recording_[AUDIBLE] && !should_be_recording_[INAUDIBLE]) |
| 129 recorder_->Stop(); | 129 recorder_->Stop(); |
| 130 playing_token_[type] = std::string(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void AudioManagerImpl::StartRecording(AudioType type) { | 133 void AudioManagerImpl::StartRecording(AudioType type) { |
| 133 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 134 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 134 should_be_recording_[type] = true; | 135 should_be_recording_[type] = true; |
| 135 recorder_->Record(); | 136 recorder_->Record(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void AudioManagerImpl::StopRecording(AudioType type) { | 139 void AudioManagerImpl::StopRecording(AudioType type) { |
| 139 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 140 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 140 should_be_recording_[type] = false; | 141 should_be_recording_[type] = false; |
| 141 recorder_->Stop(); | 142 recorder_->Stop(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void AudioManagerImpl::SetToken(AudioType type, | 145 void AudioManagerImpl::SetToken(AudioType type, |
| 145 const std::string& url_safe_token) { | 146 const std::string& url_safe_token) { |
| 146 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 147 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 147 std::string token = FromUrlSafe(url_safe_token); | 148 std::string token = FromUrlSafe(url_safe_token); |
| 148 if (!samples_cache_[type]->HasKey(token)) { | 149 if (!samples_cache_[type]->HasKey(token)) { |
| 149 whispernet_client_->EncodeToken(token, type); | 150 whispernet_client_->EncodeToken(token, type); |
| 150 } else { | 151 } else { |
| 151 UpdateToken(type, token); | 152 UpdateToken(type, token); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 const std::string AudioManagerImpl::GetToken(AudioType type) { | 156 const std::string AudioManagerImpl::GetToken(AudioType type) { |
| 156 return should_be_playing_[type] ? playing_token_[type] : ""; | 157 return playing_token_[type]; |
| 157 } | 158 } |
| 158 | 159 |
| 159 bool AudioManagerImpl::IsPlayingTokenHeard(AudioType type) { | 160 bool AudioManagerImpl::IsPlayingTokenHeard(AudioType type) { |
| 160 base::TimeDelta tokenTimeout = | 161 base::TimeDelta tokenTimeout = |
| 161 base::TimeDelta::FromMilliseconds(kTokenTimeoutMs); | 162 base::TimeDelta::FromMilliseconds(kTokenTimeoutMs); |
| 162 | 163 |
| 163 // This is a bit of a hack. If we haven't been playing long enough, | 164 // This is a bit of a hack. If we haven't been playing long enough, |
| 164 // return true to avoid tripping an audio fail alarm. | 165 // return true to avoid tripping an audio fail alarm. |
| 165 if (base::Time::Now() - started_playing_[type] < tokenTimeout) | 166 if (base::Time::Now() - started_playing_[type] < tokenTimeout) |
| 166 return true; | 167 return true; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (decode_audible && decode_inaudible) { | 244 if (decode_audible && decode_inaudible) { |
| 244 whispernet_client_->DecodeSamples(BOTH, samples, token_length_); | 245 whispernet_client_->DecodeSamples(BOTH, samples, token_length_); |
| 245 } else if (decode_audible) { | 246 } else if (decode_audible) { |
| 246 whispernet_client_->DecodeSamples(AUDIBLE, samples, token_length_); | 247 whispernet_client_->DecodeSamples(AUDIBLE, samples, token_length_); |
| 247 } else if (decode_inaudible) { | 248 } else if (decode_inaudible) { |
| 248 whispernet_client_->DecodeSamples(INAUDIBLE, samples, token_length_); | 249 whispernet_client_->DecodeSamples(INAUDIBLE, samples, token_length_); |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 252 } // namespace copresence | 253 } // namespace copresence |
| OLD | NEW |