Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / video_engine / vie_channel_manager.h
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
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"
25
26 namespace webrtc {
27
28 class Config;
29 class CriticalSectionWrapper;
30 class ProcessThread;
31 class RtcpRttStats;
32 class ViEChannel;
33 class ViEEncoder;
34 class VoEVideoSync;
35 class VoiceEngine;
36
37 typedef std::list<ChannelGroup*> ChannelGroups;
38 typedef std::list<ViEChannel*> ChannelList;
39 typedef std::map<int, ViEChannel*> ChannelMap;
40 typedef std::map<int, ViEEncoder*> EncoderMap;
41
42 class ViEChannelManager: private ViEManagerBase {
43   friend class ViEChannelManagerScoped;
44  public:
45   ViEChannelManager(int engine_id,
46                     int number_of_cores,
47                     const Config& config);
48   ~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                     const Config* config);
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   // Updates the SSRCs for a channel. If one of the SSRCs already is registered,
79   // it will simply be ignored and no error is returned.
80   void UpdateSsrcs(int channel_id, const std::list<unsigned int>& ssrcs);
81
82  private:
83   // Creates a channel object connected to |vie_encoder|. Assumed to be called
84   // protected.
85   bool CreateChannelObject(int channel_id,
86                            ViEEncoder* vie_encoder,
87                            RtcpBandwidthObserver* bandwidth_observer,
88                            RemoteBitrateEstimator* remote_bitrate_estimator,
89                            RtcpRttStats* rtcp_rtt_stats,
90                            RtcpIntraFrameObserver* intra_frame_observer,
91                            bool sender);
92
93   // Used by ViEChannelScoped, forcing a manager user to use scoped.
94   // Returns a pointer to the channel with id 'channel_id'.
95   ViEChannel* ViEChannelPtr(int channel_id) const;
96
97   // Methods used by ViECaptureScoped and ViEEncoderScoped.
98   // Gets the ViEEncoder used as input for video_channel_id
99   ViEEncoder* ViEEncoderPtr(int video_channel_id) const;
100
101   // Returns a free channel id, -1 if failing.
102   int FreeChannelId();
103
104   // Returns a previously allocated channel id.
105   void ReturnChannelId(int channel_id);
106
107   // Returns the iterator to the ChannelGroup containing |channel_id|.
108   ChannelGroup* FindGroup(int channel_id);
109
110   // Returns true if at least one other channels uses the same ViEEncoder as
111   // channel_id.
112   bool ChannelUsingViEEncoder(int channel_id) const;
113   void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
114
115   // Protects channel_map_ and free_channel_ids_.
116   CriticalSectionWrapper* channel_id_critsect_;
117   int engine_id_;
118   int number_of_cores_;
119
120   // TODO(mflodman) Make part of channel group.
121   ChannelMap channel_map_;
122   bool* free_channel_ids_;
123   int free_channel_ids_size_;
124
125   // List with all channel groups.
126   std::list<ChannelGroup*> channel_groups_;
127
128   // TODO(mflodman) Make part of channel group.
129   // Maps Channel id -> ViEEncoder.
130   EncoderMap vie_encoder_map_;
131   VoEVideoSync* voice_sync_interface_;
132
133   VoiceEngine* voice_engine_;
134   ProcessThread* module_process_thread_;
135   const Config& engine_config_;
136 };
137
138 class ViEChannelManagerScoped: private ViEManagerScopedBase {
139  public:
140   explicit ViEChannelManagerScoped(
141       const ViEChannelManager& vie_channel_manager);
142   ViEChannel* Channel(int vie_channel_id) const;
143   ViEEncoder* Encoder(int vie_channel_id) const;
144
145   // Returns true if at least one other channels uses the same ViEEncoder as
146   // channel_id.
147   bool ChannelUsingViEEncoder(int channel_id) const;
148
149   // Returns a list with pointers to all channels using the same encoder as the
150   // channel with |channel_id|, including the one with the specified id.
151   void ChannelsUsingViEEncoder(int channel_id, ChannelList* channels) const;
152 };
153
154 }  // namespace webrtc
155
156 #endif  // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_