henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Per | fb45d17 | 2016-02-29 12:07:35 +0100 | [diff] [blame^] | 11 | #ifndef WEBRTC_PC_CHANNELMANAGER_H_ |
| 12 | #define WEBRTC_PC_CHANNELMANAGER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 17 | #include "webrtc/base/criticalsection.h" |
| 18 | #include "webrtc/base/fileutils.h" |
| 19 | #include "webrtc/base/sigslotrepeater.h" |
| 20 | #include "webrtc/base/thread.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 21 | #include "webrtc/media/base/capturemanager.h" |
| 22 | #include "webrtc/media/base/mediaengine.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 23 | #include "webrtc/pc/voicechannel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 25 | namespace webrtc { |
| 26 | class MediaControllerInterface; |
| 27 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 28 | namespace cricket { |
| 29 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | class VoiceChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | |
| 32 | // ChannelManager allows the MediaEngine to run on a separate thread, and takes |
| 33 | // care of marshalling calls between threads. It also creates and keeps track of |
| 34 | // voice and video channels; by doing so, it can temporarily pause all the |
| 35 | // channels when a new audio or video device is chosen. The voice and video |
| 36 | // channels are stored in separate vectors, to easily allow operations on just |
| 37 | // voice or just video channels. |
| 38 | // ChannelManager also allows the application to discover what devices it has |
| 39 | // using device manager. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 40 | class ChannelManager : public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | public sigslot::has_slots<> { |
| 42 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | // For testing purposes. Allows the media engine and data media |
| 44 | // engine and dev manager to be mocks. The ChannelManager takes |
| 45 | // ownership of these objects. |
| 46 | ChannelManager(MediaEngineInterface* me, |
| 47 | DataEngineInterface* dme, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 49 | rtc::Thread* worker); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | // Same as above, but gives an easier default DataEngine. |
| 51 | ChannelManager(MediaEngineInterface* me, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | rtc::Thread* worker); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | ~ChannelManager(); |
| 54 | |
| 55 | // Accessors for the worker thread, allowing it to be set after construction, |
| 56 | // but before Init. set_worker_thread will return false if called after Init. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | rtc::Thread* worker_thread() const { return worker_thread_; } |
| 58 | bool set_worker_thread(rtc::Thread* thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | if (initialized_) return false; |
| 60 | worker_thread_ = thread; |
| 61 | return true; |
| 62 | } |
| 63 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 64 | MediaEngineInterface* media_engine() { return media_engine_.get(); } |
| 65 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | // Retrieves the list of supported audio & video codec types. |
| 67 | // Can be called before starting the media engine. |
| 68 | void GetSupportedAudioCodecs(std::vector<AudioCodec>* codecs) const; |
| 69 | void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 70 | void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const; |
| 71 | void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 72 | void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const; |
| 73 | |
| 74 | // Indicates whether the media engine is started. |
| 75 | bool initialized() const { return initialized_; } |
| 76 | // Starts up the media engine. |
| 77 | bool Init(); |
| 78 | // Shuts down the media engine. |
| 79 | void Terminate(); |
| 80 | |
| 81 | // The operations below all occur on the worker thread. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | // Creates a voice channel, to be associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 83 | VoiceChannel* CreateVoiceChannel( |
| 84 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 85 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 86 | const std::string& content_name, |
| 87 | bool rtcp, |
| 88 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | // Destroys a voice channel created with the Create API. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 90 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | // Creates a video channel, synced with the specified voice channel, and |
| 92 | // associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 93 | VideoChannel* CreateVideoChannel( |
| 94 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 95 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 96 | const std::string& content_name, |
| 97 | bool rtcp, |
| 98 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | // Destroys a video channel created with the Create API. |
| 100 | void DestroyVideoChannel(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 101 | DataChannel* CreateDataChannel(TransportController* transport_controller, |
| 102 | const std::string& content_name, |
| 103 | bool rtcp, |
| 104 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | // Destroys a data channel created with the Create API. |
| 106 | void DestroyDataChannel(DataChannel* data_channel); |
| 107 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | // Indicates whether any channels exist. |
| 109 | bool has_channels() const { |
Fredrik Solenberg | ccb49e7 | 2015-05-19 11:37:56 +0200 | [diff] [blame] | 110 | return (!voice_channels_.empty() || !video_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | } |
| 112 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | bool GetOutputVolume(int* level); |
| 114 | bool SetOutputVolume(int level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 116 | // engines will start offering an RTX codec. Must be called before Init(). |
| 117 | bool SetVideoRtxEnabled(bool enable); |
| 118 | |
| 119 | // Starts/stops the local microphone and enables polling of the input level. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | bool capturing() const { return capturing_; } |
| 121 | |
hbos@webrtc.org | 1e64263 | 2015-02-25 09:49:41 +0000 | [diff] [blame] | 122 | // Gets capturer's supported formats in a thread safe manner |
| 123 | std::vector<cricket::VideoFormat> GetSupportedFormats( |
| 124 | VideoCapturer* capturer) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | // The following are done in the new "CaptureManager" style that |
| 126 | // all local video capturers, processors, and managers should move to. |
| 127 | // TODO(pthatcher): Make methods nicer by having start return a handle that |
| 128 | // can be used for stop and restart, rather than needing to pass around |
| 129 | // formats a a pseudo-handle. |
| 130 | bool StartVideoCapture(VideoCapturer* video_capturer, |
| 131 | const VideoFormat& video_format); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | bool StopVideoCapture(VideoCapturer* video_capturer, |
| 133 | const VideoFormat& video_format); |
| 134 | bool RestartVideoCapture(VideoCapturer* video_capturer, |
| 135 | const VideoFormat& previous_format, |
| 136 | const VideoFormat& desired_format, |
| 137 | CaptureManager::RestartOptions options); |
| 138 | |
nisse | e73afba | 2016-01-28 04:47:08 -0800 | [diff] [blame] | 139 | virtual void AddVideoSink(VideoCapturer* video_capturer, |
| 140 | rtc::VideoSinkInterface<VideoFrame>* sink); |
| 141 | virtual void RemoveVideoSink(VideoCapturer* video_capturer, |
| 142 | rtc::VideoSinkInterface<VideoFrame>* sink); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | bool IsScreencastRunning() const; |
| 144 | |
| 145 | // The operations below occur on the main thread. |
| 146 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 147 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 148 | // bytes. When the limit is reached, logging will stop and the file will be |
| 149 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 150 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 151 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 152 | // Stops recording AEC dump. |
| 153 | void StopAecDump(); |
| 154 | |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 155 | // Starts RtcEventLog using existing file. |
| 156 | bool StartRtcEventLog(rtc::PlatformFile file); |
| 157 | |
| 158 | // Stops logging RtcEventLog. |
| 159 | void StopRtcEventLog(); |
| 160 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange; |
| 162 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | private: |
| 164 | typedef std::vector<VoiceChannel*> VoiceChannels; |
| 165 | typedef std::vector<VideoChannel*> VideoChannels; |
| 166 | typedef std::vector<DataChannel*> DataChannels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | |
| 168 | void Construct(MediaEngineInterface* me, |
| 169 | DataEngineInterface* dme, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 170 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 171 | rtc::Thread* worker_thread); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 172 | bool InitMediaEngine_w(); |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 173 | void DestructorDeletes_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | void Terminate_w(); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 175 | VoiceChannel* CreateVoiceChannel_w( |
| 176 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 177 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 178 | const std::string& content_name, |
| 179 | bool rtcp, |
| 180 | const AudioOptions& options); |
| 181 | void DestroyVoiceChannel_w(VoiceChannel* voice_channel); |
| 182 | VideoChannel* CreateVideoChannel_w( |
| 183 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 184 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 185 | const std::string& content_name, |
| 186 | bool rtcp, |
| 187 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | void DestroyVideoChannel_w(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 189 | DataChannel* CreateDataChannel_w(TransportController* transport_controller, |
| 190 | const std::string& content_name, |
| 191 | bool rtcp, |
| 192 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 193 | void DestroyDataChannel_w(DataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | void OnVideoCaptureStateChange(VideoCapturer* capturer, |
| 195 | CaptureState result); |
hbos@webrtc.org | 1e64263 | 2015-02-25 09:49:41 +0000 | [diff] [blame] | 196 | void GetSupportedFormats_w( |
| 197 | VideoCapturer* capturer, |
| 198 | std::vector<cricket::VideoFormat>* out_formats) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | bool IsScreencastRunning_w() const; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 200 | virtual void OnMessage(rtc::Message *message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 202 | rtc::scoped_ptr<MediaEngineInterface> media_engine_; |
| 203 | rtc::scoped_ptr<DataEngineInterface> data_media_engine_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 204 | rtc::scoped_ptr<CaptureManager> capture_manager_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 205 | bool initialized_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 206 | rtc::Thread* main_thread_; |
| 207 | rtc::Thread* worker_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | |
| 209 | VoiceChannels voice_channels_; |
| 210 | VideoChannels video_channels_; |
| 211 | DataChannels data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | int audio_output_volume_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | bool enable_rtx_; |
| 215 | |
| 216 | bool capturing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | } // namespace cricket |
| 220 | |
Per | fb45d17 | 2016-02-29 12:07:35 +0100 | [diff] [blame^] | 221 | #endif // WEBRTC_PC_CHANNELMANAGER_H_ |