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; |
| 30 | class MapWrapper; |
| 31 | class ProcessThread; |
mflodman@webrtc.org | 78696d3 | 2012-11-26 12:40:15 +0000 | [diff] [blame] | 32 | class RtcpRttObserver; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 33 | class ViEChannel; |
| 34 | class ViEEncoder; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 35 | class VoEVideoSync; |
| 36 | class VoiceEngine; |
| 37 | |
| 38 | typedef std::list<ChannelGroup*> ChannelGroups; |
| 39 | typedef std::list<ViEChannel*> ChannelList; |
| 40 | typedef std::map<int, ViEChannel*> ChannelMap; |
| 41 | typedef std::map<int, ViEEncoder*> EncoderMap; |
| 42 | |
| 43 | class ViEChannelManager: private ViEManagerBase { |
| 44 | friend class ViEChannelManagerScoped; |
| 45 | public: |
| 46 | ViEChannelManager(int engine_id, |
| 47 | int number_of_cores, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 48 | const Config& config); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 49 | ~ViEChannelManager(); |
| 50 | |
| 51 | void SetModuleProcessThread(ProcessThread* module_process_thread); |
| 52 | |
| 53 | // Creates a new channel. 'channel_id' will be the id of the created channel. |
| 54 | int CreateChannel(int* channel_id); |
| 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 | f40e9b6 | 2013-05-27 16:02:56 +0000 | [diff] [blame] | 78 | // Switches a channel and its associated group to use (or not) the absolute |
| 79 | // send time header extension with |id|. |
| 80 | bool SetReceiveAbsoluteSendTimeStatus(int channel_id, bool enable, int id); |
| 81 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 82 | // Updates the SSRCs for a channel. If one of the SSRCs already is registered, |
| 83 | // it will simply be ignored and no error is returned. |
| 84 | void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs); |
| 85 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 86 | private: |
| 87 | // Creates a channel object connected to |vie_encoder|. Assumed to be called |
| 88 | // protected. |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 89 | bool CreateChannelObject(int channel_id, |
| 90 | ViEEncoder* vie_encoder, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 91 | RtcpBandwidthObserver* bandwidth_observer, |
| 92 | RemoteBitrateEstimator* remote_bitrate_estimator, |
mflodman@webrtc.org | 78696d3 | 2012-11-26 12:40:15 +0000 | [diff] [blame] | 93 | RtcpRttObserver* rtcp_rtt_observer, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 94 | RtcpIntraFrameObserver* intra_frame_observer, |
| 95 | bool sender); |
| 96 | |
| 97 | // Used by ViEChannelScoped, forcing a manager user to use scoped. |
| 98 | // Returns a pointer to the channel with id 'channel_id'. |
| 99 | ViEChannel* ViEChannelPtr(int channel_id) const; |
| 100 | |
| 101 | // Methods used by ViECaptureScoped and ViEEncoderScoped. |
| 102 | // Gets the ViEEncoder used as input for video_channel_id |
| 103 | ViEEncoder* ViEEncoderPtr(int video_channel_id) const; |
| 104 | |
| 105 | // Returns a free channel id, -1 if failing. |
| 106 | int FreeChannelId(); |
| 107 | |
| 108 | // Returns a previously allocated channel id. |
| 109 | void ReturnChannelId(int channel_id); |
| 110 | |
| 111 | // Returns the iterator to the ChannelGroup containing |channel_id|. |
| 112 | ChannelGroup* FindGroup(int channel_id); |
| 113 | |
| 114 | // Returns true if at least one other channels uses the same ViEEncoder as |
| 115 | // channel_id. |
| 116 | bool ChannelUsingViEEncoder(int channel_id) const; |
| 117 | void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const; |
| 118 | |
| 119 | // Protects channel_map_ and free_channel_ids_. |
| 120 | CriticalSectionWrapper* channel_id_critsect_; |
| 121 | int engine_id_; |
| 122 | int number_of_cores_; |
| 123 | |
| 124 | // TODO(mflodman) Make part of channel group. |
| 125 | ChannelMap channel_map_; |
| 126 | bool* free_channel_ids_; |
| 127 | int free_channel_ids_size_; |
| 128 | |
| 129 | // List with all channel groups. |
| 130 | std::list<ChannelGroup*> channel_groups_; |
| 131 | |
| 132 | // TODO(mflodman) Make part of channel group. |
| 133 | // Maps Channel id -> ViEEncoder. |
| 134 | EncoderMap vie_encoder_map_; |
| 135 | VoEVideoSync* voice_sync_interface_; |
| 136 | |
| 137 | VoiceEngine* voice_engine_; |
| 138 | ProcessThread* module_process_thread_; |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 139 | const Config& config_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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_ |