2015-09-07 04:38:33 -07:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-09-07 04:38:33 -07:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-09-07 04:38:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/mediacontroller.h"
|
2015-09-15 12:26:33 +02:00
|
|
|
|
|
|
|
|
#include "webrtc/base/bind.h"
|
|
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
#include "webrtc/call.h"
|
2016-02-12 06:47:59 +01:00
|
|
|
#include "webrtc/pc/channelmanager.h"
|
2016-02-12 02:27:06 -08:00
|
|
|
#include "webrtc/media/base/mediachannel.h"
|
2015-09-15 12:26:33 +02:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const int kMinBandwidthBps = 30000;
|
|
|
|
|
const int kStartBandwidthBps = 300000;
|
|
|
|
|
const int kMaxBandwidthBps = 2000000;
|
|
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
class MediaController : public webrtc::MediaControllerInterface,
|
|
|
|
|
public sigslot::has_slots<> {
|
2015-09-15 12:26:33 +02:00
|
|
|
public:
|
2016-02-12 02:27:06 -08:00
|
|
|
MediaController(const cricket::MediaConfig& config,
|
|
|
|
|
rtc::Thread* worker_thread,
|
2015-10-15 07:26:07 -07:00
|
|
|
cricket::ChannelManager* channel_manager)
|
2016-02-12 02:27:06 -08:00
|
|
|
: worker_thread_(worker_thread),
|
|
|
|
|
config_(config),
|
|
|
|
|
channel_manager_(channel_manager) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(nullptr != worker_thread);
|
2015-09-15 12:26:33 +02:00
|
|
|
worker_thread_->Invoke<void>(
|
2015-10-15 07:26:07 -07:00
|
|
|
rtc::Bind(&MediaController::Construct_w, this,
|
2015-11-06 15:34:49 -08:00
|
|
|
channel_manager_->media_engine()));
|
2015-09-15 12:26:33 +02:00
|
|
|
}
|
|
|
|
|
~MediaController() override {
|
2015-11-06 15:34:49 -08:00
|
|
|
worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Destruct_w, this));
|
2015-09-15 12:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
webrtc::Call* call_w() override {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(worker_thread_->IsCurrent());
|
2015-09-15 12:26:33 +02:00
|
|
|
return call_.get();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
cricket::ChannelManager* channel_manager() const override {
|
|
|
|
|
return channel_manager_;
|
|
|
|
|
}
|
2016-02-12 02:27:06 -08:00
|
|
|
const cricket::MediaConfig& config() const override { return config_; }
|
2015-10-15 07:26:07 -07:00
|
|
|
|
2015-09-15 12:26:33 +02:00
|
|
|
private:
|
2015-11-06 15:34:49 -08:00
|
|
|
void Construct_w(cricket::MediaEngineInterface* media_engine) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(worker_thread_->IsCurrent());
|
2015-11-06 15:34:49 -08:00
|
|
|
RTC_DCHECK(media_engine);
|
2015-09-15 12:26:33 +02:00
|
|
|
webrtc::Call::Config config;
|
2015-11-06 15:34:49 -08:00
|
|
|
config.audio_state = media_engine->GetAudioState();
|
2015-09-15 12:26:33 +02:00
|
|
|
config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
|
|
|
|
|
config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
|
|
|
|
|
config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
|
|
|
|
|
call_.reset(webrtc::Call::Create(config));
|
|
|
|
|
}
|
|
|
|
|
void Destruct_w() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(worker_thread_->IsCurrent());
|
2015-10-15 07:26:07 -07:00
|
|
|
call_.reset();
|
2015-09-15 12:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-15 07:26:07 -07:00
|
|
|
rtc::Thread* const worker_thread_;
|
2016-02-12 02:27:06 -08:00
|
|
|
const cricket::MediaConfig config_;
|
2015-10-15 07:26:07 -07:00
|
|
|
cricket::ChannelManager* const channel_manager_;
|
2015-09-15 12:26:33 +02:00
|
|
|
rtc::scoped_ptr<webrtc::Call> call_;
|
|
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController);
|
2015-09-15 12:26:33 +02:00
|
|
|
};
|
2015-11-06 15:34:49 -08:00
|
|
|
} // namespace {
|
2015-09-15 12:26:33 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
MediaControllerInterface* MediaControllerInterface::Create(
|
2016-02-12 02:27:06 -08:00
|
|
|
const cricket::MediaConfig& config,
|
2015-10-15 07:26:07 -07:00
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
cricket::ChannelManager* channel_manager) {
|
2016-02-12 02:27:06 -08:00
|
|
|
return new MediaController(config, worker_thread, channel_manager);
|
2015-09-15 12:26:33 +02:00
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
} // namespace webrtc
|