blob: 04bd37aa8fcdaebf6d1ec807bd552cf5202cb35b [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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
26namespace webrtc {
27
28class CriticalSectionWrapper;
29class MapWrapper;
30class ProcessThread;
31class ViEChannel;
32class ViEEncoder;
33class ViEPerformanceMonitor;
34class VoEVideoSync;
35class VoiceEngine;
36
37typedef std::list<ChannelGroup*> ChannelGroups;
38typedef std::list<ViEChannel*> ChannelList;
39typedef std::map<int, ViEChannel*> ChannelMap;
40typedef std::map<int, ViEEncoder*> EncoderMap;
41
42class ViEChannelManager: private ViEManagerBase {
43 friend class ViEChannelManagerScoped;
44 public:
45 ViEChannelManager(int engine_id,
46 int number_of_cores,
47 ViEPerformanceMonitor* vie_performance_monitor,
48 const OverUseDetectorOptions& options);
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
78 // Sets the bandwidth estimation mode. This can only be changed before
79 // adding a channel.
80 bool SetBandwidthEstimationMode(BandwidthEstimationMode mode);
81
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
86 private:
87 // Creates a channel object connected to |vie_encoder|. Assumed to be called
88 // protected.
89 bool CreateChannelObject(int channel_id, ViEEncoder* vie_encoder,
90 RtcpBandwidthObserver* bandwidth_observer,
91 RemoteBitrateEstimator* remote_bitrate_estimator,
92 RtcpIntraFrameObserver* intra_frame_observer,
93 bool sender);
94
95 // Used by ViEChannelScoped, forcing a manager user to use scoped.
96 // Returns a pointer to the channel with id 'channel_id'.
97 ViEChannel* ViEChannelPtr(int channel_id) const;
98
99 // Methods used by ViECaptureScoped and ViEEncoderScoped.
100 // Gets the ViEEncoder used as input for video_channel_id
101 ViEEncoder* ViEEncoderPtr(int video_channel_id) const;
102
103 // Returns a free channel id, -1 if failing.
104 int FreeChannelId();
105
106 // Returns a previously allocated channel id.
107 void ReturnChannelId(int channel_id);
108
109 // Returns the iterator to the ChannelGroup containing |channel_id|.
110 ChannelGroup* FindGroup(int channel_id);
111
112 // Returns true if at least one other channels uses the same ViEEncoder as
113 // channel_id.
114 bool ChannelUsingViEEncoder(int channel_id) const;
115 void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
116
117 // Protects channel_map_ and free_channel_ids_.
118 CriticalSectionWrapper* channel_id_critsect_;
119 int engine_id_;
120 int number_of_cores_;
121
122 // TODO(mflodman) Make part of channel group.
123 ChannelMap channel_map_;
124 bool* free_channel_ids_;
125 int free_channel_ids_size_;
126
127 // List with all channel groups.
128 std::list<ChannelGroup*> channel_groups_;
129
130 // TODO(mflodman) Make part of channel group.
131 // Maps Channel id -> ViEEncoder.
132 EncoderMap vie_encoder_map_;
133 VoEVideoSync* voice_sync_interface_;
134
135 VoiceEngine* voice_engine_;
136 ProcessThread* module_process_thread_;
137 const OverUseDetectorOptions& over_use_detector_options_;
138 RemoteBitrateEstimator::EstimationMode bwe_mode_;
139};
140
141class ViEChannelManagerScoped: private ViEManagerScopedBase {
142 public:
143 explicit ViEChannelManagerScoped(
144 const ViEChannelManager& vie_channel_manager);
145 ViEChannel* Channel(int vie_channel_id) const;
146 ViEEncoder* Encoder(int vie_channel_id) const;
147
148 // Returns true if at least one other channels uses the same ViEEncoder as
149 // channel_id.
150 bool ChannelUsingViEEncoder(int channel_id) const;
151
152 // Returns a list with pointers to all channels using the same encoder as the
153 // channel with |channel_id|, including the one with the specified id.
154 void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
155};
156
157} // namespace webrtc
158
159#endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_