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