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 | #include "talk/session/media/channelmanager.h" |
| 29 | |
| 30 | #ifdef HAVE_CONFIG_H |
| 31 | #include <config.h> |
| 32 | #endif |
| 33 | |
| 34 | #include <algorithm> |
| 35 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 36 | #include "talk/app/webrtc/mediacontroller.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include "talk/media/base/capturemanager.h" |
| 38 | #include "talk/media/base/hybriddataengine.h" |
| 39 | #include "talk/media/base/rtpdataengine.h" |
| 40 | #include "talk/media/base/videocapturer.h" |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 41 | #include "talk/media/devices/devicemanager.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | #ifdef HAVE_SCTP |
| 43 | #include "talk/media/sctp/sctpdataengine.h" |
| 44 | #endif |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 45 | #include "talk/session/media/srtpfilter.h" |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 46 | #include "webrtc/base/bind.h" |
| 47 | #include "webrtc/base/common.h" |
| 48 | #include "webrtc/base/logging.h" |
| 49 | #include "webrtc/base/sigslotrepeater.h" |
| 50 | #include "webrtc/base/stringencode.h" |
| 51 | #include "webrtc/base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
| 53 | namespace cricket { |
| 54 | |
| 55 | enum { |
| 56 | MSG_VIDEOCAPTURESTATE = 1, |
| 57 | }; |
| 58 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 59 | using rtc::Bind; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | |
| 61 | static const int kNotSetOutputVolume = -1; |
| 62 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 63 | struct CaptureStateParams : public rtc::MessageData { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | CaptureStateParams(cricket::VideoCapturer* c, cricket::CaptureState s) |
| 65 | : capturer(c), |
| 66 | state(s) {} |
| 67 | cricket::VideoCapturer* capturer; |
| 68 | cricket::CaptureState state; |
| 69 | }; |
| 70 | |
| 71 | static DataEngineInterface* ConstructDataEngine() { |
| 72 | #ifdef HAVE_SCTP |
| 73 | return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); |
| 74 | #else |
| 75 | return new RtpDataEngine(); |
| 76 | #endif |
| 77 | } |
| 78 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | ChannelManager::ChannelManager(MediaEngineInterface* me, |
| 80 | DataEngineInterface* dme, |
| 81 | DeviceManagerInterface* dm, |
| 82 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 83 | rtc::Thread* worker_thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | Construct(me, dme, dm, cm, worker_thread); |
| 85 | } |
| 86 | |
| 87 | ChannelManager::ChannelManager(MediaEngineInterface* me, |
| 88 | DeviceManagerInterface* dm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 89 | rtc::Thread* worker_thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | Construct(me, |
| 91 | ConstructDataEngine(), |
| 92 | dm, |
| 93 | new CaptureManager(), |
| 94 | worker_thread); |
| 95 | } |
| 96 | |
| 97 | void ChannelManager::Construct(MediaEngineInterface* me, |
| 98 | DataEngineInterface* dme, |
| 99 | DeviceManagerInterface* dm, |
| 100 | CaptureManager* cm, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 101 | rtc::Thread* worker_thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | media_engine_.reset(me); |
| 103 | data_media_engine_.reset(dme); |
| 104 | device_manager_.reset(dm); |
| 105 | capture_manager_.reset(cm); |
| 106 | initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 107 | main_thread_ = rtc::Thread::Current(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | worker_thread_ = worker_thread; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 109 | // Get the default audio options from the media engine. |
| 110 | audio_options_ = media_engine_->GetAudioOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | audio_in_device_ = DeviceManagerInterface::kDefaultDeviceName; |
| 112 | audio_out_device_ = DeviceManagerInterface::kDefaultDeviceName; |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 113 | audio_delay_offset_ = kDefaultAudioDelayOffset; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | audio_output_volume_ = kNotSetOutputVolume; |
| 115 | local_renderer_ = NULL; |
| 116 | capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | enable_rtx_ = false; |
| 118 | |
| 119 | // Init the device manager immediately, and set up our default video device. |
| 120 | SignalDevicesChange.repeat(device_manager_->SignalDevicesChange); |
| 121 | device_manager_->Init(); |
| 122 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | capture_manager_->SignalCapturerStateChange.connect( |
| 124 | this, &ChannelManager::OnVideoCaptureStateChange); |
| 125 | } |
| 126 | |
| 127 | ChannelManager::~ChannelManager() { |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 128 | if (initialized_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | Terminate(); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 130 | // If srtp is initialized (done by the Channel) then we must call |
| 131 | // srtp_shutdown to free all crypto kernel lists. But we need to make sure |
| 132 | // shutdown always called at the end, after channels are destroyed. |
| 133 | // ChannelManager d'tor is always called last, it's safe place to call |
| 134 | // shutdown. |
| 135 | ShutdownSrtp(); |
| 136 | } |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 137 | // Some deletes need to be on the worker thread for thread safe destruction, |
| 138 | // this includes the media engine and capture manager. |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 139 | worker_thread_->Invoke<void>(Bind( |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 140 | &ChannelManager::DestructorDeletes_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | bool ChannelManager::SetVideoRtxEnabled(bool enable) { |
| 144 | // To be safe, this call is only allowed before initialization. Apps like |
| 145 | // Flute only have a singleton ChannelManager and we don't want this flag to |
| 146 | // be toggled between calls or when there's concurrent calls. We expect apps |
| 147 | // to enable this at startup and retain that setting for the lifetime of the |
| 148 | // app. |
| 149 | if (!initialized_) { |
| 150 | enable_rtx_ = enable; |
| 151 | return true; |
| 152 | } else { |
| 153 | LOG(LS_WARNING) << "Cannot toggle rtx after initialization!"; |
| 154 | return false; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | int ChannelManager::GetCapabilities() { |
| 159 | return media_engine_->GetCapabilities() & device_manager_->GetCapabilities(); |
| 160 | } |
| 161 | |
| 162 | void ChannelManager::GetSupportedAudioCodecs( |
| 163 | std::vector<AudioCodec>* codecs) const { |
| 164 | codecs->clear(); |
| 165 | |
| 166 | for (std::vector<AudioCodec>::const_iterator it = |
| 167 | media_engine_->audio_codecs().begin(); |
| 168 | it != media_engine_->audio_codecs().end(); ++it) { |
| 169 | codecs->push_back(*it); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void ChannelManager::GetSupportedAudioRtpHeaderExtensions( |
| 174 | RtpHeaderExtensions* ext) const { |
| 175 | *ext = media_engine_->audio_rtp_header_extensions(); |
| 176 | } |
| 177 | |
| 178 | void ChannelManager::GetSupportedVideoCodecs( |
| 179 | std::vector<VideoCodec>* codecs) const { |
| 180 | codecs->clear(); |
| 181 | |
| 182 | std::vector<VideoCodec>::const_iterator it; |
| 183 | for (it = media_engine_->video_codecs().begin(); |
| 184 | it != media_engine_->video_codecs().end(); ++it) { |
| 185 | if (!enable_rtx_ && _stricmp(kRtxCodecName, it->name.c_str()) == 0) { |
| 186 | continue; |
| 187 | } |
| 188 | codecs->push_back(*it); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | void ChannelManager::GetSupportedVideoRtpHeaderExtensions( |
| 193 | RtpHeaderExtensions* ext) const { |
| 194 | *ext = media_engine_->video_rtp_header_extensions(); |
| 195 | } |
| 196 | |
| 197 | void ChannelManager::GetSupportedDataCodecs( |
| 198 | std::vector<DataCodec>* codecs) const { |
| 199 | *codecs = data_media_engine_->data_codecs(); |
| 200 | } |
| 201 | |
| 202 | bool ChannelManager::Init() { |
| 203 | ASSERT(!initialized_); |
| 204 | if (initialized_) { |
| 205 | return false; |
| 206 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | ASSERT(worker_thread_ != NULL); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 208 | if (!worker_thread_) { |
| 209 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | } |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 211 | if (worker_thread_ != rtc::Thread::Current()) { |
| 212 | // Do not allow invoking calls to other threads on the worker thread. |
| 213 | worker_thread_->Invoke<bool>(rtc::Bind( |
| 214 | &rtc::Thread::SetAllowBlockingCalls, worker_thread_, false)); |
| 215 | } |
| 216 | |
| 217 | initialized_ = worker_thread_->Invoke<bool>(Bind( |
| 218 | &ChannelManager::InitMediaEngine_w, this)); |
| 219 | ASSERT(initialized_); |
| 220 | if (!initialized_) { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | // Now that we're initialized, apply any stored preferences. A preferred |
| 225 | // device might have been unplugged. In this case, we fallback to the |
| 226 | // default device but keep the user preferences. The preferences are |
| 227 | // changed only when the Javascript FE changes them. |
| 228 | const std::string preferred_audio_in_device = audio_in_device_; |
| 229 | const std::string preferred_audio_out_device = audio_out_device_; |
| 230 | const std::string preferred_camera_device = camera_device_; |
| 231 | Device device; |
| 232 | if (!device_manager_->GetAudioInputDevice(audio_in_device_, &device)) { |
| 233 | LOG(LS_WARNING) << "The preferred microphone '" << audio_in_device_ |
| 234 | << "' is unavailable. Fall back to the default."; |
| 235 | audio_in_device_ = DeviceManagerInterface::kDefaultDeviceName; |
| 236 | } |
| 237 | if (!device_manager_->GetAudioOutputDevice(audio_out_device_, &device)) { |
| 238 | LOG(LS_WARNING) << "The preferred speaker '" << audio_out_device_ |
| 239 | << "' is unavailable. Fall back to the default."; |
| 240 | audio_out_device_ = DeviceManagerInterface::kDefaultDeviceName; |
| 241 | } |
| 242 | if (!device_manager_->GetVideoCaptureDevice(camera_device_, &device)) { |
| 243 | if (!camera_device_.empty()) { |
| 244 | LOG(LS_WARNING) << "The preferred camera '" << camera_device_ |
| 245 | << "' is unavailable. Fall back to the default."; |
| 246 | } |
| 247 | camera_device_ = DeviceManagerInterface::kDefaultDeviceName; |
| 248 | } |
| 249 | |
| 250 | if (!SetAudioOptions(audio_in_device_, audio_out_device_, |
| 251 | audio_options_, audio_delay_offset_)) { |
| 252 | LOG(LS_WARNING) << "Failed to SetAudioOptions with" |
| 253 | << " microphone: " << audio_in_device_ |
| 254 | << " speaker: " << audio_out_device_ |
| 255 | << " options: " << audio_options_.ToString() |
| 256 | << " delay: " << audio_delay_offset_; |
| 257 | } |
| 258 | |
| 259 | // If audio_output_volume_ has been set via SetOutputVolume(), set the |
| 260 | // audio output volume of the engine. |
| 261 | if (kNotSetOutputVolume != audio_output_volume_ && |
| 262 | !SetOutputVolume(audio_output_volume_)) { |
| 263 | LOG(LS_WARNING) << "Failed to SetOutputVolume to " |
| 264 | << audio_output_volume_; |
| 265 | } |
| 266 | if (!SetCaptureDevice(camera_device_) && !camera_device_.empty()) { |
| 267 | LOG(LS_WARNING) << "Failed to SetCaptureDevice with camera: " |
| 268 | << camera_device_; |
| 269 | } |
| 270 | |
| 271 | // Restore the user preferences. |
| 272 | audio_in_device_ = preferred_audio_in_device; |
| 273 | audio_out_device_ = preferred_audio_out_device; |
| 274 | camera_device_ = preferred_camera_device; |
| 275 | |
| 276 | // Now apply the default video codec that has been set earlier. |
| 277 | if (default_video_encoder_config_.max_codec.id != 0) { |
| 278 | SetDefaultVideoEncoderConfig(default_video_encoder_config_); |
| 279 | } |
| 280 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | return initialized_; |
| 282 | } |
| 283 | |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 284 | bool ChannelManager::InitMediaEngine_w() { |
| 285 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 286 | return (media_engine_->Init(worker_thread_)); |
| 287 | } |
| 288 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | void ChannelManager::Terminate() { |
| 290 | ASSERT(initialized_); |
| 291 | if (!initialized_) { |
| 292 | return; |
| 293 | } |
| 294 | worker_thread_->Invoke<void>(Bind(&ChannelManager::Terminate_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | initialized_ = false; |
| 296 | } |
| 297 | |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 298 | void ChannelManager::DestructorDeletes_w() { |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 299 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 300 | media_engine_.reset(NULL); |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 301 | capture_manager_.reset(NULL); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 302 | } |
| 303 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | void ChannelManager::Terminate_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 305 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | // Need to destroy the voice/video channels |
| 307 | while (!video_channels_.empty()) { |
| 308 | DestroyVideoChannel_w(video_channels_.back()); |
| 309 | } |
| 310 | while (!voice_channels_.empty()) { |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 311 | DestroyVoiceChannel_w(voice_channels_.back()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 313 | if (!SetCaptureDevice_w(NULL)) { |
| 314 | LOG(LS_WARNING) << "failed to delete video capturer"; |
| 315 | } |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 316 | media_engine_->Terminate(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | VoiceChannel* ChannelManager::CreateVoiceChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 320 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 321 | TransportController* transport_controller, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 322 | const std::string& content_name, |
| 323 | bool rtcp, |
| 324 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | return worker_thread_->Invoke<VoiceChannel*>( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 326 | Bind(&ChannelManager::CreateVoiceChannel_w, this, media_controller, |
| 327 | transport_controller, content_name, rtcp, options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | VoiceChannel* ChannelManager::CreateVoiceChannel_w( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 331 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 332 | TransportController* transport_controller, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 333 | const std::string& content_name, |
| 334 | bool rtcp, |
| 335 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 337 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 338 | ASSERT(nullptr != media_controller); |
| 339 | VoiceMediaChannel* media_channel = |
| 340 | media_engine_->CreateChannel(media_controller->call_w(), options); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 341 | if (!media_channel) |
| 342 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 344 | VoiceChannel* voice_channel = |
| 345 | new VoiceChannel(worker_thread_, media_engine_.get(), media_channel, |
| 346 | transport_controller, content_name, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | if (!voice_channel->Init()) { |
| 348 | delete voice_channel; |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 349 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 350 | } |
| 351 | voice_channels_.push_back(voice_channel); |
| 352 | return voice_channel; |
| 353 | } |
| 354 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 355 | void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | if (voice_channel) { |
| 357 | worker_thread_->Invoke<void>( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 358 | Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 362 | void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 363 | // Destroy voice channel. |
| 364 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 365 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | VoiceChannels::iterator it = std::find(voice_channels_.begin(), |
| 367 | voice_channels_.end(), voice_channel); |
| 368 | ASSERT(it != voice_channels_.end()); |
| 369 | if (it == voice_channels_.end()) |
| 370 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 371 | voice_channels_.erase(it); |
| 372 | delete voice_channel; |
| 373 | } |
| 374 | |
| 375 | VideoChannel* ChannelManager::CreateVideoChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 376 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 377 | TransportController* transport_controller, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 378 | const std::string& content_name, |
| 379 | bool rtcp, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 380 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 381 | return worker_thread_->Invoke<VideoChannel*>( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 382 | Bind(&ChannelManager::CreateVideoChannel_w, this, media_controller, |
| 383 | transport_controller, content_name, rtcp, options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | VideoChannel* ChannelManager::CreateVideoChannel_w( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 387 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 388 | TransportController* transport_controller, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 389 | const std::string& content_name, |
| 390 | bool rtcp, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 391 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 392 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 393 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 394 | ASSERT(nullptr != media_controller); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | VideoMediaChannel* media_channel = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 396 | media_engine_->CreateVideoChannel(media_controller->call_w(), options); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 397 | if (media_channel == NULL) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 398 | return NULL; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 399 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | |
| 401 | VideoChannel* video_channel = new VideoChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 402 | worker_thread_, media_channel, transport_controller, content_name, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 403 | if (!video_channel->Init()) { |
| 404 | delete video_channel; |
| 405 | return NULL; |
| 406 | } |
| 407 | video_channels_.push_back(video_channel); |
| 408 | return video_channel; |
| 409 | } |
| 410 | |
| 411 | void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
| 412 | if (video_channel) { |
| 413 | worker_thread_->Invoke<void>( |
| 414 | Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { |
| 419 | // Destroy video channel. |
| 420 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 421 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 422 | VideoChannels::iterator it = std::find(video_channels_.begin(), |
| 423 | video_channels_.end(), video_channel); |
| 424 | ASSERT(it != video_channels_.end()); |
| 425 | if (it == video_channels_.end()) |
| 426 | return; |
| 427 | |
| 428 | video_channels_.erase(it); |
| 429 | delete video_channel; |
| 430 | } |
| 431 | |
| 432 | DataChannel* ChannelManager::CreateDataChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 433 | TransportController* transport_controller, |
| 434 | const std::string& content_name, |
| 435 | bool rtcp, |
| 436 | DataChannelType channel_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | return worker_thread_->Invoke<DataChannel*>( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 438 | Bind(&ChannelManager::CreateDataChannel_w, this, transport_controller, |
| 439 | content_name, rtcp, channel_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | DataChannel* ChannelManager::CreateDataChannel_w( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 443 | TransportController* transport_controller, |
| 444 | const std::string& content_name, |
| 445 | bool rtcp, |
| 446 | DataChannelType data_channel_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 447 | // This is ok to alloc from a thread other than the worker thread. |
| 448 | ASSERT(initialized_); |
| 449 | DataMediaChannel* media_channel = data_media_engine_->CreateChannel( |
| 450 | data_channel_type); |
| 451 | if (!media_channel) { |
| 452 | LOG(LS_WARNING) << "Failed to create data channel of type " |
| 453 | << data_channel_type; |
| 454 | return NULL; |
| 455 | } |
| 456 | |
| 457 | DataChannel* data_channel = new DataChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 458 | worker_thread_, media_channel, transport_controller, content_name, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | if (!data_channel->Init()) { |
| 460 | LOG(LS_WARNING) << "Failed to init data channel."; |
| 461 | delete data_channel; |
| 462 | return NULL; |
| 463 | } |
| 464 | data_channels_.push_back(data_channel); |
| 465 | return data_channel; |
| 466 | } |
| 467 | |
| 468 | void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { |
| 469 | if (data_channel) { |
| 470 | worker_thread_->Invoke<void>( |
| 471 | Bind(&ChannelManager::DestroyDataChannel_w, this, data_channel)); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) { |
| 476 | // Destroy data channel. |
| 477 | ASSERT(initialized_); |
| 478 | DataChannels::iterator it = std::find(data_channels_.begin(), |
| 479 | data_channels_.end(), data_channel); |
| 480 | ASSERT(it != data_channels_.end()); |
| 481 | if (it == data_channels_.end()) |
| 482 | return; |
| 483 | |
| 484 | data_channels_.erase(it); |
| 485 | delete data_channel; |
| 486 | } |
| 487 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 488 | bool ChannelManager::GetAudioOptions(std::string* in_name, |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 489 | std::string* out_name, |
| 490 | AudioOptions* options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 491 | if (in_name) |
| 492 | *in_name = audio_in_device_; |
| 493 | if (out_name) |
| 494 | *out_name = audio_out_device_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 495 | if (options) |
| 496 | *options = audio_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | return true; |
| 498 | } |
| 499 | |
| 500 | bool ChannelManager::SetAudioOptions(const std::string& in_name, |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 501 | const std::string& out_name, |
| 502 | const AudioOptions& options) { |
| 503 | return SetAudioOptions(in_name, out_name, options, audio_delay_offset_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | bool ChannelManager::SetAudioOptions(const std::string& in_name, |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 507 | const std::string& out_name, |
| 508 | const AudioOptions& options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | int delay_offset) { |
| 510 | // Get device ids from DeviceManager. |
| 511 | Device in_dev, out_dev; |
| 512 | if (!device_manager_->GetAudioInputDevice(in_name, &in_dev)) { |
| 513 | LOG(LS_WARNING) << "Failed to GetAudioInputDevice: " << in_name; |
| 514 | return false; |
| 515 | } |
| 516 | if (!device_manager_->GetAudioOutputDevice(out_name, &out_dev)) { |
| 517 | LOG(LS_WARNING) << "Failed to GetAudioOutputDevice: " << out_name; |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | // If we're initialized, pass the settings to the media engine. |
| 522 | bool ret = true; |
| 523 | if (initialized_) { |
| 524 | ret = worker_thread_->Invoke<bool>( |
| 525 | Bind(&ChannelManager::SetAudioOptions_w, this, |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 526 | options, delay_offset, &in_dev, &out_dev)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | // If all worked well, save the values for use in GetAudioOptions. |
| 530 | if (ret) { |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 531 | audio_options_ = options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 532 | audio_in_device_ = in_name; |
| 533 | audio_out_device_ = out_name; |
| 534 | audio_delay_offset_ = delay_offset; |
| 535 | } |
| 536 | return ret; |
| 537 | } |
| 538 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 539 | bool ChannelManager::SetAudioOptions_w( |
| 540 | const AudioOptions& options, int delay_offset, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 541 | const Device* in_dev, const Device* out_dev) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 542 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | ASSERT(initialized_); |
| 544 | |
| 545 | // Set audio options |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 546 | bool ret = media_engine_->SetAudioOptions(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 547 | |
| 548 | if (ret) { |
| 549 | ret = media_engine_->SetAudioDelayOffset(delay_offset); |
| 550 | } |
| 551 | |
| 552 | // Set the audio devices |
| 553 | if (ret) { |
| 554 | ret = media_engine_->SetSoundDevices(in_dev, out_dev); |
| 555 | } |
| 556 | |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | bool ChannelManager::GetOutputVolume(int* level) { |
| 561 | if (!initialized_) { |
| 562 | return false; |
| 563 | } |
| 564 | return worker_thread_->Invoke<bool>( |
| 565 | Bind(&MediaEngineInterface::GetOutputVolume, media_engine_.get(), level)); |
| 566 | } |
| 567 | |
| 568 | bool ChannelManager::SetOutputVolume(int level) { |
| 569 | bool ret = level >= 0 && level <= 255; |
| 570 | if (initialized_) { |
| 571 | ret &= worker_thread_->Invoke<bool>( |
| 572 | Bind(&MediaEngineInterface::SetOutputVolume, |
| 573 | media_engine_.get(), level)); |
| 574 | } |
| 575 | |
| 576 | if (ret) { |
| 577 | audio_output_volume_ = level; |
| 578 | } |
| 579 | |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | bool ChannelManager::IsSameCapturer(const std::string& capturer_name, |
| 584 | VideoCapturer* capturer) { |
| 585 | if (capturer == NULL) { |
| 586 | return false; |
| 587 | } |
| 588 | Device device; |
| 589 | if (!device_manager_->GetVideoCaptureDevice(capturer_name, &device)) { |
| 590 | return false; |
| 591 | } |
| 592 | return capturer->GetId() == device.id; |
| 593 | } |
| 594 | |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 595 | bool ChannelManager::GetVideoCaptureDevice(Device* device) { |
| 596 | std::string device_name; |
| 597 | if (!GetCaptureDevice(&device_name)) { |
| 598 | return false; |
| 599 | } |
| 600 | return device_manager_->GetVideoCaptureDevice(device_name, device); |
| 601 | } |
| 602 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | bool ChannelManager::GetCaptureDevice(std::string* cam_name) { |
| 604 | if (camera_device_.empty()) { |
| 605 | // Initialize camera_device_ with default. |
| 606 | Device device; |
| 607 | if (!device_manager_->GetVideoCaptureDevice( |
| 608 | DeviceManagerInterface::kDefaultDeviceName, &device)) { |
| 609 | LOG(LS_WARNING) << "Device manager can't find default camera: " << |
| 610 | DeviceManagerInterface::kDefaultDeviceName; |
| 611 | return false; |
| 612 | } |
| 613 | camera_device_ = device.name; |
| 614 | } |
| 615 | *cam_name = camera_device_; |
| 616 | return true; |
| 617 | } |
| 618 | |
| 619 | bool ChannelManager::SetCaptureDevice(const std::string& cam_name) { |
| 620 | Device device; |
| 621 | bool ret = true; |
| 622 | if (!device_manager_->GetVideoCaptureDevice(cam_name, &device)) { |
| 623 | if (!cam_name.empty()) { |
| 624 | LOG(LS_WARNING) << "Device manager can't find camera: " << cam_name; |
| 625 | } |
| 626 | ret = false; |
| 627 | } |
| 628 | |
| 629 | // If we're running, tell the media engine about it. |
| 630 | if (initialized_ && ret) { |
| 631 | ret = worker_thread_->Invoke<bool>( |
| 632 | Bind(&ChannelManager::SetCaptureDevice_w, this, &device)); |
| 633 | } |
| 634 | |
| 635 | // If everything worked, retain the name of the selected camera. |
| 636 | if (ret) { |
| 637 | camera_device_ = device.name; |
| 638 | } else if (camera_device_.empty()) { |
| 639 | // When video option setting fails, we still want camera_device_ to be in a |
| 640 | // good state, so we initialize it with default if it's empty. |
| 641 | Device default_device; |
| 642 | if (!device_manager_->GetVideoCaptureDevice( |
| 643 | DeviceManagerInterface::kDefaultDeviceName, &default_device)) { |
| 644 | LOG(LS_WARNING) << "Device manager can't find default camera: " << |
| 645 | DeviceManagerInterface::kDefaultDeviceName; |
| 646 | } |
| 647 | camera_device_ = default_device.name; |
| 648 | } |
| 649 | |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | VideoCapturer* ChannelManager::CreateVideoCapturer() { |
| 654 | Device device; |
| 655 | if (!device_manager_->GetVideoCaptureDevice(camera_device_, &device)) { |
| 656 | if (!camera_device_.empty()) { |
| 657 | LOG(LS_WARNING) << "Device manager can't find camera: " << camera_device_; |
| 658 | } |
| 659 | return NULL; |
| 660 | } |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 661 | VideoCapturer* capturer = device_manager_->CreateVideoCapturer(device); |
| 662 | if (capturer && default_video_encoder_config_.max_codec.id != 0) { |
| 663 | // For now, use the aspect ratio of the default_video_encoder_config_, |
| 664 | // which may be different than the native aspect ratio of the start |
| 665 | // format the camera may use. |
| 666 | capturer->UpdateAspectRatio( |
| 667 | default_video_encoder_config_.max_codec.width, |
| 668 | default_video_encoder_config_.max_codec.height); |
| 669 | } |
| 670 | return capturer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 671 | } |
| 672 | |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 673 | VideoCapturer* ChannelManager::CreateScreenCapturer( |
| 674 | const ScreencastId& screenid) { |
| 675 | return device_manager_->CreateScreenCapturer(screenid); |
| 676 | } |
| 677 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 678 | bool ChannelManager::SetCaptureDevice_w(const Device* cam_device) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 679 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 680 | ASSERT(initialized_); |
| 681 | |
| 682 | if (!cam_device) { |
| 683 | video_device_name_.clear(); |
| 684 | return true; |
| 685 | } |
| 686 | video_device_name_ = cam_device->name; |
| 687 | return true; |
| 688 | } |
| 689 | |
| 690 | bool ChannelManager::SetDefaultVideoEncoderConfig(const VideoEncoderConfig& c) { |
buildbot@webrtc.org | 992febb | 2014-09-05 16:39:08 +0000 | [diff] [blame] | 691 | bool ret = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 692 | if (initialized_) { |
buildbot@webrtc.org | 992febb | 2014-09-05 16:39:08 +0000 | [diff] [blame] | 693 | ret = worker_thread_->Invoke<bool>( |
| 694 | Bind(&MediaEngineInterface::SetDefaultVideoEncoderConfig, |
| 695 | media_engine_.get(), c)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 696 | } |
buildbot@webrtc.org | 992febb | 2014-09-05 16:39:08 +0000 | [diff] [blame] | 697 | if (ret) { |
| 698 | default_video_encoder_config_ = c; |
| 699 | } |
| 700 | return ret; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 701 | } |
| 702 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 703 | void ChannelManager::SetVoiceLogging(int level, const char* filter) { |
| 704 | if (initialized_) { |
| 705 | worker_thread_->Invoke<void>( |
| 706 | Bind(&MediaEngineInterface::SetVoiceLogging, |
| 707 | media_engine_.get(), level, filter)); |
| 708 | } else { |
| 709 | media_engine_->SetVoiceLogging(level, filter); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | void ChannelManager::SetVideoLogging(int level, const char* filter) { |
| 714 | if (initialized_) { |
| 715 | worker_thread_->Invoke<void>( |
| 716 | Bind(&MediaEngineInterface::SetVideoLogging, |
| 717 | media_engine_.get(), level, filter)); |
| 718 | } else { |
| 719 | media_engine_->SetVideoLogging(level, filter); |
| 720 | } |
| 721 | } |
| 722 | |
hbos@webrtc.org | 1e64263 | 2015-02-25 09:49:41 +0000 | [diff] [blame] | 723 | std::vector<cricket::VideoFormat> ChannelManager::GetSupportedFormats( |
| 724 | VideoCapturer* capturer) const { |
| 725 | ASSERT(capturer != NULL); |
| 726 | std::vector<VideoFormat> formats; |
| 727 | worker_thread_->Invoke<void>(rtc::Bind(&ChannelManager::GetSupportedFormats_w, |
| 728 | this, capturer, &formats)); |
| 729 | return formats; |
| 730 | } |
| 731 | |
| 732 | void ChannelManager::GetSupportedFormats_w( |
| 733 | VideoCapturer* capturer, |
| 734 | std::vector<cricket::VideoFormat>* out_formats) const { |
| 735 | const std::vector<VideoFormat>* formats = capturer->GetSupportedFormats(); |
| 736 | if (formats != NULL) |
| 737 | *out_formats = *formats; |
| 738 | } |
| 739 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 740 | // The following are done in the new "CaptureManager" style that |
| 741 | // all local video capturers, processors, and managers should move |
| 742 | // to. |
| 743 | // TODO(pthatcher): Add more of the CaptureManager interface. |
| 744 | bool ChannelManager::StartVideoCapture( |
| 745 | VideoCapturer* capturer, const VideoFormat& video_format) { |
| 746 | return initialized_ && worker_thread_->Invoke<bool>( |
| 747 | Bind(&CaptureManager::StartVideoCapture, |
| 748 | capture_manager_.get(), capturer, video_format)); |
| 749 | } |
| 750 | |
| 751 | bool ChannelManager::MuteToBlackThenPause( |
| 752 | VideoCapturer* video_capturer, bool muted) { |
| 753 | if (!initialized_) { |
| 754 | return false; |
| 755 | } |
| 756 | worker_thread_->Invoke<void>( |
| 757 | Bind(&VideoCapturer::MuteToBlackThenPause, video_capturer, muted)); |
| 758 | return true; |
| 759 | } |
| 760 | |
| 761 | bool ChannelManager::StopVideoCapture( |
| 762 | VideoCapturer* capturer, const VideoFormat& video_format) { |
| 763 | return initialized_ && worker_thread_->Invoke<bool>( |
| 764 | Bind(&CaptureManager::StopVideoCapture, |
| 765 | capture_manager_.get(), capturer, video_format)); |
| 766 | } |
| 767 | |
| 768 | bool ChannelManager::RestartVideoCapture( |
| 769 | VideoCapturer* video_capturer, |
| 770 | const VideoFormat& previous_format, |
| 771 | const VideoFormat& desired_format, |
| 772 | CaptureManager::RestartOptions options) { |
| 773 | return initialized_ && worker_thread_->Invoke<bool>( |
| 774 | Bind(&CaptureManager::RestartVideoCapture, capture_manager_.get(), |
| 775 | video_capturer, previous_format, desired_format, options)); |
| 776 | } |
| 777 | |
| 778 | bool ChannelManager::AddVideoRenderer( |
| 779 | VideoCapturer* capturer, VideoRenderer* renderer) { |
| 780 | return initialized_ && worker_thread_->Invoke<bool>( |
| 781 | Bind(&CaptureManager::AddVideoRenderer, |
| 782 | capture_manager_.get(), capturer, renderer)); |
| 783 | } |
| 784 | |
| 785 | bool ChannelManager::RemoveVideoRenderer( |
| 786 | VideoCapturer* capturer, VideoRenderer* renderer) { |
| 787 | return initialized_ && worker_thread_->Invoke<bool>( |
| 788 | Bind(&CaptureManager::RemoveVideoRenderer, |
| 789 | capture_manager_.get(), capturer, renderer)); |
| 790 | } |
| 791 | |
| 792 | bool ChannelManager::IsScreencastRunning() const { |
| 793 | return initialized_ && worker_thread_->Invoke<bool>( |
| 794 | Bind(&ChannelManager::IsScreencastRunning_w, this)); |
| 795 | } |
| 796 | |
| 797 | bool ChannelManager::IsScreencastRunning_w() const { |
| 798 | VideoChannels::const_iterator it = video_channels_.begin(); |
| 799 | for ( ; it != video_channels_.end(); ++it) { |
| 800 | if ((*it) && (*it)->IsScreencasting()) { |
| 801 | return true; |
| 802 | } |
| 803 | } |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | void ChannelManager::OnVideoCaptureStateChange(VideoCapturer* capturer, |
| 808 | CaptureState result) { |
| 809 | // TODO(whyuan): Check capturer and signal failure only for camera video, not |
| 810 | // screencast. |
| 811 | capturing_ = result == CS_RUNNING; |
| 812 | main_thread_->Post(this, MSG_VIDEOCAPTURESTATE, |
| 813 | new CaptureStateParams(capturer, result)); |
| 814 | } |
| 815 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 816 | void ChannelManager::OnMessage(rtc::Message* message) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | switch (message->message_id) { |
| 818 | case MSG_VIDEOCAPTURESTATE: { |
| 819 | CaptureStateParams* data = |
| 820 | static_cast<CaptureStateParams*>(message->pdata); |
| 821 | SignalVideoCaptureStateChange(data->capturer, data->state); |
| 822 | delete data; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | |
| 829 | static void GetDeviceNames(const std::vector<Device>& devs, |
| 830 | std::vector<std::string>* names) { |
| 831 | names->clear(); |
| 832 | for (size_t i = 0; i < devs.size(); ++i) { |
| 833 | names->push_back(devs[i].name); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | bool ChannelManager::GetAudioInputDevices(std::vector<std::string>* names) { |
| 838 | names->clear(); |
| 839 | std::vector<Device> devs; |
| 840 | bool ret = device_manager_->GetAudioInputDevices(&devs); |
| 841 | if (ret) |
| 842 | GetDeviceNames(devs, names); |
| 843 | |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | bool ChannelManager::GetAudioOutputDevices(std::vector<std::string>* names) { |
| 848 | names->clear(); |
| 849 | std::vector<Device> devs; |
| 850 | bool ret = device_manager_->GetAudioOutputDevices(&devs); |
| 851 | if (ret) |
| 852 | GetDeviceNames(devs, names); |
| 853 | |
| 854 | return ret; |
| 855 | } |
| 856 | |
| 857 | bool ChannelManager::GetVideoCaptureDevices(std::vector<std::string>* names) { |
| 858 | names->clear(); |
| 859 | std::vector<Device> devs; |
| 860 | bool ret = device_manager_->GetVideoCaptureDevices(&devs); |
| 861 | if (ret) |
| 862 | GetDeviceNames(devs, names); |
| 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | void ChannelManager::SetVideoCaptureDeviceMaxFormat( |
| 868 | const std::string& usb_id, |
| 869 | const VideoFormat& max_format) { |
| 870 | device_manager_->SetVideoCaptureDeviceMaxFormat(usb_id, max_format); |
| 871 | } |
| 872 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 873 | bool ChannelManager::StartAecDump(rtc::PlatformFile file) { |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 874 | return worker_thread_->Invoke<bool>( |
| 875 | Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), file)); |
| 876 | } |
| 877 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 878 | } // namespace cricket |