| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 AudioManagerImpl::AudioManagerImpl() | 46 AudioManagerImpl::AudioManagerImpl() |
| 47 : whispernet_client_(nullptr), recorder_(nullptr) { | 47 : whispernet_client_(nullptr), recorder_(nullptr) { |
| 48 // TODO(rkc): Move all of these into initializer lists once it is allowed. | 48 // TODO(rkc): Move all of these into initializer lists once it is allowed. |
| 49 should_be_playing_[AUDIBLE] = false; | 49 should_be_playing_[AUDIBLE] = false; |
| 50 should_be_playing_[INAUDIBLE] = false; | 50 should_be_playing_[INAUDIBLE] = false; |
| 51 should_be_recording_[AUDIBLE] = false; | 51 should_be_recording_[AUDIBLE] = false; |
| 52 should_be_recording_[INAUDIBLE] = false; | 52 should_be_recording_[INAUDIBLE] = false; |
| 53 | 53 |
| 54 player_[AUDIBLE] = nullptr; | 54 player_[AUDIBLE] = nullptr; |
| 55 player_[INAUDIBLE] = nullptr; | 55 player_[INAUDIBLE] = nullptr; |
| 56 token_length_[0] = 0; |
| 57 token_length_[1] = 0; |
| 56 } | 58 } |
| 57 | 59 |
| 58 void AudioManagerImpl::Initialize(WhispernetClient* whispernet_client, | 60 void AudioManagerImpl::Initialize(WhispernetClient* whispernet_client, |
| 59 const TokensCallback& tokens_cb) { | 61 const TokensCallback& tokens_cb) { |
| 60 samples_cache_.resize(2); | 62 samples_cache_.resize(2); |
| 61 samples_cache_[AUDIBLE] = new SamplesMap( | 63 samples_cache_[AUDIBLE] = new SamplesMap( |
| 62 base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), kMaxSamples); | 64 base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), kMaxSamples); |
| 63 samples_cache_[INAUDIBLE] = new SamplesMap( | 65 samples_cache_[INAUDIBLE] = new SamplesMap( |
| 64 base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), kMaxSamples); | 66 base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), kMaxSamples); |
| 65 | 67 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 recorder_->Record(); | 135 recorder_->Record(); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void AudioManagerImpl::StopRecording(AudioType type) { | 138 void AudioManagerImpl::StopRecording(AudioType type) { |
| 137 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 139 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 138 should_be_recording_[type] = false; | 140 should_be_recording_[type] = false; |
| 139 recorder_->Stop(); | 141 recorder_->Stop(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void AudioManagerImpl::SetToken(AudioType type, | 144 void AudioManagerImpl::SetToken(AudioType type, |
| 143 const std::string& url_unsafe_token) { | 145 const std::string& url_safe_token) { |
| 144 DCHECK(type == AUDIBLE || type == INAUDIBLE); | 146 DCHECK(type == AUDIBLE || type == INAUDIBLE); |
| 145 std::string token = FromUrlSafe(url_unsafe_token); | 147 std::string token = FromUrlSafe(url_safe_token); |
| 146 if (!samples_cache_[type]->HasKey(token)) { | 148 if (!samples_cache_[type]->HasKey(token)) { |
| 147 whispernet_client_->EncodeToken(token, type); | 149 whispernet_client_->EncodeToken(token, type); |
| 148 } else { | 150 } else { |
| 149 UpdateToken(type, token); | 151 UpdateToken(type, token); |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 | 154 |
| 153 const std::string AudioManagerImpl::GetToken(AudioType type) { | 155 const std::string AudioManagerImpl::GetToken(AudioType type) { |
| 154 return should_be_playing_[type] ? playing_token_[type] : ""; | 156 return should_be_playing_[type] ? playing_token_[type] : ""; |
| 155 } | 157 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 if (decode_audible && decode_inaudible) { | 243 if (decode_audible && decode_inaudible) { |
| 242 whispernet_client_->DecodeSamples(BOTH, samples, token_length_); | 244 whispernet_client_->DecodeSamples(BOTH, samples, token_length_); |
| 243 } else if (decode_audible) { | 245 } else if (decode_audible) { |
| 244 whispernet_client_->DecodeSamples(AUDIBLE, samples, token_length_); | 246 whispernet_client_->DecodeSamples(AUDIBLE, samples, token_length_); |
| 245 } else if (decode_inaudible) { | 247 } else if (decode_inaudible) { |
| 246 whispernet_client_->DecodeSamples(INAUDIBLE, samples, token_length_); | 248 whispernet_client_->DecodeSamples(INAUDIBLE, samples, token_length_); |
| 247 } | 249 } |
| 248 } | 250 } |
| 249 | 251 |
| 250 } // namespace copresence | 252 } // namespace copresence |
| OLD | NEW |