rtc::Buffer: Rename length to size, for conformance with the STL
And add a constructor for creating an uninitialized Buffer of a specified size. (I intend to follow up with more Buffer changes, but since it's rather widely used, the rename is quite noisy and works better as a separate CL.) R=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48579004 Cr-Commit-Position: refs/heads/master@{#8841} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8841 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
e815290828
commit
eebcab5ce9
@ -330,8 +330,8 @@ void DataChannel::OnDataReceived(cricket::DataChannel* channel,
|
||||
if (was_ever_writable_ && observer_) {
|
||||
observer_->OnMessage(*buffer.get());
|
||||
} else {
|
||||
if (queued_received_data_.byte_count() + payload.length() >
|
||||
kMaxQueuedReceivedDataBytes) {
|
||||
if (queued_received_data_.byte_count() + payload.size() >
|
||||
kMaxQueuedReceivedDataBytes) {
|
||||
LOG(LS_ERROR) << "Queued received data exceeds the max buffer size.";
|
||||
|
||||
queued_received_data_.Clear();
|
||||
|
@ -145,7 +145,7 @@ TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) {
|
||||
for (int i = 0; i < number_of_packets; ++i) {
|
||||
EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
|
||||
}
|
||||
EXPECT_EQ(buffer.data.length() * number_of_packets,
|
||||
EXPECT_EQ(buffer.data.size() * number_of_packets,
|
||||
webrtc_data_channel_->buffered_amount());
|
||||
}
|
||||
|
||||
@ -359,10 +359,8 @@ TEST_F(SctpDataChannelTest, OpenAckRoleInitialization) {
|
||||
TEST_F(SctpDataChannelTest, ClosedWhenSendBufferFull) {
|
||||
SetChannelReady();
|
||||
|
||||
const size_t buffer_size = 1024;
|
||||
rtc::Buffer buffer;
|
||||
buffer.SetLength(buffer_size);
|
||||
memset(buffer.data(), 0, buffer_size);
|
||||
rtc::Buffer buffer(1024);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
|
||||
webrtc::DataBuffer packet(buffer, true);
|
||||
provider_.set_send_blocked(true);
|
||||
@ -413,10 +411,8 @@ TEST_F(SctpDataChannelTest, RemotePeerRequestClose) {
|
||||
// Tests that the DataChannel is closed if the received buffer is full.
|
||||
TEST_F(SctpDataChannelTest, ClosedWhenReceivedBufferFull) {
|
||||
SetChannelReady();
|
||||
const size_t buffer_size = 1024;
|
||||
rtc::Buffer buffer;
|
||||
buffer.SetLength(buffer_size);
|
||||
memset(buffer.data(), 0, buffer_size);
|
||||
rtc::Buffer buffer(1024);
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
|
||||
cricket::ReceiveDataParams params;
|
||||
params.ssrc = 0;
|
||||
|
@ -76,7 +76,7 @@ struct DataBuffer {
|
||||
: data(text.data(), text.length()),
|
||||
binary(false) {
|
||||
}
|
||||
size_t size() const { return data.length(); }
|
||||
size_t size() const { return data.size(); }
|
||||
|
||||
rtc::Buffer data;
|
||||
// Indicates if the received data contains UTF-8 or binary data.
|
||||
|
@ -581,9 +581,8 @@ class DataChannelObserverWrapper : public DataChannelObserver {
|
||||
|
||||
void OnMessage(const DataBuffer& buffer) override {
|
||||
ScopedLocalRefFrame local_ref_frame(jni());
|
||||
jobject byte_buffer =
|
||||
jni()->NewDirectByteBuffer(const_cast<char*>(buffer.data.data()),
|
||||
buffer.data.length());
|
||||
jobject byte_buffer = jni()->NewDirectByteBuffer(
|
||||
const_cast<char*>(buffer.data.data()), buffer.data.size());
|
||||
jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_,
|
||||
byte_buffer, buffer.binary);
|
||||
jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer);
|
||||
|
@ -149,7 +149,7 @@ std::string StdStringFromNSString(NSString* nsString) {
|
||||
|
||||
- (NSData*)data {
|
||||
return [NSData dataWithBytes:_dataBuffer->data.data()
|
||||
length:_dataBuffer->data.length()];
|
||||
length:_dataBuffer->data.size()];
|
||||
}
|
||||
|
||||
- (BOOL)isBinary {
|
||||
|
@ -54,7 +54,7 @@ bool ParseDataChannelOpenMessage(const rtc::Buffer& payload,
|
||||
// Format defined at
|
||||
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
|
||||
|
||||
rtc::ByteBuffer buffer(payload.data(), payload.length());
|
||||
rtc::ByteBuffer buffer(payload.data(), payload.size());
|
||||
|
||||
uint8 message_type;
|
||||
if (!buffer.ReadUInt8(&message_type)) {
|
||||
@ -126,7 +126,7 @@ bool ParseDataChannelOpenMessage(const rtc::Buffer& payload,
|
||||
}
|
||||
|
||||
bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) {
|
||||
rtc::ByteBuffer buffer(payload.data(), payload.length());
|
||||
rtc::ByteBuffer buffer(payload.data(), payload.size());
|
||||
|
||||
uint8 message_type;
|
||||
if (!buffer.ReadUInt8(&message_type)) {
|
||||
|
@ -538,8 +538,8 @@ StatsReport* StatsCollector::AddOneCertificateReport(
|
||||
rtc::Buffer der_buffer;
|
||||
cert->ToDER(&der_buffer);
|
||||
std::string der_base64;
|
||||
rtc::Base64::EncodeFromArray(
|
||||
der_buffer.data(), der_buffer.length(), &der_base64);
|
||||
rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(),
|
||||
&der_base64);
|
||||
|
||||
StatsReport::Id id(StatsReport::NewTypedId(
|
||||
StatsReport::kStatsReportTypeCertificate, fingerprint));
|
||||
|
@ -45,7 +45,7 @@ class FakeDataChannelProvider : public webrtc::DataChannelProviderInterface {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transport_error_ || payload.length() == 0) {
|
||||
if (transport_error_ || payload.size() == 0) {
|
||||
*result = cricket::SDR_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class MockDataChannelObserver : public webrtc::DataChannelObserver {
|
||||
|
||||
virtual void OnStateChange() { state_ = channel_->state(); }
|
||||
virtual void OnMessage(const DataBuffer& buffer) {
|
||||
last_message_.assign(buffer.data.data(), buffer.data.length());
|
||||
last_message_.assign(buffer.data.data(), buffer.data.size());
|
||||
++received_message_count_;
|
||||
}
|
||||
|
||||
|
@ -193,11 +193,11 @@ template <class Base> class RtpHelper : public Base {
|
||||
void set_playout(bool playout) { playout_ = playout; }
|
||||
virtual void OnPacketReceived(rtc::Buffer* packet,
|
||||
const rtc::PacketTime& packet_time) {
|
||||
rtp_packets_.push_back(std::string(packet->data(), packet->length()));
|
||||
rtp_packets_.push_back(std::string(packet->data(), packet->size()));
|
||||
}
|
||||
virtual void OnRtcpReceived(rtc::Buffer* packet,
|
||||
const rtc::PacketTime& packet_time) {
|
||||
rtcp_packets_.push_back(std::string(packet->data(), packet->length()));
|
||||
rtcp_packets_.push_back(std::string(packet->data(), packet->size()));
|
||||
}
|
||||
virtual void OnReadyToSend(bool ready) {
|
||||
ready_to_send_ = ready;
|
||||
@ -686,7 +686,7 @@ class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
|
||||
return false;
|
||||
} else {
|
||||
last_sent_data_params_ = params;
|
||||
last_sent_data_ = std::string(payload.data(), payload.length());
|
||||
last_sent_data_ = std::string(payload.data(), payload.size());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
|
||||
rtc::CritScope cs(&crit_);
|
||||
int bytes = 0;
|
||||
for (size_t i = 0; i < rtp_packets_.size(); ++i) {
|
||||
bytes += static_cast<int>(rtp_packets_[i].length());
|
||||
bytes += static_cast<int>(rtp_packets_[i].size());
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
@ -138,7 +138,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
|
||||
rtc::CritScope cs(&crit_);
|
||||
|
||||
uint32 cur_ssrc = 0;
|
||||
if (!GetRtpSsrc(packet->data(), packet->length(), &cur_ssrc)) {
|
||||
if (!GetRtpSsrc(packet->data(), packet->size(), &cur_ssrc)) {
|
||||
return false;
|
||||
}
|
||||
sent_ssrcs_[cur_ssrc]++;
|
||||
@ -156,7 +156,7 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
|
||||
if (conf_) {
|
||||
rtc::Buffer buffer_copy(*packet);
|
||||
for (size_t i = 0; i < conf_sent_ssrcs_.size(); ++i) {
|
||||
if (!SetRtpSsrc(buffer_copy.data(), buffer_copy.length(),
|
||||
if (!SetRtpSsrc(buffer_copy.data(), buffer_copy.size(),
|
||||
conf_sent_ssrcs_[i])) {
|
||||
return false;
|
||||
}
|
||||
@ -221,13 +221,13 @@ class FakeNetworkInterface : public MediaChannel::NetworkInterface,
|
||||
}
|
||||
uint32 cur_ssrc = 0;
|
||||
for (size_t i = 0; i < rtp_packets_.size(); ++i) {
|
||||
if (!GetRtpSsrc(rtp_packets_[i].data(),
|
||||
rtp_packets_[i].length(), &cur_ssrc)) {
|
||||
if (!GetRtpSsrc(rtp_packets_[i].data(), rtp_packets_[i].size(),
|
||||
&cur_ssrc)) {
|
||||
return;
|
||||
}
|
||||
if (ssrc == cur_ssrc) {
|
||||
if (bytes) {
|
||||
*bytes += static_cast<int>(rtp_packets_[i].length());
|
||||
*bytes += static_cast<int>(rtp_packets_[i].size());
|
||||
}
|
||||
if (packets) {
|
||||
++(*packets);
|
||||
|
@ -230,7 +230,7 @@ void RtpSenderReceiver::SetSendSsrc(uint32 ssrc) {
|
||||
|
||||
void RtpSenderReceiver::OnPacketReceived(rtc::Buffer* packet) {
|
||||
if (rtp_dump_writer_) {
|
||||
rtp_dump_writer_->WriteRtpPacket(packet->data(), packet->length());
|
||||
rtp_dump_writer_->WriteRtpPacket(packet->data(), packet->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ class FileNetworkInterface : public MediaChannel::NetworkInterface {
|
||||
media_channel_->OnPacketReceived(packet, rtc::PacketTime());
|
||||
}
|
||||
if (dump_writer_.get() &&
|
||||
rtc::SR_SUCCESS != dump_writer_->WriteRtpPacket(
|
||||
packet->data(), packet->length())) {
|
||||
rtc::SR_SUCCESS !=
|
||||
dump_writer_->WriteRtpPacket(packet->data(), packet->size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ bool RtpDataMediaChannel::RemoveRecvStream(uint32 ssrc) {
|
||||
void RtpDataMediaChannel::OnPacketReceived(
|
||||
rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
|
||||
RtpHeader header;
|
||||
if (!GetRtpHeader(packet->data(), packet->length(), &header)) {
|
||||
if (!GetRtpHeader(packet->data(), packet->size(), &header)) {
|
||||
// Don't want to log for every corrupt packet.
|
||||
// LOG(LS_WARNING) << "Could not read rtp header from packet of length "
|
||||
// << packet->length() << ".";
|
||||
@ -224,7 +224,7 @@ void RtpDataMediaChannel::OnPacketReceived(
|
||||
}
|
||||
|
||||
size_t header_length;
|
||||
if (!GetRtpHeaderLen(packet->data(), packet->length(), &header_length)) {
|
||||
if (!GetRtpHeaderLen(packet->data(), packet->size(), &header_length)) {
|
||||
// Don't want to log for every corrupt packet.
|
||||
// LOG(LS_WARNING) << "Could not read rtp header"
|
||||
// << length from packet of length "
|
||||
@ -232,7 +232,7 @@ void RtpDataMediaChannel::OnPacketReceived(
|
||||
return;
|
||||
}
|
||||
const char* data = packet->data() + header_length + sizeof(kReservedSpace);
|
||||
size_t data_len = packet->length() - header_length - sizeof(kReservedSpace);
|
||||
size_t data_len = packet->size() - header_length - sizeof(kReservedSpace);
|
||||
|
||||
if (!receiving_) {
|
||||
LOG(LS_WARNING) << "Not receiving packet "
|
||||
@ -292,7 +292,7 @@ bool RtpDataMediaChannel::SendData(
|
||||
}
|
||||
if (!sending_) {
|
||||
LOG(LS_WARNING) << "Not sending packet with ssrc=" << params.ssrc
|
||||
<< " len=" << payload.length() << " before SetSend(true).";
|
||||
<< " len=" << payload.size() << " before SetSend(true).";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -316,8 +316,8 @@ bool RtpDataMediaChannel::SendData(
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace)
|
||||
+ payload.length() + kMaxSrtpHmacOverhead);
|
||||
size_t packet_len = (kMinRtpPacketLen + sizeof(kReservedSpace) +
|
||||
payload.size() + kMaxSrtpHmacOverhead);
|
||||
if (packet_len > kDataMaxRtpPacketLen) {
|
||||
return false;
|
||||
}
|
||||
@ -339,19 +339,18 @@ bool RtpDataMediaChannel::SendData(
|
||||
|
||||
rtc::Buffer packet;
|
||||
packet.SetCapacity(packet_len);
|
||||
packet.SetLength(kMinRtpPacketLen);
|
||||
if (!SetRtpHeader(packet.data(), packet.length(), header)) {
|
||||
packet.SetSize(kMinRtpPacketLen);
|
||||
if (!SetRtpHeader(packet.data(), packet.size(), header)) {
|
||||
return false;
|
||||
}
|
||||
packet.AppendData(&kReservedSpace, sizeof(kReservedSpace));
|
||||
packet.AppendData(payload.data(), payload.length());
|
||||
packet.AppendData(payload.data(), payload.size());
|
||||
|
||||
LOG(LS_VERBOSE) << "Sent RTP data packet: "
|
||||
<< " stream=" << found_stream->id
|
||||
<< " ssrc=" << header.ssrc
|
||||
<< " stream=" << found_stream->id << " ssrc=" << header.ssrc
|
||||
<< ", seqnum=" << header.seq_num
|
||||
<< ", timestamp=" << header.timestamp
|
||||
<< ", len=" << payload.length();
|
||||
<< ", len=" << payload.size();
|
||||
|
||||
MediaChannel::SendPacket(&packet);
|
||||
send_limiter_->Use(packet_len, now);
|
||||
|
@ -143,8 +143,8 @@ class RtpDataMediaChannelTest : public testing::Test {
|
||||
// Assume RTP header of length 12
|
||||
rtc::scoped_ptr<const rtc::Buffer> packet(
|
||||
iface_->GetRtpPacket(index));
|
||||
if (packet->length() > 12) {
|
||||
return std::string(packet->data() + 12, packet->length() - 12);
|
||||
if (packet->size() > 12) {
|
||||
return std::string(packet->data() + 12, packet->size() - 12);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
@ -154,7 +154,7 @@ class RtpDataMediaChannelTest : public testing::Test {
|
||||
rtc::scoped_ptr<const rtc::Buffer> packet(
|
||||
iface_->GetRtpPacket(index));
|
||||
cricket::RtpHeader header;
|
||||
GetRtpHeader(packet->data(), packet->length(), &header);
|
||||
GetRtpHeader(packet->data(), packet->size(), &header);
|
||||
return header;
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ class VideoMediaChannelTest : public testing::Test,
|
||||
static bool ParseRtpPacket(const rtc::Buffer* p, bool* x, int* pt,
|
||||
int* seqnum, uint32* tstamp, uint32* ssrc,
|
||||
std::string* payload) {
|
||||
rtc::ByteBuffer buf(p->data(), p->length());
|
||||
rtc::ByteBuffer buf(p->data(), p->size());
|
||||
uint8 u08 = 0;
|
||||
uint16 u16 = 0;
|
||||
uint32 u32 = 0;
|
||||
@ -730,10 +730,10 @@ class VideoMediaChannelTest : public testing::Test,
|
||||
int count = 0;
|
||||
for (int i = start_index; i < stop_index; ++i) {
|
||||
rtc::scoped_ptr<const rtc::Buffer> p(GetRtcpPacket(i));
|
||||
rtc::ByteBuffer buf(p->data(), p->length());
|
||||
rtc::ByteBuffer buf(p->data(), p->size());
|
||||
size_t total_len = 0;
|
||||
// The packet may be a compound RTCP packet.
|
||||
while (total_len < p->length()) {
|
||||
while (total_len < p->size()) {
|
||||
// Read FMT, type and length.
|
||||
uint8 fmt = 0;
|
||||
uint8 type = 0;
|
||||
|
@ -524,7 +524,7 @@ bool SctpDataMediaChannel::SendData(
|
||||
if (!sending_) {
|
||||
LOG(LS_WARNING) << debug_name_ << "->SendData(...): "
|
||||
<< "Not sending packet with ssrc=" << params.ssrc
|
||||
<< " len=" << payload.length() << " before SetSend(true).";
|
||||
<< " len=" << payload.size() << " before SetSend(true).";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -560,11 +560,9 @@ bool SctpDataMediaChannel::SendData(
|
||||
}
|
||||
|
||||
// We don't fragment.
|
||||
send_res = usrsctp_sendv(sock_, payload.data(),
|
||||
static_cast<size_t>(payload.length()),
|
||||
NULL, 0, &spa,
|
||||
rtc::checked_cast<socklen_t>(sizeof(spa)),
|
||||
SCTP_SENDV_SPA, 0);
|
||||
send_res = usrsctp_sendv(
|
||||
sock_, payload.data(), static_cast<size_t>(payload.size()), NULL, 0, &spa,
|
||||
rtc::checked_cast<socklen_t>(sizeof(spa)), SCTP_SENDV_SPA, 0);
|
||||
if (send_res < 0) {
|
||||
if (errno == SCTP_EWOULDBLOCK) {
|
||||
*result = SDR_BLOCK;
|
||||
@ -586,8 +584,8 @@ bool SctpDataMediaChannel::SendData(
|
||||
// Called by network interface when a packet has been received.
|
||||
void SctpDataMediaChannel::OnPacketReceived(
|
||||
rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
|
||||
LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): " << " length="
|
||||
<< packet->length() << ", sending: " << sending_;
|
||||
LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): "
|
||||
<< " length=" << packet->size() << ", sending: " << sending_;
|
||||
// Only give receiving packets to usrsctp after if connected. This enables two
|
||||
// peers to each make a connect call, but for them not to receive an INIT
|
||||
// packet before they have called connect; least the last receiver of the INIT
|
||||
@ -596,7 +594,7 @@ void SctpDataMediaChannel::OnPacketReceived(
|
||||
// Pass received packet to SCTP stack. Once processed by usrsctp, the data
|
||||
// will be will be given to the global OnSctpInboundData, and then,
|
||||
// marshalled by a Post and handled with OnMessage.
|
||||
usrsctp_conninput(this, packet->data(), packet->length(), 0);
|
||||
usrsctp_conninput(this, packet->data(), packet->size(), 0);
|
||||
} else {
|
||||
// TODO(ldixon): Consider caching the packet for very slightly better
|
||||
// reliability.
|
||||
@ -609,10 +607,10 @@ void SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(
|
||||
<< "Received SCTP data:"
|
||||
<< " ssrc=" << packet->params.ssrc
|
||||
<< " notification: " << (packet->flags & MSG_NOTIFICATION)
|
||||
<< " length=" << packet->buffer.length();
|
||||
<< " length=" << packet->buffer.size();
|
||||
// Sending a packet with data == NULL (no data) is SCTPs "close the
|
||||
// connection" message. This sets sock_ = NULL;
|
||||
if (!packet->buffer.length() || !packet->buffer.data()) {
|
||||
if (!packet->buffer.size() || !packet->buffer.data()) {
|
||||
LOG(LS_INFO) << debug_name_ << "->OnInboundPacketFromSctpToChannel(...): "
|
||||
"No data, closing.";
|
||||
return;
|
||||
@ -628,16 +626,15 @@ void SctpDataMediaChannel::OnDataFromSctpToChannel(
|
||||
const ReceiveDataParams& params, rtc::Buffer* buffer) {
|
||||
if (receiving_) {
|
||||
LOG(LS_VERBOSE) << debug_name_ << "->OnDataFromSctpToChannel(...): "
|
||||
<< "Posting with length: " << buffer->length()
|
||||
<< "Posting with length: " << buffer->size()
|
||||
<< " on stream " << params.ssrc;
|
||||
// Reports all received messages to upper layers, no matter whether the sid
|
||||
// is known.
|
||||
SignalDataReceived(params, buffer->data(), buffer->length());
|
||||
SignalDataReceived(params, buffer->data(), buffer->size());
|
||||
} else {
|
||||
LOG(LS_WARNING) << debug_name_ << "->OnDataFromSctpToChannel(...): "
|
||||
<< "Not receiving packet with sid=" << params.ssrc
|
||||
<< " len=" << buffer->length()
|
||||
<< " before SetReceive(true).";
|
||||
<< " len=" << buffer->size() << " before SetReceive(true).";
|
||||
}
|
||||
}
|
||||
|
||||
@ -697,7 +694,7 @@ bool SctpDataMediaChannel::ResetStream(uint32 ssrc) {
|
||||
void SctpDataMediaChannel::OnNotificationFromSctp(rtc::Buffer* buffer) {
|
||||
const sctp_notification& notification =
|
||||
reinterpret_cast<const sctp_notification&>(*buffer->data());
|
||||
ASSERT(notification.sn_header.sn_length == buffer->length());
|
||||
ASSERT(notification.sn_header.sn_length == buffer->size());
|
||||
|
||||
// TODO(ldixon): handle notifications appropriately.
|
||||
switch (notification.sn_header.sn_type) {
|
||||
@ -891,7 +888,7 @@ bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) {
|
||||
|
||||
void SctpDataMediaChannel::OnPacketFromSctpToNetwork(
|
||||
rtc::Buffer* buffer) {
|
||||
if (buffer->length() > kSctpMtu) {
|
||||
if (buffer->size() > kSctpMtu) {
|
||||
LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): "
|
||||
<< "SCTP seems to have made a packet that is bigger "
|
||||
"than its official MTU.";
|
||||
|
@ -74,7 +74,7 @@ class SctpFakeNetworkInterface : public cricket::MediaChannel::NetworkInterface,
|
||||
|
||||
// TODO(ldixon): Can/should we use Buffer.TransferTo here?
|
||||
// Note: this assignment does a deep copy of data from packet.
|
||||
rtc::Buffer* buffer = new rtc::Buffer(packet->data(), packet->length());
|
||||
rtc::Buffer* buffer = new rtc::Buffer(packet->data(), packet->size());
|
||||
thread_->Post(this, MSG_PACKET, rtc::WrapMessageData(buffer));
|
||||
LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message.";
|
||||
return true;
|
||||
|
@ -2849,7 +2849,7 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
|
||||
// any multiplexed streams, just send it to the default channel. Otherwise,
|
||||
// send it to the specific decoder instance for that stream.
|
||||
uint32 ssrc = 0;
|
||||
if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc))
|
||||
if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc))
|
||||
return;
|
||||
int processing_channel_id = GetRecvChannelId(ssrc);
|
||||
if (processing_channel_id == kChannelIdUnset) {
|
||||
@ -2865,9 +2865,7 @@ void WebRtcVideoMediaChannel::OnPacketReceived(
|
||||
}
|
||||
|
||||
engine()->vie()->network()->ReceivedRTPPacket(
|
||||
processing_channel_id,
|
||||
packet->data(),
|
||||
packet->length(),
|
||||
processing_channel_id, packet->data(), packet->size(),
|
||||
webrtc::PacketTime(packet_time.timestamp, packet_time.not_before));
|
||||
}
|
||||
|
||||
@ -2879,12 +2877,12 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
|
||||
// correct receiver reports.
|
||||
|
||||
uint32 ssrc = 0;
|
||||
if (!GetRtcpSsrc(packet->data(), packet->length(), &ssrc)) {
|
||||
if (!GetRtcpSsrc(packet->data(), packet->size(), &ssrc)) {
|
||||
LOG(LS_WARNING) << "Failed to parse SSRC from received RTCP packet";
|
||||
return;
|
||||
}
|
||||
int type = 0;
|
||||
if (!GetRtcpType(packet->data(), packet->length(), &type)) {
|
||||
if (!GetRtcpType(packet->data(), packet->size(), &type)) {
|
||||
LOG(LS_WARNING) << "Failed to parse type from received RTCP packet";
|
||||
return;
|
||||
}
|
||||
@ -2894,9 +2892,7 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
|
||||
int recv_channel_id = GetRecvChannelId(ssrc);
|
||||
if (recv_channel_id != kChannelIdUnset && !IsDefaultChannelId(recv_channel_id)) {
|
||||
engine_->vie()->network()->ReceivedRTCPPacket(
|
||||
recv_channel_id,
|
||||
packet->data(),
|
||||
packet->length());
|
||||
recv_channel_id, packet->data(), packet->size());
|
||||
}
|
||||
}
|
||||
// SR may continue RR and any RR entry may correspond to any one of the send
|
||||
@ -2906,10 +2902,8 @@ void WebRtcVideoMediaChannel::OnRtcpReceived(
|
||||
iter != send_channels_.end(); ++iter) {
|
||||
WebRtcVideoChannelSendInfo* send_channel = iter->second;
|
||||
int channel_id = send_channel->channel_id();
|
||||
engine_->vie()->network()->ReceivedRTCPPacket(
|
||||
channel_id,
|
||||
packet->data(),
|
||||
packet->length());
|
||||
engine_->vie()->network()->ReceivedRTCPPacket(channel_id, packet->data(),
|
||||
packet->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1105,7 +1105,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
|
||||
const rtc::PacketTime& packet_time) {
|
||||
const webrtc::PacketReceiver::DeliveryStatus delivery_result =
|
||||
call_->Receiver()->DeliverPacket(
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->length());
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->size());
|
||||
switch (delivery_result) {
|
||||
case webrtc::PacketReceiver::DELIVERY_OK:
|
||||
return;
|
||||
@ -1116,7 +1116,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
|
||||
}
|
||||
|
||||
uint32 ssrc = 0;
|
||||
if (!GetRtpSsrc(packet->data(), packet->length(), &ssrc)) {
|
||||
if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1131,7 +1131,7 @@ void WebRtcVideoChannel2::OnPacketReceived(
|
||||
}
|
||||
|
||||
if (call_->Receiver()->DeliverPacket(
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->length()) !=
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) !=
|
||||
webrtc::PacketReceiver::DELIVERY_OK) {
|
||||
LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
|
||||
return;
|
||||
@ -1142,7 +1142,7 @@ void WebRtcVideoChannel2::OnRtcpReceived(
|
||||
rtc::Buffer* packet,
|
||||
const rtc::PacketTime& packet_time) {
|
||||
if (call_->Receiver()->DeliverPacket(
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->length()) !=
|
||||
reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) !=
|
||||
webrtc::PacketReceiver::DELIVERY_OK) {
|
||||
LOG(LS_WARNING) << "Failed to deliver RTCP packet.";
|
||||
}
|
||||
|
@ -3107,8 +3107,8 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(
|
||||
// Pick which channel to send this packet to. If this packet doesn't match
|
||||
// any multiplexed streams, just send it to the default channel. Otherwise,
|
||||
// send it to the specific decoder instance for that stream.
|
||||
int which_channel = GetReceiveChannelNum(
|
||||
ParseSsrc(packet->data(), packet->length(), false));
|
||||
int which_channel =
|
||||
GetReceiveChannelNum(ParseSsrc(packet->data(), packet->size(), false));
|
||||
if (which_channel == -1) {
|
||||
which_channel = voe_channel();
|
||||
}
|
||||
@ -3131,9 +3131,7 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(
|
||||
|
||||
// Pass it off to the decoder.
|
||||
engine()->voe()->network()->ReceivedRTPPacket(
|
||||
which_channel,
|
||||
packet->data(),
|
||||
packet->length(),
|
||||
which_channel, packet->data(), packet->size(),
|
||||
webrtc::PacketTime(packet_time.timestamp, packet_time.not_before));
|
||||
}
|
||||
|
||||
@ -3144,7 +3142,7 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
|
||||
// Receiving channels need sender reports in order to create
|
||||
// correct receiver reports.
|
||||
int type = 0;
|
||||
if (!GetRtcpType(packet->data(), packet->length(), &type)) {
|
||||
if (!GetRtcpType(packet->data(), packet->size(), &type)) {
|
||||
LOG(LS_WARNING) << "Failed to parse type from received RTCP packet";
|
||||
return;
|
||||
}
|
||||
@ -3152,13 +3150,11 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
|
||||
// If it is a sender report, find the channel that is listening.
|
||||
bool has_sent_to_default_channel = false;
|
||||
if (type == kRtcpTypeSR) {
|
||||
int which_channel = GetReceiveChannelNum(
|
||||
ParseSsrc(packet->data(), packet->length(), true));
|
||||
int which_channel =
|
||||
GetReceiveChannelNum(ParseSsrc(packet->data(), packet->size(), true));
|
||||
if (which_channel != -1) {
|
||||
engine()->voe()->network()->ReceivedRTCPPacket(
|
||||
which_channel,
|
||||
packet->data(),
|
||||
packet->length());
|
||||
which_channel, packet->data(), packet->size());
|
||||
|
||||
if (IsDefaultChannel(which_channel))
|
||||
has_sent_to_default_channel = true;
|
||||
@ -3176,9 +3172,7 @@ void WebRtcVoiceMediaChannel::OnRtcpReceived(
|
||||
continue;
|
||||
|
||||
engine()->voe()->network()->ReceivedRTCPPacket(
|
||||
iter->second->channel(),
|
||||
packet->data(),
|
||||
packet->length());
|
||||
iter->second->channel(), packet->data(), packet->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,8 @@ static const char* PacketType(bool rtcp) {
|
||||
static bool ValidPacket(bool rtcp, const rtc::Buffer* packet) {
|
||||
// Check the packet size. We could check the header too if needed.
|
||||
return (packet &&
|
||||
packet->length() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) &&
|
||||
packet->length() <= kMaxRtpPacketLen);
|
||||
packet->size() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) &&
|
||||
packet->size() <= kMaxRtpPacketLen);
|
||||
}
|
||||
|
||||
static bool IsReceiveContentDirection(MediaContentDirection direction) {
|
||||
@ -497,15 +497,15 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
|
||||
// Protect ourselves against crazy data.
|
||||
if (!ValidPacket(rtcp, packet)) {
|
||||
LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
|
||||
<< PacketType(rtcp) << " packet: wrong size="
|
||||
<< packet->length();
|
||||
<< PacketType(rtcp)
|
||||
<< " packet: wrong size=" << packet->size();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Signal to the media sink before protecting the packet.
|
||||
{
|
||||
rtc::CritScope cs(&signal_send_packet_cs_);
|
||||
SignalSendPacketPreCrypto(packet->data(), packet->length(), rtcp);
|
||||
SignalSendPacketPreCrypto(packet->data(), packet->size(), rtcp);
|
||||
}
|
||||
|
||||
rtc::PacketOptions options(dscp);
|
||||
@ -513,7 +513,7 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
|
||||
if (srtp_filter_.IsActive()) {
|
||||
bool res;
|
||||
char* data = packet->data();
|
||||
int len = static_cast<int>(packet->length());
|
||||
int len = static_cast<int>(packet->size());
|
||||
if (!rtcp) {
|
||||
// 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
|
||||
@ -566,7 +566,7 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
|
||||
}
|
||||
|
||||
// Update the length of the packet now that we've added the auth tag.
|
||||
packet->SetLength(len);
|
||||
packet->SetSize(len);
|
||||
} else if (secure_required_) {
|
||||
// This is a double check for something that supposedly can't happen.
|
||||
LOG(LS_ERROR) << "Can't send outgoing " << PacketType(rtcp)
|
||||
@ -579,13 +579,14 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
|
||||
// Signal to the media sink after protecting the packet.
|
||||
{
|
||||
rtc::CritScope cs(&signal_send_packet_cs_);
|
||||
SignalSendPacketPostCrypto(packet->data(), packet->length(), rtcp);
|
||||
SignalSendPacketPostCrypto(packet->data(), packet->size(), rtcp);
|
||||
}
|
||||
|
||||
// Bon voyage.
|
||||
int ret = channel->SendPacket(packet->data(), packet->length(), options,
|
||||
(secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
|
||||
if (ret != static_cast<int>(packet->length())) {
|
||||
int ret =
|
||||
channel->SendPacket(packet->data(), packet->size(), options,
|
||||
(secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
|
||||
if (ret != static_cast<int>(packet->size())) {
|
||||
if (channel->GetError() == EWOULDBLOCK) {
|
||||
LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
|
||||
SetReadyToSend(channel, false);
|
||||
@ -599,13 +600,13 @@ bool BaseChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
|
||||
// Protect ourselves against crazy data.
|
||||
if (!ValidPacket(rtcp, packet)) {
|
||||
LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " "
|
||||
<< PacketType(rtcp) << " packet: wrong size="
|
||||
<< packet->length();
|
||||
<< PacketType(rtcp)
|
||||
<< " packet: wrong size=" << packet->size();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bundle filter handles both rtp and rtcp packets.
|
||||
return bundle_filter_.DemuxPacket(packet->data(), packet->length(), rtcp);
|
||||
return bundle_filter_.DemuxPacket(packet->data(), packet->size(), rtcp);
|
||||
}
|
||||
|
||||
void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
|
||||
@ -624,13 +625,13 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
|
||||
// Signal to the media sink before unprotecting the packet.
|
||||
{
|
||||
rtc::CritScope cs(&signal_recv_packet_cs_);
|
||||
SignalRecvPacketPostCrypto(packet->data(), packet->length(), rtcp);
|
||||
SignalRecvPacketPostCrypto(packet->data(), packet->size(), rtcp);
|
||||
}
|
||||
|
||||
// Unprotect the packet, if needed.
|
||||
if (srtp_filter_.IsActive()) {
|
||||
char* data = packet->data();
|
||||
int len = static_cast<int>(packet->length());
|
||||
int len = static_cast<int>(packet->size());
|
||||
bool res;
|
||||
if (!rtcp) {
|
||||
res = srtp_filter_.UnprotectRtp(data, len, &len);
|
||||
@ -655,7 +656,7 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
|
||||
}
|
||||
}
|
||||
|
||||
packet->SetLength(len);
|
||||
packet->SetSize(len);
|
||||
} else if (secure_required_) {
|
||||
// Our session description indicates that SRTP is required, but we got a
|
||||
// packet before our SRTP filter is active. This means either that
|
||||
@ -675,7 +676,7 @@ void BaseChannel::HandlePacket(bool rtcp, rtc::Buffer* packet,
|
||||
// Signal to the media sink after unprotecting the packet.
|
||||
{
|
||||
rtc::CritScope cs(&signal_recv_packet_cs_);
|
||||
SignalRecvPacketPreCrypto(packet->data(), packet->length(), rtcp);
|
||||
SignalRecvPacketPreCrypto(packet->data(), packet->size(), rtcp);
|
||||
}
|
||||
|
||||
// Push it down to the media channel.
|
||||
@ -2213,7 +2214,7 @@ bool DataChannel::WantsPacket(bool rtcp, rtc::Buffer* packet) {
|
||||
if (data_channel_type_ == DCT_SCTP) {
|
||||
// TODO(pthatcher): Do this in a more robust way by checking for
|
||||
// SCTP or DTLS.
|
||||
return !IsRtpPacket(packet->data(), packet->length());
|
||||
return !IsRtpPacket(packet->data(), packet->size());
|
||||
} else if (data_channel_type_ == DCT_RTP) {
|
||||
return BaseChannel::WantsPacket(rtcp, packet);
|
||||
}
|
||||
|
@ -16,16 +16,20 @@ Buffer::Buffer() {
|
||||
Construct(NULL, 0, 0);
|
||||
}
|
||||
|
||||
Buffer::Buffer(const void* data, size_t length) {
|
||||
Construct(data, length, length);
|
||||
Buffer::Buffer(size_t size) : Buffer() {
|
||||
SetSize(size);
|
||||
}
|
||||
|
||||
Buffer::Buffer(const void* data, size_t length, size_t capacity) {
|
||||
Construct(data, length, capacity);
|
||||
Buffer::Buffer(const void* data, size_t size) {
|
||||
Construct(data, size, size);
|
||||
}
|
||||
|
||||
Buffer::Buffer(const void* data, size_t size, size_t capacity) {
|
||||
Construct(data, size, capacity);
|
||||
}
|
||||
|
||||
Buffer::Buffer(const Buffer& buf) {
|
||||
Construct(buf.data(), buf.length(), buf.length());
|
||||
Construct(buf.data(), buf.size(), buf.size());
|
||||
}
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
@ -23,50 +23,49 @@ namespace rtc {
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer();
|
||||
Buffer(const void* data, size_t length);
|
||||
Buffer(const void* data, size_t length, size_t capacity);
|
||||
explicit Buffer(size_t size);
|
||||
Buffer(const void* data, size_t size);
|
||||
Buffer(const void* data, size_t size, size_t capacity);
|
||||
Buffer(const Buffer& buf);
|
||||
~Buffer();
|
||||
|
||||
const char* data() const { return data_.get(); }
|
||||
char* data() { return data_.get(); }
|
||||
// TODO: should this be size(), like STL?
|
||||
size_t length() const { return length_; }
|
||||
size_t size() const { return size_; }
|
||||
size_t capacity() const { return capacity_; }
|
||||
|
||||
Buffer& operator=(const Buffer& buf) {
|
||||
if (&buf != this) {
|
||||
Construct(buf.data(), buf.length(), buf.length());
|
||||
Construct(buf.data(), buf.size(), buf.size());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const Buffer& buf) const {
|
||||
return (length_ == buf.length() &&
|
||||
memcmp(data_.get(), buf.data(), length_) == 0);
|
||||
return (size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0);
|
||||
}
|
||||
bool operator!=(const Buffer& buf) const {
|
||||
return !operator==(buf);
|
||||
}
|
||||
|
||||
void SetData(const void* data, size_t length) {
|
||||
ASSERT(data != NULL || length == 0);
|
||||
SetLength(length);
|
||||
memcpy(data_.get(), data, length);
|
||||
void SetData(const void* data, size_t size) {
|
||||
ASSERT(data != NULL || size == 0);
|
||||
SetSize(size);
|
||||
memcpy(data_.get(), data, size);
|
||||
}
|
||||
void AppendData(const void* data, size_t length) {
|
||||
ASSERT(data != NULL || length == 0);
|
||||
size_t old_length = length_;
|
||||
SetLength(length_ + length);
|
||||
memcpy(data_.get() + old_length, data, length);
|
||||
void AppendData(const void* data, size_t size) {
|
||||
ASSERT(data != NULL || size == 0);
|
||||
size_t old_size = size_;
|
||||
SetSize(size_ + size);
|
||||
memcpy(data_.get() + old_size, data, size);
|
||||
}
|
||||
void SetLength(size_t length) {
|
||||
SetCapacity(length);
|
||||
length_ = length;
|
||||
void SetSize(size_t size) {
|
||||
SetCapacity(size);
|
||||
size_ = size;
|
||||
}
|
||||
void SetCapacity(size_t capacity) {
|
||||
if (capacity > capacity_) {
|
||||
rtc::scoped_ptr<char[]> data(new char[capacity]);
|
||||
memcpy(data.get(), data_.get(), length_);
|
||||
memcpy(data.get(), data_.get(), size_);
|
||||
data_.swap(data);
|
||||
capacity_ = capacity;
|
||||
}
|
||||
@ -75,19 +74,19 @@ class Buffer {
|
||||
void TransferTo(Buffer* buf) {
|
||||
ASSERT(buf != NULL);
|
||||
buf->data_.reset(data_.release());
|
||||
buf->length_ = length_;
|
||||
buf->size_ = size_;
|
||||
buf->capacity_ = capacity_;
|
||||
Construct(NULL, 0, 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void Construct(const void* data, size_t length, size_t capacity) {
|
||||
void Construct(const void* data, size_t size, size_t capacity) {
|
||||
data_.reset(new char[capacity_ = capacity]);
|
||||
SetData(data, length);
|
||||
SetData(data, size);
|
||||
}
|
||||
|
||||
scoped_ptr<char[]> data_;
|
||||
size_t length_;
|
||||
size_t size_;
|
||||
size_t capacity_;
|
||||
};
|
||||
|
||||
|
@ -19,21 +19,21 @@ static const char kTestData[] = {
|
||||
|
||||
TEST(BufferTest, TestConstructDefault) {
|
||||
Buffer buf;
|
||||
EXPECT_EQ(0U, buf.length());
|
||||
EXPECT_EQ(0U, buf.size());
|
||||
EXPECT_EQ(0U, buf.capacity());
|
||||
EXPECT_EQ(Buffer(), buf);
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestConstructEmptyWithCapacity) {
|
||||
Buffer buf(NULL, 0, 256U);
|
||||
EXPECT_EQ(0U, buf.length());
|
||||
EXPECT_EQ(0U, buf.size());
|
||||
EXPECT_EQ(256U, buf.capacity());
|
||||
EXPECT_EQ(Buffer(), buf);
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestConstructData) {
|
||||
Buffer buf(kTestData, sizeof(kTestData));
|
||||
EXPECT_EQ(sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf);
|
||||
@ -41,7 +41,7 @@ TEST(BufferTest, TestConstructData) {
|
||||
|
||||
TEST(BufferTest, TestConstructDataWithCapacity) {
|
||||
Buffer buf(kTestData, sizeof(kTestData), 256U);
|
||||
EXPECT_EQ(sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(256U, buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(Buffer(kTestData, sizeof(kTestData)), buf);
|
||||
@ -49,7 +49,7 @@ TEST(BufferTest, TestConstructDataWithCapacity) {
|
||||
|
||||
TEST(BufferTest, TestConstructCopy) {
|
||||
Buffer buf1(kTestData, sizeof(kTestData), 256), buf2(buf1);
|
||||
EXPECT_EQ(sizeof(kTestData), buf2.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf2.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf2.capacity()); // capacity isn't copied
|
||||
EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(buf1, buf2);
|
||||
@ -59,7 +59,7 @@ TEST(BufferTest, TestAssign) {
|
||||
Buffer buf1, buf2(kTestData, sizeof(kTestData), 256);
|
||||
EXPECT_NE(buf1, buf2);
|
||||
buf1 = buf2;
|
||||
EXPECT_EQ(sizeof(kTestData), buf1.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf1.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf1.capacity()); // capacity isn't copied
|
||||
EXPECT_EQ(0, memcmp(buf1.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(buf1, buf2);
|
||||
@ -68,7 +68,7 @@ TEST(BufferTest, TestAssign) {
|
||||
TEST(BufferTest, TestSetData) {
|
||||
Buffer buf;
|
||||
buf.SetData(kTestData, sizeof(kTestData));
|
||||
EXPECT_EQ(sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
}
|
||||
@ -76,27 +76,27 @@ TEST(BufferTest, TestSetData) {
|
||||
TEST(BufferTest, TestAppendData) {
|
||||
Buffer buf(kTestData, sizeof(kTestData));
|
||||
buf.AppendData(kTestData, sizeof(kTestData));
|
||||
EXPECT_EQ(2 * sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(2 * sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(2 * sizeof(kTestData), buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData),
|
||||
kTestData, sizeof(kTestData)));
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestSetLengthSmaller) {
|
||||
TEST(BufferTest, TestSetSizeSmaller) {
|
||||
Buffer buf;
|
||||
buf.SetData(kTestData, sizeof(kTestData));
|
||||
buf.SetLength(sizeof(kTestData) / 2);
|
||||
EXPECT_EQ(sizeof(kTestData) / 2, buf.length());
|
||||
buf.SetSize(sizeof(kTestData) / 2);
|
||||
EXPECT_EQ(sizeof(kTestData) / 2, buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData) / 2));
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestSetLengthLarger) {
|
||||
TEST(BufferTest, TestSetSizeLarger) {
|
||||
Buffer buf;
|
||||
buf.SetData(kTestData, sizeof(kTestData));
|
||||
buf.SetLength(sizeof(kTestData) * 2);
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.length());
|
||||
buf.SetSize(sizeof(kTestData) * 2);
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
}
|
||||
@ -105,7 +105,7 @@ TEST(BufferTest, TestSetCapacitySmaller) {
|
||||
Buffer buf;
|
||||
buf.SetData(kTestData, sizeof(kTestData));
|
||||
buf.SetCapacity(sizeof(kTestData) / 2); // should be ignored
|
||||
EXPECT_EQ(sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
}
|
||||
@ -113,17 +113,17 @@ TEST(BufferTest, TestSetCapacitySmaller) {
|
||||
TEST(BufferTest, TestSetCapacityLarger) {
|
||||
Buffer buf(kTestData, sizeof(kTestData));
|
||||
buf.SetCapacity(sizeof(kTestData) * 2);
|
||||
EXPECT_EQ(sizeof(kTestData), buf.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestSetCapacityThenSetLength) {
|
||||
TEST(BufferTest, TestSetCapacityThenSetSize) {
|
||||
Buffer buf(kTestData, sizeof(kTestData));
|
||||
buf.SetCapacity(sizeof(kTestData) * 4);
|
||||
memcpy(buf.data() + sizeof(kTestData), kTestData, sizeof(kTestData));
|
||||
buf.SetLength(sizeof(kTestData) * 2);
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.length());
|
||||
buf.SetSize(sizeof(kTestData) * 2);
|
||||
EXPECT_EQ(sizeof(kTestData) * 2, buf.size());
|
||||
EXPECT_EQ(sizeof(kTestData) * 4, buf.capacity());
|
||||
EXPECT_EQ(0, memcmp(buf.data(), kTestData, sizeof(kTestData)));
|
||||
EXPECT_EQ(0, memcmp(buf.data() + sizeof(kTestData),
|
||||
@ -133,9 +133,9 @@ TEST(BufferTest, TestSetCapacityThenSetLength) {
|
||||
TEST(BufferTest, TestTransfer) {
|
||||
Buffer buf1(kTestData, sizeof(kTestData), 256U), buf2;
|
||||
buf1.TransferTo(&buf2);
|
||||
EXPECT_EQ(0U, buf1.length());
|
||||
EXPECT_EQ(0U, buf1.size());
|
||||
EXPECT_EQ(0U, buf1.capacity());
|
||||
EXPECT_EQ(sizeof(kTestData), buf2.length());
|
||||
EXPECT_EQ(sizeof(kTestData), buf2.size());
|
||||
EXPECT_EQ(256U, buf2.capacity()); // capacity does transfer
|
||||
EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData)));
|
||||
}
|
||||
|
@ -79,8 +79,7 @@ bool SSLFingerprint::operator==(const SSLFingerprint& other) const {
|
||||
|
||||
std::string SSLFingerprint::GetRfc4572Fingerprint() const {
|
||||
std::string fingerprint =
|
||||
rtc::hex_encode_with_delimiter(
|
||||
digest.data(), digest.length(), ':');
|
||||
rtc::hex_encode_with_delimiter(digest.data(), digest.size(), ':');
|
||||
std::transform(fingerprint.begin(), fingerprint.end(),
|
||||
fingerprint.begin(), ::toupper);
|
||||
return fingerprint;
|
||||
|
@ -754,7 +754,7 @@ StreamResult AsyncWriteStream::Write(const void* data, size_t data_len,
|
||||
size_t previous_buffer_length = 0;
|
||||
{
|
||||
CritScope cs(&crit_buffer_);
|
||||
previous_buffer_length = buffer_.length();
|
||||
previous_buffer_length = buffer_.size();
|
||||
buffer_.AppendData(data, data_len);
|
||||
}
|
||||
|
||||
@ -793,9 +793,9 @@ void AsyncWriteStream::ClearBufferAndWrite() {
|
||||
buffer_.TransferTo(&to_write);
|
||||
}
|
||||
|
||||
if (to_write.length() > 0) {
|
||||
if (to_write.size() > 0) {
|
||||
CritScope cs(&crit_stream_);
|
||||
stream_->WriteAll(to_write.data(), to_write.length(), NULL, NULL);
|
||||
stream_->WriteAll(to_write.data(), to_write.size(), NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1354,13 +1354,13 @@ TEST_F(RtpSenderVideoTest, SendVideoWithCVO) {
|
||||
// Verify that this packet doesn't have CVO byte.
|
||||
VerifyCVOPacket(
|
||||
reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()),
|
||||
transport_.sent_packets_[0]->length(), false, &map, kSeqNum,
|
||||
transport_.sent_packets_[0]->size(), false, &map, kSeqNum,
|
||||
kVideoRotation_0);
|
||||
|
||||
// Verify that this packet doesn't have CVO byte.
|
||||
VerifyCVOPacket(
|
||||
reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()),
|
||||
transport_.sent_packets_[1]->length(), true, &map, kSeqNum + 1,
|
||||
transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1,
|
||||
hdr.rotation);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
@ -220,10 +220,9 @@ class DtlsTransport : public Base {
|
||||
}
|
||||
// Apply remote fingerprint.
|
||||
if (!channel->SetRemoteFingerprint(
|
||||
remote_fingerprint_->algorithm,
|
||||
reinterpret_cast<const uint8 *>(remote_fingerprint_->
|
||||
digest.data()),
|
||||
remote_fingerprint_->digest.length())) {
|
||||
remote_fingerprint_->algorithm,
|
||||
reinterpret_cast<const uint8*>(remote_fingerprint_->digest.data()),
|
||||
remote_fingerprint_->digest.size())) {
|
||||
return BadTransportDescription("Failed to apply remote fingerprint.",
|
||||
error_desc);
|
||||
}
|
||||
|
@ -263,8 +263,8 @@ bool DtlsTransportChannelWrapper::SetupDtls() {
|
||||
dtls_->SignalEvent.connect(this, &DtlsTransportChannelWrapper::OnDtlsEvent);
|
||||
if (!dtls_->SetPeerCertificateDigest(
|
||||
remote_fingerprint_algorithm_,
|
||||
reinterpret_cast<unsigned char *>(remote_fingerprint_value_.data()),
|
||||
remote_fingerprint_value_.length())) {
|
||||
reinterpret_cast<unsigned char*>(remote_fingerprint_value_.data()),
|
||||
remote_fingerprint_value_.size())) {
|
||||
LOG_J(LS_ERROR, this) << "Couldn't set DTLS certificate digest.";
|
||||
return false;
|
||||
}
|
||||
|
@ -213,8 +213,7 @@ class FakeTransportChannel : public TransportChannelImpl,
|
||||
virtual void OnMessage(rtc::Message* msg) {
|
||||
PacketMessageData* data = static_cast<PacketMessageData*>(
|
||||
msg->pdata);
|
||||
dest_->SignalReadPacket(dest_, data->packet.data(),
|
||||
data->packet.length(),
|
||||
dest_->SignalReadPacket(dest_, data->packet.data(), data->packet.size(),
|
||||
rtc::CreatePacketTime(0), 0);
|
||||
delete data;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class TransportDescriptionFactoryTest : public testing::Test {
|
||||
} else {
|
||||
ASSERT_TRUE(desc->identity_fingerprint.get() != NULL);
|
||||
EXPECT_EQ(desc->identity_fingerprint->algorithm, dtls_alg);
|
||||
EXPECT_GT(desc->identity_fingerprint->digest.length(), 0U);
|
||||
EXPECT_GT(desc->identity_fingerprint->digest.size(), 0U);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,8 +437,8 @@ class TurnPortTest : public testing::Test,
|
||||
ASSERT_EQ_WAIT(num_packets, turn_packets_.size(), kTimeout);
|
||||
ASSERT_EQ_WAIT(num_packets, udp_packets_.size(), kTimeout);
|
||||
for (size_t i = 0; i < num_packets; ++i) {
|
||||
EXPECT_EQ(i + 1, turn_packets_[i].length());
|
||||
EXPECT_EQ(i + 1, udp_packets_[i].length());
|
||||
EXPECT_EQ(i + 1, turn_packets_[i].size());
|
||||
EXPECT_EQ(i + 1, udp_packets_[i].size());
|
||||
EXPECT_EQ(turn_packets_[i], udp_packets_[i]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user