Use rtc::CopyOnWriteBuffer::MutableData through webrtc
where mutable access is required. Bug: webrtc:12334 Change-Id: I4b2b74f836aaf7f12278c3569d0d49936297716b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/198846 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32936}
This commit is contained in:
parent
da06e8f6bd
commit
e15dc58f32
@ -129,7 +129,8 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
|
||||
rtp_packets_.push_back(*packet);
|
||||
if (conf_) {
|
||||
for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) {
|
||||
if (!SetRtpSsrc(packet->data(), packet->size(), conf_sent_ssrcs_[i])) {
|
||||
if (!SetRtpSsrc(packet->MutableData(), packet->size(),
|
||||
conf_sent_ssrcs_[i])) {
|
||||
return false;
|
||||
}
|
||||
PostMessage(ST_RTP, *packet);
|
||||
|
||||
@ -312,7 +312,7 @@ bool RtpDataMediaChannel::SendData(const SendDataParams& params,
|
||||
&header.timestamp);
|
||||
|
||||
rtc::CopyOnWriteBuffer packet(kMinRtpPacketLen, packet_len);
|
||||
if (!SetRtpHeader(packet.data(), packet.size(), header)) {
|
||||
if (!SetRtpHeader(packet.MutableData(), packet.size(), header)) {
|
||||
return false;
|
||||
}
|
||||
packet.AppendData(kReservedSpace);
|
||||
|
||||
@ -2050,7 +2050,7 @@ TEST_F(WebRtcVideoChannelBaseTest, SetSink) {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
rtc::CopyOnWriteBuffer packet1(data1, sizeof(data1));
|
||||
rtc::SetBE32(packet1.data() + 8, kSsrc);
|
||||
rtc::SetBE32(packet1.MutableData() + 8, kSsrc);
|
||||
channel_->SetDefaultSink(NULL);
|
||||
EXPECT_TRUE(SetDefaultCodec());
|
||||
EXPECT_TRUE(SetSend(true));
|
||||
|
||||
@ -1136,14 +1136,14 @@ void SctpTransport::OnPacketFromSctpToNetwork(
|
||||
}
|
||||
|
||||
int SctpTransport::InjectDataOrNotificationFromSctpForTesting(
|
||||
void* data,
|
||||
const void* data,
|
||||
size_t length,
|
||||
struct sctp_rcvinfo rcv,
|
||||
int flags) {
|
||||
return OnDataOrNotificationFromSctp(data, length, rcv, flags);
|
||||
}
|
||||
|
||||
int SctpTransport::OnDataOrNotificationFromSctp(void* data,
|
||||
int SctpTransport::OnDataOrNotificationFromSctp(const void* data,
|
||||
size_t length,
|
||||
struct sctp_rcvinfo rcv,
|
||||
int flags) {
|
||||
@ -1166,7 +1166,7 @@ int SctpTransport::OnDataOrNotificationFromSctp(void* data,
|
||||
<< " length=" << length;
|
||||
|
||||
// Copy and dispatch asynchronously
|
||||
rtc::CopyOnWriteBuffer notification(reinterpret_cast<uint8_t*>(data),
|
||||
rtc::CopyOnWriteBuffer notification(reinterpret_cast<const uint8_t*>(data),
|
||||
length);
|
||||
network_thread_->PostTask(ToQueuedTask(
|
||||
task_safety_, [this, notification = std::move(notification)]() {
|
||||
@ -1216,7 +1216,7 @@ int SctpTransport::OnDataOrNotificationFromSctp(void* data,
|
||||
params.timestamp = 0;
|
||||
|
||||
// Append the chunk's data to the message buffer
|
||||
partial_incoming_message_.AppendData(reinterpret_cast<uint8_t*>(data),
|
||||
partial_incoming_message_.AppendData(reinterpret_cast<const uint8_t*>(data),
|
||||
length);
|
||||
partial_params_ = params;
|
||||
partial_flags_ = flags;
|
||||
|
||||
@ -96,7 +96,7 @@ class SctpTransport : public SctpTransportInternal,
|
||||
void set_debug_name_for_testing(const char* debug_name) override {
|
||||
debug_name_ = debug_name;
|
||||
}
|
||||
int InjectDataOrNotificationFromSctpForTesting(void* data,
|
||||
int InjectDataOrNotificationFromSctpForTesting(const void* data,
|
||||
size_t length,
|
||||
struct sctp_rcvinfo rcv,
|
||||
int flags);
|
||||
@ -182,7 +182,7 @@ class SctpTransport : public SctpTransportInternal,
|
||||
|
||||
// Called on the SCTP thread.
|
||||
// Flags are standard socket API flags (RFC 6458).
|
||||
int OnDataOrNotificationFromSctp(void* data,
|
||||
int OnDataOrNotificationFromSctp(const void* data,
|
||||
size_t length,
|
||||
struct sctp_rcvinfo rcv,
|
||||
int flags);
|
||||
|
||||
@ -589,7 +589,7 @@ TEST_P(SctpTransportTestWithOrdered, SignalReadyToSendDataAfterBlocked) {
|
||||
params.sid = 1;
|
||||
params.ordered = GetParam();
|
||||
rtc::CopyOnWriteBuffer buf(1024);
|
||||
memset(buf.data<uint8_t>(), 0, 1024);
|
||||
memset(buf.MutableData(), 0, 1024);
|
||||
SendDataResult result;
|
||||
size_t message_count = 0;
|
||||
for (; message_count < kMaxMessages; ++message_count) {
|
||||
|
||||
@ -57,7 +57,7 @@ ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
|
||||
media_packet->data.SetSize(
|
||||
random_->Rand(min_packet_size_, max_packet_size_));
|
||||
|
||||
uint8_t* data = media_packet->data.data();
|
||||
uint8_t* data = media_packet->data.MutableData();
|
||||
// Generate random values for the first 2 bytes
|
||||
data[0] = random_->Rand<uint8_t>();
|
||||
data[1] = random_->Rand<uint8_t>();
|
||||
@ -88,7 +88,7 @@ ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
|
||||
// Last packet, set marker bit.
|
||||
ForwardErrorCorrection::Packet* media_packet = media_packets.back().get();
|
||||
RTC_DCHECK(media_packet);
|
||||
media_packet->data[1] |= 0x80;
|
||||
media_packet->data.MutableData()[1] |= 0x80;
|
||||
|
||||
next_seq_num_ = seq_num;
|
||||
|
||||
@ -122,7 +122,7 @@ std::unique_ptr<AugmentedPacket> AugmentedPacketGenerator::NextPacket(
|
||||
std::unique_ptr<AugmentedPacket> packet(new AugmentedPacket());
|
||||
|
||||
packet->data.SetSize(length + kRtpHeaderSize);
|
||||
uint8_t* data = packet->data.data();
|
||||
uint8_t* data = packet->data.MutableData();
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
data[i + kRtpHeaderSize] = offset + i;
|
||||
packet->data.SetSize(length + kRtpHeaderSize);
|
||||
@ -132,7 +132,7 @@ std::unique_ptr<AugmentedPacket> AugmentedPacketGenerator::NextPacket(
|
||||
packet->header.sequenceNumber = seq_num_;
|
||||
packet->header.timestamp = timestamp_;
|
||||
packet->header.ssrc = ssrc_;
|
||||
WriteRtpHeader(packet->header, packet->data.data());
|
||||
WriteRtpHeader(packet->header, data);
|
||||
++seq_num_;
|
||||
--num_packets_;
|
||||
|
||||
@ -171,8 +171,8 @@ std::unique_ptr<AugmentedPacket> FlexfecPacketGenerator::BuildFlexfecPacket(
|
||||
std::unique_ptr<AugmentedPacket> packet_with_rtp_header(
|
||||
new AugmentedPacket());
|
||||
packet_with_rtp_header->data.SetSize(kRtpHeaderSize + packet.data.size());
|
||||
WriteRtpHeader(header, packet_with_rtp_header->data.data());
|
||||
memcpy(packet_with_rtp_header->data.data() + kRtpHeaderSize,
|
||||
WriteRtpHeader(header, packet_with_rtp_header->data.MutableData());
|
||||
memcpy(packet_with_rtp_header->data.MutableData() + kRtpHeaderSize,
|
||||
packet.data.cdata(), packet.data.size());
|
||||
|
||||
return packet_with_rtp_header;
|
||||
|
||||
@ -85,7 +85,7 @@ bool FlexfecHeaderReader::ReadFecHeader(
|
||||
RTC_LOG(LS_WARNING) << "Discarding truncated FlexFEC packet.";
|
||||
return false;
|
||||
}
|
||||
uint8_t* const data = fec_packet->pkt->data.data();
|
||||
uint8_t* const data = fec_packet->pkt->data.MutableData();
|
||||
bool r_bit = (data[0] & 0x80) != 0;
|
||||
if (r_bit) {
|
||||
RTC_LOG(LS_INFO)
|
||||
@ -249,7 +249,7 @@ void FlexfecHeaderWriter::FinalizeFecHeader(
|
||||
const uint8_t* packet_mask,
|
||||
size_t packet_mask_size,
|
||||
ForwardErrorCorrection::Packet* fec_packet) const {
|
||||
uint8_t* data = fec_packet->data.data();
|
||||
uint8_t* data = fec_packet->data.MutableData();
|
||||
data[0] &= 0x7f; // Clear R bit.
|
||||
data[0] &= 0xbf; // Clear F bit.
|
||||
ByteWriter<uint8_t>::WriteBigEndian(&data[8], kSsrcCount);
|
||||
@ -260,8 +260,7 @@ void FlexfecHeaderWriter::FinalizeFecHeader(
|
||||
//
|
||||
// We treat the mask parts as unsigned integers with host order endianness
|
||||
// in order to simplify the bit shifting between bytes.
|
||||
uint8_t* const written_packet_mask =
|
||||
fec_packet->data.data() + kPacketMaskOffset;
|
||||
uint8_t* const written_packet_mask = data + kPacketMaskOffset;
|
||||
if (packet_mask_size == kUlpfecPacketMaskSizeLBitSet) {
|
||||
// The packet mask is 48 bits long.
|
||||
uint16_t tmp_mask_part0 =
|
||||
|
||||
@ -78,8 +78,9 @@ rtc::scoped_refptr<Packet> WriteHeader(const uint8_t* packet_mask,
|
||||
FlexfecHeaderWriter writer;
|
||||
rtc::scoped_refptr<Packet> written_packet(new Packet());
|
||||
written_packet->data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet->data.MutableData();
|
||||
for (size_t i = 0; i < written_packet->data.size(); ++i) {
|
||||
written_packet->data[i] = i; // Actual content doesn't matter.
|
||||
data[i] = i; // Actual content doesn't matter.
|
||||
}
|
||||
writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask,
|
||||
packet_mask_size, written_packet.get());
|
||||
@ -328,8 +329,9 @@ TEST(FlexfecHeaderWriterTest, FinalizesHeaderWithKBit0Set) {
|
||||
constexpr uint8_t kUlpfecPacketMask[] = {0x11, 0x02};
|
||||
Packet written_packet;
|
||||
written_packet.data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet.data.MutableData();
|
||||
for (size_t i = 0; i < written_packet.data.size(); ++i) {
|
||||
written_packet.data[i] = i;
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
FlexfecHeaderWriter writer;
|
||||
@ -346,8 +348,9 @@ TEST(FlexfecHeaderWriterTest, FinalizesHeaderWithKBit1Set) {
|
||||
constexpr uint8_t kUlpfecPacketMask[] = {0x91, 0x02, 0x08, 0x44, 0x00, 0x84};
|
||||
Packet written_packet;
|
||||
written_packet.data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet.data.MutableData();
|
||||
for (size_t i = 0; i < written_packet.data.size(); ++i) {
|
||||
written_packet.data[i] = i;
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
FlexfecHeaderWriter writer;
|
||||
@ -368,8 +371,9 @@ TEST(FlexfecHeaderWriterTest, FinalizesHeaderWithKBit2Set) {
|
||||
constexpr uint8_t kUlpfecPacketMask[] = {0x22, 0x22, 0x44, 0x44, 0x44, 0x41};
|
||||
Packet written_packet;
|
||||
written_packet.data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet.data.MutableData();
|
||||
for (size_t i = 0; i < written_packet.data.size(); ++i) {
|
||||
written_packet.data[i] = i;
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
FlexfecHeaderWriter writer;
|
||||
|
||||
@ -165,10 +165,10 @@ TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) {
|
||||
PacketizeFrame(kNumMediaPackets, 0, &media_packets);
|
||||
auto& media_packet = media_packets.front();
|
||||
// Corrupt the SSRC.
|
||||
media_packet->data[8] = 0;
|
||||
media_packet->data[9] = 1;
|
||||
media_packet->data[10] = 2;
|
||||
media_packet->data[11] = 3;
|
||||
media_packet->data.MutableData()[8] = 0;
|
||||
media_packet->data.MutableData()[9] = 1;
|
||||
media_packet->data.MutableData()[10] = 2;
|
||||
media_packet->data.MutableData()[11] = 3;
|
||||
|
||||
EXPECT_FALSE(receiver_.AddReceivedPacket(ParsePacket(*media_packet)));
|
||||
}
|
||||
@ -183,10 +183,10 @@ TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) {
|
||||
const auto& media_packet = media_packets.front();
|
||||
auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front());
|
||||
// Corrupt the SSRC.
|
||||
fec_packet->data[8] = 4;
|
||||
fec_packet->data[9] = 5;
|
||||
fec_packet->data[10] = 6;
|
||||
fec_packet->data[11] = 7;
|
||||
fec_packet->data.MutableData()[8] = 4;
|
||||
fec_packet->data.MutableData()[9] = 5;
|
||||
fec_packet->data.MutableData()[10] = 6;
|
||||
fec_packet->data.MutableData()[11] = 7;
|
||||
|
||||
std::unique_ptr<ForwardErrorCorrection::ReceivedPacket> received_packet =
|
||||
receiver_.AddReceivedPacket(ParsePacket(*media_packet));
|
||||
|
||||
@ -151,7 +151,7 @@ int ForwardErrorCorrection::EncodeFec(const PacketList& media_packets,
|
||||
}
|
||||
for (int i = 0; i < num_fec_packets; ++i) {
|
||||
generated_fec_packets_[i].data.EnsureCapacity(IP_PACKET_SIZE);
|
||||
memset(generated_fec_packets_[i].data.data(), 0, IP_PACKET_SIZE);
|
||||
memset(generated_fec_packets_[i].data.MutableData(), 0, IP_PACKET_SIZE);
|
||||
// Use this as a marker for untouched packets.
|
||||
generated_fec_packets_[i].data.SetSize(0);
|
||||
fec_packets->push_back(&generated_fec_packets_[i]);
|
||||
@ -231,7 +231,7 @@ void ForwardErrorCorrection::GenerateFecPayloads(
|
||||
fec_packet->data.SetSize(fec_packet_length);
|
||||
}
|
||||
if (first_protected_packet) {
|
||||
uint8_t* data = fec_packet->data.data();
|
||||
uint8_t* data = fec_packet->data.MutableData();
|
||||
// Write P, X, CC, M, and PT recovery fields.
|
||||
// Note that bits 0, 1, and 16 are overwritten in FinalizeFecHeaders.
|
||||
memcpy(&data[0], &media_packet_data[0], 2);
|
||||
@ -567,11 +567,11 @@ bool ForwardErrorCorrection::StartPacketRecovery(
|
||||
// Copy bytes corresponding to minimum RTP header size.
|
||||
// Note that the sequence number and SSRC fields will be overwritten
|
||||
// at the end of packet recovery.
|
||||
memcpy(recovered_packet->pkt->data.data(), fec_packet.pkt->data.cdata(),
|
||||
kRtpHeaderSize);
|
||||
memcpy(recovered_packet->pkt->data.MutableData(),
|
||||
fec_packet.pkt->data.cdata(), kRtpHeaderSize);
|
||||
// Copy remaining FEC payload.
|
||||
if (fec_packet.protection_length > 0) {
|
||||
memcpy(recovered_packet->pkt->data.data() + kRtpHeaderSize,
|
||||
memcpy(recovered_packet->pkt->data.MutableData() + kRtpHeaderSize,
|
||||
fec_packet.pkt->data.cdata() + fec_packet.fec_header_size,
|
||||
fec_packet.protection_length);
|
||||
}
|
||||
@ -581,7 +581,7 @@ bool ForwardErrorCorrection::StartPacketRecovery(
|
||||
bool ForwardErrorCorrection::FinishPacketRecovery(
|
||||
const ReceivedFecPacket& fec_packet,
|
||||
RecoveredPacket* recovered_packet) {
|
||||
uint8_t* data = recovered_packet->pkt->data.data();
|
||||
uint8_t* data = recovered_packet->pkt->data.MutableData();
|
||||
// Set the RTP version to 2.
|
||||
data[0] |= 0x80; // Set the 1st bit.
|
||||
data[0] &= 0xbf; // Clear the 2nd bit.
|
||||
@ -603,7 +603,7 @@ bool ForwardErrorCorrection::FinishPacketRecovery(
|
||||
}
|
||||
|
||||
void ForwardErrorCorrection::XorHeaders(const Packet& src, Packet* dst) {
|
||||
uint8_t* dst_data = dst->data.data();
|
||||
uint8_t* dst_data = dst->data.MutableData();
|
||||
const uint8_t* src_data = src.data.cdata();
|
||||
// XOR the first 2 bytes of the header: V, P, X, CC, M, PT fields.
|
||||
dst_data[0] ^= src_data[0];
|
||||
@ -635,7 +635,7 @@ void ForwardErrorCorrection::XorPayloads(const Packet& src,
|
||||
if (dst_offset + payload_length > dst->data.size()) {
|
||||
dst->data.SetSize(dst_offset + payload_length);
|
||||
}
|
||||
uint8_t* dst_data = dst->data.data();
|
||||
uint8_t* dst_data = dst->data.MutableData();
|
||||
const uint8_t* src_data = src.data.cdata();
|
||||
for (size_t i = 0; i < payload_length; ++i) {
|
||||
dst_data[dst_offset + i] ^= src_data[kRtpHeaderSize + i];
|
||||
@ -731,11 +731,11 @@ void ForwardErrorCorrection::DiscardOldRecoveredPackets(
|
||||
RTC_DCHECK_LE(recovered_packets->size(), max_media_packets);
|
||||
}
|
||||
|
||||
uint16_t ForwardErrorCorrection::ParseSequenceNumber(uint8_t* packet) {
|
||||
uint16_t ForwardErrorCorrection::ParseSequenceNumber(const uint8_t* packet) {
|
||||
return (packet[2] << 8) + packet[3];
|
||||
}
|
||||
|
||||
uint32_t ForwardErrorCorrection::ParseSsrc(uint8_t* packet) {
|
||||
uint32_t ForwardErrorCorrection::ParseSsrc(const uint8_t* packet) {
|
||||
return (packet[8] << 24) + (packet[9] << 16) + (packet[10] << 8) + packet[11];
|
||||
}
|
||||
|
||||
|
||||
@ -235,8 +235,8 @@ class ForwardErrorCorrection {
|
||||
|
||||
// TODO(brandtr): Remove these functions when the Packet classes
|
||||
// have been refactored.
|
||||
static uint16_t ParseSequenceNumber(uint8_t* packet);
|
||||
static uint32_t ParseSsrc(uint8_t* packet);
|
||||
static uint16_t ParseSequenceNumber(const uint8_t* packet);
|
||||
static uint32_t ParseSsrc(const uint8_t* packet);
|
||||
|
||||
protected:
|
||||
ForwardErrorCorrection(std::unique_ptr<FecHeaderReader> fec_header_reader,
|
||||
|
||||
@ -127,7 +127,7 @@ void RtpFecTest<ForwardErrorCorrectionType>::ReceivedPackets(
|
||||
// For media packets, the sequence number is obtained from the
|
||||
// RTP header as written by MediaPacketGenerator::ConstructMediaPackets.
|
||||
received_packet->seq_num =
|
||||
ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]);
|
||||
ByteReader<uint16_t>::ReadBigEndian(packet->data.data() + 2);
|
||||
} else {
|
||||
received_packet->ssrc = ForwardErrorCorrectionType::kFecSsrc;
|
||||
// For FEC packets, we simulate the sequence numbers differently
|
||||
@ -222,10 +222,10 @@ TYPED_TEST(RtpFecTest, WillProtectMediaPacketsWithLargeSequenceNumberGap) {
|
||||
this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
|
||||
|
||||
// Create |kMaxMediaPackets - 1| sequence number difference.
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.front()->data[2],
|
||||
1);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.back()->data[2],
|
||||
kMaxMediaPackets);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(
|
||||
this->media_packets_.front()->data.MutableData() + 2, 1);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(
|
||||
this->media_packets_.back()->data.MutableData() + 2, kMaxMediaPackets);
|
||||
|
||||
EXPECT_EQ(
|
||||
0, this->fec_.EncodeFec(this->media_packets_, kProtectionFactor,
|
||||
@ -245,9 +245,10 @@ TYPED_TEST(RtpFecTest,
|
||||
this->media_packet_generator_.ConstructMediaPackets(kNumMediaPackets);
|
||||
|
||||
// Create |kMaxMediaPackets| sequence number difference.
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.front()->data[2],
|
||||
1);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&this->media_packets_.back()->data[2],
|
||||
ByteWriter<uint16_t>::WriteBigEndian(
|
||||
this->media_packets_.front()->data.MutableData() + 2, 1);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(
|
||||
this->media_packets_.back()->data.MutableData() + 2,
|
||||
kMaxMediaPackets + 1);
|
||||
|
||||
EXPECT_EQ(
|
||||
@ -526,9 +527,9 @@ TEST_F(RtpFecTestFlexfecOnly, FecRecoveryWithSeqNumGapOneFrameNoRecovery) {
|
||||
// Overwrite the sequence numbers generated by ConstructMediaPackets,
|
||||
// to make sure that we do have a wrap.
|
||||
auto it = this->generated_fec_packets_.begin();
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 65535);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data.MutableData()[2], 65535);
|
||||
++it;
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data[2], 0);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(&(*it)->data.MutableData()[2], 0);
|
||||
|
||||
// Lose the last two media packets (seq# 65533, 65534).
|
||||
memset(this->media_loss_mask_, 0, sizeof(this->media_loss_mask_));
|
||||
|
||||
@ -180,8 +180,10 @@ class RtpPacket {
|
||||
|
||||
uint16_t SetExtensionLengthMaybeAddZeroPadding(size_t extensions_offset);
|
||||
|
||||
uint8_t* WriteAt(size_t offset) { return buffer_.data() + offset; }
|
||||
void WriteAt(size_t offset, uint8_t byte) { buffer_.data()[offset] = byte; }
|
||||
uint8_t* WriteAt(size_t offset) { return buffer_.MutableData() + offset; }
|
||||
void WriteAt(size_t offset, uint8_t byte) {
|
||||
buffer_.MutableData()[offset] = byte;
|
||||
}
|
||||
const uint8_t* ReadAt(size_t offset) const { return buffer_.data() + offset; }
|
||||
|
||||
// Header.
|
||||
|
||||
@ -57,7 +57,7 @@ UlpfecHeaderReader::~UlpfecHeaderReader() = default;
|
||||
|
||||
bool UlpfecHeaderReader::ReadFecHeader(
|
||||
ForwardErrorCorrection::ReceivedFecPacket* fec_packet) const {
|
||||
uint8_t* data = fec_packet->pkt->data.data();
|
||||
uint8_t* data = fec_packet->pkt->data.MutableData();
|
||||
if (fec_packet->pkt->data.size() < kPacketMaskOffset) {
|
||||
return false; // Truncated packet.
|
||||
}
|
||||
@ -108,7 +108,7 @@ void UlpfecHeaderWriter::FinalizeFecHeader(
|
||||
const uint8_t* packet_mask,
|
||||
size_t packet_mask_size,
|
||||
ForwardErrorCorrection::Packet* fec_packet) const {
|
||||
uint8_t* data = fec_packet->data.data();
|
||||
uint8_t* data = fec_packet->data.MutableData();
|
||||
// Set E bit to zero.
|
||||
data[0] &= 0x7f;
|
||||
// Set L bit based on packet mask size. (Note that the packet mask
|
||||
|
||||
@ -53,8 +53,9 @@ std::unique_ptr<Packet> WriteHeader(const uint8_t* packet_mask,
|
||||
UlpfecHeaderWriter writer;
|
||||
std::unique_ptr<Packet> written_packet(new Packet());
|
||||
written_packet->data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet->data.MutableData();
|
||||
for (size_t i = 0; i < written_packet->data.size(); ++i) {
|
||||
written_packet->data[i] = i; // Actual content doesn't matter.
|
||||
data[i] = i; // Actual content doesn't matter.
|
||||
}
|
||||
writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask,
|
||||
packet_mask_size, written_packet.get());
|
||||
@ -85,7 +86,8 @@ void VerifyHeaders(size_t expected_fec_header_size,
|
||||
EXPECT_EQ(written_packet.data.size() - expected_fec_header_size,
|
||||
read_packet.protection_length);
|
||||
EXPECT_EQ(0, memcmp(expected_packet_mask,
|
||||
&read_packet.pkt->data[read_packet.packet_mask_offset],
|
||||
read_packet.pkt->data.MutableData() +
|
||||
read_packet.packet_mask_offset,
|
||||
read_packet.packet_mask_size));
|
||||
// Verify that the call to ReadFecHeader did not tamper with the payload.
|
||||
EXPECT_EQ(0, memcmp(written_packet.data.data() + expected_fec_header_size,
|
||||
@ -147,8 +149,9 @@ TEST(UlpfecHeaderWriterTest, FinalizesSmallHeader) {
|
||||
auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd);
|
||||
Packet written_packet;
|
||||
written_packet.data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet.data.MutableData();
|
||||
for (size_t i = 0; i < written_packet.data.size(); ++i) {
|
||||
written_packet.data[i] = i;
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
UlpfecHeaderWriter writer;
|
||||
@ -171,8 +174,9 @@ TEST(UlpfecHeaderWriterTest, FinalizesLargeHeader) {
|
||||
auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd);
|
||||
Packet written_packet;
|
||||
written_packet.data.SetSize(kMediaPacketLength);
|
||||
uint8_t* data = written_packet.data.MutableData();
|
||||
for (size_t i = 0; i < written_packet.data.size(); ++i) {
|
||||
written_packet.data[i] = i;
|
||||
data[i] = i;
|
||||
}
|
||||
|
||||
UlpfecHeaderWriter writer;
|
||||
|
||||
@ -135,8 +135,9 @@ bool UlpfecReceiverImpl::AddReceivedRedPacket(
|
||||
received_packet->pkt->data.SetData(rtp_packet.data(),
|
||||
rtp_packet.headers_size());
|
||||
// Set payload type.
|
||||
received_packet->pkt->data[1] &= 0x80; // Reset RED payload type.
|
||||
received_packet->pkt->data[1] += payload_type; // Set media payload type.
|
||||
uint8_t& payload_type_byte = received_packet->pkt->data.MutableData()[1];
|
||||
payload_type_byte &= 0x80; // Reset RED payload type.
|
||||
payload_type_byte += payload_type; // Set media payload type.
|
||||
// Copy payload data.
|
||||
received_packet->pkt->data.AppendData(red_payload.data(),
|
||||
red_payload.size());
|
||||
|
||||
@ -158,7 +158,7 @@ void UlpfecReceiverTest::InjectGarbagePacketLength(size_t fec_garbage_offset) {
|
||||
std::list<ForwardErrorCorrection::Packet*> fec_packets;
|
||||
EncodeFec(media_packets, kNumFecPackets, &fec_packets);
|
||||
ByteWriter<uint16_t>::WriteBigEndian(
|
||||
&fec_packets.front()->data[fec_garbage_offset], 0x4711);
|
||||
fec_packets.front()->data.MutableData() + fec_garbage_offset, 0x4711);
|
||||
|
||||
// Inject first media packet, then first FEC packet, skipping the second media
|
||||
// packet to cause a recovery from the FEC packet.
|
||||
|
||||
@ -264,7 +264,7 @@ absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> ParseFuaNalu(
|
||||
uint8_t original_nal_header = fnri | original_nal_type;
|
||||
rtp_payload =
|
||||
rtp_payload.Slice(kNalHeaderSize, rtp_payload.size() - kNalHeaderSize);
|
||||
rtp_payload[0] = original_nal_header;
|
||||
rtp_payload.MutableData()[0] = original_nal_header;
|
||||
parsed_payload->video_payload = std::move(rtp_payload);
|
||||
} else {
|
||||
parsed_payload->video_payload =
|
||||
|
||||
@ -254,7 +254,7 @@ void RunTest(bool use_flexfec) {
|
||||
random.Rand(kMinPacketSize, kMaxPacketSize);
|
||||
media_packet->data.SetSize(packet_length);
|
||||
|
||||
uint8_t* data = media_packet->data.data();
|
||||
uint8_t* data = media_packet->data.MutableData();
|
||||
// Generate random values for the first 2 bytes.
|
||||
data[0] = random.Rand<uint8_t>();
|
||||
data[1] = random.Rand<uint8_t>();
|
||||
@ -285,7 +285,7 @@ void RunTest(bool use_flexfec) {
|
||||
media_packet_list.push_back(std::move(media_packet));
|
||||
seq_num++;
|
||||
}
|
||||
media_packet_list.back()->data[1] |= 0x80;
|
||||
media_packet_list.back()->data.MutableData()[1] |= 0x80;
|
||||
|
||||
ASSERT_EQ(0, fec->EncodeFec(media_packet_list, protection_factor,
|
||||
num_imp_packets, kUseUnequalProtection,
|
||||
@ -312,8 +312,8 @@ void RunTest(bool use_flexfec) {
|
||||
received_packet->pkt = new ForwardErrorCorrection::Packet();
|
||||
received_packet->pkt->data = media_packet->data;
|
||||
received_packet->ssrc = media_ssrc;
|
||||
received_packet->seq_num =
|
||||
ByteReader<uint16_t>::ReadBigEndian(&media_packet->data[2]);
|
||||
received_packet->seq_num = ByteReader<uint16_t>::ReadBigEndian(
|
||||
media_packet->data.data() + 2);
|
||||
received_packet->is_fec = false;
|
||||
received_packet_list.push_back(std::move(received_packet));
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ void SetRemoteFingerprintFromCert(
|
||||
std::unique_ptr<rtc::SSLFingerprint> fingerprint =
|
||||
rtc::SSLFingerprint::CreateFromCertificate(*cert);
|
||||
if (modify_digest) {
|
||||
++fingerprint->digest[0];
|
||||
++fingerprint->digest.MutableData()[0];
|
||||
}
|
||||
// Even if digest is verified to be incorrect, should fail asynchrnously.
|
||||
EXPECT_TRUE(transport->SetRemoteFingerprint(
|
||||
|
||||
@ -546,7 +546,7 @@ TEST_F(SctpDataChannelTest, ClosedWhenSendBufferFull) {
|
||||
SetChannelReady();
|
||||
|
||||
rtc::CopyOnWriteBuffer buffer(1024);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
memset(buffer.MutableData(), 0, buffer.size());
|
||||
|
||||
webrtc::DataBuffer packet(buffer, true);
|
||||
provider_->set_send_blocked(true);
|
||||
@ -581,7 +581,7 @@ TEST_F(SctpDataChannelTest, ClosedOnTransportError) {
|
||||
TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) {
|
||||
SetChannelReady();
|
||||
rtc::CopyOnWriteBuffer buffer(1024);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
memset(buffer.MutableData(), 0, buffer.size());
|
||||
|
||||
cricket::ReceiveDataParams params;
|
||||
params.ssrc = 0;
|
||||
@ -623,7 +623,7 @@ TEST_F(SctpDataChannelTest, TransportDestroyedWhileDataBuffered) {
|
||||
SetChannelReady();
|
||||
|
||||
rtc::CopyOnWriteBuffer buffer(1024);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
memset(buffer.MutableData(), 0, buffer.size());
|
||||
webrtc::DataBuffer packet(buffer, true);
|
||||
|
||||
// Send a packet while sending is blocked so it ends up buffered.
|
||||
|
||||
@ -178,15 +178,15 @@ TEST_F(SctpUtilsTest, WriteParseAckMessage) {
|
||||
|
||||
TEST_F(SctpUtilsTest, TestIsOpenMessage) {
|
||||
rtc::CopyOnWriteBuffer open(1);
|
||||
open[0] = 0x03;
|
||||
open.MutableData()[0] = 0x03;
|
||||
EXPECT_TRUE(webrtc::IsOpenMessage(open));
|
||||
|
||||
rtc::CopyOnWriteBuffer openAck(1);
|
||||
openAck[0] = 0x02;
|
||||
openAck.MutableData()[0] = 0x02;
|
||||
EXPECT_FALSE(webrtc::IsOpenMessage(openAck));
|
||||
|
||||
rtc::CopyOnWriteBuffer invalid(1);
|
||||
invalid[0] = 0x01;
|
||||
invalid.MutableData()[0] = 0x01;
|
||||
EXPECT_FALSE(webrtc::IsOpenMessage(invalid));
|
||||
|
||||
rtc::CopyOnWriteBuffer empty;
|
||||
|
||||
@ -128,7 +128,7 @@ bool SrtpTransport::SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
|
||||
rtc::PacketOptions updated_options = options;
|
||||
TRACE_EVENT0("webrtc", "SRTP Encode");
|
||||
bool res;
|
||||
uint8_t* data = packet->data();
|
||||
uint8_t* data = packet->MutableData();
|
||||
int len = rtc::checked_cast<int>(packet->size());
|
||||
// If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done
|
||||
// inside libsrtp for a RTP packet. A external HMAC module will be writing
|
||||
@ -185,7 +185,7 @@ bool SrtpTransport::SendRtcpPacket(rtc::CopyOnWriteBuffer* packet,
|
||||
}
|
||||
|
||||
TRACE_EVENT0("webrtc", "SRTP Encode");
|
||||
uint8_t* data = packet->data();
|
||||
uint8_t* data = packet->MutableData();
|
||||
int len = rtc::checked_cast<int>(packet->size());
|
||||
if (!ProtectRtcp(data, len, static_cast<int>(packet->capacity()), &len)) {
|
||||
int type = -1;
|
||||
@ -208,7 +208,7 @@ void SrtpTransport::OnRtpPacketReceived(rtc::CopyOnWriteBuffer packet,
|
||||
return;
|
||||
}
|
||||
TRACE_EVENT0("webrtc", "SRTP Decode");
|
||||
char* data = packet.data<char>();
|
||||
char* data = packet.MutableData<char>();
|
||||
int len = rtc::checked_cast<int>(packet.size());
|
||||
if (!UnprotectRtp(data, len, &len)) {
|
||||
int seq_num = -1;
|
||||
@ -240,7 +240,7 @@ void SrtpTransport::OnRtcpPacketReceived(rtc::CopyOnWriteBuffer packet,
|
||||
return;
|
||||
}
|
||||
TRACE_EVENT0("webrtc", "SRTP Decode");
|
||||
char* data = packet.data<char>();
|
||||
char* data = packet.MutableData<char>();
|
||||
int len = rtc::checked_cast<int>(packet.size());
|
||||
if (!UnprotectRtcp(data, len, &len)) {
|
||||
int type = -1;
|
||||
|
||||
@ -593,12 +593,12 @@ class FakePacketRoute : public EmulatedNetworkReceiverInterface {
|
||||
RTC_CHECK_GE(size, sizeof(int));
|
||||
sent_.emplace(next_packet_id_, packet);
|
||||
rtc::CopyOnWriteBuffer buf(size);
|
||||
reinterpret_cast<int*>(buf.data())[0] = next_packet_id_++;
|
||||
reinterpret_cast<int*>(buf.MutableData())[0] = next_packet_id_++;
|
||||
route_->from->SendPacket(send_addr_, recv_addr_, buf);
|
||||
}
|
||||
|
||||
void OnPacketReceived(EmulatedIpPacket packet) override {
|
||||
int packet_id = reinterpret_cast<int*>(packet.data.data())[0];
|
||||
int packet_id = reinterpret_cast<const int*>(packet.data.data())[0];
|
||||
action_(std::move(sent_[packet_id]), packet.arrival_time);
|
||||
sent_.erase(packet_id);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ void TrafficRoute::SendPacket(size_t packet_size) {
|
||||
|
||||
void TrafficRoute::SendPacket(size_t packet_size, uint16_t dest_port) {
|
||||
rtc::CopyOnWriteBuffer data(packet_size);
|
||||
std::fill_n(data.data<uint8_t>(), data.size(), 0);
|
||||
std::fill_n(data.MutableData(), data.size(), 0);
|
||||
receiver_->OnPacketReceived(EmulatedIpPacket(
|
||||
/*from=*/rtc::SocketAddress(),
|
||||
rtc::SocketAddress(endpoint_->GetPeerLocalAddress(), dest_port), data,
|
||||
|
||||
@ -114,8 +114,8 @@ TEST(UnsignaledStreamTest, ReplacesUnsignaledStreamOnCompletedSignaling) {
|
||||
first_ssrc &&
|
||||
!got_unsignaled_packet) {
|
||||
rtc::CopyOnWriteBuffer updated_buffer = packet.data;
|
||||
ByteWriter<uint32_t>::WriteBigEndian(&updated_buffer.data()[8],
|
||||
second_ssrc);
|
||||
ByteWriter<uint32_t>::WriteBigEndian(
|
||||
updated_buffer.MutableData() + 8, second_ssrc);
|
||||
EmulatedIpPacket updated_packet(
|
||||
packet.from, packet.to, updated_buffer, packet.arrival_time);
|
||||
send_node->OnPacketReceived(std::move(updated_packet));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user