| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/api/mediacontroller.h" | |
| 12 | |
| 13 #include <memory> | |
| 14 | |
| 15 #include "webrtc/base/bind.h" | |
| 16 #include "webrtc/base/checks.h" | |
| 17 #include "webrtc/base/constructormagic.h" | |
| 18 #include "webrtc/call/call.h" | |
| 19 #include "webrtc/pc/channelmanager.h" | |
| 20 #include "webrtc/media/base/mediachannel.h" | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const int kMinBandwidthBps = 30000; | |
| 25 const int kStartBandwidthBps = 300000; | |
| 26 const int kMaxBandwidthBps = 2000000; | |
| 27 | |
| 28 class MediaController : public webrtc::MediaControllerInterface, | |
| 29 public sigslot::has_slots<> { | |
| 30 public: | |
| 31 MediaController(const cricket::MediaConfig& media_config, | |
| 32 rtc::Thread* worker_thread, | |
| 33 cricket::ChannelManager* channel_manager, | |
| 34 webrtc::RtcEventLog* event_log) | |
| 35 : worker_thread_(worker_thread), | |
| 36 media_config_(media_config), | |
| 37 channel_manager_(channel_manager), | |
| 38 call_config_(event_log) { | |
| 39 RTC_DCHECK(worker_thread); | |
| 40 RTC_DCHECK(event_log); | |
| 41 worker_thread_->Invoke<void>(RTC_FROM_HERE, | |
| 42 rtc::Bind(&MediaController::Construct_w, this, | |
| 43 channel_manager_->media_engine())); | |
| 44 } | |
| 45 ~MediaController() override { | |
| 46 Close(); | |
| 47 } | |
| 48 | |
| 49 // webrtc::MediaControllerInterface implementation. | |
| 50 void Close() override { | |
| 51 worker_thread_->Invoke<void>(RTC_FROM_HERE, | |
| 52 rtc::Bind(&MediaController::Close_w, this)); | |
| 53 } | |
| 54 webrtc::Call* call_w() override { | |
| 55 RTC_DCHECK(worker_thread_->IsCurrent()); | |
| 56 if (!call_) { | |
| 57 call_.reset(webrtc::Call::Create(call_config_)); | |
| 58 } | |
| 59 return call_.get(); | |
| 60 } | |
| 61 cricket::ChannelManager* channel_manager() const override { | |
| 62 return channel_manager_; | |
| 63 } | |
| 64 const cricket::MediaConfig& config() const override { return media_config_; } | |
| 65 | |
| 66 private: | |
| 67 void Construct_w(cricket::MediaEngineInterface* media_engine) { | |
| 68 RTC_DCHECK(worker_thread_->IsCurrent()); | |
| 69 RTC_DCHECK(media_engine); | |
| 70 call_config_.audio_state = media_engine->GetAudioState(); | |
| 71 call_config_.bitrate_config.min_bitrate_bps = kMinBandwidthBps; | |
| 72 call_config_.bitrate_config.start_bitrate_bps = kStartBandwidthBps; | |
| 73 call_config_.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; | |
| 74 } | |
| 75 void Close_w() { | |
| 76 RTC_DCHECK(worker_thread_->IsCurrent()); | |
| 77 call_.reset(); | |
| 78 } | |
| 79 | |
| 80 rtc::Thread* const worker_thread_; | |
| 81 const cricket::MediaConfig media_config_; | |
| 82 cricket::ChannelManager* const channel_manager_; | |
| 83 webrtc::Call::Config call_config_; | |
| 84 std::unique_ptr<webrtc::Call> call_; | |
| 85 | |
| 86 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController); | |
| 87 }; | |
| 88 } // namespace { | |
| 89 | |
| 90 namespace webrtc { | |
| 91 | |
| 92 MediaControllerInterface* MediaControllerInterface::Create( | |
| 93 const cricket::MediaConfig& config, | |
| 94 rtc::Thread* worker_thread, | |
| 95 cricket::ChannelManager* channel_manager, | |
| 96 webrtc::RtcEventLog* event_log) { | |
| 97 return new MediaController(config, worker_thread, channel_manager, event_log); | |
| 98 } | |
| 99 } // namespace webrtc | |
| OLD | NEW |