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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtcp_sender.cc

Issue 1639253007: Validates sending RTCP before RTP. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: adjusted RtpRtcpImplTest to comply with stricter conditions for Sender Report Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
index 37ea6922f78b770a1d13a3ca17090df371c7a8ea..5c3d03ec59744ef69d120503fe7c7ef7125e68ab 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
@@ -485,6 +485,8 @@ rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) {
last_rtcp_time_[0] = Clock::NtpToMs(ctx.ntp_sec_, ctx.ntp_frac_);
last_send_report_[0] = (ctx.ntp_sec_ << 16) + (ctx.ntp_frac_ >> 16);
+ // Timestamp shouldn't be esitmated before frame was received.
+ RTC_DCHECK_GE(last_frame_capture_time_ms_, 0);
// The timestamp of this RTCP packet should be estimated as the timestamp of
// the frame being captured at this moment. We are calculating that
// timestamp as the last frame's timestamp + the time since the last frame
@@ -823,6 +825,28 @@ int32_t RTCPSender::SendCompoundRTCP(
LOG(LS_WARNING) << "Can't send rtcp if it is disabled.";
return -1;
}
+ // Add all flags as volatile. Non volatile entries will not be overwritten.
+ // All new volatile flags added will be consumed by the end of this call.
+ SetFlags(packet_types, true);
+
+ // Prevent sending streams to send SR before any media has been sent.
+ const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0);
+ if (sending_ && !can_calculate_rtp_timestamp) {
+ bool consumed_report_flag = ConsumeFlag(kRtcpReport);
+ bool consumed_sr_flag = ConsumeFlag(kRtcpSr);
+ bool sender_report = consumed_report_flag || consumed_sr_flag;
+ if (sender_report && AllVolatileFlagsConsumed()) {
+ // This call was for Sender Report and nothing else.
+ return 0;
+ }
+ if (method_ == RtcpMode::kCompound) {
+ // Not allowed to send any RTCP packet without sender report.
+ return -1;
+ }
+ }
+
+ if (packet_type_counter_.first_packet_time_ms == -1)
+ packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
// We need to send our NTP even if we haven't received any reports.
uint32_t ntp_sec;
@@ -831,7 +855,7 @@ int32_t RTCPSender::SendCompoundRTCP(
RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID,
ntp_sec, ntp_frac, &container);
- PrepareReport(packet_types, feedback_state);
+ PrepareReport(feedback_state);
auto it = report_flags_.begin();
while (it != report_flags_.end()) {
@@ -862,15 +886,7 @@ int32_t RTCPSender::SendCompoundRTCP(
return bytes_sent == 0 ? -1 : 0;
}
-void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes,
- const FeedbackState& feedback_state) {
- // Add all flags as volatile. Non volatile entries will not be overwritten
- // and all new volatile flags added will be consumed by the end of this call.
- SetFlags(packetTypes, true);
-
- if (packet_type_counter_.first_packet_time_ms == -1)
- packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
-
+void RTCPSender::PrepareReport(const FeedbackState& feedback_state) {
bool generate_report;
if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) {
// Report type already explicitly set, don't automatically populate.

Powered by Google App Engine
This is Rietveld 408576698