| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 if (channel->ChannelId() == channel_id) { | 100 if (channel->ChannelId() == channel_id) { |
| 101 to_delete = it; | 101 to_delete = it; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 if (to_delete != channels_.end()) { | 104 if (to_delete != channels_.end()) { |
| 105 reference = *to_delete; | 105 reference = *to_delete; |
| 106 channels_.erase(to_delete); | 106 channels_.erase(to_delete); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 if (reference.channel()) { |
| 110 // Ensure the channel is torn down now, on this thread, since a reference |
| 111 // may still be held on a different thread (e.g. in the audio capture |
| 112 // thread). |
| 113 reference.channel()->Terminate(); |
| 114 } |
| 109 } | 115 } |
| 110 | 116 |
| 111 void ChannelManager::DestroyAllChannels() { | 117 void ChannelManager::DestroyAllChannels() { |
| 112 // Holds references so that Channels are not destroyed while holding this | 118 // Holds references so that Channels are not destroyed while holding this |
| 113 // lock, but rather when the method returns. | 119 // lock, but rather when the method returns. |
| 114 std::vector<ChannelOwner> references; | 120 std::vector<ChannelOwner> references; |
| 115 { | 121 { |
| 116 rtc::CritScope crit(&lock_); | 122 rtc::CritScope crit(&lock_); |
| 117 references = channels_; | 123 references = channels_; |
| 118 channels_.clear(); | 124 channels_.clear(); |
| 119 } | 125 } |
| 126 for (auto& owner : references) { |
| 127 if (owner.channel()) |
| 128 owner.channel()->Terminate(); |
| 129 } |
| 120 } | 130 } |
| 121 | 131 |
| 122 size_t ChannelManager::NumOfChannels() const { | 132 size_t ChannelManager::NumOfChannels() const { |
| 123 rtc::CritScope crit(&lock_); | 133 rtc::CritScope crit(&lock_); |
| 124 return channels_.size(); | 134 return channels_.size(); |
| 125 } | 135 } |
| 126 | 136 |
| 127 ChannelManager::Iterator::Iterator(ChannelManager* channel_manager) | 137 ChannelManager::Iterator::Iterator(ChannelManager* channel_manager) |
| 128 : iterator_pos_(0) { | 138 : iterator_pos_(0) { |
| 129 channel_manager->GetAllChannels(&channels_); | 139 channel_manager->GetAllChannels(&channels_); |
| 130 } | 140 } |
| 131 | 141 |
| 132 Channel* ChannelManager::Iterator::GetChannel() { | 142 Channel* ChannelManager::Iterator::GetChannel() { |
| 133 if (iterator_pos_ < channels_.size()) | 143 if (iterator_pos_ < channels_.size()) |
| 134 return channels_[iterator_pos_].channel(); | 144 return channels_[iterator_pos_].channel(); |
| 135 return NULL; | 145 return NULL; |
| 136 } | 146 } |
| 137 | 147 |
| 138 bool ChannelManager::Iterator::IsValid() { | 148 bool ChannelManager::Iterator::IsValid() { |
| 139 return iterator_pos_ < channels_.size(); | 149 return iterator_pos_ < channels_.size(); |
| 140 } | 150 } |
| 141 | 151 |
| 142 void ChannelManager::Iterator::Increment() { | 152 void ChannelManager::Iterator::Increment() { |
| 143 ++iterator_pos_; | 153 ++iterator_pos_; |
| 144 } | 154 } |
| 145 | 155 |
| 146 } // namespace voe | 156 } // namespace voe |
| 147 } // namespace webrtc | 157 } // namespace webrtc |
| OLD | NEW |