Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1137)

Side by Side Diff: webrtc/audio/audio_send_stream.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Response to comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/audio/audio_send_stream.h ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)) {}
ossu 2016/12/19 14:09:27 How do you move from a const&?
michaelt 2016/12/19 14:43:28 I pass rtc::WeakPtr<AudioSendStream> send_stream n
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),
54 config_(config), 72 config_(config),
55 audio_state_(audio_state), 73 audio_state_(audio_state),
56 bitrate_allocator_(bitrate_allocator) { 74 bitrate_allocator_(bitrate_allocator),
75 adapt_codec_task_started_(false) {
57 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); 76 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString();
58 RTC_DCHECK_NE(config_.voe_channel_id, -1); 77 RTC_DCHECK_NE(config_.voe_channel_id, -1);
59 RTC_DCHECK(audio_state_.get()); 78 RTC_DCHECK(audio_state_.get());
60 RTC_DCHECK(congestion_controller); 79 RTC_DCHECK(congestion_controller);
61 80
62 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); 81 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
63 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id); 82 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
64 channel_proxy_->SetRtcEventLog(event_log); 83 channel_proxy_->SetRtcEventLog(event_log);
65 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats); 84 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats);
66 channel_proxy_->RegisterSenderCongestionControlObjects( 85 channel_proxy_->RegisterSenderCongestionControlObjects(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 channel_proxy_->SetRtcEventLog(nullptr); 117 channel_proxy_->SetRtcEventLog(nullptr);
99 channel_proxy_->SetRtcpRttStats(nullptr); 118 channel_proxy_->SetRtcpRttStats(nullptr);
100 } 119 }
101 120
102 void AudioSendStream::Start() { 121 void AudioSendStream::Start() {
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 122 RTC_DCHECK(thread_checker_.CalledOnValidThread());
104 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) { 123 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) {
105 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps); 124 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps);
106 rtc::Event thread_sync_event(false /* manual_reset */, false); 125 rtc::Event thread_sync_event(false /* manual_reset */, false);
107 worker_queue_->PostTask([this, &thread_sync_event] { 126 worker_queue_->PostTask([this, &thread_sync_event] {
127 weak_ptr_factory_.reset(new rtc::WeakPtrFactory<AudioSendStream>(this));
128 audio_send_stream_for_adapt_codec_task_ = weak_ptr_factory_->GetWeakPtr();
108 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps, 129 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps,
109 config_.max_bitrate_bps, 0, true); 130 config_.max_bitrate_bps, 0, true);
110 thread_sync_event.Set(); 131 thread_sync_event.Set();
111 }); 132 });
112 thread_sync_event.Wait(rtc::Event::kForever); 133 thread_sync_event.Wait(rtc::Event::kForever);
113 } 134 }
114 135
115 ScopedVoEInterface<VoEBase> base(voice_engine()); 136 ScopedVoEInterface<VoEBase> base(voice_engine());
116 int error = base->StartSend(config_.voe_channel_id); 137 int error = base->StartSend(config_.voe_channel_id);
117 if (error != 0) { 138 if (error != 0) {
118 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error; 139 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error;
119 } 140 }
120 } 141 }
121 142
122 void AudioSendStream::Stop() { 143 void AudioSendStream::Stop() {
123 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 144 RTC_DCHECK(thread_checker_.CalledOnValidThread());
124 rtc::Event thread_sync_event(false /* manual_reset */, false); 145 rtc::Event thread_sync_event(false /* manual_reset */, false);
125 worker_queue_->PostTask([this, &thread_sync_event] { 146 worker_queue_->PostTask([this, &thread_sync_event] {
126 bitrate_allocator_->RemoveObserver(this); 147 bitrate_allocator_->RemoveObserver(this);
148 weak_ptr_factory_.reset(nullptr);
149 adapt_codec_task_started_ = false;
127 thread_sync_event.Set(); 150 thread_sync_event.Set();
128 }); 151 });
129 thread_sync_event.Wait(rtc::Event::kForever); 152 thread_sync_event.Wait(rtc::Event::kForever);
130 153
131 ScopedVoEInterface<VoEBase> base(voice_engine()); 154 ScopedVoEInterface<VoEBase> base(voice_engine());
132 int error = base->StopSend(config_.voe_channel_id); 155 int error = base->StopSend(config_.voe_channel_id);
133 if (error != 0) { 156 if (error != 0) {
134 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error; 157 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error;
135 } 158 }
136 } 159 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 RTC_DCHECK_GE(bitrate_bps, 260 RTC_DCHECK_GE(bitrate_bps,
238 static_cast<uint32_t>(config_.min_bitrate_bps)); 261 static_cast<uint32_t>(config_.min_bitrate_bps));
239 // The bitrate allocator might allocate an higher than max configured bitrate 262 // 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. 263 // 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; 264 const uint32_t max_bitrate_bps = config_.max_bitrate_bps;
242 if (bitrate_bps > max_bitrate_bps) 265 if (bitrate_bps > max_bitrate_bps)
243 bitrate_bps = max_bitrate_bps; 266 bitrate_bps = max_bitrate_bps;
244 267
245 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms); 268 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms);
246 269
270 if (!adapt_codec_task_started_) {
271 // Starts adapt codec task, which calls AdaptCodec on a timely base.
272 worker_queue_->PostTask([this]() { AdaptCodec(); });
273 adapt_codec_task_started_ = true;
274 }
275
247 // The amount of audio protection is not exposed by the encoder, hence 276 // The amount of audio protection is not exposed by the encoder, hence
248 // always returning 0. 277 // always returning 0.
249 return 0; 278 return 0;
250 } 279 }
251 280
252 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { 281 const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
253 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 282 RTC_DCHECK(thread_checker_.CalledOnValidThread());
254 return config_; 283 return config_;
255 } 284 }
256 285
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // interaction between VAD and Opus FEC. 408 // interaction between VAD and Opus FEC.
380 if (codec->SetVADStatus(channel, true) != 0) { 409 if (codec->SetVADStatus(channel, true) != 0) {
381 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); 410 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError();
382 return false; 411 return false;
383 } 412 }
384 } 413 }
385 } 414 }
386 return true; 415 return true;
387 } 416 }
388 417
418 void AudioSendStream::AdaptCodec() {
419 RTC_DCHECK_RUN_ON(worker_queue_);
420 channel_proxy_->AdaptCodec();
421 worker_queue_->PostDelayedTask(
ossu 2016/12/19 14:09:27 Why isn't this up in AdaptCodecTask and why isn't
michaelt 2016/12/19 14:43:28 Done.
422 std::unique_ptr<rtc::QueuedTask>(
423 new AdaptCodecTask(audio_send_stream_for_adapt_codec_task_)),
424 config_.adapt_codec_interval_ms);
425 }
426
389 } // namespace internal 427 } // namespace internal
390 } // namespace webrtc 428 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_send_stream.h ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698