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 | |
andresp@webrtc.org | 0425392 | 2013-05-14 12:10:58 +0000 | [diff] [blame] | 17 | #include "webrtc/engine_configurations.h" |
| 18 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 19 | #include "webrtc/typedefs.h" |
| 20 | #include "webrtc/video_engine/include/vie_rtp_rtcp.h" |
| 21 | #include "webrtc/video_engine/vie_channel_group.h" |
| 22 | #include "webrtc/video_engine/vie_defines.h" |
| 23 | #include "webrtc/video_engine/vie_manager_base.h" |
| 24 | #include "webrtc/video_engine/vie_remb.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 28 | class Config; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 29 | class CriticalSectionWrapper; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | class ProcessThread; |
asapersson@webrtc.org | c4af4cf | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 31 | class RtcpRttStats; |
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, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 47 | const Config& config); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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. |
henrik.lundin@webrtc.org | d2f95a8 | 2014-01-29 08:47:15 +0000 | [diff] [blame] | 53 | int CreateChannel(int* channel_id, |
| 54 | const Config* config); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 55 | |
| 56 | // Creates a new channel grouped with |original_channel|. The new channel |
| 57 | // will get its own |ViEEncoder| if |sender| is set to true. It will be a |
| 58 | // receive only channel, without an own |ViEEncoder| if |sender| is false. |
| 59 | int CreateChannel(int* channel_id, int original_channel, bool sender); |
| 60 | |
| 61 | // Deletes a channel. |
| 62 | int DeleteChannel(int channel_id); |
| 63 | |
| 64 | // Set the voice engine instance to be used by all video channels. |
| 65 | int SetVoiceEngine(VoiceEngine* voice_engine); |
| 66 | |
| 67 | // Enables lip sync of the channel. |
| 68 | int ConnectVoiceChannel(int channel_id, int audio_channel_id); |
| 69 | |
| 70 | // Disables lip sync of the channel. |
| 71 | int DisconnectVoiceChannel(int channel_id); |
| 72 | |
| 73 | VoiceEngine* GetVoiceEngine(); |
| 74 | |
| 75 | // Adds a channel to include when sending REMB. |
| 76 | bool SetRembStatus(int channel_id, bool sender, bool receiver); |
| 77 | |
solenberg@webrtc.org | 2f0c5f7 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 78 | bool SetReservedTransmitBitrate(int channel_id, |
| 79 | uint32_t reserved_transmit_bitrate_bps); |
| 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 | |
stefan@webrtc.org | 5d8c954 | 2014-03-25 10:37:31 +0000 | [diff] [blame] | 85 | // Sets bandwidth estimation related configurations. |
| 86 | bool SetBandwidthEstimationConfig(int channel_id, |
| 87 | const webrtc::Config& config); |
| 88 | |
stefan@webrtc.org | 4d61a36 | 2014-05-02 12:35:37 +0000 | [diff] [blame] | 89 | bool GetEstimatedSendBandwidth(int channel_id, |
| 90 | uint32_t* estimated_bandwidth) const; |
| 91 | bool GetEstimatedReceiveBandwidth(int channel_id, |
| 92 | uint32_t* estimated_bandwidth) const; |
| 93 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 94 | private: |
| 95 | // Creates a channel object connected to |vie_encoder|. Assumed to be called |
| 96 | // protected. |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 97 | bool CreateChannelObject(int channel_id, |
| 98 | ViEEncoder* vie_encoder, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 99 | RtcpBandwidthObserver* bandwidth_observer, |
| 100 | RemoteBitrateEstimator* remote_bitrate_estimator, |
asapersson@webrtc.org | c4af4cf | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 101 | RtcpRttStats* rtcp_rtt_stats, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 102 | RtcpIntraFrameObserver* intra_frame_observer, |
| 103 | bool sender); |
| 104 | |
| 105 | // Used by ViEChannelScoped, forcing a manager user to use scoped. |
| 106 | // Returns a pointer to the channel with id 'channel_id'. |
| 107 | ViEChannel* ViEChannelPtr(int channel_id) const; |
| 108 | |
| 109 | // Methods used by ViECaptureScoped and ViEEncoderScoped. |
| 110 | // Gets the ViEEncoder used as input for video_channel_id |
| 111 | ViEEncoder* ViEEncoderPtr(int video_channel_id) const; |
| 112 | |
| 113 | // Returns a free channel id, -1 if failing. |
| 114 | int FreeChannelId(); |
| 115 | |
| 116 | // Returns a previously allocated channel id. |
| 117 | void ReturnChannelId(int channel_id); |
| 118 | |
| 119 | // Returns the iterator to the ChannelGroup containing |channel_id|. |
stefan@webrtc.org | 4d61a36 | 2014-05-02 12:35:37 +0000 | [diff] [blame] | 120 | ChannelGroup* FindGroup(int channel_id) const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 121 | |
| 122 | // Returns true if at least one other channels uses the same ViEEncoder as |
| 123 | // channel_id. |
| 124 | bool ChannelUsingViEEncoder(int channel_id) const; |
| 125 | void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const; |
| 126 | |
| 127 | // Protects channel_map_ and free_channel_ids_. |
| 128 | CriticalSectionWrapper* channel_id_critsect_; |
| 129 | int engine_id_; |
| 130 | int number_of_cores_; |
| 131 | |
| 132 | // TODO(mflodman) Make part of channel group. |
| 133 | ChannelMap channel_map_; |
| 134 | bool* free_channel_ids_; |
| 135 | int free_channel_ids_size_; |
| 136 | |
| 137 | // List with all channel groups. |
| 138 | std::list<ChannelGroup*> channel_groups_; |
| 139 | |
| 140 | // TODO(mflodman) Make part of channel group. |
| 141 | // Maps Channel id -> ViEEncoder. |
| 142 | EncoderMap vie_encoder_map_; |
| 143 | VoEVideoSync* voice_sync_interface_; |
| 144 | |
| 145 | VoiceEngine* voice_engine_; |
| 146 | ProcessThread* module_process_thread_; |
henrik.lundin@webrtc.org | d2f95a8 | 2014-01-29 08:47:15 +0000 | [diff] [blame] | 147 | const Config& engine_config_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | class ViEChannelManagerScoped: private ViEManagerScopedBase { |
| 151 | public: |
| 152 | explicit ViEChannelManagerScoped( |
| 153 | const ViEChannelManager& vie_channel_manager); |
| 154 | ViEChannel* Channel(int vie_channel_id) const; |
| 155 | ViEEncoder* Encoder(int vie_channel_id) const; |
| 156 | |
| 157 | // Returns true if at least one other channels uses the same ViEEncoder as |
| 158 | // channel_id. |
| 159 | bool ChannelUsingViEEncoder(int channel_id) const; |
| 160 | |
| 161 | // Returns a list with pointers to all channels using the same encoder as the |
| 162 | // channel with |channel_id|, including the one with the specified id. |
| 163 | void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const; |
| 164 | }; |
| 165 | |
| 166 | } // namespace webrtc |
| 167 | |
| 168 | #endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_ |