OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 13 matching lines...) Expand all Loading... | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/app/webrtc/datachannel.h" | 28 #include "talk/app/webrtc/datachannel.h" |
29 | 29 |
30 #include <string> | 30 #include <string> |
31 | 31 |
32 #include "talk/app/webrtc/mediastreamprovider.h" | 32 #include "talk/app/webrtc/mediastreamprovider.h" |
33 #include "talk/app/webrtc/sctputils.h" | 33 #include "talk/app/webrtc/sctputils.h" |
34 #include "talk/media/sctp/sctpdataengine.h" | |
34 #include "webrtc/base/logging.h" | 35 #include "webrtc/base/logging.h" |
35 #include "webrtc/base/refcount.h" | 36 #include "webrtc/base/refcount.h" |
36 | 37 |
37 namespace webrtc { | 38 namespace webrtc { |
38 | 39 |
39 static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024; | 40 static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024; |
40 static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024; | 41 static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024; |
41 | 42 |
42 enum { | 43 enum { |
43 MSG_CHANNELREADY, | 44 MSG_CHANNELREADY, |
44 }; | 45 }; |
45 | 46 |
47 bool SctpSidAllocator::AllocateSctpSid(rtc::SSLRole role, int* sid) { | |
pthatcher1
2015/10/07 02:50:51
Might as well remove "Sctp" from the method name a
Taylor Brandstetter
2015/10/09 19:54:08
Done.
| |
48 int potential_sid = (role == rtc::SSL_CLIENT) ? 0 : 1; | |
49 while (!IsSctpSidAvailable(potential_sid)) { | |
50 potential_sid += 2; | |
51 if (potential_sid > static_cast<int>(cricket::kMaxSctpSid)) { | |
52 return false; | |
53 } | |
54 } | |
55 | |
56 *sid = potential_sid; | |
57 used_sids_.insert(potential_sid); | |
58 return true; | |
59 } | |
60 | |
61 bool SctpSidAllocator::ReserveSctpSid(int sid) { | |
62 if (!IsSctpSidAvailable(sid)) { | |
63 return false; | |
64 } | |
65 used_sids_.insert(sid); | |
66 return true; | |
67 } | |
68 | |
69 void SctpSidAllocator::ReleaseSctpSid(int sid) { | |
70 auto it = used_sids_.find(sid); | |
71 if (it != used_sids_.end()) { | |
72 used_sids_.erase(it); | |
73 } | |
74 } | |
75 | |
76 bool SctpSidAllocator::IsSctpSidAvailable(int sid) const { | |
77 if (sid < 0 || sid > static_cast<int>(cricket::kMaxSctpSid)) { | |
78 return false; | |
79 } | |
80 return used_sids_.find(sid) == used_sids_.end(); | |
81 } | |
82 | |
46 DataChannel::PacketQueue::PacketQueue() : byte_count_(0) {} | 83 DataChannel::PacketQueue::PacketQueue() : byte_count_(0) {} |
47 | 84 |
48 DataChannel::PacketQueue::~PacketQueue() { | 85 DataChannel::PacketQueue::~PacketQueue() { |
49 Clear(); | 86 Clear(); |
50 } | 87 } |
51 | 88 |
52 bool DataChannel::PacketQueue::Empty() const { | 89 bool DataChannel::PacketQueue::Empty() const { |
53 return packets_.empty(); | 90 return packets_.empty(); |
54 } | 91 } |
55 | 92 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 if (data_channel_type_ != cricket::DCT_RTP) { | 391 if (data_channel_type_ != cricket::DCT_RTP) { |
355 Close(); | 392 Close(); |
356 } | 393 } |
357 | 394 |
358 return; | 395 return; |
359 } | 396 } |
360 queued_received_data_.Push(buffer.release()); | 397 queued_received_data_.Push(buffer.release()); |
361 } | 398 } |
362 } | 399 } |
363 | 400 |
401 void DataChannel::OnStreamClosedRemotely(uint32 sid) { | |
Taylor Brandstetter
2015/10/07 00:26:19
Was previously MediaStreamSignaling::OnRemoteSctpD
| |
402 if (data_channel_type_ == cricket::DCT_SCTP && sid == config_.id) { | |
403 Close(); | |
404 } | |
405 } | |
406 | |
364 void DataChannel::OnChannelReady(bool writable) { | 407 void DataChannel::OnChannelReady(bool writable) { |
365 writable_ = writable; | 408 writable_ = writable; |
366 if (!writable) { | 409 if (!writable) { |
367 return; | 410 return; |
368 } | 411 } |
369 | 412 |
370 SendQueuedControlMessages(); | 413 SendQueuedControlMessages(); |
371 SendQueuedDataMessages(); | 414 SendQueuedDataMessages(); |
372 UpdateState(); | 415 UpdateState(); |
373 } | 416 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 } | 472 } |
430 } | 473 } |
431 break; | 474 break; |
432 } | 475 } |
433 case kClosed: | 476 case kClosed: |
434 break; | 477 break; |
435 } | 478 } |
436 } | 479 } |
437 | 480 |
438 void DataChannel::SetState(DataState state) { | 481 void DataChannel::SetState(DataState state) { |
439 if (state_ == state) | 482 if (state_ == state) { |
440 return; | 483 return; |
484 } | |
441 | 485 |
442 state_ = state; | 486 state_ = state; |
443 if (observer_) { | 487 if (observer_) { |
444 observer_->OnStateChange(); | 488 observer_->OnStateChange(); |
445 } | 489 } |
490 if (state_ == kClosed) { | |
491 SignalClosed(this); | |
492 } | |
446 } | 493 } |
447 | 494 |
448 void DataChannel::DisconnectFromProvider() { | 495 void DataChannel::DisconnectFromProvider() { |
449 if (!connected_to_provider_) | 496 if (!connected_to_provider_) |
450 return; | 497 return; |
451 | 498 |
452 provider_->DisconnectDataChannel(this); | 499 provider_->DisconnectDataChannel(this); |
453 connected_to_provider_ = false; | 500 connected_to_provider_ = false; |
454 | 501 |
455 if (data_channel_type_ == cricket::DCT_SCTP && config_.id >= 0) { | 502 if (data_channel_type_ == cricket::DCT_SCTP && config_.id >= 0) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 QueueControlMessage(buffer); | 645 QueueControlMessage(buffer); |
599 } else { | 646 } else { |
600 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" | 647 LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" |
601 << " the CONTROL message, send_result = " << send_result; | 648 << " the CONTROL message, send_result = " << send_result; |
602 Close(); | 649 Close(); |
603 } | 650 } |
604 return retval; | 651 return retval; |
605 } | 652 } |
606 | 653 |
607 } // namespace webrtc | 654 } // namespace webrtc |
OLD | NEW |