blob: 7d94a1a5693fec69b7934a54b0b11c7006465c03 [file] [log] [blame]
solenberg7b38f692015-09-07 04:38:33 -07001/*
2 * libjingle
3 * Copyright 2015 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
Henrik Kjellander15583c12016-02-10 10:53:12 +010028#include "webrtc/api/mediacontroller.h"
Fredrik Solenberg709ed672015-09-15 12:26:33 +020029
stefanc1aeaf02015-10-15 07:26:07 -070030#include "talk/session/media/channelmanager.h"
Fredrik Solenberg709ed672015-09-15 12:26:33 +020031#include "webrtc/base/bind.h"
32#include "webrtc/base/checks.h"
33#include "webrtc/call.h"
34
35namespace {
36
37const int kMinBandwidthBps = 30000;
38const int kStartBandwidthBps = 300000;
39const int kMaxBandwidthBps = 2000000;
40
stefanc1aeaf02015-10-15 07:26:07 -070041class MediaController : public webrtc::MediaControllerInterface,
42 public sigslot::has_slots<> {
Fredrik Solenberg709ed672015-09-15 12:26:33 +020043 public:
44 MediaController(rtc::Thread* worker_thread,
stefanc1aeaf02015-10-15 07:26:07 -070045 cricket::ChannelManager* channel_manager)
46 : worker_thread_(worker_thread), channel_manager_(channel_manager) {
henrikg91d6ede2015-09-17 00:24:34 -070047 RTC_DCHECK(nullptr != worker_thread);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020048 worker_thread_->Invoke<void>(
stefanc1aeaf02015-10-15 07:26:07 -070049 rtc::Bind(&MediaController::Construct_w, this,
solenberg566ef242015-11-06 15:34:49 -080050 channel_manager_->media_engine()));
Fredrik Solenberg709ed672015-09-15 12:26:33 +020051 }
52 ~MediaController() override {
solenberg566ef242015-11-06 15:34:49 -080053 worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Destruct_w, this));
Fredrik Solenberg709ed672015-09-15 12:26:33 +020054 }
55
56 webrtc::Call* call_w() override {
henrikg91d6ede2015-09-17 00:24:34 -070057 RTC_DCHECK(worker_thread_->IsCurrent());
Fredrik Solenberg709ed672015-09-15 12:26:33 +020058 return call_.get();
59 }
60
stefanc1aeaf02015-10-15 07:26:07 -070061 cricket::ChannelManager* channel_manager() const override {
62 return channel_manager_;
63 }
64
Fredrik Solenberg709ed672015-09-15 12:26:33 +020065 private:
solenberg566ef242015-11-06 15:34:49 -080066 void Construct_w(cricket::MediaEngineInterface* media_engine) {
henrikg91d6ede2015-09-17 00:24:34 -070067 RTC_DCHECK(worker_thread_->IsCurrent());
solenberg566ef242015-11-06 15:34:49 -080068 RTC_DCHECK(media_engine);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020069 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080070 config.audio_state = media_engine->GetAudioState();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
72 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
73 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
74 call_.reset(webrtc::Call::Create(config));
75 }
76 void Destruct_w() {
henrikg91d6ede2015-09-17 00:24:34 -070077 RTC_DCHECK(worker_thread_->IsCurrent());
stefanc1aeaf02015-10-15 07:26:07 -070078 call_.reset();
Fredrik Solenberg709ed672015-09-15 12:26:33 +020079 }
80
stefanc1aeaf02015-10-15 07:26:07 -070081 rtc::Thread* const worker_thread_;
82 cricket::ChannelManager* const channel_manager_;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020083 rtc::scoped_ptr<webrtc::Call> call_;
84
henrikg3c089d72015-09-16 05:37:44 -070085 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020086};
solenberg566ef242015-11-06 15:34:49 -080087} // namespace {
Fredrik Solenberg709ed672015-09-15 12:26:33 +020088
89namespace webrtc {
90
91MediaControllerInterface* MediaControllerInterface::Create(
stefanc1aeaf02015-10-15 07:26:07 -070092 rtc::Thread* worker_thread,
93 cricket::ChannelManager* channel_manager) {
94 return new MediaController(worker_thread, channel_manager);
Fredrik Solenberg709ed672015-09-15 12:26:33 +020095}
solenberg566ef242015-11-06 15:34:49 -080096} // namespace webrtc