Index: webrtc/audio/audio_send_stream.cc |
diff --git a/webrtc/audio/audio_send_stream.cc b/webrtc/audio/audio_send_stream.cc |
index 438d1cc78a5aca5d7657b6368bfbac03fa5aed8e..4299ff68fc929a24f8ac0190543a274810761f31 100644 |
--- a/webrtc/audio/audio_send_stream.cc |
+++ b/webrtc/audio/audio_send_stream.cc |
@@ -11,6 +11,8 @@ |
#include "webrtc/audio/audio_send_stream.h" |
#include <string> |
+#include <utility> |
+#include <vector> |
#include "webrtc/audio/audio_state.h" |
#include "webrtc/audio/conversion.h" |
@@ -18,6 +20,7 @@ |
#include "webrtc/base/checks.h" |
#include "webrtc/base/event.h" |
#include "webrtc/base/logging.h" |
+#include "webrtc/base/mod_ops.h" |
#include "webrtc/base/task_queue.h" |
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
#include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
@@ -49,7 +52,8 @@ AudioSendStream::AudioSendStream( |
BitrateAllocator* bitrate_allocator, |
RtcEventLog* event_log, |
RtcpRttStats* rtcp_rtt_stats) |
- : worker_queue_(worker_queue), |
+ : clock_(Clock::GetRealTimeClock()), |
+ worker_queue_(worker_queue), |
config_(config), |
audio_state_(audio_state), |
bitrate_allocator_(bitrate_allocator), |
@@ -72,6 +76,7 @@ AudioSendStream::AudioSendStream( |
config_.rtp.nack.rtp_history_ms / 20); |
channel_proxy_->RegisterExternalTransport(config.send_transport); |
+ congestion_controller_->RegisterTransportFeedbackAdapterObserver(this); |
for (const auto& extension : config.rtp.extensions) { |
if (extension.uri == RtpExtension::kAudioLevelUri) { |
@@ -96,6 +101,7 @@ AudioSendStream::AudioSendStream( |
AudioSendStream::~AudioSendStream() { |
RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); |
+ congestion_controller_->DeRegisterTransportFeedbackAdapterObserver(this); |
channel_proxy_->DeRegisterExternalTransport(); |
channel_proxy_->ResetCongestionControlObjects(); |
channel_proxy_->SetRtcEventLog(nullptr); |
@@ -247,6 +253,55 @@ uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
return 0; |
} |
+void AudioSendStream::OnPacketAdded(uint32_t ssrc, uint16_t seq_num) { |
+ if (ssrc != config_.rtp.ssrc) |
+ return; |
+ |
+ const int64_t sent_time_ms = clock_->TimeInMilliseconds(); |
+ |
+ // To make sure everything happens on the same thread, we'll buffer |
+ // this information and pass it down with the first OnTransportFeedback, |
+ // which is called on the thread which channel_proxy_ mostly works on. |
minyue-webrtc
2017/03/15 10:54:13
second "which" -> that
elad.alon_webrtc.org
2017/03/16 18:37:35
This code no longer exists after the redesign.
|
+ rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); |
+ |
+ // Prevent unbounded memory consumption if OnTransportFeedback ends up |
minyue-webrtc
2017/03/15 10:54:13
I think this may be better taken care inside the p
elad.alon_webrtc.org
2017/03/16 18:37:34
No longer relevant after redesign, but for posteri
|
+ // never being called. Messages which are 0x8000 (or more) sequence numbers |
+ // away from the newest message will end up having no effect, so we can |
+ // discard those. |
+ if (!packets_sent_since_last_feedback_.empty() && |
+ (packets_sent_since_last_feedback_[0].sequence_number == seq_num || |
+ ForwardDiff(packets_sent_since_last_feedback_[0].sequence_number, |
+ seq_num) >= 0x8000)) { |
+ // The element are ordered (circularly), so we can batch-remove. No need |
+ // for binary search, because we expect to usually find the edge in the |
+ // beginning of the container. |
+ auto it = packets_sent_since_last_feedback_.cbegin(); |
+ while (it != packets_sent_since_last_feedback_.cend() && |
+ (it->sequence_number == seq_num || |
+ ForwardDiff(it->sequence_number, seq_num) >= 0x8000)) { |
+ ++it; |
+ } |
+ packets_sent_since_last_feedback_.erase( |
+ packets_sent_since_last_feedback_.cbegin(), it); |
+ } |
+ |
+ packets_sent_since_last_feedback_.emplace_back( |
+ SentTransportPacketRecord{seq_num, sent_time_ms}); |
+} |
+ |
+void AudioSendStream::OnTransportFeedback( |
+ const rtcp::TransportFeedback& feedback) { |
+ RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ std::vector<SentTransportPacketRecord> packets_sent_since_last_feedback; |
+ { |
+ rtc::CritScope lock(&packets_sent_since_last_feedback_cs_); |
+ std::swap(packets_sent_since_last_feedback_, |
+ packets_sent_since_last_feedback); |
+ } |
+ channel_proxy_->HandleTransportFeedback(packets_sent_since_last_feedback, |
+ feedback); |
+} |
+ |
const webrtc::AudioSendStream::Config& AudioSendStream::config() const { |
RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
return config_; |