| OLD | NEW |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return NULL; | 119 return NULL; |
| 120 } | 120 } |
| 121 return channel; | 121 return channel; |
| 122 } | 122 } |
| 123 | 123 |
| 124 DataChannel::DataChannel( | 124 DataChannel::DataChannel( |
| 125 DataChannelProviderInterface* provider, | 125 DataChannelProviderInterface* provider, |
| 126 cricket::DataChannelType dct, | 126 cricket::DataChannelType dct, |
| 127 const std::string& label) | 127 const std::string& label) |
| 128 : label_(label), | 128 : label_(label), |
| 129 observer_(NULL), | 129 observer_(nullptr), |
| 130 state_(kConnecting), | 130 state_(kConnecting), |
| 131 messages_sent_(0), |
| 132 bytes_sent_(0), |
| 133 messages_received_(0), |
| 134 bytes_received_(0), |
| 131 data_channel_type_(dct), | 135 data_channel_type_(dct), |
| 132 provider_(provider), | 136 provider_(provider), |
| 133 handshake_state_(kHandshakeInit), | 137 handshake_state_(kHandshakeInit), |
| 134 connected_to_provider_(false), | 138 connected_to_provider_(false), |
| 135 send_ssrc_set_(false), | 139 send_ssrc_set_(false), |
| 136 receive_ssrc_set_(false), | 140 receive_ssrc_set_(false), |
| 137 writable_(false), | 141 writable_(false), |
| 138 send_ssrc_(0), | 142 send_ssrc_(0), |
| 139 receive_ssrc_(0) { | 143 receive_ssrc_(0) { |
| 140 } | 144 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // We can send unordered as soon as we receive any DATA message since the | 364 // We can send unordered as soon as we receive any DATA message since the |
| 361 // remote side must have received the OPEN (and old clients do not send | 365 // remote side must have received the OPEN (and old clients do not send |
| 362 // OPEN_ACK). | 366 // OPEN_ACK). |
| 363 if (handshake_state_ == kHandshakeWaitingForAck) { | 367 if (handshake_state_ == kHandshakeWaitingForAck) { |
| 364 handshake_state_ = kHandshakeReady; | 368 handshake_state_ = kHandshakeReady; |
| 365 } | 369 } |
| 366 | 370 |
| 367 bool binary = (params.type == cricket::DMT_BINARY); | 371 bool binary = (params.type == cricket::DMT_BINARY); |
| 368 std::unique_ptr<DataBuffer> buffer(new DataBuffer(payload, binary)); | 372 std::unique_ptr<DataBuffer> buffer(new DataBuffer(payload, binary)); |
| 369 if (state_ == kOpen && observer_) { | 373 if (state_ == kOpen && observer_) { |
| 374 ++messages_received_; |
| 375 bytes_received_ += buffer->size(); |
| 370 observer_->OnMessage(*buffer.get()); | 376 observer_->OnMessage(*buffer.get()); |
| 371 } else { | 377 } else { |
| 372 if (queued_received_data_.byte_count() + payload.size() > | 378 if (queued_received_data_.byte_count() + payload.size() > |
| 373 kMaxQueuedReceivedDataBytes) { | 379 kMaxQueuedReceivedDataBytes) { |
| 374 LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; | 380 LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; |
| 375 | 381 |
| 376 queued_received_data_.Clear(); | 382 queued_received_data_.Clear(); |
| 377 if (data_channel_type_ != cricket::DCT_RTP) { | 383 if (data_channel_type_ != cricket::DCT_RTP) { |
| 378 Close(); | 384 Close(); |
| 379 } | 385 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 497 } |
| 492 } | 498 } |
| 493 | 499 |
| 494 void DataChannel::DeliverQueuedReceivedData() { | 500 void DataChannel::DeliverQueuedReceivedData() { |
| 495 if (!observer_) { | 501 if (!observer_) { |
| 496 return; | 502 return; |
| 497 } | 503 } |
| 498 | 504 |
| 499 while (!queued_received_data_.Empty()) { | 505 while (!queued_received_data_.Empty()) { |
| 500 std::unique_ptr<DataBuffer> buffer(queued_received_data_.Front()); | 506 std::unique_ptr<DataBuffer> buffer(queued_received_data_.Front()); |
| 507 ++messages_received_; |
| 508 bytes_received_ += buffer->size(); |
| 501 observer_->OnMessage(*buffer); | 509 observer_->OnMessage(*buffer); |
| 502 queued_received_data_.Pop(); | 510 queued_received_data_.Pop(); |
| 503 } | 511 } |
| 504 } | 512 } |
| 505 | 513 |
| 506 void DataChannel::SendQueuedDataMessages() { | 514 void DataChannel::SendQueuedDataMessages() { |
| 507 if (queued_send_data_.Empty()) { | 515 if (queued_send_data_.Empty()) { |
| 508 return; | 516 return; |
| 509 } | 517 } |
| 510 | 518 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 send_params.ssrc = config_.id; | 552 send_params.ssrc = config_.id; |
| 545 } else { | 553 } else { |
| 546 send_params.ssrc = send_ssrc_; | 554 send_params.ssrc = send_ssrc_; |
| 547 } | 555 } |
| 548 send_params.type = buffer.binary ? cricket::DMT_BINARY : cricket::DMT_TEXT; | 556 send_params.type = buffer.binary ? cricket::DMT_BINARY : cricket::DMT_TEXT; |
| 549 | 557 |
| 550 cricket::SendDataResult send_result = cricket::SDR_SUCCESS; | 558 cricket::SendDataResult send_result = cricket::SDR_SUCCESS; |
| 551 bool success = provider_->SendData(send_params, buffer.data, &send_result); | 559 bool success = provider_->SendData(send_params, buffer.data, &send_result); |
| 552 | 560 |
| 553 if (success) { | 561 if (success) { |
| 562 ++messages_sent_; |
| 563 bytes_sent_ += buffer.size(); |
| 554 return true; | 564 return true; |
| 555 } | 565 } |
| 556 | 566 |
| 557 if (data_channel_type_ != cricket::DCT_SCTP) { | 567 if (data_channel_type_ != cricket::DCT_SCTP) { |
| 558 return false; | 568 return false; |
| 559 } | 569 } |
| 560 | 570 |
| 561 if (send_result == cricket::SDR_BLOCK) { | 571 if (send_result == cricket::SDR_BLOCK) { |
| 562 if (!queue_if_blocked || QueueSendDataMessage(buffer)) { | 572 if (!queue_if_blocked || QueueSendDataMessage(buffer)) { |
| 563 return false; | 573 return false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 QueueControlMessage(buffer); | 642 QueueControlMessage(buffer); |
| 633 } else { | 643 } else { |
| 634 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" | 644 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" |
| 635 << " the CONTROL message, send_result = " << send_result; | 645 << " the CONTROL message, send_result = " << send_result; |
| 636 Close(); | 646 Close(); |
| 637 } | 647 } |
| 638 return retval; | 648 return retval; |
| 639 } | 649 } |
| 640 | 650 |
| 641 } // namespace webrtc | 651 } // namespace webrtc |
| OLD | NEW |