blob: 15a3752c44a730ae85ecaac07576825a990ffc8c [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
kwiberg31022942016-03-11 14:18:21 -080014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
16#include <vector>
17
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000018#include "webrtc/base/fileutils.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000019#include "webrtc/base/thread.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/media/base/mediaengine.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010021#include "webrtc/pc/voicechannel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
Fredrik Solenberg709ed672015-09-15 12:26:33 +020023namespace webrtc {
24class MediaControllerInterface;
25}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026namespace cricket {
27
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028class VoiceChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30// ChannelManager allows the MediaEngine to run on a separate thread, and takes
31// care of marshalling calls between threads. It also creates and keeps track of
32// voice and video channels; by doing so, it can temporarily pause all the
33// channels when a new audio or video device is chosen. The voice and video
34// channels are stored in separate vectors, to easily allow operations on just
35// voice or just video channels.
36// ChannelManager also allows the application to discover what devices it has
37// using device manager.
perkjc11b1842016-03-07 17:34:13 -080038class ChannelManager {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040 // For testing purposes. Allows the media engine and data media
41 // engine and dev manager to be mocks. The ChannelManager takes
42 // ownership of these objects.
43 ChannelManager(MediaEngineInterface* me,
44 DataEngineInterface* dme,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020045 rtc::Thread* worker_and_network);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046 // Same as above, but gives an easier default DataEngine.
47 ChannelManager(MediaEngineInterface* me,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020048 rtc::Thread* worker,
49 rtc::Thread* network);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 ~ChannelManager();
51
52 // Accessors for the worker thread, allowing it to be set after construction,
53 // but before Init. set_worker_thread will return false if called after Init.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054 rtc::Thread* worker_thread() const { return worker_thread_; }
55 bool set_worker_thread(rtc::Thread* thread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +020056 if (initialized_) {
57 return false;
58 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 worker_thread_ = thread;
60 return true;
61 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020062 rtc::Thread* network_thread() const { return network_thread_; }
63 bool set_network_thread(rtc::Thread* thread) {
64 if (initialized_) {
65 return false;
66 }
67 network_thread_ = thread;
68 return true;
69 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071 MediaEngineInterface* media_engine() { return media_engine_.get(); }
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 // Retrieves the list of supported audio & video codec types.
74 // Can be called before starting the media engine.
ossudedfd282016-06-14 07:12:39 -070075 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
76 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
magjed3cf8ece2016-11-10 03:36:53 -080078 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
80 void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const;
81
82 // Indicates whether the media engine is started.
83 bool initialized() const { return initialized_; }
84 // Starts up the media engine.
85 bool Init();
86 // Shuts down the media engine.
87 void Terminate();
88
89 // The operations below all occur on the worker thread.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 // Creates a voice channel, to be associated with the specified session.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020091 VoiceChannel* CreateVoiceChannel(
92 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -070093 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020094 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -070095 const std::string* bundle_transport_name,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020096 bool rtcp,
97 const AudioOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 // Destroys a voice channel created with the Create API.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020099 void DestroyVoiceChannel(VoiceChannel* voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 // Creates a video channel, synced with the specified voice channel, and
101 // associated with the specified session.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200102 VideoChannel* CreateVideoChannel(
103 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700104 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200105 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700106 const std::string* bundle_transport_name,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200107 bool rtcp,
108 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 // Destroys a video channel created with the Create API.
110 void DestroyVideoChannel(VideoChannel* video_channel);
deadbeefcbecd352015-09-23 11:50:27 -0700111 DataChannel* CreateDataChannel(TransportController* transport_controller,
112 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700113 const std::string* bundle_transport_name,
deadbeefcbecd352015-09-23 11:50:27 -0700114 bool rtcp,
115 DataChannelType data_channel_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 // Destroys a data channel created with the Create API.
117 void DestroyDataChannel(DataChannel* data_channel);
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 // Indicates whether any channels exist.
120 bool has_channels() const {
Fredrik Solenbergccb49e72015-05-19 11:37:56 +0200121 return (!voice_channels_.empty() || !video_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 }
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 // RTX will be enabled/disabled in engines that support it. The supporting
125 // engines will start offering an RTX codec. Must be called before Init().
126 bool SetVideoRtxEnabled(bool enable);
127
jbauchcb560652016-08-04 05:20:32 -0700128 // Define crypto options to set on newly created channels. Doesn't change
129 // options on already created channels.
130 bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options);
131
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 bool capturing() const { return capturing_; }
134
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 // The operations below occur on the main thread.
136
ivocd66b44d2016-01-15 03:06:36 -0800137 // Starts AEC dump using existing file, with a specified maximum file size in
138 // bytes. When the limit is reached, logging will stop and the file will be
139 // closed. If max_size_bytes is set to <= 0, no limit will be used.
140 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000141
ivoc797ef122015-10-22 03:25:41 -0700142 // Stops recording AEC dump.
143 void StopAecDump();
144
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 private:
146 typedef std::vector<VoiceChannel*> VoiceChannels;
147 typedef std::vector<VideoChannel*> VideoChannels;
148 typedef std::vector<DataChannel*> DataChannels;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149
150 void Construct(MediaEngineInterface* me,
151 DataEngineInterface* dme,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200152 rtc::Thread* worker_thread,
153 rtc::Thread* network_thread);
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000154 bool InitMediaEngine_w();
hbos@webrtc.org4aef5fe2015-02-25 10:09:05 +0000155 void DestructorDeletes_w();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 void Terminate_w();
jbauchcb560652016-08-04 05:20:32 -0700157 bool SetCryptoOptions_w(const rtc::CryptoOptions& crypto_options);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200158 VoiceChannel* CreateVoiceChannel_w(
159 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700160 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200161 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700162 const std::string* bundle_transport_name,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200163 bool rtcp,
164 const AudioOptions& options);
165 void DestroyVoiceChannel_w(VoiceChannel* voice_channel);
166 VideoChannel* CreateVideoChannel_w(
167 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700168 TransportController* transport_controller,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200169 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700170 const std::string* bundle_transport_name,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200171 bool rtcp,
172 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 void DestroyVideoChannel_w(VideoChannel* video_channel);
deadbeefcbecd352015-09-23 11:50:27 -0700174 DataChannel* CreateDataChannel_w(TransportController* transport_controller,
175 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700176 const std::string* bundle_transport_name,
deadbeefcbecd352015-09-23 11:50:27 -0700177 bool rtcp,
178 DataChannelType data_channel_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 void DestroyDataChannel_w(DataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180
kwiberg31022942016-03-11 14:18:21 -0800181 std::unique_ptr<MediaEngineInterface> media_engine_;
182 std::unique_ptr<DataEngineInterface> data_media_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 bool initialized_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000184 rtc::Thread* main_thread_;
185 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200186 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187
188 VoiceChannels voice_channels_;
189 VideoChannels video_channels_;
190 DataChannels data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 bool enable_rtx_;
jbauchcb560652016-08-04 05:20:32 -0700193 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194
195 bool capturing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196};
197
198} // namespace cricket
199
Perfb45d172016-02-29 12:07:35 +0100200#endif // WEBRTC_PC_CHANNELMANAGER_H_