blob: 6895fa36440b0172e0b815a0c8feb47a5507c819 [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;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000033class VoEVideoSync;
34class VoiceEngine;
35
36typedef std::list<ChannelGroup*> ChannelGroups;
37typedef std::list<ViEChannel*> ChannelList;
38typedef std::map<int, ViEChannel*> ChannelMap;
39typedef std::map<int, ViEEncoder*> EncoderMap;
40
41class ViEChannelManager: private ViEManagerBase {
42 friend class ViEChannelManagerScoped;
43 public:
44 ViEChannelManager(int engine_id,
45 int number_of_cores,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000046 const OverUseDetectorOptions& options);
47 ~ViEChannelManager();
48
49 void SetModuleProcessThread(ProcessThread* module_process_thread);
50
51 // Creates a new channel. 'channel_id' will be the id of the created channel.
52 int CreateChannel(int* channel_id);
53
54 // Creates a new channel grouped with |original_channel|. The new channel
55 // will get its own |ViEEncoder| if |sender| is set to true. It will be a
56 // receive only channel, without an own |ViEEncoder| if |sender| is false.
57 int CreateChannel(int* channel_id, int original_channel, bool sender);
58
59 // Deletes a channel.
60 int DeleteChannel(int channel_id);
61
62 // Set the voice engine instance to be used by all video channels.
63 int SetVoiceEngine(VoiceEngine* voice_engine);
64
65 // Enables lip sync of the channel.
66 int ConnectVoiceChannel(int channel_id, int audio_channel_id);
67
68 // Disables lip sync of the channel.
69 int DisconnectVoiceChannel(int channel_id);
70
71 VoiceEngine* GetVoiceEngine();
72
73 // Adds a channel to include when sending REMB.
74 bool SetRembStatus(int channel_id, bool sender, bool receiver);
75
76 // Sets the bandwidth estimation mode. This can only be changed before
77 // adding a channel.
78 bool SetBandwidthEstimationMode(BandwidthEstimationMode mode);
79
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +000080 // Updates the SSRCs for a channel. If one of the SSRCs already is registered,
81 // it will simply be ignored and no error is returned.
82 void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs);
83
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000084 private:
85 // Creates a channel object connected to |vie_encoder|. Assumed to be called
86 // protected.
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +000087 bool CreateChannelObject(int channel_id,
88 ViEEncoder* vie_encoder,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000089 RtcpBandwidthObserver* bandwidth_observer,
90 RemoteBitrateEstimator* remote_bitrate_estimator,
91 RtcpIntraFrameObserver* intra_frame_observer,
92 bool sender);
93
94 // Used by ViEChannelScoped, forcing a manager user to use scoped.
95 // Returns a pointer to the channel with id 'channel_id'.
96 ViEChannel* ViEChannelPtr(int channel_id) const;
97
98 // Methods used by ViECaptureScoped and ViEEncoderScoped.
99 // Gets the ViEEncoder used as input for video_channel_id
100 ViEEncoder* ViEEncoderPtr(int video_channel_id) const;
101
102 // Returns a free channel id, -1 if failing.
103 int FreeChannelId();
104
105 // Returns a previously allocated channel id.
106 void ReturnChannelId(int channel_id);
107
108 // Returns the iterator to the ChannelGroup containing |channel_id|.
109 ChannelGroup* FindGroup(int channel_id);
110
111 // Returns true if at least one other channels uses the same ViEEncoder as
112 // channel_id.
113 bool ChannelUsingViEEncoder(int channel_id) const;
114 void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
115
116 // Protects channel_map_ and free_channel_ids_.
117 CriticalSectionWrapper* channel_id_critsect_;
118 int engine_id_;
119 int number_of_cores_;
120
121 // TODO(mflodman) Make part of channel group.
122 ChannelMap channel_map_;
123 bool* free_channel_ids_;
124 int free_channel_ids_size_;
125
126 // List with all channel groups.
127 std::list<ChannelGroup*> channel_groups_;
128
129 // TODO(mflodman) Make part of channel group.
130 // Maps Channel id -> ViEEncoder.
131 EncoderMap vie_encoder_map_;
132 VoEVideoSync* voice_sync_interface_;
133
134 VoiceEngine* voice_engine_;
135 ProcessThread* module_process_thread_;
136 const OverUseDetectorOptions& over_use_detector_options_;
137 RemoteBitrateEstimator::EstimationMode bwe_mode_;
138};
139
140class ViEChannelManagerScoped: private ViEManagerScopedBase {
141 public:
142 explicit ViEChannelManagerScoped(
143 const ViEChannelManager& vie_channel_manager);
144 ViEChannel* Channel(int vie_channel_id) const;
145 ViEEncoder* Encoder(int vie_channel_id) const;
146
147 // Returns true if at least one other channels uses the same ViEEncoder as
148 // channel_id.
149 bool ChannelUsingViEEncoder(int channel_id) const;
150
151 // Returns a list with pointers to all channels using the same encoder as the
152 // channel with |channel_id|, including the one with the specified id.
153 void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
154};
155
156} // namespace webrtc
157
158#endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_