From b0d4b415cc59916a300ceb478b29759bcb94cf8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Tue, 28 Aug 2018 13:58:15 +0200 Subject: [PATCH] Use a lock to protect members accessed by RtpVideoStreamReceiver::GetSyncInfo() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Proper synchronization was overlooked in https://webrtc-review.googlesource.com/93261 Bug: chromium:878319, webrtc:7135 Change-Id: Ifc850c4d67a4e9dd2660dab9b6da67258338553e Reviewed-on: https://webrtc-review.googlesource.com/96461 Reviewed-by: Danil Chapovalov Reviewed-by: Erik Språng Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#24495} --- video/rtp_video_stream_receiver.cc | 22 ++++++++++++++-------- video/rtp_video_stream_receiver.h | 6 ++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc index 46563477e2..e2139b8e8b 100644 --- a/video/rtp_video_stream_receiver.cc +++ b/video/rtp_video_stream_receiver.cc @@ -176,17 +176,20 @@ void RtpVideoStreamReceiver::AddReceiveCodec( } absl::optional RtpVideoStreamReceiver::GetSyncInfo() const { - if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) { - return absl::nullopt; - } Syncable::Info info; if (rtp_rtcp_->RemoteNTP(&info.capture_time_ntp_secs, &info.capture_time_ntp_frac, nullptr, nullptr, &info.capture_time_source_clock) != 0) { return absl::nullopt; } - info.latest_received_capture_timestamp = *last_received_rtp_timestamp_; - info.latest_receive_time_ms = *last_received_rtp_system_time_ms_; + { + rtc::CritScope lock(&last_seq_num_cs_); + if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) { + return absl::nullopt; + } + info.latest_received_capture_timestamp = *last_received_rtp_timestamp_; + info.latest_receive_time_ms = *last_received_rtp_system_time_ms_; + } // Leaves info.current_delay_ms uninitialized. return info; @@ -279,10 +282,13 @@ void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { if (!packet.recovered()) { int64_t now_ms = clock_->TimeInMilliseconds(); - // TODO(nisse): Exclude out-of-order packets? - last_received_rtp_timestamp_ = packet.Timestamp(); - last_received_rtp_system_time_ms_ = now_ms; + { + rtc::CritScope lock(&last_seq_num_cs_); + // TODO(nisse): Exclude out-of-order packets? + last_received_rtp_timestamp_ = packet.Timestamp(); + last_received_rtp_system_time_ms_ = now_ms; + } // Periodically log the RTP header of incoming packets. if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) { std::stringstream ss; diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h index a351c92eaf..e67d66389e 100644 --- a/video/rtp_video_stream_receiver.h +++ b/video/rtp_video_stream_receiver.h @@ -177,8 +177,10 @@ class RtpVideoStreamReceiver : public RtpData, RTC_GUARDED_BY(last_seq_num_cs_); video_coding::H264SpsPpsTracker tracker_; - absl::optional last_received_rtp_timestamp_; - absl::optional last_received_rtp_system_time_ms_; + absl::optional last_received_rtp_timestamp_ + RTC_GUARDED_BY(last_seq_num_cs_); + absl::optional last_received_rtp_system_time_ms_ + RTC_GUARDED_BY(last_seq_num_cs_); std::map pt_codec_type_; // TODO(johan): Remove pt_codec_params_ once // https://bugs.chromium.org/p/webrtc/issues/detail?id=6883 is resolved.