| Index: talk/app/webrtc/datachannel.cc
|
| diff --git a/talk/app/webrtc/datachannel.cc b/talk/app/webrtc/datachannel.cc
|
| index 2028dc9f0317547c0358088cb98f5c3b4dcd095f..20cf7433555aa2262ff08f7cc41a0d6e43dc3f97 100644
|
| --- a/talk/app/webrtc/datachannel.cc
|
| +++ b/talk/app/webrtc/datachannel.cc
|
| @@ -31,6 +31,7 @@
|
|
|
| #include "talk/app/webrtc/mediastreamprovider.h"
|
| #include "talk/app/webrtc/sctputils.h"
|
| +#include "talk/media/sctp/sctpdataengine.h"
|
| #include "webrtc/base/logging.h"
|
| #include "webrtc/base/refcount.h"
|
|
|
| @@ -43,6 +44,42 @@ enum {
|
| MSG_CHANNELREADY,
|
| };
|
|
|
| +bool SctpSidAllocator::AllocateSid(rtc::SSLRole role, int* sid) {
|
| + int potential_sid = (role == rtc::SSL_CLIENT) ? 0 : 1;
|
| + while (!IsSidAvailable(potential_sid)) {
|
| + potential_sid += 2;
|
| + if (potential_sid > static_cast<int>(cricket::kMaxSctpSid)) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + *sid = potential_sid;
|
| + used_sids_.insert(potential_sid);
|
| + return true;
|
| +}
|
| +
|
| +bool SctpSidAllocator::ReserveSid(int sid) {
|
| + if (!IsSidAvailable(sid)) {
|
| + return false;
|
| + }
|
| + used_sids_.insert(sid);
|
| + return true;
|
| +}
|
| +
|
| +void SctpSidAllocator::ReleaseSid(int sid) {
|
| + auto it = used_sids_.find(sid);
|
| + if (it != used_sids_.end()) {
|
| + used_sids_.erase(it);
|
| + }
|
| +}
|
| +
|
| +bool SctpSidAllocator::IsSidAvailable(int sid) const {
|
| + if (sid < 0 || sid > static_cast<int>(cricket::kMaxSctpSid)) {
|
| + return false;
|
| + }
|
| + return used_sids_.find(sid) == used_sids_.end();
|
| +}
|
| +
|
| DataChannel::PacketQueue::PacketQueue() : byte_count_(0) {}
|
|
|
| DataChannel::PacketQueue::~PacketQueue() {
|
| @@ -257,8 +294,9 @@ void DataChannel::RemotePeerRequestClose() {
|
|
|
| void DataChannel::SetSctpSid(int sid) {
|
| ASSERT(config_.id < 0 && sid >= 0 && data_channel_type_ == cricket::DCT_SCTP);
|
| - if (config_.id == sid)
|
| + if (config_.id == sid) {
|
| return;
|
| + }
|
|
|
| config_.id = sid;
|
| provider_->AddSctpDataStream(sid);
|
| @@ -276,6 +314,13 @@ void DataChannel::OnTransportChannelCreated() {
|
| }
|
| }
|
|
|
| +// The underlying transport channel was destroyed.
|
| +// This function makes sure the DataChannel is disconnected and changes state to
|
| +// kClosed.
|
| +void DataChannel::OnTransportChannelDestroyed() {
|
| + DoClose();
|
| +}
|
| +
|
| void DataChannel::SetSendSsrc(uint32_t send_ssrc) {
|
| ASSERT(data_channel_type_ == cricket::DCT_RTP);
|
| if (send_ssrc_set_) {
|
| @@ -294,13 +339,6 @@ void DataChannel::OnMessage(rtc::Message* msg) {
|
| }
|
| }
|
|
|
| -// The underlaying data engine is closing.
|
| -// This function makes sure the DataChannel is disconnected and changes state to
|
| -// kClosed.
|
| -void DataChannel::OnDataEngineClose() {
|
| - DoClose();
|
| -}
|
| -
|
| void DataChannel::OnDataReceived(cricket::DataChannel* channel,
|
| const cricket::ReceiveDataParams& params,
|
| const rtc::Buffer& payload) {
|
| @@ -361,6 +399,12 @@ void DataChannel::OnDataReceived(cricket::DataChannel* channel,
|
| }
|
| }
|
|
|
| +void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
|
| + if (data_channel_type_ == cricket::DCT_SCTP && sid == config_.id) {
|
| + Close();
|
| + }
|
| +}
|
| +
|
| void DataChannel::OnChannelReady(bool writable) {
|
| writable_ = writable;
|
| if (!writable) {
|
| @@ -436,13 +480,17 @@ void DataChannel::UpdateState() {
|
| }
|
|
|
| void DataChannel::SetState(DataState state) {
|
| - if (state_ == state)
|
| + if (state_ == state) {
|
| return;
|
| + }
|
|
|
| state_ = state;
|
| if (observer_) {
|
| observer_->OnStateChange();
|
| }
|
| + if (state_ == kClosed) {
|
| + SignalClosed(this);
|
| + }
|
| }
|
|
|
| void DataChannel::DisconnectFromProvider() {
|
|
|