| 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 11 matching lines...) Expand all Loading... |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 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 #ifndef TALK_APP_WEBRTC_DATACHANNEL_H_ | 28 #ifndef TALK_APP_WEBRTC_DATACHANNEL_H_ |
| 29 #define TALK_APP_WEBRTC_DATACHANNEL_H_ | 29 #define TALK_APP_WEBRTC_DATACHANNEL_H_ |
| 30 | 30 |
| 31 #include <deque> | 31 #include <deque> |
| 32 #include <set> |
| 32 #include <string> | 33 #include <string> |
| 33 | 34 |
| 34 #include "talk/app/webrtc/datachannelinterface.h" | 35 #include "talk/app/webrtc/datachannelinterface.h" |
| 35 #include "talk/app/webrtc/proxy.h" | 36 #include "talk/app/webrtc/proxy.h" |
| 36 #include "talk/media/base/mediachannel.h" | 37 #include "talk/media/base/mediachannel.h" |
| 37 #include "talk/session/media/channel.h" | 38 #include "talk/session/media/channel.h" |
| 38 #include "webrtc/base/messagehandler.h" | 39 #include "webrtc/base/messagehandler.h" |
| 39 #include "webrtc/base/scoped_ref_ptr.h" | 40 #include "webrtc/base/scoped_ref_ptr.h" |
| 40 #include "webrtc/base/sigslot.h" | 41 #include "webrtc/base/sigslot.h" |
| 41 | 42 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 : DataChannelInit(base), open_handshake_role(kOpener) { | 77 : DataChannelInit(base), open_handshake_role(kOpener) { |
| 77 // If the channel is externally negotiated, do not send the OPEN message. | 78 // If the channel is externally negotiated, do not send the OPEN message. |
| 78 if (base.negotiated) { | 79 if (base.negotiated) { |
| 79 open_handshake_role = kNone; | 80 open_handshake_role = kNone; |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 OpenHandshakeRole open_handshake_role; | 84 OpenHandshakeRole open_handshake_role; |
| 84 }; | 85 }; |
| 85 | 86 |
| 87 // Helper class to allocate unique IDs for SCTP DataChannels |
| 88 class SctpSidAllocator { |
| 89 public: |
| 90 // Gets the first unused odd/even id based on the DTLS role. If |role| is |
| 91 // SSL_CLIENT, the allocated id starts from 0 and takes even numbers; |
| 92 // otherwise, the id starts from 1 and takes odd numbers. |
| 93 // Returns false if no id can be allocated. |
| 94 bool AllocateSctpSid(rtc::SSLRole role, int* sid); |
| 95 |
| 96 // Attempts to reserve a specific sid. Returns false if it's unavailable. |
| 97 bool ReserveSctpSid(int sid); |
| 98 |
| 99 // Indicates that |sid| isn't in use any more, and is thus available again. |
| 100 void ReleaseSctpSid(int sid); |
| 101 |
| 102 private: |
| 103 // Checks if |sid| is available to be assigned to a new SCTP data channel. |
| 104 bool IsSctpSidAvailable(int sid) const; |
| 105 |
| 106 std::set<int> used_sids_; |
| 107 }; |
| 108 |
| 86 // DataChannel is a an implementation of the DataChannelInterface based on | 109 // DataChannel is a an implementation of the DataChannelInterface based on |
| 87 // libjingle's data engine. It provides an implementation of unreliable or | 110 // libjingle's data engine. It provides an implementation of unreliable or |
| 88 // reliabledata channels. Currently this class is specifically designed to use | 111 // reliabledata channels. Currently this class is specifically designed to use |
| 89 // both RtpDataEngine and SctpDataEngine. | 112 // both RtpDataEngine and SctpDataEngine. |
| 90 | 113 |
| 91 // DataChannel states: | 114 // DataChannel states: |
| 92 // kConnecting: The channel has been created the transport might not yet be | 115 // kConnecting: The channel has been created the transport might not yet be |
| 93 // ready. | 116 // ready. |
| 94 // kOpen: The channel have a local SSRC set by a call to UpdateSendSsrc | 117 // kOpen: The channel have a local SSRC set by a call to UpdateSendSsrc |
| 95 // and a remote SSRC set by call to UpdateReceiveSsrc and the transport | 118 // and a remote SSRC set by call to UpdateReceiveSsrc and the transport |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 159 |
| 137 // Called when the channel's ready to use. That can happen when the | 160 // Called when the channel's ready to use. That can happen when the |
| 138 // underlying DataMediaChannel becomes ready, or when this channel is a new | 161 // underlying DataMediaChannel becomes ready, or when this channel is a new |
| 139 // stream on an existing DataMediaChannel, and we've finished negotiation. | 162 // stream on an existing DataMediaChannel, and we've finished negotiation. |
| 140 void OnChannelReady(bool writable); | 163 void OnChannelReady(bool writable); |
| 141 | 164 |
| 142 // Sigslots from cricket::DataChannel | 165 // Sigslots from cricket::DataChannel |
| 143 void OnDataReceived(cricket::DataChannel* channel, | 166 void OnDataReceived(cricket::DataChannel* channel, |
| 144 const cricket::ReceiveDataParams& params, | 167 const cricket::ReceiveDataParams& params, |
| 145 const rtc::Buffer& payload); | 168 const rtc::Buffer& payload); |
| 169 void OnStreamClosedRemotely(uint32 sid); |
| 146 | 170 |
| 147 // The remote peer request that this channel should be closed. | 171 // The remote peer request that this channel should be closed. |
| 148 void RemotePeerRequestClose(); | 172 void RemotePeerRequestClose(); |
| 149 | 173 |
| 150 // The following methods are for SCTP only. | 174 // The following methods are for SCTP only. |
| 151 | 175 |
| 152 // Sets the SCTP sid and adds to transport layer if not set yet. Should only | 176 // Sets the SCTP sid and adds to transport layer if not set yet. Should only |
| 153 // be called once. | 177 // be called once. |
| 154 void SetSctpSid(int sid); | 178 void SetSctpSid(int sid); |
| 155 // Called when the transport channel is created. | 179 // Called when the transport channel is created. |
| 156 void OnTransportChannelCreated(); | 180 void OnTransportChannelCreated(); |
| 157 | 181 |
| 158 // The following methods are for RTP only. | 182 // The following methods are for RTP only. |
| 159 | 183 |
| 160 // Set the SSRC this channel should use to send data on the | 184 // Set the SSRC this channel should use to send data on the |
| 161 // underlying data engine. |send_ssrc| == 0 means that the channel is no | 185 // underlying data engine. |send_ssrc| == 0 means that the channel is no |
| 162 // longer part of the session negotiation. | 186 // longer part of the session negotiation. |
| 163 void SetSendSsrc(uint32 send_ssrc); | 187 void SetSendSsrc(uint32 send_ssrc); |
| 164 // Set the SSRC this channel should use to receive data from the | 188 // Set the SSRC this channel should use to receive data from the |
| 165 // underlying data engine. | 189 // underlying data engine. |
| 166 void SetReceiveSsrc(uint32 receive_ssrc); | 190 void SetReceiveSsrc(uint32 receive_ssrc); |
| 167 | 191 |
| 168 cricket::DataChannelType data_channel_type() const { | 192 cricket::DataChannelType data_channel_type() const { |
| 169 return data_channel_type_; | 193 return data_channel_type_; |
| 170 } | 194 } |
| 171 | 195 |
| 196 // Emitted when state transitions to kClosed. |
| 197 // In the case of SCTP channels, this signal can be used to tell when the |
| 198 // channel's sid is free. |
| 199 sigslot::signal1<DataChannel*> SignalClosed; |
| 200 |
| 172 protected: | 201 protected: |
| 173 DataChannel(DataChannelProviderInterface* client, | 202 DataChannel(DataChannelProviderInterface* client, |
| 174 cricket::DataChannelType dct, | 203 cricket::DataChannelType dct, |
| 175 const std::string& label); | 204 const std::string& label); |
| 176 virtual ~DataChannel(); | 205 virtual ~DataChannel(); |
| 177 | 206 |
| 178 private: | 207 private: |
| 179 // A packet queue which tracks the total queued bytes. Queued packets are | 208 // A packet queue which tracks the total queued bytes. Queued packets are |
| 180 // owned by this class. | 209 // owned by this class. |
| 181 class PacketQueue { | 210 class PacketQueue { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 bool writable_; | 271 bool writable_; |
| 243 uint32 send_ssrc_; | 272 uint32 send_ssrc_; |
| 244 uint32 receive_ssrc_; | 273 uint32 receive_ssrc_; |
| 245 // Control messages that always have to get sent out before any queued | 274 // Control messages that always have to get sent out before any queued |
| 246 // data. | 275 // data. |
| 247 PacketQueue queued_control_data_; | 276 PacketQueue queued_control_data_; |
| 248 PacketQueue queued_received_data_; | 277 PacketQueue queued_received_data_; |
| 249 PacketQueue queued_send_data_; | 278 PacketQueue queued_send_data_; |
| 250 }; | 279 }; |
| 251 | 280 |
| 252 class DataChannelFactory { | |
| 253 public: | |
| 254 virtual rtc::scoped_refptr<DataChannel> CreateDataChannel( | |
| 255 const std::string& label, | |
| 256 const InternalDataChannelInit* config) = 0; | |
| 257 | |
| 258 protected: | |
| 259 virtual ~DataChannelFactory() {} | |
| 260 }; | |
| 261 | |
| 262 // Define proxy for DataChannelInterface. | 281 // Define proxy for DataChannelInterface. |
| 263 BEGIN_PROXY_MAP(DataChannel) | 282 BEGIN_PROXY_MAP(DataChannel) |
| 264 PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*) | 283 PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*) |
| 265 PROXY_METHOD0(void, UnregisterObserver) | 284 PROXY_METHOD0(void, UnregisterObserver) |
| 266 PROXY_CONSTMETHOD0(std::string, label) | 285 PROXY_CONSTMETHOD0(std::string, label) |
| 267 PROXY_CONSTMETHOD0(bool, reliable) | 286 PROXY_CONSTMETHOD0(bool, reliable) |
| 268 PROXY_CONSTMETHOD0(bool, ordered) | 287 PROXY_CONSTMETHOD0(bool, ordered) |
| 269 PROXY_CONSTMETHOD0(uint16, maxRetransmitTime) | 288 PROXY_CONSTMETHOD0(uint16, maxRetransmitTime) |
| 270 PROXY_CONSTMETHOD0(uint16, maxRetransmits) | 289 PROXY_CONSTMETHOD0(uint16, maxRetransmits) |
| 271 PROXY_CONSTMETHOD0(std::string, protocol) | 290 PROXY_CONSTMETHOD0(std::string, protocol) |
| 272 PROXY_CONSTMETHOD0(bool, negotiated) | 291 PROXY_CONSTMETHOD0(bool, negotiated) |
| 273 PROXY_CONSTMETHOD0(int, id) | 292 PROXY_CONSTMETHOD0(int, id) |
| 274 PROXY_CONSTMETHOD0(DataState, state) | 293 PROXY_CONSTMETHOD0(DataState, state) |
| 275 PROXY_CONSTMETHOD0(uint64, buffered_amount) | 294 PROXY_CONSTMETHOD0(uint64, buffered_amount) |
| 276 PROXY_METHOD0(void, Close) | 295 PROXY_METHOD0(void, Close) |
| 277 PROXY_METHOD1(bool, Send, const DataBuffer&) | 296 PROXY_METHOD1(bool, Send, const DataBuffer&) |
| 278 END_PROXY() | 297 END_PROXY() |
| 279 | 298 |
| 280 } // namespace webrtc | 299 } // namespace webrtc |
| 281 | 300 |
| 282 #endif // TALK_APP_WEBRTC_DATACHANNEL_H_ | 301 #endif // TALK_APP_WEBRTC_DATACHANNEL_H_ |
| OLD | NEW |