blob: 0c7d73389e5f4da0555f1c74f554dc4b0be99c8d [file] [log] [blame]
solenberg7b38f692015-09-07 04:38:33 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
solenberg7b38f692015-09-07 04:38:33 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
solenberg7b38f692015-09-07 04:38:33 -07009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#include "webrtc/api/mediacontroller.h"
Fredrik Solenberg709ed672015-09-15 12:26:33 +020012
13#include "webrtc/base/bind.h"
14#include "webrtc/base/checks.h"
15#include "webrtc/call.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010016#include "webrtc/pc/channelmanager.h"
Fredrik Solenberg709ed672015-09-15 12:26:33 +020017
18namespace {
19
20const int kMinBandwidthBps = 30000;
21const int kStartBandwidthBps = 300000;
22const int kMaxBandwidthBps = 2000000;
23
stefanc1aeaf02015-10-15 07:26:07 -070024class MediaController : public webrtc::MediaControllerInterface,
25 public sigslot::has_slots<> {
Fredrik Solenberg709ed672015-09-15 12:26:33 +020026 public:
27 MediaController(rtc::Thread* worker_thread,
stefanc1aeaf02015-10-15 07:26:07 -070028 cricket::ChannelManager* channel_manager)
29 : worker_thread_(worker_thread), channel_manager_(channel_manager) {
henrikg91d6ede2015-09-17 00:24:34 -070030 RTC_DCHECK(nullptr != worker_thread);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020031 worker_thread_->Invoke<void>(
stefanc1aeaf02015-10-15 07:26:07 -070032 rtc::Bind(&MediaController::Construct_w, this,
solenberg566ef242015-11-06 15:34:49 -080033 channel_manager_->media_engine()));
Fredrik Solenberg709ed672015-09-15 12:26:33 +020034 }
35 ~MediaController() override {
solenberg566ef242015-11-06 15:34:49 -080036 worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Destruct_w, this));
Fredrik Solenberg709ed672015-09-15 12:26:33 +020037 }
38
39 webrtc::Call* call_w() override {
henrikg91d6ede2015-09-17 00:24:34 -070040 RTC_DCHECK(worker_thread_->IsCurrent());
Fredrik Solenberg709ed672015-09-15 12:26:33 +020041 return call_.get();
42 }
43
stefanc1aeaf02015-10-15 07:26:07 -070044 cricket::ChannelManager* channel_manager() const override {
45 return channel_manager_;
46 }
47
Fredrik Solenberg709ed672015-09-15 12:26:33 +020048 private:
solenberg566ef242015-11-06 15:34:49 -080049 void Construct_w(cricket::MediaEngineInterface* media_engine) {
henrikg91d6ede2015-09-17 00:24:34 -070050 RTC_DCHECK(worker_thread_->IsCurrent());
solenberg566ef242015-11-06 15:34:49 -080051 RTC_DCHECK(media_engine);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020052 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080053 config.audio_state = media_engine->GetAudioState();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020054 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
55 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
56 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
57 call_.reset(webrtc::Call::Create(config));
58 }
59 void Destruct_w() {
henrikg91d6ede2015-09-17 00:24:34 -070060 RTC_DCHECK(worker_thread_->IsCurrent());
stefanc1aeaf02015-10-15 07:26:07 -070061 call_.reset();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020062 }
63
stefanc1aeaf02015-10-15 07:26:07 -070064 rtc::Thread* const worker_thread_;
65 cricket::ChannelManager* const channel_manager_;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020066 rtc::scoped_ptr<webrtc::Call> call_;
67
henrikg3c089d72015-09-16 05:37:44 -070068 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020069};
solenberg566ef242015-11-06 15:34:49 -080070} // namespace {
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071
72namespace webrtc {
73
74MediaControllerInterface* MediaControllerInterface::Create(
stefanc1aeaf02015-10-15 07:26:07 -070075 rtc::Thread* worker_thread,
76 cricket::ChannelManager* channel_manager) {
77 return new MediaController(worker_thread, channel_manager);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020078}
solenberg566ef242015-11-06 15:34:49 -080079} // namespace webrtc