blob: 9776435f66dab01ec2ae89fecae5b830c6a788c4 [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
andresp@webrtc.org04253922013-05-14 12:10:58 +000017#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.orgb015cbe2012-10-22 18:19:23 +000025
26namespace webrtc {
27
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000028class Config;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000029class CriticalSectionWrapper;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030class ProcessThread;
asapersson@webrtc.orgc4af4cf2013-11-20 12:46:11 +000031class RtcpRttStats;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032class ViEChannel;
33class ViEEncoder;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000034class 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,
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000047 const Config& config);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000048 ~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.
53 int CreateChannel(int* channel_id);
54
55 // Creates a new channel grouped with |original_channel|. The new channel
56 // will get its own |ViEEncoder| if |sender| is set to true. It will be a
57 // receive only channel, without an own |ViEEncoder| if |sender| is false.
58 int CreateChannel(int* channel_id, int original_channel, bool sender);
59
60 // Deletes a channel.
61 int DeleteChannel(int channel_id);
62
63 // Set the voice engine instance to be used by all video channels.
64 int SetVoiceEngine(VoiceEngine* voice_engine);
65
66 // Enables lip sync of the channel.
67 int ConnectVoiceChannel(int channel_id, int audio_channel_id);
68
69 // Disables lip sync of the channel.
70 int DisconnectVoiceChannel(int channel_id);
71
72 VoiceEngine* GetVoiceEngine();
73
74 // Adds a channel to include when sending REMB.
75 bool SetRembStatus(int channel_id, bool sender, bool receiver);
76
solenberg@webrtc.orgf40e9b62013-05-27 16:02:56 +000077 // Switches a channel and its associated group to use (or not) the absolute
78 // send time header extension with |id|.
79 bool SetReceiveAbsoluteSendTimeStatus(int channel_id, bool enable, int id);
80
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +000081 // 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
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000085 private:
86 // Creates a channel object connected to |vie_encoder|. Assumed to be called
87 // protected.
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +000088 bool CreateChannelObject(int channel_id,
89 ViEEncoder* vie_encoder,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000090 RtcpBandwidthObserver* bandwidth_observer,
91 RemoteBitrateEstimator* remote_bitrate_estimator,
asapersson@webrtc.orgc4af4cf2013-11-20 12:46:11 +000092 RtcpRttStats* rtcp_rtt_stats,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000093 RtcpIntraFrameObserver* intra_frame_observer,
94 bool sender);
95
96 // Used by ViEChannelScoped, forcing a manager user to use scoped.
97 // Returns a pointer to the channel with id 'channel_id'.
98 ViEChannel* ViEChannelPtr(int channel_id) const;
99
100 // Methods used by ViECaptureScoped and ViEEncoderScoped.
101 // Gets the ViEEncoder used as input for video_channel_id
102 ViEEncoder* ViEEncoderPtr(int video_channel_id) const;
103
104 // Returns a free channel id, -1 if failing.
105 int FreeChannelId();
106
107 // Returns a previously allocated channel id.
108 void ReturnChannelId(int channel_id);
109
110 // Returns the iterator to the ChannelGroup containing |channel_id|.
111 ChannelGroup* FindGroup(int channel_id);
112
113 // Returns true if at least one other channels uses the same ViEEncoder as
114 // channel_id.
115 bool ChannelUsingViEEncoder(int channel_id) const;
116 void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
117
118 // Protects channel_map_ and free_channel_ids_.
119 CriticalSectionWrapper* channel_id_critsect_;
120 int engine_id_;
121 int number_of_cores_;
122
123 // TODO(mflodman) Make part of channel group.
124 ChannelMap channel_map_;
125 bool* free_channel_ids_;
126 int free_channel_ids_size_;
127
128 // List with all channel groups.
129 std::list<ChannelGroup*> channel_groups_;
130
131 // TODO(mflodman) Make part of channel group.
132 // Maps Channel id -> ViEEncoder.
133 EncoderMap vie_encoder_map_;
134 VoEVideoSync* voice_sync_interface_;
135
136 VoiceEngine* voice_engine_;
137 ProcessThread* module_process_thread_;
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +0000138 const Config& config_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000139};
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_