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

Unified Diff: webrtc/audio/audio_send_stream.cc

Issue 2546493002: Update smoothed bitrate. (Closed)
Patch Set: Fix thread safety problem and changed smoothing filter. 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 b031762b4cecd173e21766e4ab3f91c070a37fd9..d31e7a1903b1f492059041102a31ca25586fd44a 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,
@@ -56,7 +74,6 @@ AudioSendStream::AudioSendStream(
RTC_DCHECK_NE(config_.voe_channel_id, -1);
RTC_DCHECK(audio_state_.get());
RTC_DCHECK(congestion_controller);
-
VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
channel_proxy_->SetRtcEventLog(event_log);
@@ -102,6 +119,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();
@@ -121,6 +140,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);
@@ -240,6 +260,10 @@ uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
channel_proxy_->SetBitrate(bitrate_bps);
+ if (first_update_bitrate_()) {
+ AdaptCodec();
+ }
+
// The amount of audio protection is not exposed by the encoder, hence
// always returning 0.
return 0;
@@ -382,5 +406,14 @@ bool AudioSendStream::SetupSendCodec() {
return true;
}
+void AudioSendStream::AdaptCodec() {
+ RTC_DCHECK_RUN_ON(worker_queue_);
+ channel_proxy_->AdaptCodec();
+ constexpr uint32_t kAdaptCodecIntervalMs = 200;
+ 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