Chromium Code Reviews| 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 |
| 11 #include "webrtc/audio/audio_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | |
| 14 | 15 |
| 15 #include "webrtc/audio/audio_state.h" | 16 #include "webrtc/audio/audio_state.h" |
| 16 #include "webrtc/audio/conversion.h" | 17 #include "webrtc/audio/conversion.h" |
| 17 #include "webrtc/audio/scoped_voe_interface.h" | 18 #include "webrtc/audio/scoped_voe_interface.h" |
| 18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/event.h" | 20 #include "webrtc/base/event.h" |
| 20 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/task_queue.h" | 22 #include "webrtc/base/task_queue.h" |
| 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 23 #include "webrtc/modules/pacing/paced_sender.h" | 24 #include "webrtc/modules/pacing/paced_sender.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 constexpr char kOpusCodecName[] = "opus"; | 37 constexpr char kOpusCodecName[] = "opus"; |
| 37 | 38 |
| 38 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { | 39 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { |
| 39 return (_stricmp(codec.plname, ref_name) == 0); | 40 return (_stricmp(codec.plname, ref_name) == 0); |
| 40 } | 41 } |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 namespace internal { | 44 namespace internal { |
| 45 | |
| 46 class AudioSendStream::AdaptCodecTask : public rtc::QueuedTask { | |
| 47 public: | |
| 48 explicit AdaptCodecTask(const rtc::WeakPtr<AudioSendStream>& send_stream) | |
| 49 : send_stream_(std::move(send_stream)) {} | |
| 50 | |
| 51 private: | |
| 52 bool Run() override { | |
| 53 if (send_stream_) { | |
| 54 send_stream_->AdaptCodec(); | |
| 55 } | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 rtc::WeakPtr<AudioSendStream> send_stream_; | |
| 60 }; | |
| 61 | |
| 44 AudioSendStream::AudioSendStream( | 62 AudioSendStream::AudioSendStream( |
| 45 const webrtc::AudioSendStream::Config& config, | 63 const webrtc::AudioSendStream::Config& config, |
| 46 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, | 64 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 47 rtc::TaskQueue* worker_queue, | 65 rtc::TaskQueue* worker_queue, |
| 48 PacketRouter* packet_router, | 66 PacketRouter* packet_router, |
| 49 CongestionController* congestion_controller, | 67 CongestionController* congestion_controller, |
| 50 BitrateAllocator* bitrate_allocator, | 68 BitrateAllocator* bitrate_allocator, |
| 51 RtcEventLog* event_log, | 69 RtcEventLog* event_log, |
| 52 RtcpRttStats* rtcp_rtt_stats) | 70 RtcpRttStats* rtcp_rtt_stats) |
| 53 : worker_queue_(worker_queue), | 71 : worker_queue_(worker_queue), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 channel_proxy_->SetRtcEventLog(nullptr); | 116 channel_proxy_->SetRtcEventLog(nullptr); |
| 99 channel_proxy_->SetRtcpRttStats(nullptr); | 117 channel_proxy_->SetRtcpRttStats(nullptr); |
| 100 } | 118 } |
| 101 | 119 |
| 102 void AudioSendStream::Start() { | 120 void AudioSendStream::Start() { |
| 103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 121 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { | 122 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { |
| 105 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); | 123 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); |
| 106 rtc::Event thread_sync_event(false /* manual_reset */, false); | 124 rtc::Event thread_sync_event(false /* manual_reset */, false); |
| 107 worker_queue_->PostTask([this, &thread_sync_event] { | 125 worker_queue_->PostTask([this, &thread_sync_event] { |
| 126 weak_ptr_factory_.reset(new rtc::WeakPtrFactory<AudioSendStream>(this)); | |
| 127 weak_ptr_ = weak_ptr_factory_->GetWeakPtr(); | |
| 108 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps, | 128 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps, |
| 109 config_.max_bitrate_bps, 0, true); | 129 config_.max_bitrate_bps, 0, true); |
| 110 thread_sync_event.Set(); | 130 thread_sync_event.Set(); |
| 111 }); | 131 }); |
| 112 thread_sync_event.Wait(rtc::Event::kForever); | 132 thread_sync_event.Wait(rtc::Event::kForever); |
| 113 } | 133 } |
| 114 | 134 |
| 115 ScopedVoEInterface<VoEBase> base(voice_engine()); | 135 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 116 int error = base->StartSend(config_.voe_channel_id); | 136 int error = base->StartSend(config_.voe_channel_id); |
| 117 if (error != 0) { | 137 if (error != 0) { |
| 118 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; | 138 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; |
| 119 } | 139 } |
| 120 } | 140 } |
| 121 | 141 |
| 122 void AudioSendStream::Stop() { | 142 void AudioSendStream::Stop() { |
| 123 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 143 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 124 rtc::Event thread_sync_event(false /* manual_reset */, false); | 144 rtc::Event thread_sync_event(false /* manual_reset */, false); |
| 125 worker_queue_->PostTask([this, &thread_sync_event] { | 145 worker_queue_->PostTask([this, &thread_sync_event] { |
| 126 bitrate_allocator_->RemoveObserver(this); | 146 bitrate_allocator_->RemoveObserver(this); |
| 147 weak_ptr_factory_.reset(nullptr); | |
| 127 thread_sync_event.Set(); | 148 thread_sync_event.Set(); |
| 128 }); | 149 }); |
| 129 thread_sync_event.Wait(rtc::Event::kForever); | 150 thread_sync_event.Wait(rtc::Event::kForever); |
| 130 | 151 |
| 131 ScopedVoEInterface<VoEBase> base(voice_engine()); | 152 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 132 int error = base->StopSend(config_.voe_channel_id); | 153 int error = base->StopSend(config_.voe_channel_id); |
| 133 if (error != 0) { | 154 if (error != 0) { |
| 134 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; | 155 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; |
| 135 } | 156 } |
| 136 } | 157 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 RTC_DCHECK_GE(bitrate_bps, | 258 RTC_DCHECK_GE(bitrate_bps, |
| 238 static_cast<uint32_t>(config_.min_bitrate_bps)); | 259 static_cast<uint32_t>(config_.min_bitrate_bps)); |
| 239 // The bitrate allocator might allocate an higher than max configured bitrate | 260 // The bitrate allocator might allocate an higher than max configured bitrate |
| 240 // if there is room, to allow for, as example, extra FEC. Ignore that for now. | 261 // if there is room, to allow for, as example, extra FEC. Ignore that for now. |
| 241 const uint32_t max_bitrate_bps = config_.max_bitrate_bps; | 262 const uint32_t max_bitrate_bps = config_.max_bitrate_bps; |
| 242 if (bitrate_bps > max_bitrate_bps) | 263 if (bitrate_bps > max_bitrate_bps) |
| 243 bitrate_bps = max_bitrate_bps; | 264 bitrate_bps = max_bitrate_bps; |
| 244 | 265 |
| 245 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); | 266 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); |
| 246 | 267 |
| 268 if (first_update_bitrate_()) { | |
| 269 worker_queue_->PostTask([this]() { AdaptCodec(); }); | |
| 270 } | |
| 271 | |
| 247 // The amount of audio protection is not exposed by the encoder, hence | 272 // The amount of audio protection is not exposed by the encoder, hence |
| 248 // always returning 0. | 273 // always returning 0. |
| 249 return 0; | 274 return 0; |
| 250 } | 275 } |
| 251 | 276 |
| 252 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | 277 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
| 253 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 278 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 254 return config_; | 279 return config_; |
| 255 } | 280 } |
| 256 | 281 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 // interaction between VAD and Opus FEC. | 404 // interaction between VAD and Opus FEC. |
| 380 if (codec->SetVADStatus(channel, true) != 0) { | 405 if (codec->SetVADStatus(channel, true) != 0) { |
| 381 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); | 406 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); |
| 382 return false; | 407 return false; |
| 383 } | 408 } |
| 384 } | 409 } |
| 385 } | 410 } |
| 386 return true; | 411 return true; |
| 387 } | 412 } |
| 388 | 413 |
| 414 void AudioSendStream::AdaptCodec() { | |
| 415 RTC_DCHECK_RUN_ON(worker_queue_); | |
| 416 channel_proxy_->AdaptCodec(); | |
| 417 constexpr uint32_t kAdaptCodecIntervalMs = 200; | |
|
minyue-webrtc
2016/12/07 16:44:44
any reason for this value?
michaelt
2016/12/08 14:06:40
No this was just a first guess.
| |
| 418 worker_queue_->PostDelayedTask( | |
| 419 std::unique_ptr<rtc::QueuedTask>(new AdaptCodecTask(weak_ptr_)), | |
| 420 kAdaptCodecIntervalMs); | |
| 421 } | |
| 422 | |
| 389 } // namespace internal | 423 } // namespace internal |
| 390 } // namespace webrtc | 424 } // namespace webrtc |
| OLD | NEW |