andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_ |
| 13 | |
| 14 | #include <list> |
| 15 | #include <map> |
| 16 | |
| 17 | #include "engine_configurations.h" // NOLINT |
| 18 | #include "system_wrappers/interface/scoped_ptr.h" |
| 19 | #include "typedefs.h" // NOLINT |
| 20 | #include "video_engine/include/vie_rtp_rtcp.h" |
| 21 | #include "video_engine/vie_channel_group.h" |
| 22 | #include "video_engine/vie_defines.h" |
| 23 | #include "video_engine/vie_manager_base.h" |
| 24 | #include "video_engine/vie_remb.h" |
| 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | class CriticalSectionWrapper; |
| 29 | class MapWrapper; |
| 30 | class ProcessThread; |
mflodman@webrtc.org | 78696d3 | 2012-11-26 12:40:15 +0000 | [diff] [blame^] | 31 | class RtcpRttObserver; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | class ViEChannel; |
| 33 | class ViEEncoder; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 34 | class VoEVideoSync; |
| 35 | class VoiceEngine; |
| 36 | |
| 37 | typedef std::list<ChannelGroup*> ChannelGroups; |
| 38 | typedef std::list<ViEChannel*> ChannelList; |
| 39 | typedef std::map<int, ViEChannel*> ChannelMap; |
| 40 | typedef std::map<int, ViEEncoder*> EncoderMap; |
| 41 | |
| 42 | class ViEChannelManager: private ViEManagerBase { |
| 43 | friend class ViEChannelManagerScoped; |
| 44 | public: |
| 45 | ViEChannelManager(int engine_id, |
| 46 | int number_of_cores, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 47 | const OverUseDetectorOptions& options); |
| 48 | ~ViEChannelManager(); |
| 49 | |
| 50 | void SetModuleProcessThread(ProcessThread* module_process_thread); |
| 51 | |
| 52 | // Creates a new channel. 'channel_id' will be the id of the created channel. |
| 53 | int CreateChannel(int* channel_id); |
| 54 | |
| 55 | // Creates a new channel grouped with |original_channel|. The new channel |
| 56 | // will get its own |ViEEncoder| if |sender| is set to true. It will be a |
| 57 | // receive only channel, without an own |ViEEncoder| if |sender| is false. |
| 58 | int CreateChannel(int* channel_id, int original_channel, bool sender); |
| 59 | |
| 60 | // Deletes a channel. |
| 61 | int DeleteChannel(int channel_id); |
| 62 | |
| 63 | // Set the voice engine instance to be used by all video channels. |
| 64 | int SetVoiceEngine(VoiceEngine* voice_engine); |
| 65 | |
| 66 | // Enables lip sync of the channel. |
| 67 | int ConnectVoiceChannel(int channel_id, int audio_channel_id); |
| 68 | |
| 69 | // Disables lip sync of the channel. |
| 70 | int DisconnectVoiceChannel(int channel_id); |
| 71 | |
| 72 | VoiceEngine* GetVoiceEngine(); |
| 73 | |
| 74 | // Adds a channel to include when sending REMB. |
| 75 | bool SetRembStatus(int channel_id, bool sender, bool receiver); |
| 76 | |
| 77 | // Sets the bandwidth estimation mode. This can only be changed before |
| 78 | // adding a channel. |
| 79 | bool SetBandwidthEstimationMode(BandwidthEstimationMode mode); |
| 80 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 81 | // Updates the SSRCs for a channel. If one of the SSRCs already is registered, |
| 82 | // it will simply be ignored and no error is returned. |
| 83 | void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs); |
| 84 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 85 | private: |
| 86 | // Creates a channel object connected to |vie_encoder|. Assumed to be called |
| 87 | // protected. |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 88 | bool CreateChannelObject(int channel_id, |
| 89 | ViEEncoder* vie_encoder, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 90 | RtcpBandwidthObserver* bandwidth_observer, |
| 91 | RemoteBitrateEstimator* remote_bitrate_estimator, |
mflodman@webrtc.org | 78696d3 | 2012-11-26 12:40:15 +0000 | [diff] [blame^] | 92 | RtcpRttObserver* rtcp_rtt_observer, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 93 | RtcpIntraFrameObserver* intra_frame_observer, |
| 94 | bool sender); |
| 95 | |
| 96 | // Used by ViEChannelScoped, forcing a manager user to use scoped. |
| 97 | // Returns a pointer to the channel with id 'channel_id'. |
| 98 | ViEChannel* ViEChannelPtr(int channel_id) const; |
| 99 | |
| 100 | // Methods used by ViECaptureScoped and ViEEncoderScoped. |
| 101 | // Gets the ViEEncoder used as input for video_channel_id |
| 102 | ViEEncoder* ViEEncoderPtr(int video_channel_id) const; |
| 103 | |
| 104 | // Returns a free channel id, -1 if failing. |
| 105 | int FreeChannelId(); |
| 106 | |
| 107 | // Returns a previously allocated channel id. |
| 108 | void ReturnChannelId(int channel_id); |
| 109 | |
| 110 | // Returns the iterator to the ChannelGroup containing |channel_id|. |
| 111 | ChannelGroup* FindGroup(int channel_id); |
| 112 | |
| 113 | // Returns true if at least one other channels uses the same ViEEncoder as |
| 114 | // channel_id. |
| 115 | bool ChannelUsingViEEncoder(int channel_id) const; |
| 116 | void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const; |
| 117 | |
| 118 | // Protects channel_map_ and free_channel_ids_. |
| 119 | CriticalSectionWrapper* channel_id_critsect_; |
| 120 | int engine_id_; |
| 121 | int number_of_cores_; |
| 122 | |
| 123 | // TODO(mflodman) Make part of channel group. |
| 124 | ChannelMap channel_map_; |
| 125 | bool* free_channel_ids_; |
| 126 | int free_channel_ids_size_; |
| 127 | |
| 128 | // List with all channel groups. |
| 129 | std::list<ChannelGroup*> channel_groups_; |
| 130 | |
| 131 | // TODO(mflodman) Make part of channel group. |
| 132 | // Maps Channel id -> ViEEncoder. |
| 133 | EncoderMap vie_encoder_map_; |
| 134 | VoEVideoSync* voice_sync_interface_; |
| 135 | |
| 136 | VoiceEngine* voice_engine_; |
| 137 | ProcessThread* module_process_thread_; |
| 138 | const OverUseDetectorOptions& over_use_detector_options_; |
| 139 | RemoteBitrateEstimator::EstimationMode bwe_mode_; |
| 140 | }; |
| 141 | |
| 142 | class ViEChannelManagerScoped: private ViEManagerScopedBase { |
| 143 | public: |
| 144 | explicit ViEChannelManagerScoped( |
| 145 | const ViEChannelManager& vie_channel_manager); |
| 146 | ViEChannel* Channel(int vie_channel_id) const; |
| 147 | ViEEncoder* Encoder(int vie_channel_id) const; |
| 148 | |
| 149 | // Returns true if at least one other channels uses the same ViEEncoder as |
| 150 | // channel_id. |
| 151 | bool ChannelUsingViEEncoder(int channel_id) const; |
| 152 | |
| 153 | // Returns a list with pointers to all channels using the same encoder as the |
| 154 | // channel with |channel_id|, including the one with the specified id. |
| 155 | void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const; |
| 156 | }; |
| 157 | |
| 158 | } // namespace webrtc |
| 159 | |
| 160 | #endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_ |