OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // TODO(solenberg): Encoder config. | 52 // TODO(solenberg): Encoder config. |
53 ss << ", cng_payload_type: " << cng_payload_type; | 53 ss << ", cng_payload_type: " << cng_payload_type; |
54 ss << '}'; | 54 ss << '}'; |
55 return ss.str(); | 55 return ss.str(); |
56 } | 56 } |
57 | 57 |
58 namespace internal { | 58 namespace internal { |
59 AudioSendStream::AudioSendStream( | 59 AudioSendStream::AudioSendStream( |
60 const webrtc::AudioSendStream::Config& config, | 60 const webrtc::AudioSendStream::Config& config, |
61 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 61 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
62 CongestionController* congestion_controller) | 62 CongestionController* congestion_controller, |
63 : config_(config), audio_state_(audio_state) { | 63 BitrateAllocator* bitrate_allocator) |
| 64 : config_(config), |
| 65 audio_state_(audio_state), |
| 66 bitrate_allocator_(bitrate_allocator) { |
64 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 67 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); |
65 RTC_DCHECK_NE(config_.voe_channel_id, -1); | 68 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
66 RTC_DCHECK(audio_state_.get()); | 69 RTC_DCHECK(audio_state_.get()); |
67 RTC_DCHECK(congestion_controller); | 70 RTC_DCHECK(congestion_controller); |
68 | 71 |
69 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 72 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
70 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); | 73 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); |
71 channel_proxy_->RegisterSenderCongestionControlObjects( | 74 channel_proxy_->RegisterSenderCongestionControlObjects( |
72 congestion_controller->pacer(), | 75 congestion_controller->pacer(), |
73 congestion_controller->GetTransportFeedbackObserver(), | 76 congestion_controller->GetTransportFeedbackObserver(), |
(...skipping 23 matching lines...) Expand all Loading... |
97 | 100 |
98 AudioSendStream::~AudioSendStream() { | 101 AudioSendStream::~AudioSendStream() { |
99 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 102 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
100 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 103 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
101 channel_proxy_->DeRegisterExternalTransport(); | 104 channel_proxy_->DeRegisterExternalTransport(); |
102 channel_proxy_->ResetCongestionControlObjects(); | 105 channel_proxy_->ResetCongestionControlObjects(); |
103 } | 106 } |
104 | 107 |
105 void AudioSendStream::Start() { | 108 void AudioSendStream::Start() { |
106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 109 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) { |
| 111 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps); |
| 112 bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000, |
| 113 config_.max_bitrate_kbps * 1000, 0, true); |
| 114 } |
| 115 |
107 ScopedVoEInterface<VoEBase> base(voice_engine()); | 116 ScopedVoEInterface<VoEBase> base(voice_engine()); |
108 int error = base->StartSend(config_.voe_channel_id); | 117 int error = base->StartSend(config_.voe_channel_id); |
109 if (error != 0) { | 118 if (error != 0) { |
110 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; | 119 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; |
111 } | 120 } |
112 } | 121 } |
113 | 122 |
114 void AudioSendStream::Stop() { | 123 void AudioSendStream::Stop() { |
115 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 124 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 125 bitrate_allocator_->RemoveObserver(this); |
116 ScopedVoEInterface<VoEBase> base(voice_engine()); | 126 ScopedVoEInterface<VoEBase> base(voice_engine()); |
117 int error = base->StopSend(config_.voe_channel_id); | 127 int error = base->StopSend(config_.voe_channel_id); |
118 if (error != 0) { | 128 if (error != 0) { |
119 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; | 129 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; |
120 } | 130 } |
121 } | 131 } |
122 | 132 |
123 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, | 133 bool AudioSendStream::SendTelephoneEvent(int payload_type, int event, |
124 int duration_ms) { | 134 int duration_ms) { |
125 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 230 } |
221 | 231 |
222 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 232 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
223 // TODO(solenberg): Tests call this function on a network thread, libjingle | 233 // TODO(solenberg): Tests call this function on a network thread, libjingle |
224 // calls on the worker thread. We should move towards always using a network | 234 // calls on the worker thread. We should move towards always using a network |
225 // thread. Then this check can be enabled. | 235 // thread. Then this check can be enabled. |
226 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 236 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
227 return channel_proxy_->ReceivedRTCPPacket(packet, length); | 237 return channel_proxy_->ReceivedRTCPPacket(packet, length); |
228 } | 238 } |
229 | 239 |
| 240 uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
| 241 uint8_t fraction_loss, |
| 242 int64_t rtt) { |
| 243 RTC_DCHECK_GE(bitrate_bps, |
| 244 static_cast<uint32_t>(config_.min_bitrate_kbps * 1000)); |
| 245 // The bitrate allocator might allocate an higher than max configured bitrate |
| 246 // if there is room, to allow for, as example, extra FEC. Ignore that for now. |
| 247 const uint32_t max_bitrate_bps = config_.max_bitrate_kbps * 1000; |
| 248 if (bitrate_bps > max_bitrate_bps) |
| 249 bitrate_bps = max_bitrate_bps; |
| 250 |
| 251 channel_proxy_->SetBitrate(bitrate_bps); |
| 252 |
| 253 // The amount of audio protection is not exposed by the encoder, hence |
| 254 // always returning 0. |
| 255 return 0; |
| 256 } |
| 257 |
230 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 258 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
231 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 259 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
232 return config_; | 260 return config_; |
233 } | 261 } |
234 | 262 |
235 VoiceEngine* AudioSendStream::voice_engine() const { | 263 VoiceEngine* AudioSendStream::voice_engine() const { |
236 internal::AudioState* audio_state = | 264 internal::AudioState* audio_state = |
237 static_cast<internal::AudioState*>(audio_state_.get()); | 265 static_cast<internal::AudioState*>(audio_state_.get()); |
238 VoiceEngine* voice_engine = audio_state->voice_engine(); | 266 VoiceEngine* voice_engine = audio_state->voice_engine(); |
239 RTC_DCHECK(voice_engine); | 267 RTC_DCHECK(voice_engine); |
240 return voice_engine; | 268 return voice_engine; |
241 } | 269 } |
242 } // namespace internal | 270 } // namespace internal |
243 } // namespace webrtc | 271 } // namespace webrtc |
OLD | NEW |