commit 0aee617948e8f398912e2bcd0e1d6c6c48b62749
parent d6c5c8ce4043ea71e4317c1c5039b6894a4ccc25
Author: Michael Froman <mfroman@mozilla.com>
Date: Thu, 9 Oct 2025 09:30:42 -0500
Bug 1993083 - Vendor libwebrtc from 2714423841
Upstream commit: https://webrtc.googlesource.com/src/+/2714423841486c1dc6f931a17d6ff78dd88679d7
Use ArrayView in media/base/rtp_utils
Bug: webrtc:42225170
Change-Id: Ie865c465d5b0a4a807324e746090cafd4e20b40b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/399660
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45123}
Diffstat:
4 files changed, 53 insertions(+), 47 deletions(-)
diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor
@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
-libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-09T14:29:06.700462+00:00.
+libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-09T14:30:33.121460+00:00.
# base of lastest vendoring
-97a3382bf6
+2714423841
diff --git a/third_party/libwebrtc/media/base/rtp_utils.cc b/third_party/libwebrtc/media/base/rtp_utils.cc
@@ -74,8 +74,7 @@ void UpdateAbsSendTimeExtensionValue(uint8_t* extension_data,
// Assumes `length` is actual packet length + tag length. Updates HMAC at end of
// the RTP packet.
-void UpdateRtpAuthTag(uint8_t* rtp,
- size_t length,
+void UpdateRtpAuthTag(ArrayView<uint8_t> rtp,
const PacketTimeUpdateParams& packet_time_params) {
// If there is no key, return.
if (packet_time_params.srtp_auth_key.empty()) {
@@ -86,12 +85,12 @@ void UpdateRtpAuthTag(uint8_t* rtp,
// ROC (rollover counter) is at the beginning of the auth tag.
const size_t kRocLength = 4;
- if (tag_length < kRocLength || tag_length > length) {
+ if (tag_length < kRocLength || tag_length > rtp.size()) {
RTC_DCHECK_NOTREACHED();
return;
}
- uint8_t* auth_tag = rtp + (length - tag_length);
+ uint8_t* auth_tag = rtp.data() + (rtp.size() - tag_length);
// We should have a fake HMAC value @ auth_tag.
RTC_DCHECK_EQ(0, memcmp(auth_tag, kFakeAuthTag, tag_length));
@@ -99,12 +98,12 @@ void UpdateRtpAuthTag(uint8_t* rtp,
// Copy ROC after end of rtp packet.
memcpy(auth_tag, &packet_time_params.srtp_packet_index, kRocLength);
// Authentication of a RTP packet will have RTP packet + ROC size.
- size_t auth_required_length = length - tag_length + kRocLength;
+ size_t auth_required_length = rtp.size() - tag_length + kRocLength;
uint8_t output[64];
size_t result =
ComputeHmac(DIGEST_SHA_1, &packet_time_params.srtp_auth_key[0],
- packet_time_params.srtp_auth_key.size(), rtp,
+ packet_time_params.srtp_auth_key.size(), rtp.data(),
auth_required_length, output, sizeof(output));
if (result < tag_length) {
@@ -188,6 +187,12 @@ RtpPacketType InferRtpPacketType(ArrayView<const uint8_t> packet) {
bool ValidateRtpHeader(const uint8_t* rtp,
size_t length,
size_t* header_length) {
+ return ValidateRtpHeader(ArrayView<const uint8_t>(rtp, length),
+ header_length);
+}
+
+bool ValidateRtpHeader(ArrayView<const uint8_t> rtp, size_t* header_length) {
+ size_t length = rtp.size();
if (header_length) {
*header_length = 0;
}
@@ -211,15 +216,14 @@ bool ValidateRtpHeader(const uint8_t* rtp,
return true;
}
- rtp += header_length_without_extension;
-
if (header_length_without_extension + kRtpExtensionHeaderLen > length) {
return false;
}
// Getting extension profile length.
// Length is in 32 bit words.
- uint16_t extension_length_in_32bits = GetBE16(rtp + 2);
+ uint16_t extension_length_in_32bits =
+ GetBE16(&rtp[header_length_without_extension + 2]);
size_t extension_length = extension_length_in_32bits * 4;
size_t rtp_header_length = extension_length +
@@ -239,8 +243,7 @@ bool ValidateRtpHeader(const uint8_t* rtp,
// ValidateRtpHeader() must be called before this method to make sure, we have
// a sane rtp packet.
-bool UpdateRtpAbsSendTimeExtension(uint8_t* rtp,
- size_t /* length */,
+bool UpdateRtpAbsSendTimeExtension(ArrayView<uint8_t> packet,
int extension_id,
uint64_t time_us) {
// 0 1 2 3
@@ -257,13 +260,14 @@ bool UpdateRtpAbsSendTimeExtension(uint8_t* rtp,
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Return if extension bit is not set.
- if (!(rtp[0] & 0x10)) {
+ if (!(packet[0] & 0x10)) {
return true;
}
- size_t cc_count = rtp[0] & 0x0F;
+ size_t cc_count = packet[0] & 0x0F;
size_t header_length_without_extension = kMinRtpPacketLen + 4 * cc_count;
+ uint8_t* rtp = packet.data();
rtp += header_length_without_extension;
// Getting extension profile ID and length.
@@ -360,6 +364,14 @@ bool ApplyPacketOptions(uint8_t* data,
uint64_t time_us) {
RTC_DCHECK(data);
RTC_DCHECK(length);
+ return ApplyPacketOptions(ArrayView<uint8_t>(data, length),
+ packet_time_params, time_us);
+}
+
+bool ApplyPacketOptions(ArrayView<uint8_t> data,
+ const PacketTimeUpdateParams& packet_time_params,
+ uint64_t time_us) {
+ RTC_DCHECK(data.size() > 0);
// if there is no valid `rtp_sendtime_extension_id` and `srtp_auth_key` in
// PacketOptions, nothing to be updated in this packet.
@@ -373,30 +385,28 @@ bool ApplyPacketOptions(uint8_t* data,
// indication.
size_t rtp_start_pos;
size_t rtp_length;
- if (!UnwrapTurnPacket(data, length, &rtp_start_pos, &rtp_length)) {
+ if (!UnwrapTurnPacket(data.data(), data.size(), &rtp_start_pos,
+ &rtp_length)) {
RTC_DCHECK_NOTREACHED();
return false;
}
// Making sure we have a valid RTP packet at the end.
- auto packet = MakeArrayView(data + rtp_start_pos, rtp_length);
- if (!IsRtpPacket(packet) ||
- !ValidateRtpHeader(data + rtp_start_pos, rtp_length, nullptr)) {
+ auto packet = data.subview(rtp_start_pos, rtp_length);
+ if (!IsRtpPacket(packet) || !ValidateRtpHeader(packet, nullptr)) {
RTC_DCHECK_NOTREACHED();
return false;
}
- uint8_t* start = data + rtp_start_pos;
// If packet option has non default value (-1) for sendtime extension id,
// then we should parse the rtp packet to update the timestamp. Otherwise
// just calculate HMAC and update packet with it.
if (packet_time_params.rtp_sendtime_extension_id != -1) {
- UpdateRtpAbsSendTimeExtension(start, rtp_length,
- packet_time_params.rtp_sendtime_extension_id,
- time_us);
+ UpdateRtpAbsSendTimeExtension(
+ packet, packet_time_params.rtp_sendtime_extension_id, time_us);
}
- UpdateRtpAuthTag(start, rtp_length, packet_time_params);
+ UpdateRtpAuthTag(packet, packet_time_params);
return true;
}
diff --git a/third_party/libwebrtc/media/base/rtp_utils.h b/third_party/libwebrtc/media/base/rtp_utils.h
@@ -56,23 +56,30 @@ bool IsValidRtpPacketSize(RtpPacketType packet_type, size_t size);
absl::string_view RtpPacketTypeToString(RtpPacketType packet_type);
// Verifies that a packet has a valid RTP header.
+// TODO: issues.webrtc.org/42225170 - deprecate when Chrome does not use
bool RTC_EXPORT ValidateRtpHeader(const uint8_t* rtp,
size_t length,
size_t* header_length);
+bool RTC_EXPORT ValidateRtpHeader(ArrayView<const uint8_t> rtp,
+ size_t* header_length);
-// Helper method which updates the absolute send time extension if present.
-bool UpdateRtpAbsSendTimeExtension(uint8_t* rtp,
- size_t length,
+bool UpdateRtpAbsSendTimeExtension(ArrayView<uint8_t> rtp,
int extension_id,
uint64_t time_us);
// Applies specified `options` to the packet. It updates the absolute send time
// extension header if it is present present then updates HMAC.
+
+// TODO: issues.webrtc.org/42225170 - deprecate when Chrome does not use
bool RTC_EXPORT
ApplyPacketOptions(uint8_t* data,
size_t length,
const PacketTimeUpdateParams& packet_time_params,
uint64_t time_us);
+bool RTC_EXPORT
+ApplyPacketOptions(ArrayView<uint8_t> data,
+ const PacketTimeUpdateParams& packet_time_params,
+ uint64_t time_us);
} // namespace webrtc
diff --git a/third_party/libwebrtc/media/base/rtp_utils_unittest.cc b/third_party/libwebrtc/media/base/rtp_utils_unittest.cc
@@ -107,8 +107,7 @@ TEST(RtpUtilsTest, InvalidRtpHeader) {
0xDD, 0xCC, 0xBB, 0xAA, // Only 1 CSRC, but CC count is 4.
// clang-format on
};
- EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength,
- sizeof(kRtpMsgWithInvalidLength), nullptr));
+ EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength, nullptr));
// Rtp message with single byte header extension, invalid extension length.
const uint8_t kRtpMsgWithInvalidExtnLength[] = {
@@ -116,27 +115,23 @@ TEST(RtpUtilsTest, InvalidRtpHeader) {
0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, 0x0A, 0x00, // Extn length - 0x0A00
};
EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength,
- sizeof(kRtpMsgWithInvalidExtnLength),
nullptr));
}
// Valid RTP packet with a 2byte header extension.
TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) {
- EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader,
- sizeof(kRtpMsgWith2ByteExtnHeader), nullptr));
+ EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader, nullptr));
}
// Valid RTP packet which has 1 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithOneByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithOneByteAbsSendTimeExtension,
- sizeof(kRtpMsgWithOneByteAbsSendTimeExtension),
nullptr));
}
// Valid RTP packet which has 2 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithTwoByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithTwoByteAbsSendTimeExtension,
- sizeof(kRtpMsgWithTwoByteAbsSendTimeExtension),
nullptr));
}
@@ -160,8 +155,7 @@ TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) {
0x00, 0x00, 0x00, 0x00,
// clang-format on
};
- EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(
- message_without_extension, sizeof(message_without_extension), 3, 0));
+ EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message_without_extension, 3, 0));
// A valid STUN indication message with a valid RTP header and a extension
// header.
@@ -181,7 +175,7 @@ TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) {
0x00, 0x02, 0x22, 0xaa, 0xbb, 0xcc, 0x32, 0xaa, 0xbb, 0xcc,
// clang-format on
};
- EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, sizeof(message), 3, 0));
+ EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, 3, 0));
}
// Test without any packet options variables set. This method should return
@@ -193,8 +187,7 @@ TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) {
kRtpMsgWithOneByteAbsSendTimeExtension +
sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
- EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
- packet_time_params, 0));
+ EXPECT_TRUE(ApplyPacketOptions(rtp_packet, packet_time_params, 0));
// Making sure HMAC wasn't updated..
EXPECT_EQ(0,
@@ -218,8 +211,7 @@ TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParams) {
kRtpMsgWithOneByteAbsSendTimeExtension +
sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
- EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
- packet_time_params, 0));
+ EXPECT_TRUE(ApplyPacketOptions(rtp_packet, packet_time_params, 0));
uint8_t kExpectedTag[] = {0xc1, 0x7a, 0x8c, 0xa0};
EXPECT_EQ(0,
@@ -238,8 +230,7 @@ TEST(RtpUtilsTest, UpdateOneByteAbsSendTimeExtensionInRtpPacket) {
kRtpMsgWithOneByteAbsSendTimeExtension +
sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
- EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(),
- 3, 51183266));
+ EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(rtp_packet, 3, 51183266));
// Verify that the timestamp was updated.
const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
@@ -254,8 +245,7 @@ TEST(RtpUtilsTest, UpdateTwoByteAbsSendTimeExtensionInRtpPacket) {
kRtpMsgWithTwoByteAbsSendTimeExtension +
sizeof(kRtpMsgWithTwoByteAbsSendTimeExtension));
- EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(),
- 3, 51183266));
+ EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(rtp_packet, 3, 51183266));
// Verify that the timestamp was updated.
const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
@@ -277,8 +267,7 @@ TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) {
kRtpMsgWithOneByteAbsSendTimeExtension +
sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
- EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
- packet_time_params, 51183266));
+ EXPECT_TRUE(ApplyPacketOptions(rtp_packet, packet_time_params, 51183266));
const uint8_t kExpectedTag[] = {0x81, 0xd1, 0x2c, 0x0e};
EXPECT_EQ(0,