OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/mediacontroller.h" | 11 #include "webrtc/api/mediacontroller.h" |
12 | 12 |
13 #include "webrtc/base/bind.h" | 13 #include "webrtc/base/bind.h" |
14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
15 #include "webrtc/call.h" | 15 #include "webrtc/call.h" |
16 #include "webrtc/pc/channelmanager.h" | 16 #include "webrtc/pc/channelmanager.h" |
17 #include "webrtc/media/base/mediachannel.h" | 17 #include "webrtc/media/base/mediachannel.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const int kMinBandwidthBps = 30000; | 21 const int kMinBandwidthBps = 30000; |
22 const int kStartBandwidthBps = 300000; | 22 const int kStartBandwidthBps = 300000; |
23 const int kMaxBandwidthBps = 2000000; | 23 const int kMaxBandwidthBps = 2000000; |
24 | 24 |
25 class MediaController : public webrtc::MediaControllerInterface, | 25 class MediaController : public webrtc::MediaControllerInterface, |
26 public sigslot::has_slots<> { | 26 public sigslot::has_slots<> { |
27 public: | 27 public: |
28 MediaController(const cricket::MediaConfig& config, | 28 MediaController(const cricket::MediaConfig& media_config, |
29 rtc::Thread* worker_thread, | 29 rtc::Thread* worker_thread, |
30 cricket::ChannelManager* channel_manager) | 30 cricket::ChannelManager* channel_manager) |
31 : worker_thread_(worker_thread), | 31 : worker_thread_(worker_thread), |
32 config_(config), | 32 media_config_(media_config), |
33 channel_manager_(channel_manager) { | 33 channel_manager_(channel_manager) { |
34 RTC_DCHECK(nullptr != worker_thread); | 34 RTC_DCHECK(worker_thread); |
35 worker_thread_->Invoke<void>( | 35 worker_thread_->Invoke<void>( |
36 rtc::Bind(&MediaController::Construct_w, this, | 36 rtc::Bind(&MediaController::Construct_w, this, |
37 channel_manager_->media_engine())); | 37 channel_manager_->media_engine())); |
38 } | 38 } |
39 ~MediaController() override { | 39 ~MediaController() override { |
40 worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Destruct_w, this)); | 40 Close(); |
41 } | 41 } |
42 | 42 |
| 43 // webrtc::MediaControllerInterface implementation. |
| 44 void Close() override { |
| 45 worker_thread_->Invoke<void>(rtc::Bind(&MediaController::Close_w, this)); |
| 46 } |
43 webrtc::Call* call_w() override { | 47 webrtc::Call* call_w() override { |
44 RTC_DCHECK(worker_thread_->IsCurrent()); | 48 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 49 if (!call_) { |
| 50 call_.reset(webrtc::Call::Create(call_config_)); |
| 51 } |
45 return call_.get(); | 52 return call_.get(); |
46 } | 53 } |
47 | |
48 cricket::ChannelManager* channel_manager() const override { | 54 cricket::ChannelManager* channel_manager() const override { |
49 return channel_manager_; | 55 return channel_manager_; |
50 } | 56 } |
51 const cricket::MediaConfig& config() const override { return config_; } | 57 const cricket::MediaConfig& config() const override { return media_config_; } |
52 | 58 |
53 private: | 59 private: |
54 void Construct_w(cricket::MediaEngineInterface* media_engine) { | 60 void Construct_w(cricket::MediaEngineInterface* media_engine) { |
55 RTC_DCHECK(worker_thread_->IsCurrent()); | 61 RTC_DCHECK(worker_thread_->IsCurrent()); |
56 RTC_DCHECK(media_engine); | 62 RTC_DCHECK(media_engine); |
57 webrtc::Call::Config config; | 63 call_config_.audio_state = media_engine->GetAudioState(); |
58 config.audio_state = media_engine->GetAudioState(); | 64 call_config_.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
59 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; | 65 call_config_.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
60 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; | 66 call_config_.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
61 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; | |
62 call_.reset(webrtc::Call::Create(config)); | |
63 } | 67 } |
64 void Destruct_w() { | 68 void Close_w() { |
65 RTC_DCHECK(worker_thread_->IsCurrent()); | 69 RTC_DCHECK(worker_thread_->IsCurrent()); |
66 call_.reset(); | 70 call_.reset(); |
67 } | 71 } |
68 | 72 |
69 rtc::Thread* const worker_thread_; | 73 rtc::Thread* const worker_thread_; |
70 const cricket::MediaConfig config_; | 74 const cricket::MediaConfig media_config_; |
71 cricket::ChannelManager* const channel_manager_; | 75 cricket::ChannelManager* const channel_manager_; |
| 76 webrtc::Call::Config call_config_; |
72 rtc::scoped_ptr<webrtc::Call> call_; | 77 rtc::scoped_ptr<webrtc::Call> call_; |
73 | 78 |
74 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController); | 79 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MediaController); |
75 }; | 80 }; |
76 } // namespace { | 81 } // namespace { |
77 | 82 |
78 namespace webrtc { | 83 namespace webrtc { |
79 | 84 |
80 MediaControllerInterface* MediaControllerInterface::Create( | 85 MediaControllerInterface* MediaControllerInterface::Create( |
81 const cricket::MediaConfig& config, | 86 const cricket::MediaConfig& config, |
82 rtc::Thread* worker_thread, | 87 rtc::Thread* worker_thread, |
83 cricket::ChannelManager* channel_manager) { | 88 cricket::ChannelManager* channel_manager) { |
84 return new MediaController(config, worker_thread, channel_manager); | 89 return new MediaController(config, worker_thread, channel_manager); |
85 } | 90 } |
86 } // namespace webrtc | 91 } // namespace webrtc |
OLD | NEW |