| 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_impl.h" | 5 #include "components/copresence/handlers/audio/audio_directive_handler_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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 void AudioDirectiveHandlerImpl::AddInstruction( | 82 void AudioDirectiveHandlerImpl::AddInstruction( |
| 83 const Directive& directive, | 83 const Directive& directive, |
| 84 const std::string& op_id) { | 84 const std::string& op_id) { |
| 85 DCHECK(transmits_lists_.size() == 2u && receives_lists_.size() == 2u) | 85 DCHECK(transmits_lists_.size() == 2u && receives_lists_.size() == 2u) |
| 86 << "Call Initialize() before other AudioDirectiveHandler methods"; | 86 << "Call Initialize() before other AudioDirectiveHandler methods"; |
| 87 | 87 |
| 88 const TokenInstruction& instruction = directive.token_instruction(); | 88 const TokenInstruction& instruction = directive.token_instruction(); |
| 89 base::TimeDelta ttl = | 89 base::TimeDelta ttl = |
| 90 base::TimeDelta::FromMilliseconds(directive.ttl_millis()); | 90 base::TimeDelta::FromMilliseconds(directive.ttl_millis()); |
| 91 const size_t token_length = directive.configuration().token_params().length(); |
| 91 | 92 |
| 92 size_t token_length = 0; | |
| 93 switch (instruction.token_instruction_type()) { | 93 switch (instruction.token_instruction_type()) { |
| 94 case TRANSMIT: | 94 case TRANSMIT: |
| 95 DVLOG(2) << "Audio Transmit Directive received. Token: " | 95 DVLOG(2) << "Audio Transmit Directive received. Token: " |
| 96 << instruction.token_id() | 96 << instruction.token_id() |
| 97 << " with medium=" << instruction.medium() | 97 << " with medium=" << instruction.medium() |
| 98 << " with TTL=" << ttl.InMilliseconds(); | 98 << " with TTL=" << ttl.InMilliseconds(); |
| 99 DCHECK_GT(token_length, 0u); |
| 99 switch (instruction.medium()) { | 100 switch (instruction.medium()) { |
| 100 case AUDIO_ULTRASOUND_PASSBAND: | 101 case AUDIO_ULTRASOUND_PASSBAND: |
| 102 audio_manager_->SetTokenLength(INAUDIBLE, token_length); |
| 101 transmits_lists_[INAUDIBLE]->AddDirective(op_id, directive); | 103 transmits_lists_[INAUDIBLE]->AddDirective(op_id, directive); |
| 102 audio_manager_->SetToken(INAUDIBLE, instruction.token_id()); | 104 audio_manager_->SetToken(INAUDIBLE, instruction.token_id()); |
| 103 break; | 105 break; |
| 104 case AUDIO_AUDIBLE_DTMF: | 106 case AUDIO_AUDIBLE_DTMF: |
| 107 audio_manager_->SetTokenLength(AUDIBLE, token_length); |
| 105 transmits_lists_[AUDIBLE]->AddDirective(op_id, directive); | 108 transmits_lists_[AUDIBLE]->AddDirective(op_id, directive); |
| 106 audio_manager_->SetToken(AUDIBLE, instruction.token_id()); | 109 audio_manager_->SetToken(AUDIBLE, instruction.token_id()); |
| 107 break; | 110 break; |
| 108 default: | 111 default: |
| 109 NOTREACHED(); | 112 NOTREACHED(); |
| 110 } | 113 } |
| 111 break; | 114 break; |
| 115 |
| 112 case RECEIVE: | 116 case RECEIVE: |
| 113 DVLOG(2) << "Audio Receive Directive received." | 117 DVLOG(2) << "Audio Receive Directive received." |
| 114 << " with medium=" << instruction.medium() | 118 << " with medium=" << instruction.medium() |
| 115 << " with TTL=" << ttl.InMilliseconds(); | 119 << " with TTL=" << ttl.InMilliseconds(); |
| 120 DCHECK_GT(token_length, 0u); |
| 116 switch (instruction.medium()) { | 121 switch (instruction.medium()) { |
| 117 case AUDIO_ULTRASOUND_PASSBAND: | 122 case AUDIO_ULTRASOUND_PASSBAND: |
| 123 audio_manager_->SetTokenLength(INAUDIBLE, token_length); |
| 118 receives_lists_[INAUDIBLE]->AddDirective(op_id, directive); | 124 receives_lists_[INAUDIBLE]->AddDirective(op_id, directive); |
| 119 if ((token_length = | |
| 120 directive.configuration().token_params().length()) > 0) | |
| 121 audio_manager_->SetTokenLength(INAUDIBLE, token_length); | |
| 122 break; | 125 break; |
| 123 case AUDIO_AUDIBLE_DTMF: | 126 case AUDIO_AUDIBLE_DTMF: |
| 124 if ((token_length = | 127 audio_manager_->SetTokenLength(AUDIBLE, token_length); |
| 125 directive.configuration().token_params().length()) > 0) | |
| 126 audio_manager_->SetTokenLength(AUDIBLE, token_length); | |
| 127 receives_lists_[AUDIBLE]->AddDirective(op_id, directive); | 128 receives_lists_[AUDIBLE]->AddDirective(op_id, directive); |
| 128 break; | 129 break; |
| 129 default: | 130 default: |
| 130 NOTREACHED(); | 131 NOTREACHED(); |
| 131 } | 132 } |
| 132 break; | 133 break; |
| 134 |
| 133 case UNKNOWN_TOKEN_INSTRUCTION_TYPE: | 135 case UNKNOWN_TOKEN_INSTRUCTION_TYPE: |
| 134 default: | 136 default: |
| 135 LOG(WARNING) << "Unknown Audio Transmit Directive received. type = " | 137 LOG(WARNING) << "Unknown Audio Transmit Directive received. type = " |
| 136 << instruction.token_instruction_type(); | 138 << instruction.token_instruction_type(); |
| 137 } | 139 } |
| 140 |
| 138 ProcessNextInstruction(); | 141 ProcessNextInstruction(); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void AudioDirectiveHandlerImpl::RemoveInstructions(const std::string& op_id) { | 144 void AudioDirectiveHandlerImpl::RemoveInstructions(const std::string& op_id) { |
| 142 DCHECK(transmits_lists_.size() == 2u && receives_lists_.size() == 2u) | 145 DCHECK(transmits_lists_.size() == 2u && receives_lists_.size() == 2u) |
| 143 << "Call Initialize() before other AudioDirectiveHandler methods"; | 146 << "Call Initialize() before other AudioDirectiveHandler methods"; |
| 144 | 147 |
| 145 transmits_lists_[AUDIBLE]->RemoveDirective(op_id); | 148 transmits_lists_[AUDIBLE]->RemoveDirective(op_id); |
| 146 transmits_lists_[INAUDIBLE]->RemoveDirective(op_id); | 149 transmits_lists_[INAUDIBLE]->RemoveDirective(op_id); |
| 147 receives_lists_[AUDIBLE]->RemoveDirective(op_id); | 150 receives_lists_[AUDIBLE]->RemoveDirective(op_id); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 218 |
| 216 *expiry = GetEarliestEventTime(transmits_lists_[AUDIBLE], base::TimeTicks()); | 219 *expiry = GetEarliestEventTime(transmits_lists_[AUDIBLE], base::TimeTicks()); |
| 217 *expiry = GetEarliestEventTime(transmits_lists_[INAUDIBLE], *expiry); | 220 *expiry = GetEarliestEventTime(transmits_lists_[INAUDIBLE], *expiry); |
| 218 *expiry = GetEarliestEventTime(receives_lists_[AUDIBLE], *expiry); | 221 *expiry = GetEarliestEventTime(receives_lists_[AUDIBLE], *expiry); |
| 219 *expiry = GetEarliestEventTime(receives_lists_[INAUDIBLE], *expiry); | 222 *expiry = GetEarliestEventTime(receives_lists_[INAUDIBLE], *expiry); |
| 220 | 223 |
| 221 return !expiry->is_null(); | 224 return !expiry->is_null(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 } // namespace copresence | 227 } // namespace copresence |
| OLD | NEW |