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 |
11 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 11 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
12 #define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 12 #define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/system_wrappers/interface/atomic32.h" | 18 #include "webrtc/system_wrappers/interface/atomic32.h" |
19 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
20 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 class Config; | 24 class Config; |
| 25 class RtcEventLog; |
25 | 26 |
26 namespace voe { | 27 namespace voe { |
27 | 28 |
28 class Channel; | 29 class Channel; |
29 | 30 |
30 // Shared-pointer implementation for keeping track of Channels. The underlying | 31 // Shared-pointer implementation for keeping track of Channels. The underlying |
31 // shared instance will be dropped when no more ChannelOwners point to it. | 32 // shared instance will be dropped when no more ChannelOwners point to it. |
32 // | 33 // |
33 // One common source of ChannelOwner instances are | 34 // One common source of ChannelOwner instances are |
34 // ChannelManager::CreateChannel() and ChannelManager::GetChannel(...). | 35 // ChannelManager::CreateChannel() and ChannelManager::GetChannel(...). |
(...skipping 28 matching lines...) Expand all Loading... |
63 ChannelRef(Channel* channel); | 64 ChannelRef(Channel* channel); |
64 const rtc::scoped_ptr<Channel> channel; | 65 const rtc::scoped_ptr<Channel> channel; |
65 Atomic32 ref_count; | 66 Atomic32 ref_count; |
66 }; | 67 }; |
67 | 68 |
68 ChannelRef* channel_ref_; | 69 ChannelRef* channel_ref_; |
69 }; | 70 }; |
70 | 71 |
71 class ChannelManager { | 72 class ChannelManager { |
72 public: | 73 public: |
73 ChannelManager(uint32_t instance_id, const Config& config); | 74 ChannelManager(uint32_t instance_id, |
| 75 const Config& config, |
| 76 RtcEventLog* const event_log); |
74 | 77 |
75 // Upon construction of an Iterator it will grab a copy of the channel list of | 78 // Upon construction of an Iterator it will grab a copy of the channel list of |
76 // the ChannelManager. The iteration will then occur over this state, not the | 79 // the ChannelManager. The iteration will then occur over this state, not the |
77 // current one of the ChannelManager. As the Iterator holds its own references | 80 // current one of the ChannelManager. As the Iterator holds its own references |
78 // to the Channels, they will remain valid even if they are removed from the | 81 // to the Channels, they will remain valid even if they are removed from the |
79 // ChannelManager. | 82 // ChannelManager. |
80 class Iterator { | 83 class Iterator { |
81 public: | 84 public: |
82 explicit Iterator(ChannelManager* channel_manager); | 85 explicit Iterator(ChannelManager* channel_manager); |
83 | 86 |
84 Channel* GetChannel(); | 87 Channel* GetChannel(); |
85 bool IsValid(); | 88 bool IsValid(); |
86 | 89 |
87 void Increment(); | 90 void Increment(); |
88 | 91 |
89 private: | 92 private: |
90 size_t iterator_pos_; | 93 size_t iterator_pos_; |
91 std::vector<ChannelOwner> channels_; | 94 std::vector<ChannelOwner> channels_; |
92 | 95 |
93 DISALLOW_COPY_AND_ASSIGN(Iterator); | 96 DISALLOW_COPY_AND_ASSIGN(Iterator); |
94 }; | 97 }; |
95 | 98 |
96 // CreateChannel will always return a valid ChannelOwner instance. The channel | 99 // CreateChannel will always return a valid ChannelOwner instance. The channel |
97 // is created either based on internal configuration, i.e. |config_|, by | 100 // is created either based on internal configuration, i.e. |config_| and |
98 // calling CreateChannel(), or using and external configuration | 101 // |event_log_|, by calling CreateChannel(), or using and external |
99 // |external_config| if the overloaded method | 102 // configuration |external_config| and external event log |event_log| if the |
100 // CreateChannel(const Config& external_config) is called. | 103 // overloaded method |
| 104 // CreateChannel(const Config& external_config, RtcEventLog* const event_log) |
| 105 // is called. |
101 ChannelOwner CreateChannel(); | 106 ChannelOwner CreateChannel(); |
102 ChannelOwner CreateChannel(const Config& external_config); | 107 ChannelOwner CreateChannel(const Config& external_config, |
| 108 RtcEventLog* const event_log); |
103 | 109 |
104 // ChannelOwner.channel() will be NULL if channel_id is invalid or no longer | 110 // ChannelOwner.channel() will be NULL if channel_id is invalid or no longer |
105 // exists. This should be checked with ChannelOwner::IsValid(). | 111 // exists. This should be checked with ChannelOwner::IsValid(). |
106 ChannelOwner GetChannel(int32_t channel_id); | 112 ChannelOwner GetChannel(int32_t channel_id); |
107 void GetAllChannels(std::vector<ChannelOwner>* channels); | 113 void GetAllChannels(std::vector<ChannelOwner>* channels); |
108 | 114 |
109 void DestroyChannel(int32_t channel_id); | 115 void DestroyChannel(int32_t channel_id); |
110 void DestroyAllChannels(); | 116 void DestroyAllChannels(); |
111 | 117 |
112 size_t NumOfChannels() const; | 118 size_t NumOfChannels() const; |
113 | 119 |
114 private: | 120 private: |
115 // Create a channel given a configuration, |config|. | 121 // Create a channel given a configuration, |config|. |
116 ChannelOwner CreateChannelInternal(const Config& config); | 122 ChannelOwner CreateChannelInternal(const Config& config, |
| 123 RtcEventLog* const event_log); |
117 | 124 |
118 uint32_t instance_id_; | 125 uint32_t instance_id_; |
119 | 126 |
120 Atomic32 last_channel_id_; | 127 Atomic32 last_channel_id_; |
121 | 128 |
122 rtc::scoped_ptr<CriticalSectionWrapper> lock_; | 129 rtc::scoped_ptr<CriticalSectionWrapper> lock_; |
123 std::vector<ChannelOwner> channels_; | 130 std::vector<ChannelOwner> channels_; |
124 | 131 |
125 const Config& config_; | 132 const Config& config_; |
| 133 RtcEventLog* const event_log_; |
126 | 134 |
127 DISALLOW_COPY_AND_ASSIGN(ChannelManager); | 135 DISALLOW_COPY_AND_ASSIGN(ChannelManager); |
128 }; | 136 }; |
129 } // namespace voe | 137 } // namespace voe |
130 } // namespace webrtc | 138 } // namespace webrtc |
131 | 139 |
132 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 140 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
OLD | NEW |