blob: 89b9e1d4eb076862f7570b12e2b7b81a4b1430bb [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Perfb45d172016-02-29 12:07:35 +010011#ifndef WEBRTC_PC_CHANNELMANAGER_H_
12#define WEBRTC_PC_CHANNELMANAGER_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15#include <vector>
16
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000017#include "webrtc/base/fileutils.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000018#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/mediaengine.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010020#include "webrtc/pc/voicechannel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
Fredrik Solenberg709ed672015-09-15 12:26:33 +020022namespace webrtc {
23class MediaControllerInterface;
24}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025namespace cricket {
26
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027class VoiceChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
29// ChannelManager allows the MediaEngine to run on a separate thread, and takes
30// care of marshalling calls between threads. It also creates and keeps track of
31// voice and video channels; by doing so, it can temporarily pause all the
32// channels when a new audio or video device is chosen. The voice and video
33// channels are stored in separate vectors, to easily allow operations on just
34// voice or just video channels.
35// ChannelManager also allows the application to discover what devices it has
36// using device manager.
perkjc11b1842016-03-07 17:34:13 -080037class ChannelManager {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039 // For testing purposes. Allows the media engine and data media
40 // engine and dev manager to be mocks. The ChannelManager takes
41 // ownership of these objects.
42 ChannelManager(MediaEngineInterface* me,
43 DataEngineInterface* dme,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000044 rtc::Thread* worker);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045 // Same as above, but gives an easier default DataEngine.
46 ChannelManager(MediaEngineInterface* me,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047 rtc::Thread* worker);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 ~ChannelManager();
49
50 // Accessors for the worker thread, allowing it to be set after construction,
51 // but before Init. set_worker_thread will return false if called after Init.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052 rtc::Thread* worker_thread() const { return worker_thread_; }
53 bool set_worker_thread(rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 if (initialized_) return false;
55 worker_thread_ = thread;
56 return true;
57 }
58
Fredrik Solenberg709ed672015-09-15 12:26:33 +020059 MediaEngineInterface* media_engine() { return media_engine_.get(); }
60
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 // Retrieves the list of supported audio & video codec types.
62 // Can be called before starting the media engine.
63 void GetSupportedAudioCodecs(std::vector<AudioCodec>* codecs) const;
64 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
65 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
66 void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
67 void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const;
68
69 // Indicates whether the media engine is started.
70 bool initialized() const { return initialized_; }
71 // Starts up the media engine.
72 bool Init();
73 // Shuts down the media engine.
74 void Terminate();
75
76 // The operations below all occur on the worker thread.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 // Creates a voice channel, to be associated with the specified session.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020078 VoiceChannel* CreateVoiceChannel(
79 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -070080 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020081 const std::string& content_name,
82 bool rtcp,
83 const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 // Destroys a voice channel created with the Create API.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020085 void DestroyVoiceChannel(VoiceChannel* voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 // Creates a video channel, synced with the specified voice channel, and
87 // associated with the specified session.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020088 VideoChannel* CreateVideoChannel(
89 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -070090 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020091 const std::string& content_name,
92 bool rtcp,
93 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 // Destroys a video channel created with the Create API.
95 void DestroyVideoChannel(VideoChannel* video_channel);
deadbeefcbecd352015-09-23 11:50:27 -070096 DataChannel* CreateDataChannel(TransportController* transport_controller,
97 const std::string& content_name,
98 bool rtcp,
99 DataChannelType data_channel_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 // Destroys a data channel created with the Create API.
101 void DestroyDataChannel(DataChannel* data_channel);
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 // Indicates whether any channels exist.
104 bool has_channels() const {
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200105 return (!voice_channels_.empty() || !video_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 }
107
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 bool GetOutputVolume(int* level);
109 bool SetOutputVolume(int level);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 // RTX will be enabled/disabled in engines that support it. The supporting
111 // engines will start offering an RTX codec. Must be called before Init().
112 bool SetVideoRtxEnabled(bool enable);
113
114 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 bool capturing() const { return capturing_; }
116
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 // The operations below occur on the main thread.
118
ivocd66b44d2016-01-15 03:06:36 -0800119 // Starts AEC dump using existing file, with a specified maximum file size in
120 // bytes. When the limit is reached, logging will stop and the file will be
121 // closed. If max_size_bytes is set to <= 0, no limit will be used.
122 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000123
ivoc797ef122015-10-22 03:25:41 -0700124 // Stops recording AEC dump.
125 void StopAecDump();
126
ivoc112a3d82015-10-16 02:22:18 -0700127 // Starts RtcEventLog using existing file.
128 bool StartRtcEventLog(rtc::PlatformFile file);
129
130 // Stops logging RtcEventLog.
131 void StopRtcEventLog();
132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 private:
134 typedef std::vector<VoiceChannel*> VoiceChannels;
135 typedef std::vector<VideoChannel*> VideoChannels;
136 typedef std::vector<DataChannel*> DataChannels;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137
138 void Construct(MediaEngineInterface* me,
139 DataEngineInterface* dme,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000140 rtc::Thread* worker_thread);
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000141 bool InitMediaEngine_w();
hbos@webrtc.org4aef5fe2015-02-25 10:09:05 +0000142 void DestructorDeletes_w();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 void Terminate_w();
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200144 VoiceChannel* CreateVoiceChannel_w(
145 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700146 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200147 const std::string& content_name,
148 bool rtcp,
149 const AudioOptions& options);
150 void DestroyVoiceChannel_w(VoiceChannel* voice_channel);
151 VideoChannel* CreateVideoChannel_w(
152 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700153 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200154 const std::string& content_name,
155 bool rtcp,
156 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 void DestroyVideoChannel_w(VideoChannel* video_channel);
deadbeefcbecd352015-09-23 11:50:27 -0700158 DataChannel* CreateDataChannel_w(TransportController* transport_controller,
159 const std::string& content_name,
160 bool rtcp,
161 DataChannelType data_channel_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 void DestroyDataChannel_w(DataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 rtc::scoped_ptr<MediaEngineInterface> media_engine_;
165 rtc::scoped_ptr<DataEngineInterface> data_media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 bool initialized_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000167 rtc::Thread* main_thread_;
168 rtc::Thread* worker_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169
170 VoiceChannels voice_channels_;
171 VideoChannels video_channels_;
172 DataChannels data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 int audio_output_volume_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 bool enable_rtx_;
176
177 bool capturing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178};
179
180} // namespace cricket
181
Perfb45d172016-02-29 12:07:35 +0100182#endif // WEBRTC_PC_CHANNELMANAGER_H_