Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "talk/session/media/channelmanager.h" | 28 #include "talk/session/media/channelmanager.h" |
| 29 | 29 |
| 30 #ifdef HAVE_CONFIG_H | 30 #ifdef HAVE_CONFIG_H |
| 31 #include <config.h> | 31 #include <config.h> |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #include <algorithm> | 34 #include <algorithm> |
| 35 | 35 |
| 36 #include "talk/app/webrtc/mediacontroller.h" | 36 #include "talk/app/webrtc/mediacontroller.h" |
| 37 #include "talk/media/base/capturemanager.h" | 37 #include "talk/media/base/capturemanager.h" |
| 38 #include "talk/media/base/device.h" | |
| 38 #include "talk/media/base/hybriddataengine.h" | 39 #include "talk/media/base/hybriddataengine.h" |
| 39 #include "talk/media/base/rtpdataengine.h" | 40 #include "talk/media/base/rtpdataengine.h" |
| 40 #include "talk/media/base/videocapturer.h" | 41 #include "talk/media/base/videocapturer.h" |
| 41 #include "talk/media/devices/devicemanager.h" | |
| 42 #ifdef HAVE_SCTP | 42 #ifdef HAVE_SCTP |
| 43 #include "talk/media/sctp/sctpdataengine.h" | 43 #include "talk/media/sctp/sctpdataengine.h" |
| 44 #endif | 44 #endif |
| 45 #include "talk/session/media/srtpfilter.h" | 45 #include "talk/session/media/srtpfilter.h" |
| 46 #include "webrtc/base/bind.h" | 46 #include "webrtc/base/bind.h" |
| 47 #include "webrtc/base/common.h" | 47 #include "webrtc/base/common.h" |
| 48 #include "webrtc/base/logging.h" | 48 #include "webrtc/base/logging.h" |
| 49 #include "webrtc/base/sigslotrepeater.h" | 49 #include "webrtc/base/sigslotrepeater.h" |
| 50 #include "webrtc/base/stringencode.h" | 50 #include "webrtc/base/stringencode.h" |
| 51 #include "webrtc/base/stringutils.h" | 51 #include "webrtc/base/stringutils.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 71 static DataEngineInterface* ConstructDataEngine() { | 71 static DataEngineInterface* ConstructDataEngine() { |
| 72 #ifdef HAVE_SCTP | 72 #ifdef HAVE_SCTP |
| 73 return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); | 73 return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); |
| 74 #else | 74 #else |
| 75 return new RtpDataEngine(); | 75 return new RtpDataEngine(); |
| 76 #endif | 76 #endif |
| 77 } | 77 } |
| 78 | 78 |
| 79 ChannelManager::ChannelManager(MediaEngineInterface* me, | 79 ChannelManager::ChannelManager(MediaEngineInterface* me, |
| 80 DataEngineInterface* dme, | 80 DataEngineInterface* dme, |
| 81 DeviceManagerInterface* dm, | |
| 82 CaptureManager* cm, | 81 CaptureManager* cm, |
| 83 rtc::Thread* worker_thread) { | 82 rtc::Thread* worker_thread) { |
| 84 Construct(me, dme, dm, cm, worker_thread); | 83 Construct(me, dme, cm, worker_thread); |
| 85 } | 84 } |
| 86 | 85 |
| 87 ChannelManager::ChannelManager(MediaEngineInterface* me, | 86 ChannelManager::ChannelManager(MediaEngineInterface* me, |
| 88 DeviceManagerInterface* dm, | |
| 89 rtc::Thread* worker_thread) { | 87 rtc::Thread* worker_thread) { |
| 90 Construct(me, | 88 Construct(me, |
| 91 ConstructDataEngine(), | 89 ConstructDataEngine(), |
| 92 dm, | |
| 93 new CaptureManager(), | 90 new CaptureManager(), |
| 94 worker_thread); | 91 worker_thread); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void ChannelManager::Construct(MediaEngineInterface* me, | 94 void ChannelManager::Construct(MediaEngineInterface* me, |
| 98 DataEngineInterface* dme, | 95 DataEngineInterface* dme, |
| 99 DeviceManagerInterface* dm, | |
| 100 CaptureManager* cm, | 96 CaptureManager* cm, |
| 101 rtc::Thread* worker_thread) { | 97 rtc::Thread* worker_thread) { |
| 102 media_engine_.reset(me); | 98 media_engine_.reset(me); |
| 103 data_media_engine_.reset(dme); | 99 data_media_engine_.reset(dme); |
| 104 device_manager_.reset(dm); | |
| 105 capture_manager_.reset(cm); | 100 capture_manager_.reset(cm); |
| 106 initialized_ = false; | 101 initialized_ = false; |
| 107 main_thread_ = rtc::Thread::Current(); | 102 main_thread_ = rtc::Thread::Current(); |
| 108 worker_thread_ = worker_thread; | 103 worker_thread_ = worker_thread; |
| 109 // Get the default audio options from the media engine. | 104 // Get the default audio options from the media engine. |
| 110 audio_options_ = media_engine_->GetAudioOptions(); | 105 audio_options_ = media_engine_->GetAudioOptions(); |
| 111 audio_in_device_ = DeviceManagerInterface::kDefaultDeviceName; | |
| 112 audio_out_device_ = DeviceManagerInterface::kDefaultDeviceName; | |
| 113 audio_delay_offset_ = kDefaultAudioDelayOffset; | 106 audio_delay_offset_ = kDefaultAudioDelayOffset; |
| 114 audio_output_volume_ = kNotSetOutputVolume; | 107 audio_output_volume_ = kNotSetOutputVolume; |
| 115 local_renderer_ = NULL; | 108 local_renderer_ = NULL; |
| 116 capturing_ = false; | 109 capturing_ = false; |
| 117 enable_rtx_ = false; | 110 enable_rtx_ = false; |
| 118 | 111 |
| 119 // Init the device manager immediately, and set up our default video device. | |
| 120 SignalDevicesChange.repeat(device_manager_->SignalDevicesChange); | |
| 121 device_manager_->Init(); | |
| 122 | |
| 123 capture_manager_->SignalCapturerStateChange.connect( | 112 capture_manager_->SignalCapturerStateChange.connect( |
| 124 this, &ChannelManager::OnVideoCaptureStateChange); | 113 this, &ChannelManager::OnVideoCaptureStateChange); |
| 125 } | 114 } |
| 126 | 115 |
| 127 ChannelManager::~ChannelManager() { | 116 ChannelManager::~ChannelManager() { |
| 128 if (initialized_) { | 117 if (initialized_) { |
| 129 Terminate(); | 118 Terminate(); |
| 130 // If srtp is initialized (done by the Channel) then we must call | 119 // 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 | 120 // 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. | 121 // shutdown always called at the end, after channels are destroyed. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 149 if (!initialized_) { | 138 if (!initialized_) { |
| 150 enable_rtx_ = enable; | 139 enable_rtx_ = enable; |
| 151 return true; | 140 return true; |
| 152 } else { | 141 } else { |
| 153 LOG(LS_WARNING) << "Cannot toggle rtx after initialization!"; | 142 LOG(LS_WARNING) << "Cannot toggle rtx after initialization!"; |
| 154 return false; | 143 return false; |
| 155 } | 144 } |
| 156 } | 145 } |
| 157 | 146 |
| 158 int ChannelManager::GetCapabilities() { | 147 int ChannelManager::GetCapabilities() { |
| 159 return media_engine_->GetCapabilities() & device_manager_->GetCapabilities(); | 148 return media_engine_->GetCapabilities(); |
| 160 } | 149 } |
| 161 | 150 |
| 162 void ChannelManager::GetSupportedAudioCodecs( | 151 void ChannelManager::GetSupportedAudioCodecs( |
| 163 std::vector<AudioCodec>* codecs) const { | 152 std::vector<AudioCodec>* codecs) const { |
| 164 codecs->clear(); | 153 codecs->clear(); |
| 165 | 154 |
| 166 for (std::vector<AudioCodec>::const_iterator it = | 155 for (std::vector<AudioCodec>::const_iterator it = |
| 167 media_engine_->audio_codecs().begin(); | 156 media_engine_->audio_codecs().begin(); |
| 168 it != media_engine_->audio_codecs().end(); ++it) { | 157 it != media_engine_->audio_codecs().end(); ++it) { |
| 169 codecs->push_back(*it); | 158 codecs->push_back(*it); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 &rtc::Thread::SetAllowBlockingCalls, worker_thread_, false)); | 203 &rtc::Thread::SetAllowBlockingCalls, worker_thread_, false)); |
| 215 } | 204 } |
| 216 | 205 |
| 217 initialized_ = worker_thread_->Invoke<bool>(Bind( | 206 initialized_ = worker_thread_->Invoke<bool>(Bind( |
| 218 &ChannelManager::InitMediaEngine_w, this)); | 207 &ChannelManager::InitMediaEngine_w, this)); |
| 219 ASSERT(initialized_); | 208 ASSERT(initialized_); |
| 220 if (!initialized_) { | 209 if (!initialized_) { |
| 221 return false; | 210 return false; |
| 222 } | 211 } |
| 223 | 212 |
| 224 // Now that we're initialized, apply any stored preferences. A preferred | 213 if (!SetAudioOptions(audio_options_, audio_delay_offset_)) { |
| 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" | 214 LOG(LS_WARNING) << "Failed to SetAudioOptions with" |
| 253 << " microphone: " << audio_in_device_ | |
| 254 << " speaker: " << audio_out_device_ | |
| 255 << " options: " << audio_options_.ToString() | 215 << " options: " << audio_options_.ToString() |
| 256 << " delay: " << audio_delay_offset_; | 216 << " delay: " << audio_delay_offset_; |
| 257 } | 217 } |
| 258 | 218 |
| 259 // If audio_output_volume_ has been set via SetOutputVolume(), set the | 219 // If audio_output_volume_ has been set via SetOutputVolume(), set the |
| 260 // audio output volume of the engine. | 220 // audio output volume of the engine. |
| 261 if (kNotSetOutputVolume != audio_output_volume_ && | 221 if (kNotSetOutputVolume != audio_output_volume_ && |
| 262 !SetOutputVolume(audio_output_volume_)) { | 222 !SetOutputVolume(audio_output_volume_)) { |
| 263 LOG(LS_WARNING) << "Failed to SetOutputVolume to " | 223 LOG(LS_WARNING) << "Failed to SetOutputVolume to " |
| 264 << audio_output_volume_; | 224 << audio_output_volume_; |
| 265 } | 225 } |
| 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 | 226 |
| 276 // Now apply the default video codec that has been set earlier. | 227 // Now apply the default video codec that has been set earlier. |
| 277 if (default_video_encoder_config_.max_codec.id != 0) { | 228 if (default_video_encoder_config_.max_codec.id != 0) { |
| 278 SetDefaultVideoEncoderConfig(default_video_encoder_config_); | 229 SetDefaultVideoEncoderConfig(default_video_encoder_config_); |
| 279 } | 230 } |
| 280 | 231 |
| 281 return initialized_; | 232 return initialized_; |
| 282 } | 233 } |
| 283 | 234 |
| 284 bool ChannelManager::InitMediaEngine_w() { | 235 bool ChannelManager::InitMediaEngine_w() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 303 | 254 |
| 304 void ChannelManager::Terminate_w() { | 255 void ChannelManager::Terminate_w() { |
| 305 ASSERT(worker_thread_ == rtc::Thread::Current()); | 256 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 306 // Need to destroy the voice/video channels | 257 // Need to destroy the voice/video channels |
| 307 while (!video_channels_.empty()) { | 258 while (!video_channels_.empty()) { |
| 308 DestroyVideoChannel_w(video_channels_.back()); | 259 DestroyVideoChannel_w(video_channels_.back()); |
| 309 } | 260 } |
| 310 while (!voice_channels_.empty()) { | 261 while (!voice_channels_.empty()) { |
| 311 DestroyVoiceChannel_w(voice_channels_.back()); | 262 DestroyVoiceChannel_w(voice_channels_.back()); |
| 312 } | 263 } |
| 313 if (!SetCaptureDevice_w(NULL)) { | |
| 314 LOG(LS_WARNING) << "failed to delete video capturer"; | |
| 315 } | |
| 316 media_engine_->Terminate(); | 264 media_engine_->Terminate(); |
| 317 } | 265 } |
| 318 | 266 |
| 319 VoiceChannel* ChannelManager::CreateVoiceChannel( | 267 VoiceChannel* ChannelManager::CreateVoiceChannel( |
| 320 webrtc::MediaControllerInterface* media_controller, | 268 webrtc::MediaControllerInterface* media_controller, |
| 321 TransportController* transport_controller, | 269 TransportController* transport_controller, |
| 322 const std::string& content_name, | 270 const std::string& content_name, |
| 323 bool rtcp, | 271 bool rtcp, |
| 324 const AudioOptions& options) { | 272 const AudioOptions& options) { |
| 325 return worker_thread_->Invoke<VoiceChannel*>( | 273 return worker_thread_->Invoke<VoiceChannel*>( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 DataChannels::iterator it = std::find(data_channels_.begin(), | 426 DataChannels::iterator it = std::find(data_channels_.begin(), |
| 479 data_channels_.end(), data_channel); | 427 data_channels_.end(), data_channel); |
| 480 ASSERT(it != data_channels_.end()); | 428 ASSERT(it != data_channels_.end()); |
| 481 if (it == data_channels_.end()) | 429 if (it == data_channels_.end()) |
| 482 return; | 430 return; |
| 483 | 431 |
| 484 data_channels_.erase(it); | 432 data_channels_.erase(it); |
| 485 delete data_channel; | 433 delete data_channel; |
| 486 } | 434 } |
| 487 | 435 |
| 488 bool ChannelManager::GetAudioOptions(std::string* in_name, | 436 bool ChannelManager::SetAudioOptions(const AudioOptions& options, |
| 489 std::string* out_name, | |
| 490 AudioOptions* options) { | |
| 491 if (in_name) | |
| 492 *in_name = audio_in_device_; | |
| 493 if (out_name) | |
| 494 *out_name = audio_out_device_; | |
| 495 if (options) | |
| 496 *options = audio_options_; | |
| 497 return true; | |
| 498 } | |
| 499 | |
| 500 bool ChannelManager::SetAudioOptions(const std::string& in_name, | |
| 501 const std::string& out_name, | |
| 502 const AudioOptions& options) { | |
| 503 return SetAudioOptions(in_name, out_name, options, audio_delay_offset_); | |
| 504 } | |
| 505 | |
| 506 bool ChannelManager::SetAudioOptions(const std::string& in_name, | |
| 507 const std::string& out_name, | |
| 508 const AudioOptions& options, | |
| 509 int delay_offset) { | 437 int delay_offset) { |
| 510 // Get device ids from DeviceManager. | 438 // "Get device ids from DeviceManager" - these are the defaults returned. |
| 511 Device in_dev, out_dev; | 439 Device in_dev("", -1); |
| 512 if (!device_manager_->GetAudioInputDevice(in_name, &in_dev)) { | 440 Device out_dev("", -1); |
| 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 | 441 |
| 521 // If we're initialized, pass the settings to the media engine. | 442 // If we're initialized, pass the settings to the media engine. |
| 522 bool ret = true; | 443 bool ret = true; |
| 523 if (initialized_) { | 444 if (initialized_) { |
| 524 ret = worker_thread_->Invoke<bool>( | 445 ret = worker_thread_->Invoke<bool>( |
| 525 Bind(&ChannelManager::SetAudioOptions_w, this, | 446 Bind(&ChannelManager::SetAudioOptions_w, this, |
| 526 options, delay_offset, &in_dev, &out_dev)); | 447 options, delay_offset, &in_dev, &out_dev)); |
| 527 } | 448 } |
| 528 | 449 |
| 529 // If all worked well, save the values for use in GetAudioOptions. | 450 // If all worked well, save the values for use in GetAudioOptions. |
| 530 if (ret) { | 451 if (ret) { |
| 531 audio_options_ = options; | 452 audio_options_ = options; |
| 532 audio_in_device_ = in_name; | |
| 533 audio_out_device_ = out_name; | |
| 534 audio_delay_offset_ = delay_offset; | 453 audio_delay_offset_ = delay_offset; |
| 535 } | 454 } |
| 536 return ret; | 455 return ret; |
| 537 } | 456 } |
| 538 | 457 |
| 539 bool ChannelManager::SetAudioOptions_w( | 458 bool ChannelManager::SetAudioOptions_w( |
| 540 const AudioOptions& options, int delay_offset, | 459 const AudioOptions& options, int delay_offset, |
| 541 const Device* in_dev, const Device* out_dev) { | 460 const Device* in_dev, const Device* out_dev) { |
| 542 ASSERT(worker_thread_ == rtc::Thread::Current()); | 461 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 543 ASSERT(initialized_); | 462 ASSERT(initialized_); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 573 media_engine_.get(), level)); | 492 media_engine_.get(), level)); |
| 574 } | 493 } |
| 575 | 494 |
| 576 if (ret) { | 495 if (ret) { |
| 577 audio_output_volume_ = level; | 496 audio_output_volume_ = level; |
| 578 } | 497 } |
| 579 | 498 |
| 580 return ret; | 499 return ret; |
| 581 } | 500 } |
| 582 | 501 |
| 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 | |
| 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 | |
| 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 } | |
| 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; | |
| 671 } | |
| 672 | |
| 673 VideoCapturer* ChannelManager::CreateScreenCapturer( | |
| 674 const ScreencastId& screenid) { | |
| 675 return device_manager_->CreateScreenCapturer(screenid); | |
| 676 } | |
| 677 | |
| 678 bool ChannelManager::SetCaptureDevice_w(const Device* cam_device) { | |
| 679 ASSERT(worker_thread_ == rtc::Thread::Current()); | |
| 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) { | 502 bool ChannelManager::SetDefaultVideoEncoderConfig(const VideoEncoderConfig& c) { |
| 691 bool ret = true; | 503 bool ret = true; |
| 692 if (initialized_) { | 504 if (initialized_) { |
| 693 ret = worker_thread_->Invoke<bool>( | 505 ret = worker_thread_->Invoke<bool>( |
| 694 Bind(&MediaEngineInterface::SetDefaultVideoEncoderConfig, | 506 Bind(&MediaEngineInterface::SetDefaultVideoEncoderConfig, |
| 695 media_engine_.get(), c)); | 507 media_engine_.get(), c)); |
| 696 } | 508 } |
| 697 if (ret) { | 509 if (ret) { |
| 698 default_video_encoder_config_ = c; | 510 default_video_encoder_config_ = c; |
| 699 } | 511 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 CaptureStateParams* data = | 631 CaptureStateParams* data = |
| 820 static_cast<CaptureStateParams*>(message->pdata); | 632 static_cast<CaptureStateParams*>(message->pdata); |
| 821 SignalVideoCaptureStateChange(data->capturer, data->state); | 633 SignalVideoCaptureStateChange(data->capturer, data->state); |
| 822 delete data; | 634 delete data; |
| 823 break; | 635 break; |
| 824 } | 636 } |
| 825 } | 637 } |
| 826 } | 638 } |
| 827 | 639 |
| 828 | 640 |
| 829 static void GetDeviceNames(const std::vector<Device>& devs, | 641 static void GetDeviceNames(const std::vector<Device>& devs, |
|
Nico
2015/09/29 07:08:57
This function is now unused. Can you remove this t
| |
| 830 std::vector<std::string>* names) { | 642 std::vector<std::string>* names) { |
| 831 names->clear(); | 643 names->clear(); |
| 832 for (size_t i = 0; i < devs.size(); ++i) { | 644 for (size_t i = 0; i < devs.size(); ++i) { |
| 833 names->push_back(devs[i].name); | 645 names->push_back(devs[i].name); |
| 834 } | 646 } |
| 835 } | 647 } |
| 836 | 648 |
| 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 | |
| 873 bool ChannelManager::StartAecDump(rtc::PlatformFile file) { | 649 bool ChannelManager::StartAecDump(rtc::PlatformFile file) { |
| 874 return worker_thread_->Invoke<bool>( | 650 return worker_thread_->Invoke<bool>( |
| 875 Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), file)); | 651 Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), file)); |
| 876 } | 652 } |
| 877 | 653 |
| 878 } // namespace cricket | 654 } // namespace cricket |
| OLD | NEW |