henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_SESSION_MEDIA_CHANNELMANAGER_H_ |
| 29 | #define TALK_SESSION_MEDIA_CHANNELMANAGER_H_ |
| 30 | |
| 31 | #include <string> |
| 32 | #include <vector> |
| 33 | |
buildbot@webrtc.org | 5b1ebac | 2014-08-07 17:18:00 +0000 | [diff] [blame] | 34 | #include "talk/session/media/voicechannel.h" |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 35 | #include "webrtc/base/criticalsection.h" |
| 36 | #include "webrtc/base/fileutils.h" |
| 37 | #include "webrtc/base/sigslotrepeater.h" |
| 38 | #include "webrtc/base/thread.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame^] | 39 | #include "webrtc/media/base/capturemanager.h" |
| 40 | #include "webrtc/media/base/mediaengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 42 | namespace webrtc { |
| 43 | class MediaControllerInterface; |
| 44 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | namespace cricket { |
| 46 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | class VoiceChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | // ChannelManager allows the MediaEngine to run on a separate thread, and takes |
| 50 | // care of marshalling calls between threads. It also creates and keeps track of |
| 51 | // voice and video channels; by doing so, it can temporarily pause all the |
| 52 | // channels when a new audio or video device is chosen. The voice and video |
| 53 | // channels are stored in separate vectors, to easily allow operations on just |
| 54 | // voice or just video channels. |
| 55 | // ChannelManager also allows the application to discover what devices it has |
| 56 | // using device manager. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | class ChannelManager : public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | public sigslot::has_slots<> { |
| 59 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | // For testing purposes. Allows the media engine and data media |
| 61 | // engine and dev manager to be mocks. The ChannelManager takes |
| 62 | // ownership of these objects. |
| 63 | ChannelManager(MediaEngineInterface* me, |
| 64 | DataEngineInterface* dme, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 66 | rtc::Thread* worker); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | // Same as above, but gives an easier default DataEngine. |
| 68 | ChannelManager(MediaEngineInterface* me, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 69 | rtc::Thread* worker); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | ~ChannelManager(); |
| 71 | |
| 72 | // Accessors for the worker thread, allowing it to be set after construction, |
| 73 | // 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] | 74 | rtc::Thread* worker_thread() const { return worker_thread_; } |
| 75 | bool set_worker_thread(rtc::Thread* thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | if (initialized_) return false; |
| 77 | worker_thread_ = thread; |
| 78 | return true; |
| 79 | } |
| 80 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 81 | MediaEngineInterface* media_engine() { return media_engine_.get(); } |
| 82 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | // Retrieves the list of supported audio & video codec types. |
| 84 | // Can be called before starting the media engine. |
| 85 | void GetSupportedAudioCodecs(std::vector<AudioCodec>* codecs) const; |
| 86 | void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 87 | void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const; |
| 88 | void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 89 | void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const; |
| 90 | |
| 91 | // Indicates whether the media engine is started. |
| 92 | bool initialized() const { return initialized_; } |
| 93 | // Starts up the media engine. |
| 94 | bool Init(); |
| 95 | // Shuts down the media engine. |
| 96 | void Terminate(); |
| 97 | |
| 98 | // The operations below all occur on the worker thread. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | // Creates a voice channel, to be associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 100 | VoiceChannel* CreateVoiceChannel( |
| 101 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 102 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 103 | const std::string& content_name, |
| 104 | bool rtcp, |
| 105 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | // Destroys a voice channel created with the Create API. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 107 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | // Creates a video channel, synced with the specified voice channel, and |
| 109 | // associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 110 | VideoChannel* CreateVideoChannel( |
| 111 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 112 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 113 | const std::string& content_name, |
| 114 | bool rtcp, |
| 115 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Destroys a video channel created with the Create API. |
| 117 | void DestroyVideoChannel(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 118 | DataChannel* CreateDataChannel(TransportController* transport_controller, |
| 119 | const std::string& content_name, |
| 120 | bool rtcp, |
| 121 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | // Destroys a data channel created with the Create API. |
| 123 | void DestroyDataChannel(DataChannel* data_channel); |
| 124 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | // Indicates whether any channels exist. |
| 126 | bool has_channels() const { |
Fredrik Solenberg | ccb49e7 | 2015-05-19 11:37:56 +0200 | [diff] [blame] | 127 | return (!voice_channels_.empty() || !video_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | } |
| 129 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | bool GetOutputVolume(int* level); |
| 131 | bool SetOutputVolume(int level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 133 | // engines will start offering an RTX codec. Must be called before Init(). |
| 134 | bool SetVideoRtxEnabled(bool enable); |
| 135 | |
| 136 | // 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] | 137 | bool capturing() const { return capturing_; } |
| 138 | |
hbos@webrtc.org | 1e64263 | 2015-02-25 09:49:41 +0000 | [diff] [blame] | 139 | // Gets capturer's supported formats in a thread safe manner |
| 140 | std::vector<cricket::VideoFormat> GetSupportedFormats( |
| 141 | VideoCapturer* capturer) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | // The following are done in the new "CaptureManager" style that |
| 143 | // all local video capturers, processors, and managers should move to. |
| 144 | // TODO(pthatcher): Make methods nicer by having start return a handle that |
| 145 | // can be used for stop and restart, rather than needing to pass around |
| 146 | // formats a a pseudo-handle. |
| 147 | bool StartVideoCapture(VideoCapturer* video_capturer, |
| 148 | const VideoFormat& video_format); |
| 149 | // When muting, produce black frames then pause the camera. |
| 150 | // When unmuting, start the camera. Camera starts unmuted. |
| 151 | bool MuteToBlackThenPause(VideoCapturer* video_capturer, bool muted); |
| 152 | bool StopVideoCapture(VideoCapturer* video_capturer, |
| 153 | const VideoFormat& video_format); |
| 154 | bool RestartVideoCapture(VideoCapturer* video_capturer, |
| 155 | const VideoFormat& previous_format, |
| 156 | const VideoFormat& desired_format, |
| 157 | CaptureManager::RestartOptions options); |
| 158 | |
nisse | e73afba | 2016-01-28 04:47:08 -0800 | [diff] [blame] | 159 | virtual void AddVideoSink(VideoCapturer* video_capturer, |
| 160 | rtc::VideoSinkInterface<VideoFrame>* sink); |
| 161 | virtual void RemoveVideoSink(VideoCapturer* video_capturer, |
| 162 | rtc::VideoSinkInterface<VideoFrame>* sink); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | bool IsScreencastRunning() const; |
| 164 | |
| 165 | // The operations below occur on the main thread. |
| 166 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 167 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 168 | // bytes. When the limit is reached, logging will stop and the file will be |
| 169 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 170 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 171 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 172 | // Stops recording AEC dump. |
| 173 | void StopAecDump(); |
| 174 | |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 175 | // Starts RtcEventLog using existing file. |
| 176 | bool StartRtcEventLog(rtc::PlatformFile file); |
| 177 | |
| 178 | // Stops logging RtcEventLog. |
| 179 | void StopRtcEventLog(); |
| 180 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange; |
| 182 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | private: |
| 184 | typedef std::vector<VoiceChannel*> VoiceChannels; |
| 185 | typedef std::vector<VideoChannel*> VideoChannels; |
| 186 | typedef std::vector<DataChannel*> DataChannels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | |
| 188 | void Construct(MediaEngineInterface* me, |
| 189 | DataEngineInterface* dme, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 191 | rtc::Thread* worker_thread); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 192 | bool InitMediaEngine_w(); |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 193 | void DestructorDeletes_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | void Terminate_w(); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 195 | VoiceChannel* CreateVoiceChannel_w( |
| 196 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 197 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 198 | const std::string& content_name, |
| 199 | bool rtcp, |
| 200 | const AudioOptions& options); |
| 201 | void DestroyVoiceChannel_w(VoiceChannel* voice_channel); |
| 202 | VideoChannel* CreateVideoChannel_w( |
| 203 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 204 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 205 | const std::string& content_name, |
| 206 | bool rtcp, |
| 207 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | void DestroyVideoChannel_w(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 209 | DataChannel* CreateDataChannel_w(TransportController* transport_controller, |
| 210 | const std::string& content_name, |
| 211 | bool rtcp, |
| 212 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | void DestroyDataChannel_w(DataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | void OnVideoCaptureStateChange(VideoCapturer* capturer, |
| 215 | CaptureState result); |
hbos@webrtc.org | 1e64263 | 2015-02-25 09:49:41 +0000 | [diff] [blame] | 216 | void GetSupportedFormats_w( |
| 217 | VideoCapturer* capturer, |
| 218 | std::vector<cricket::VideoFormat>* out_formats) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | bool IsScreencastRunning_w() const; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 220 | virtual void OnMessage(rtc::Message *message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 222 | rtc::scoped_ptr<MediaEngineInterface> media_engine_; |
| 223 | rtc::scoped_ptr<DataEngineInterface> data_media_engine_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 224 | rtc::scoped_ptr<CaptureManager> capture_manager_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | bool initialized_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 226 | rtc::Thread* main_thread_; |
| 227 | rtc::Thread* worker_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 228 | |
| 229 | VoiceChannels voice_channels_; |
| 230 | VideoChannels video_channels_; |
| 231 | DataChannels data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | int audio_output_volume_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | VideoRenderer* local_renderer_; |
| 235 | bool enable_rtx_; |
| 236 | |
| 237 | bool capturing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | } // namespace cricket |
| 241 | |
| 242 | #endif // TALK_SESSION_MEDIA_CHANNELMANAGER_H_ |