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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc

Issue 2960363002: Implement RTP keepalive in native stack. (Closed)
Patch Set: Cleanup Created 3 years, 5 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/modules/rtp_rtcp/source/rtp_rtcp_impl.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <algorithm>
15 #include <set> 16 #include <set>
16 #include <string> 17 #include <string>
17 18
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
20 #include "webrtc/common_types.h" 21 #include "webrtc/common_types.h"
21 #include "webrtc/config.h" 22 #include "webrtc/config.h"
22 23
23 #ifdef _WIN32 24 #ifdef _WIN32
24 // Disable warning C4355: 'this' : used in base member initializer list. 25 // Disable warning C4355: 'this' : used in base member initializer list.
25 #pragma warning(disable : 4355) 26 #pragma warning(disable : 4355)
26 #endif 27 #endif
27 28
28 namespace webrtc { 29 namespace webrtc {
30 namespace {
31 const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5;
32 const int64_t kRtpRtcpRttProcessTimeMs = 1000;
33 const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
34 } // namespace
29 35
30 RTPExtensionType StringToRtpExtensionType(const std::string& extension) { 36 RTPExtensionType StringToRtpExtensionType(const std::string& extension) {
31 if (extension == RtpExtension::kTimestampOffsetUri) 37 if (extension == RtpExtension::kTimestampOffsetUri)
32 return kRtpExtensionTransmissionTimeOffset; 38 return kRtpExtensionTransmissionTimeOffset;
33 if (extension == RtpExtension::kAudioLevelUri) 39 if (extension == RtpExtension::kAudioLevelUri)
34 return kRtpExtensionAudioLevel; 40 return kRtpExtensionAudioLevel;
35 if (extension == RtpExtension::kAbsSendTimeUri) 41 if (extension == RtpExtension::kAbsSendTimeUri)
36 return kRtpExtensionAbsoluteSendTime; 42 return kRtpExtensionAbsoluteSendTime;
37 if (extension == RtpExtension::kVideoRotationUri) 43 if (extension == RtpExtension::kVideoRotationUri)
38 return kRtpExtensionVideoRotation; 44 return kRtpExtensionVideoRotation;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 rtcp_receiver_(configuration.clock, 88 rtcp_receiver_(configuration.clock,
83 configuration.receiver_only, 89 configuration.receiver_only,
84 configuration.rtcp_packet_type_counter_observer, 90 configuration.rtcp_packet_type_counter_observer,
85 configuration.bandwidth_callback, 91 configuration.bandwidth_callback,
86 configuration.intra_frame_callback, 92 configuration.intra_frame_callback,
87 configuration.transport_feedback_callback, 93 configuration.transport_feedback_callback,
88 configuration.bitrate_allocation_observer, 94 configuration.bitrate_allocation_observer,
89 this), 95 this),
90 clock_(configuration.clock), 96 clock_(configuration.clock),
91 audio_(configuration.audio), 97 audio_(configuration.audio),
92 last_process_time_(configuration.clock->TimeInMilliseconds()), 98 keepalive_config_(configuration.keepalive_config),
93 last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()), 99 last_bitrate_process_time_(clock_->TimeInMilliseconds()),
94 last_rtt_process_time_(configuration.clock->TimeInMilliseconds()), 100 last_rtt_process_time_(clock_->TimeInMilliseconds()),
101 next_process_time_(clock_->TimeInMilliseconds() +
102 kRtpRtcpMaxIdleTimeProcessMs),
103 next_keepalive_time_(-1),
95 packet_overhead_(28), // IPV4 UDP. 104 packet_overhead_(28), // IPV4 UDP.
96 nack_last_time_sent_full_(0), 105 nack_last_time_sent_full_(0),
97 nack_last_time_sent_full_prev_(0), 106 nack_last_time_sent_full_prev_(0),
98 nack_last_seq_number_sent_(0), 107 nack_last_seq_number_sent_(0),
99 key_frame_req_method_(kKeyFrameReqPliRtcp), 108 key_frame_req_method_(kKeyFrameReqPliRtcp),
100 remote_bitrate_(configuration.remote_bitrate_estimator), 109 remote_bitrate_(configuration.remote_bitrate_estimator),
101 rtt_stats_(configuration.rtt_stats), 110 rtt_stats_(configuration.rtt_stats),
102 rtt_ms_(0) { 111 rtt_ms_(0) {
103 if (!configuration.receiver_only) { 112 if (!configuration.receiver_only) {
104 rtp_sender_.reset(new RTPSender( 113 rtp_sender_.reset(new RTPSender(
105 configuration.audio, 114 configuration.audio,
106 configuration.clock, 115 configuration.clock,
107 configuration.outgoing_transport, 116 configuration.outgoing_transport,
108 configuration.paced_sender, 117 configuration.paced_sender,
109 configuration.flexfec_sender, 118 configuration.flexfec_sender,
110 configuration.transport_sequence_number_allocator, 119 configuration.transport_sequence_number_allocator,
111 configuration.transport_feedback_callback, 120 configuration.transport_feedback_callback,
112 configuration.send_bitrate_observer, 121 configuration.send_bitrate_observer,
113 configuration.send_frame_count_observer, 122 configuration.send_frame_count_observer,
114 configuration.send_side_delay_observer, 123 configuration.send_side_delay_observer,
115 configuration.event_log, 124 configuration.event_log,
116 configuration.send_packet_observer, 125 configuration.send_packet_observer,
117 configuration.retransmission_rate_limiter, 126 configuration.retransmission_rate_limiter,
118 configuration.overhead_observer)); 127 configuration.overhead_observer));
119 // Make sure rtcp sender use same timestamp offset as rtp sender. 128 // Make sure rtcp sender use same timestamp offset as rtp sender.
120 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset()); 129 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
130
131 if (keepalive_config_.timeout_interval_ms != -1) {
132 next_keepalive_time_ =
133 clock_->TimeInMilliseconds() + keepalive_config_.timeout_interval_ms;
134 }
121 } 135 }
122 136
123 // Set default packet size limit. 137 // Set default packet size limit.
124 // TODO(nisse): Kind-of duplicates 138 // TODO(nisse): Kind-of duplicates
125 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize. 139 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
126 const size_t kTcpOverIpv4HeaderSize = 40; 140 const size_t kTcpOverIpv4HeaderSize = 40;
127 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); 141 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
128 } 142 }
129 143
130 // Returns the number of milliseconds until the module want a worker thread 144 // Returns the number of milliseconds until the module want a worker thread
131 // to call Process. 145 // to call Process.
132 int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { 146 int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
133 const int64_t now = clock_->TimeInMilliseconds(); 147 return std::max<int64_t>(0,
134 const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; 148 next_process_time_ - clock_->TimeInMilliseconds());
135 return kRtpRtcpMaxIdleTimeProcessMs - (now - last_process_time_);
136 } 149 }
137 150
138 // Process any pending tasks such as timeouts (non time critical events). 151 // Process any pending tasks such as timeouts (non time critical events).
139 void ModuleRtpRtcpImpl::Process() { 152 void ModuleRtpRtcpImpl::Process() {
140 const int64_t now = clock_->TimeInMilliseconds(); 153 const int64_t now = clock_->TimeInMilliseconds();
141 last_process_time_ = now; 154 next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs;
142 155
143 if (rtp_sender_) { 156 if (rtp_sender_) {
144 const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
145 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { 157 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
146 rtp_sender_->ProcessBitrate(); 158 rtp_sender_->ProcessBitrate();
147 last_bitrate_process_time_ = now; 159 last_bitrate_process_time_ = now;
160 next_process_time_ =
161 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs);
162 }
163 if (keepalive_config_.timeout_interval_ms > 0 &&
164 now >= next_keepalive_time_) {
165 int64_t last_send_time_ms = rtp_sender_->LastTimestampTimeMs();
166 // If no packet has been sent, |last_send_time_ms| will be 0, and so the
167 // keep-alive will be triggered as expected.
168 if (now >= last_send_time_ms + keepalive_config_.timeout_interval_ms) {
169 rtp_sender_->SendKeepAlive(keepalive_config_.payload_type);
170 next_keepalive_time_ = now + keepalive_config_.timeout_interval_ms;
171 } else {
172 next_keepalive_time_ =
173 last_send_time_ms + keepalive_config_.timeout_interval_ms;
174 }
175 next_process_time_ = std::min(next_process_time_, next_keepalive_time_);
148 } 176 }
149 } 177 }
150 const int64_t kRtpRtcpRttProcessTimeMs = 1000; 178
151 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; 179 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
152 if (rtcp_sender_.Sending()) { 180 if (rtcp_sender_.Sending()) {
153 // Process RTT if we have received a receiver report and we haven't 181 // Process RTT if we have received a receiver report and we haven't
154 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. 182 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
155 if (rtcp_receiver_.LastReceivedReceiverReport() > 183 if (rtcp_receiver_.LastReceivedReceiverReport() >
156 last_rtt_process_time_ && process_rtt) { 184 last_rtt_process_time_ && process_rtt) {
157 std::vector<RTCPReportBlock> receive_blocks; 185 std::vector<RTCPReportBlock> receive_blocks;
158 rtcp_receiver_.StatisticsReceived(&receive_blocks); 186 rtcp_receiver_.StatisticsReceived(&receive_blocks);
159 int64_t max_rtt = 0; 187 int64_t max_rtt = 0;
160 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin(); 188 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 int64_t rtt_ms; 222 int64_t rtt_ms;
195 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { 223 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
196 rtt_stats_->OnRttUpdate(rtt_ms); 224 rtt_stats_->OnRttUpdate(rtt_ms);
197 } 225 }
198 } 226 }
199 } 227 }
200 228
201 // Get processed rtt. 229 // Get processed rtt.
202 if (process_rtt) { 230 if (process_rtt) {
203 last_rtt_process_time_ = now; 231 last_rtt_process_time_ = now;
232 next_process_time_ = std::min(
233 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs);
204 if (rtt_stats_) { 234 if (rtt_stats_) {
205 // Make sure we have a valid RTT before setting. 235 // Make sure we have a valid RTT before setting.
206 int64_t last_rtt = rtt_stats_->LastProcessedRtt(); 236 int64_t last_rtt = rtt_stats_->LastProcessedRtt();
207 if (last_rtt >= 0) 237 if (last_rtt >= 0)
208 set_rtt_ms(last_rtt); 238 set_rtt_ms(last_rtt);
209 } 239 }
210 } 240 }
211 241
212 if (rtcp_sender_.TimeToSendRTCPReport()) 242 if (rtcp_sender_.TimeToSendRTCPReport())
213 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); 243 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 StreamDataCountersCallback* 916 StreamDataCountersCallback*
887 ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { 917 ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
888 return rtp_sender_->GetRtpStatisticsCallback(); 918 return rtp_sender_->GetRtpStatisticsCallback();
889 } 919 }
890 920
891 void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( 921 void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
892 const BitrateAllocation& bitrate) { 922 const BitrateAllocation& bitrate) {
893 rtcp_sender_.SetVideoBitrateAllocation(bitrate); 923 rtcp_sender_.SetVideoBitrateAllocation(bitrate);
894 } 924 }
895 } // namespace webrtc 925 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698