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