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

Unified Diff: webrtc/audio/audio_send_stream.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Check if AdaptCodec runs on worker queue. 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
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..9256a04e3c49ec49be6efd68fab2134e6dbd5613 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,
@@ -105,6 +123,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 +144,7 @@ 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);
thread_sync_event.Set();
});
thread_sync_event.Wait(rtc::Event::kForever);
@@ -244,6 +265,10 @@ uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms);
+ if (first_update_bitrate_()) {
+ worker_queue_->PostTask([this]() { AdaptCodec(); });
+ }
+
// The amount of audio protection is not exposed by the encoder, hence
// always returning 0.
return 0;
@@ -386,5 +411,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/07 16:44:44 any reason for this value?
michaelt 2016/12/08 14:06:40 No this was just a first guess.
+ worker_queue_->PostDelayedTask(
+ std::unique_ptr<rtc::QueuedTask>(new AdaptCodecTask(weak_ptr_)),
+ kAdaptCodecIntervalMs);
+}
+
} // namespace internal
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698