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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/audio/audio_send_stream.cc
diff --git a/webrtc/audio/audio_send_stream.cc b/webrtc/audio/audio_send_stream.cc
index aff605fe6a6845b995fd2082d458d8e5b9f45f4c..ea3c60e2cd4b1a6f0af056844b2c9c6546f71d8a 100644
--- a/webrtc/audio/audio_send_stream.cc
+++ b/webrtc/audio/audio_send_stream.cc
@@ -11,6 +11,7 @@
#include "webrtc/audio/audio_send_stream.h"
#include <string>
+#include <utility>
#include "webrtc/audio/audio_state.h"
#include "webrtc/audio/conversion.h"
@@ -41,6 +42,23 @@ bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
} // namespace
namespace internal {
+
+class AudioSendStream::AdaptCodecTask : public rtc::QueuedTask {
+ public:
+ explicit AdaptCodecTask(const rtc::WeakPtr<AudioSendStream>& send_stream)
+ : send_stream_(std::move(send_stream)) {}
+
+ private:
+ bool Run() override {
+ if (send_stream_) {
+ send_stream_->AdaptCodec();
+ }
+ return true;
+ }
+
+ rtc::WeakPtr<AudioSendStream> send_stream_;
+};
+
AudioSendStream::AudioSendStream(
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
@@ -53,7 +71,8 @@ AudioSendStream::AudioSendStream(
: worker_queue_(worker_queue),
config_(config),
audio_state_(audio_state),
- bitrate_allocator_(bitrate_allocator) {
+ bitrate_allocator_(bitrate_allocator),
+ adapt_codec_task_started_(false) {
LOG(LS_INFO) << "AudioSendStream: " << config_.ToString();
RTC_DCHECK_NE(config_.voe_channel_id, -1);
RTC_DCHECK(audio_state_.get());
@@ -105,6 +124,8 @@ void AudioSendStream::Start() {
RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps);
rtc::Event thread_sync_event(false /* manual_reset */, false);
worker_queue_->PostTask([this, &thread_sync_event] {
+ weak_ptr_factory_.reset(new rtc::WeakPtrFactory<AudioSendStream>(this));
+ weak_ptr_ = weak_ptr_factory_->GetWeakPtr();
bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps,
config_.max_bitrate_bps, 0, true);
thread_sync_event.Set();
@@ -124,6 +145,8 @@ void AudioSendStream::Stop() {
rtc::Event thread_sync_event(false /* manual_reset */, false);
worker_queue_->PostTask([this, &thread_sync_event] {
bitrate_allocator_->RemoveObserver(this);
+ weak_ptr_factory_.reset(nullptr);
+ adapt_codec_task_started_ = false;
thread_sync_event.Set();
});
thread_sync_event.Wait(rtc::Event::kForever);
@@ -234,6 +257,7 @@ uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
uint8_t fraction_loss,
int64_t rtt,
int64_t probing_interval_ms) {
+ RTC_DCHECK_RUN_ON(worker_queue_);
RTC_DCHECK_GE(bitrate_bps,
static_cast<uint32_t>(config_.min_bitrate_bps));
// The bitrate allocator might allocate an higher than max configured bitrate
@@ -244,6 +268,12 @@ uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms);
+ if (!adapt_codec_task_started_) {
+ // Starts adapt codec task, which calls AdaptCodec on a timely base.
+ worker_queue_->PostTask([this]() { AdaptCodec(); });
+ adapt_codec_task_started_ = true;
+ }
+
// The amount of audio protection is not exposed by the encoder, hence
// always returning 0.
return 0;
@@ -386,5 +416,14 @@ bool AudioSendStream::SetupSendCodec() {
return true;
}
+void AudioSendStream::AdaptCodec() {
+ RTC_DCHECK_RUN_ON(worker_queue_);
+ channel_proxy_->AdaptCodec();
+ constexpr uint32_t kAdaptCodecIntervalMs = 200;
minyue-webrtc 2016/12/13 17:21:27 oh, this, how about making it a config_ field?
michaelt 2016/12/14 11:31:21 Done.
+ worker_queue_->PostDelayedTask(
+ std::unique_ptr<rtc::QueuedTask>(new AdaptCodecTask(weak_ptr_)),
+ kAdaptCodecIntervalMs);
+}
+
} // namespace internal
} // namespace webrtc
« 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