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