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

Side by Side Diff: webrtc/api/datachannel.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void DataChannel::OnMessage(rtc::Message* msg) { 317 void DataChannel::OnMessage(rtc::Message* msg) {
318 switch (msg->message_id) { 318 switch (msg->message_id) {
319 case MSG_CHANNELREADY: 319 case MSG_CHANNELREADY:
320 OnChannelReady(true); 320 OnChannelReady(true);
321 break; 321 break;
322 } 322 }
323 } 323 }
324 324
325 void DataChannel::OnDataReceived(cricket::DataChannel* channel, 325 void DataChannel::OnDataReceived(cricket::DataChannel* channel,
326 const cricket::ReceiveDataParams& params, 326 const cricket::ReceiveDataParams& params,
327 const rtc::Buffer& payload) { 327 const rtc::CopyOnWriteBuffer& payload) {
328 uint32_t expected_ssrc = 328 uint32_t expected_ssrc =
329 (data_channel_type_ == cricket::DCT_RTP) ? receive_ssrc_ : config_.id; 329 (data_channel_type_ == cricket::DCT_RTP) ? receive_ssrc_ : config_.id;
330 if (params.ssrc != expected_ssrc) { 330 if (params.ssrc != expected_ssrc) {
331 return; 331 return;
332 } 332 }
333 333
334 if (params.type == cricket::DMT_CONTROL) { 334 if (params.type == cricket::DMT_CONTROL) {
335 ASSERT(data_channel_type_ == cricket::DCT_SCTP); 335 ASSERT(data_channel_type_ == cricket::DCT_SCTP);
336 if (handshake_state_ != kHandshakeWaitingForAck) { 336 if (handshake_state_ != kHandshakeWaitingForAck) {
337 // Ignore it if we are not expecting an ACK message. 337 // Ignore it if we are not expecting an ACK message.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // clarity. OnChannelReady(true) will send any queued data and then invoke 415 // clarity. OnChannelReady(true) will send any queued data and then invoke
416 // UpdateState(). 416 // UpdateState().
417 switch (state_) { 417 switch (state_) {
418 case kConnecting: { 418 case kConnecting: {
419 if (send_ssrc_set_ == receive_ssrc_set_) { 419 if (send_ssrc_set_ == receive_ssrc_set_) {
420 if (data_channel_type_ == cricket::DCT_RTP && !connected_to_provider_) { 420 if (data_channel_type_ == cricket::DCT_RTP && !connected_to_provider_) {
421 connected_to_provider_ = provider_->ConnectDataChannel(this); 421 connected_to_provider_ = provider_->ConnectDataChannel(this);
422 } 422 }
423 if (connected_to_provider_) { 423 if (connected_to_provider_) {
424 if (handshake_state_ == kHandshakeShouldSendOpen) { 424 if (handshake_state_ == kHandshakeShouldSendOpen) {
425 rtc::Buffer payload; 425 rtc::CopyOnWriteBuffer payload;
426 WriteDataChannelOpenMessage(label_, config_, &payload); 426 WriteDataChannelOpenMessage(label_, config_, &payload);
427 SendControlMessage(payload); 427 SendControlMessage(payload);
428 } else if (handshake_state_ == kHandshakeShouldSendAck) { 428 } else if (handshake_state_ == kHandshakeShouldSendAck) {
429 rtc::Buffer payload; 429 rtc::CopyOnWriteBuffer payload;
430 WriteDataChannelOpenAckMessage(&payload); 430 WriteDataChannelOpenAckMessage(&payload);
431 SendControlMessage(payload); 431 SendControlMessage(payload);
432 } 432 }
433 if (writable_ && 433 if (writable_ &&
434 (handshake_state_ == kHandshakeReady || 434 (handshake_state_ == kHandshakeReady ||
435 handshake_state_ == kHandshakeWaitingForAck)) { 435 handshake_state_ == kHandshakeWaitingForAck)) {
436 SetState(kOpen); 436 SetState(kOpen);
437 // If we have received buffers before the channel got writable. 437 // If we have received buffers before the channel got writable.
438 // Deliver them now. 438 // Deliver them now.
439 DeliverQueuedReceivedData(); 439 DeliverQueuedReceivedData();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 PacketQueue control_packets; 588 PacketQueue control_packets;
589 control_packets.Swap(&queued_control_data_); 589 control_packets.Swap(&queued_control_data_);
590 590
591 while (!control_packets.Empty()) { 591 while (!control_packets.Empty()) {
592 rtc::scoped_ptr<DataBuffer> buf(control_packets.Front()); 592 rtc::scoped_ptr<DataBuffer> buf(control_packets.Front());
593 SendControlMessage(buf->data); 593 SendControlMessage(buf->data);
594 control_packets.Pop(); 594 control_packets.Pop();
595 } 595 }
596 } 596 }
597 597
598 void DataChannel::QueueControlMessage(const rtc::Buffer& buffer) { 598 void DataChannel::QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer) {
599 queued_control_data_.Push(new DataBuffer(buffer, true)); 599 queued_control_data_.Push(new DataBuffer(buffer, true));
600 } 600 }
601 601
602 bool DataChannel::SendControlMessage(const rtc::Buffer& buffer) { 602 bool DataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) {
603 bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen; 603 bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen;
604 604
605 ASSERT(data_channel_type_ == cricket::DCT_SCTP && 605 ASSERT(data_channel_type_ == cricket::DCT_SCTP &&
606 writable_ && 606 writable_ &&
607 config_.id >= 0 && 607 config_.id >= 0 &&
608 (!is_open_message || !config_.negotiated)); 608 (!is_open_message || !config_.negotiated));
609 609
610 cricket::SendDataParams send_params; 610 cricket::SendDataParams send_params;
611 send_params.ssrc = config_.id; 611 send_params.ssrc = config_.id;
612 // Send data as ordered before we receive any message from the remote peer to 612 // Send data as ordered before we receive any message from the remote peer to
(...skipping 16 matching lines...) Expand all
629 QueueControlMessage(buffer); 629 QueueControlMessage(buffer);
630 } else { 630 } else {
631 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" 631 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send"
632 << " the CONTROL message, send_result = " << send_result; 632 << " the CONTROL message, send_result = " << send_result;
633 Close(); 633 Close();
634 } 634 }
635 return retval; 635 return retval;
636 } 636 }
637 637
638 } // namespace webrtc 638 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698