| 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_list.h" | 5 #include "components/copresence/handlers/audio/audio_directive_list.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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 base::Time end_time, | 44 base::Time end_time, |
| 45 const scoped_refptr<media::AudioBusRefCounted>& samples) | 45 const scoped_refptr<media::AudioBusRefCounted>& samples) |
| 46 : token(token), op_id(op_id), end_time(end_time), samples(samples) { | 46 : token(token), op_id(op_id), end_time(end_time), samples(samples) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 AudioDirective::~AudioDirective() { | 49 AudioDirective::~AudioDirective() { |
| 50 } | 50 } |
| 51 | 51 |
| 52 AudioDirectiveList::AudioDirectiveList( | 52 AudioDirectiveList::AudioDirectiveList( |
| 53 const EncodeTokenCallback& encode_token_callback, | 53 const EncodeTokenCallback& encode_token_callback, |
| 54 const base::Closure& token_added_callback) | 54 const base::Closure& token_added_callback, |
| 55 bool use_audible_encoding) |
| 55 : encode_token_callback_(encode_token_callback), | 56 : encode_token_callback_(encode_token_callback), |
| 56 token_added_callback_(token_added_callback), | 57 token_added_callback_(token_added_callback), |
| 58 use_audible_encoding_(use_audible_encoding), |
| 57 samples_cache_(base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), | 59 samples_cache_(base::TimeDelta::FromMilliseconds(kSampleExpiryTimeMs), |
| 58 kMaxSamples) { | 60 kMaxSamples) { |
| 59 } | 61 } |
| 60 | 62 |
| 61 AudioDirectiveList::~AudioDirectiveList() { | 63 AudioDirectiveList::~AudioDirectiveList() { |
| 62 } | 64 } |
| 63 | 65 |
| 64 void AudioDirectiveList::AddTransmitDirective(const std::string& token, | 66 void AudioDirectiveList::AddTransmitDirective(const std::string& token, |
| 65 const std::string& op_id, | 67 const std::string& op_id, |
| 66 base::TimeDelta ttl) { | 68 base::TimeDelta ttl) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 pending_transmit_tokens_.end()) { | 80 pending_transmit_tokens_.end()) { |
| 79 return; | 81 return; |
| 80 } | 82 } |
| 81 | 83 |
| 82 pending_transmit_tokens_[valid_token] = | 84 pending_transmit_tokens_[valid_token] = |
| 83 AudioDirective(valid_token, op_id, end_time); | 85 AudioDirective(valid_token, op_id, end_time); |
| 84 // All whispernet callbacks will be cleared before we are destructed, so | 86 // All whispernet callbacks will be cleared before we are destructed, so |
| 85 // unretained is safe to use here. | 87 // unretained is safe to use here. |
| 86 encode_token_callback_.Run( | 88 encode_token_callback_.Run( |
| 87 valid_token, | 89 valid_token, |
| 90 use_audible_encoding_, |
| 88 base::Bind(&AudioDirectiveList::OnTokenEncoded, base::Unretained(this))); | 91 base::Bind(&AudioDirectiveList::OnTokenEncoded, base::Unretained(this))); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void AudioDirectiveList::AddReceiveDirective(const std::string& op_id, | 94 void AudioDirectiveList::AddReceiveDirective(const std::string& op_id, |
| 92 base::TimeDelta ttl) { | 95 base::TimeDelta ttl) { |
| 93 active_receive_tokens_.push( | 96 active_receive_tokens_.push( |
| 94 AudioDirective(std::string(), op_id, base::Time::Now() + ttl)); | 97 AudioDirective(std::string(), op_id, base::Time::Now() + ttl)); |
| 95 } | 98 } |
| 96 | 99 |
| 97 scoped_ptr<AudioDirective> AudioDirectiveList::GetNextTransmit() { | 100 scoped_ptr<AudioDirective> AudioDirectiveList::GetNextTransmit() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 138 |
| 136 it->second.samples = samples; | 139 it->second.samples = samples; |
| 137 active_transmit_tokens_.push(it->second); | 140 active_transmit_tokens_.push(it->second); |
| 138 pending_transmit_tokens_.erase(it); | 141 pending_transmit_tokens_.erase(it); |
| 139 | 142 |
| 140 if (!token_added_callback_.is_null()) | 143 if (!token_added_callback_.is_null()) |
| 141 token_added_callback_.Run(); | 144 token_added_callback_.Run(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 } // namespace copresence | 147 } // namespace copresence |
| OLD | NEW |