Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: webrtc/media/sctp/sctpdataengine.cc

Issue 1823503002: Reland Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/sctp/sctpdataengine.h ('k') | webrtc/media/sctp/sctpdataengine_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/media/sctp/sctpdataengine.cc
diff --git a/webrtc/media/sctp/sctpdataengine.cc b/webrtc/media/sctp/sctpdataengine.cc
index ce0f91ae3919c0d50059c438154f0374ed75c02d..ba3b8f2408444e590510a58391b5e3e6f4b9a5ec 100644
--- a/webrtc/media/sctp/sctpdataengine.cc
+++ b/webrtc/media/sctp/sctpdataengine.cc
@@ -19,7 +19,7 @@
#include "usrsctplib/usrsctp.h"
#include "webrtc/base/arraysize.h"
-#include "webrtc/base/buffer.h"
+#include "webrtc/base/copyonwritebuffer.h"
#include "webrtc/base/helpers.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/safe_conversions.h"
@@ -89,7 +89,7 @@ std::string ListArray(const uint16_t* array, int num_elems) {
namespace cricket {
typedef rtc::ScopedMessageData<SctpInboundPacket> InboundPacketMessage;
-typedef rtc::ScopedMessageData<rtc::Buffer> OutboundPacketMessage;
+typedef rtc::ScopedMessageData<rtc::CopyOnWriteBuffer> OutboundPacketMessage;
// The biggest SCTP packet. Starting from a 'safe' wire MTU value of 1280,
// take off 80 bytes for DTLS/TURN/TCP/IP overhead.
@@ -103,7 +103,7 @@ enum {
};
struct SctpInboundPacket {
- rtc::Buffer buffer;
+ rtc::CopyOnWriteBuffer buffer;
ReceiveDataParams params;
// The |flags| parameter is used by SCTP to distinguish notification packets
// from other types of packets.
@@ -165,11 +165,14 @@ static bool GetDataMediaType(
}
// Log the packet in text2pcap format, if log level is at LS_VERBOSE.
-static void VerboseLogPacket(void *data, size_t length, int direction) {
+static void VerboseLogPacket(const void *data, size_t length, int direction) {
if (LOG_CHECK_LEVEL(LS_VERBOSE) && length > 0) {
char *dump_buf;
+ // Some downstream project uses an older version of usrsctp that expects
+ // a non-const "void*" as first parameter when dumping the packet, so we
+ // need to cast the const away here to avoid a compiler error.
if ((dump_buf = usrsctp_dumppacket(
- data, length, direction)) != NULL) {
+ const_cast<void*>(data), length, direction)) != NULL) {
joachim 2016/03/20 10:14:10 This is the change compared to https://codereview.
LOG(LS_VERBOSE) << dump_buf;
usrsctp_freedumpbuffer(dump_buf);
}
@@ -189,7 +192,7 @@ static int OnSctpOutboundPacket(void* addr, void* data, size_t length,
VerboseLogPacket(addr, length, SCTP_DUMP_OUTBOUND);
// Note: We have to copy the data; the caller will delete it.
auto* msg = new OutboundPacketMessage(
- new rtc::Buffer(reinterpret_cast<uint8_t*>(data), length));
+ new rtc::CopyOnWriteBuffer(reinterpret_cast<uint8_t*>(data), length));
channel->worker_thread()->Post(channel, MSG_SCTPOUTBOUNDPACKET, msg);
return 0;
}
@@ -581,7 +584,7 @@ bool SctpDataMediaChannel::RemoveRecvStream(uint32_t ssrc) {
bool SctpDataMediaChannel::SendData(
const SendDataParams& params,
- const rtc::Buffer& payload,
+ const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result) {
if (result) {
// Preset |result| to assume an error. If SendData succeeds, we'll
@@ -651,7 +654,7 @@ bool SctpDataMediaChannel::SendData(
// Called by network interface when a packet has been received.
void SctpDataMediaChannel::OnPacketReceived(
- rtc::Buffer* packet, const rtc::PacketTime& packet_time) {
+ rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) {
RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): "
<< " length=" << packet->size() << ", sending: " << sending_;
@@ -663,8 +666,8 @@ 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.
- VerboseLogPacket(packet->data(), packet->size(), SCTP_DUMP_INBOUND);
- usrsctp_conninput(this, packet->data(), packet->size(), 0);
+ VerboseLogPacket(packet->cdata(), packet->size(), SCTP_DUMP_INBOUND);
+ usrsctp_conninput(this, packet->cdata(), packet->size(), 0);
} else {
// TODO(ldixon): Consider caching the packet for very slightly better
// reliability.
@@ -686,25 +689,25 @@ void SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(
return;
}
if (packet->flags & MSG_NOTIFICATION) {
- OnNotificationFromSctp(&packet->buffer);
+ OnNotificationFromSctp(packet->buffer);
} else {
- OnDataFromSctpToChannel(packet->params, &packet->buffer);
+ OnDataFromSctpToChannel(packet->params, packet->buffer);
}
}
void SctpDataMediaChannel::OnDataFromSctpToChannel(
- const ReceiveDataParams& params, rtc::Buffer* buffer) {
+ const ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer) {
if (receiving_) {
LOG(LS_VERBOSE) << debug_name_ << "->OnDataFromSctpToChannel(...): "
- << "Posting with length: " << buffer->size()
+ << "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<char>(), buffer->size());
+ SignalDataReceived(params, buffer.data<char>(), buffer.size());
} else {
LOG(LS_WARNING) << debug_name_ << "->OnDataFromSctpToChannel(...): "
<< "Not receiving packet with sid=" << params.ssrc
- << " len=" << buffer->size() << " before SetReceive(true).";
+ << " len=" << buffer.size() << " before SetReceive(true).";
}
}
@@ -767,10 +770,11 @@ bool SctpDataMediaChannel::ResetStream(uint32_t ssrc) {
return true;
}
-void SctpDataMediaChannel::OnNotificationFromSctp(rtc::Buffer* buffer) {
+void SctpDataMediaChannel::OnNotificationFromSctp(
+ const rtc::CopyOnWriteBuffer& buffer) {
const sctp_notification& notification =
- reinterpret_cast<const sctp_notification&>(*buffer->data());
- ASSERT(notification.sn_header.sn_length == buffer->size());
+ reinterpret_cast<const sctp_notification&>(*buffer.data());
+ ASSERT(notification.sn_header.sn_length == buffer.size());
// TODO(ldixon): handle notifications appropriately.
switch (notification.sn_header.sn_type) {
@@ -963,7 +967,7 @@ bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) {
}
void SctpDataMediaChannel::OnPacketFromSctpToNetwork(
- rtc::Buffer* buffer) {
+ rtc::CopyOnWriteBuffer* buffer) {
// usrsctp seems to interpret the MTU we give it strangely -- it seems to
// give us back packets bigger than that MTU, if only by a fixed amount.
// This is that amount that we've observed.
« no previous file with comments | « webrtc/media/sctp/sctpdataengine.h ('k') | webrtc/media/sctp/sctpdataengine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698