| 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  | 
|   11 #include "webrtc/api/datachannel.h" |   11 #include "webrtc/api/datachannel.h" | 
|   12  |   12  | 
 |   13 #include <memory> | 
|   13 #include <string> |   14 #include <string> | 
|   14  |   15  | 
|   15 #include "webrtc/api/mediastreamprovider.h" |   16 #include "webrtc/api/mediastreamprovider.h" | 
|   16 #include "webrtc/api/sctputils.h" |   17 #include "webrtc/api/sctputils.h" | 
|   17 #include "webrtc/base/logging.h" |   18 #include "webrtc/base/logging.h" | 
|   18 #include "webrtc/base/refcount.h" |   19 #include "webrtc/base/refcount.h" | 
|   19 #include "webrtc/media/sctp/sctpdataengine.h" |   20 #include "webrtc/media/sctp/sctpdataengine.h" | 
|   20  |   21  | 
|   21 namespace webrtc { |   22 namespace webrtc { | 
|   22  |   23  | 
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  356  |  357  | 
|  357   LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = " << params.ssrc; |  358   LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = " << params.ssrc; | 
|  358   // We can send unordered as soon as we receive any DATA message since the |  359   // We can send unordered as soon as we receive any DATA message since the | 
|  359   // remote side must have received the OPEN (and old clients do not send |  360   // remote side must have received the OPEN (and old clients do not send | 
|  360   // OPEN_ACK). |  361   // OPEN_ACK). | 
|  361   if (handshake_state_ == kHandshakeWaitingForAck) { |  362   if (handshake_state_ == kHandshakeWaitingForAck) { | 
|  362     handshake_state_ = kHandshakeReady; |  363     handshake_state_ = kHandshakeReady; | 
|  363   } |  364   } | 
|  364  |  365  | 
|  365   bool binary = (params.type == cricket::DMT_BINARY); |  366   bool binary = (params.type == cricket::DMT_BINARY); | 
|  366   rtc::scoped_ptr<DataBuffer> buffer(new DataBuffer(payload, binary)); |  367   std::unique_ptr<DataBuffer> buffer(new DataBuffer(payload, binary)); | 
|  367   if (state_ == kOpen && observer_) { |  368   if (state_ == kOpen && observer_) { | 
|  368     observer_->OnMessage(*buffer.get()); |  369     observer_->OnMessage(*buffer.get()); | 
|  369   } else { |  370   } else { | 
|  370     if (queued_received_data_.byte_count() + payload.size() > |  371     if (queued_received_data_.byte_count() + payload.size() > | 
|  371         kMaxQueuedReceivedDataBytes) { |  372         kMaxQueuedReceivedDataBytes) { | 
|  372       LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; |  373       LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; | 
|  373  |  374  | 
|  374       queued_received_data_.Clear(); |  375       queued_received_data_.Clear(); | 
|  375       if (data_channel_type_ != cricket::DCT_RTP) { |  376       if (data_channel_type_ != cricket::DCT_RTP) { | 
|  376         Close(); |  377         Close(); | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  487     provider_->RemoveSctpDataStream(config_.id); |  488     provider_->RemoveSctpDataStream(config_.id); | 
|  488   } |  489   } | 
|  489 } |  490 } | 
|  490  |  491  | 
|  491 void DataChannel::DeliverQueuedReceivedData() { |  492 void DataChannel::DeliverQueuedReceivedData() { | 
|  492   if (!observer_) { |  493   if (!observer_) { | 
|  493     return; |  494     return; | 
|  494   } |  495   } | 
|  495  |  496  | 
|  496   while (!queued_received_data_.Empty()) { |  497   while (!queued_received_data_.Empty()) { | 
|  497     rtc::scoped_ptr<DataBuffer> buffer(queued_received_data_.Front()); |  498     std::unique_ptr<DataBuffer> buffer(queued_received_data_.Front()); | 
|  498     observer_->OnMessage(*buffer); |  499     observer_->OnMessage(*buffer); | 
|  499     queued_received_data_.Pop(); |  500     queued_received_data_.Pop(); | 
|  500   } |  501   } | 
|  501 } |  502 } | 
|  502  |  503  | 
|  503 void DataChannel::SendQueuedDataMessages() { |  504 void DataChannel::SendQueuedDataMessages() { | 
|  504   if (queued_send_data_.Empty()) { |  505   if (queued_send_data_.Empty()) { | 
|  505     return; |  506     return; | 
|  506   } |  507   } | 
|  507  |  508  | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  582     observer_->OnBufferedAmountChange(start_buffered_amount); |  583     observer_->OnBufferedAmountChange(start_buffered_amount); | 
|  583   } |  584   } | 
|  584   return true; |  585   return true; | 
|  585 } |  586 } | 
|  586  |  587  | 
|  587 void DataChannel::SendQueuedControlMessages() { |  588 void DataChannel::SendQueuedControlMessages() { | 
|  588   PacketQueue control_packets; |  589   PacketQueue control_packets; | 
|  589   control_packets.Swap(&queued_control_data_); |  590   control_packets.Swap(&queued_control_data_); | 
|  590  |  591  | 
|  591   while (!control_packets.Empty()) { |  592   while (!control_packets.Empty()) { | 
|  592     rtc::scoped_ptr<DataBuffer> buf(control_packets.Front()); |  593     std::unique_ptr<DataBuffer> buf(control_packets.Front()); | 
|  593     SendControlMessage(buf->data); |  594     SendControlMessage(buf->data); | 
|  594     control_packets.Pop(); |  595     control_packets.Pop(); | 
|  595   } |  596   } | 
|  596 } |  597 } | 
|  597  |  598  | 
|  598 void DataChannel::QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer) { |  599 void DataChannel::QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer) { | 
|  599   queued_control_data_.Push(new DataBuffer(buffer, true)); |  600   queued_control_data_.Push(new DataBuffer(buffer, true)); | 
|  600 } |  601 } | 
|  601  |  602  | 
|  602 bool DataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) { |  603 bool DataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) { | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  629     QueueControlMessage(buffer); |  630     QueueControlMessage(buffer); | 
|  630   } else { |  631   } else { | 
|  631     LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" |  632     LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" | 
|  632                   << " the CONTROL message, send_result = " << send_result; |  633                   << " the CONTROL message, send_result = " << send_result; | 
|  633     Close(); |  634     Close(); | 
|  634   } |  635   } | 
|  635   return retval; |  636   return retval; | 
|  636 } |  637 } | 
|  637  |  638  | 
|  638 }  // namespace webrtc |  639 }  // namespace webrtc | 
| OLD | NEW |