In ReceiveStatistics fix a signed integer overflow undefined behavior
Bug: b/318332290 Change-Id: I279dcaf8c9cb801482f0e29343304c854af78792 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/333060 Reviewed-by: Johannes Kron <kron@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41463}
This commit is contained in:
parent
764ac7ec0a
commit
8a74636d46
@ -18,6 +18,7 @@
|
||||
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
@ -159,16 +160,15 @@ void StreamStatisticianImpl::UpdateJitter(const RtpPacketReceived& packet,
|
||||
int32_t time_diff_samples =
|
||||
receive_diff_rtp - (packet.Timestamp() - last_received_timestamp_);
|
||||
|
||||
time_diff_samples = std::abs(time_diff_samples);
|
||||
|
||||
ReviseFrequencyAndJitter(packet.payload_type_frequency());
|
||||
|
||||
// lib_jingle sometimes deliver crazy jumps in TS for the same stream.
|
||||
// If this happens, don't update jitter value. Use 5 secs video frequency
|
||||
// as the threshold.
|
||||
if (time_diff_samples < 450000) {
|
||||
if (time_diff_samples < 5 * kVideoPayloadTypeFrequency &&
|
||||
time_diff_samples > -5 * kVideoPayloadTypeFrequency) {
|
||||
// Note we calculate in Q4 to avoid using float.
|
||||
int32_t jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_;
|
||||
int32_t jitter_diff_q4 = (std::abs(time_diff_samples) << 4) - jitter_q4_;
|
||||
jitter_q4_ += ((jitter_diff_q4 + 8) >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
@ -898,5 +898,22 @@ TEST(ReviseJitterTest,
|
||||
EXPECT_EQ(GetJitter(*statistics), 172U);
|
||||
}
|
||||
|
||||
TEST(ReviseJitterTest, TwoPacketsWithMaximumRtpTimestampDifference) {
|
||||
SimulatedClock clock(0);
|
||||
std::unique_ptr<ReceiveStatistics> statistics =
|
||||
ReceiveStatistics::Create(&clock);
|
||||
RtpPacketReceived packet1 = MakeRtpPacket(/*payload_type_frequency=*/90'000,
|
||||
/*timestamp=*/0x01234567);
|
||||
RtpPacketReceived packet2 =
|
||||
MakeNextRtpPacket(packet1,
|
||||
/*payload_type_frequency=*/90'000,
|
||||
/*timestamp=*/0x81234567);
|
||||
statistics->OnRtpPacket(packet1);
|
||||
statistics->OnRtpPacket(packet2);
|
||||
|
||||
// Expect large jump in RTP timestamp is ignored for jitter calculation.
|
||||
EXPECT_EQ(GetJitter(*statistics), 0U);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user