Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: talk/app/webrtc/datachannel.h

Issue 1393563002: Moving MediaStreamSignaling logic into PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing copyright header Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | talk/app/webrtc/datachannel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 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
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 26 matching lines...) Expand all
122 virtual bool negotiated() const { return config_.negotiated; } 145 virtual bool negotiated() const { return config_.negotiated; }
123 virtual int id() const { return config_.id; } 146 virtual int id() const { return config_.id; }
124 virtual uint64_t buffered_amount() const; 147 virtual uint64_t buffered_amount() const;
125 virtual void Close(); 148 virtual void Close();
126 virtual DataState state() const { return state_; } 149 virtual DataState state() const { return state_; }
127 virtual bool Send(const DataBuffer& buffer); 150 virtual bool Send(const DataBuffer& buffer);
128 151
129 // rtc::MessageHandler override. 152 // rtc::MessageHandler override.
130 virtual void OnMessage(rtc::Message* msg); 153 virtual void OnMessage(rtc::Message* msg);
131 154
132 // Called if the underlying data engine is closing.
133 void OnDataEngineClose();
134
135 // Called when the channel's ready to use. That can happen when the 155 // Called when the channel's ready to use. That can happen when the
136 // underlying DataMediaChannel becomes ready, or when this channel is a new 156 // underlying DataMediaChannel becomes ready, or when this channel is a new
137 // stream on an existing DataMediaChannel, and we've finished negotiation. 157 // stream on an existing DataMediaChannel, and we've finished negotiation.
138 void OnChannelReady(bool writable); 158 void OnChannelReady(bool writable);
139 159
140 // Sigslots from cricket::DataChannel 160 // Sigslots from cricket::DataChannel
141 void OnDataReceived(cricket::DataChannel* channel, 161 void OnDataReceived(cricket::DataChannel* channel,
142 const cricket::ReceiveDataParams& params, 162 const cricket::ReceiveDataParams& params,
143 const rtc::Buffer& payload); 163 const rtc::Buffer& payload);
164 void OnStreamClosedRemotely(uint32_t sid);
144 165
145 // The remote peer request that this channel should be closed. 166 // The remote peer request that this channel should be closed.
146 void RemotePeerRequestClose(); 167 void RemotePeerRequestClose();
147 168
148 // The following methods are for SCTP only. 169 // The following methods are for SCTP only.
149 170
150 // Sets the SCTP sid and adds to transport layer if not set yet. Should only 171 // Sets the SCTP sid and adds to transport layer if not set yet. Should only
151 // be called once. 172 // be called once.
152 void SetSctpSid(int sid); 173 void SetSctpSid(int sid);
153 // Called when the transport channel is created. 174 // Called when the transport channel is created.
175 // Only needs to be called for SCTP data channels.
154 void OnTransportChannelCreated(); 176 void OnTransportChannelCreated();
177 // Called when the transport channel is destroyed.
178 void OnTransportChannelDestroyed();
155 179
156 // The following methods are for RTP only. 180 // The following methods are for RTP only.
157 181
158 // Set the SSRC this channel should use to send data on the 182 // Set the SSRC this channel should use to send data on the
159 // underlying data engine. |send_ssrc| == 0 means that the channel is no 183 // underlying data engine. |send_ssrc| == 0 means that the channel is no
160 // longer part of the session negotiation. 184 // longer part of the session negotiation.
161 void SetSendSsrc(uint32_t send_ssrc); 185 void SetSendSsrc(uint32_t send_ssrc);
162 // Set the SSRC this channel should use to receive data from the 186 // Set the SSRC this channel should use to receive data from the
163 // underlying data engine. 187 // underlying data engine.
164 void SetReceiveSsrc(uint32_t receive_ssrc); 188 void SetReceiveSsrc(uint32_t receive_ssrc);
165 189
166 cricket::DataChannelType data_channel_type() const { 190 cricket::DataChannelType data_channel_type() const {
167 return data_channel_type_; 191 return data_channel_type_;
168 } 192 }
169 193
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
170 protected: 199 protected:
171 DataChannel(DataChannelProviderInterface* client, 200 DataChannel(DataChannelProviderInterface* client,
172 cricket::DataChannelType dct, 201 cricket::DataChannelType dct,
173 const std::string& label); 202 const std::string& label);
174 virtual ~DataChannel(); 203 virtual ~DataChannel();
175 204
176 private: 205 private:
177 // A packet queue which tracks the total queued bytes. Queued packets are 206 // A packet queue which tracks the total queued bytes. Queued packets are
178 // owned by this class. 207 // owned by this class.
179 class PacketQueue { 208 class PacketQueue {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool writable_; 269 bool writable_;
241 uint32_t send_ssrc_; 270 uint32_t send_ssrc_;
242 uint32_t receive_ssrc_; 271 uint32_t receive_ssrc_;
243 // Control messages that always have to get sent out before any queued 272 // Control messages that always have to get sent out before any queued
244 // data. 273 // data.
245 PacketQueue queued_control_data_; 274 PacketQueue queued_control_data_;
246 PacketQueue queued_received_data_; 275 PacketQueue queued_received_data_;
247 PacketQueue queued_send_data_; 276 PacketQueue queued_send_data_;
248 }; 277 };
249 278
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
260 // Define proxy for DataChannelInterface. 279 // Define proxy for DataChannelInterface.
261 BEGIN_PROXY_MAP(DataChannel) 280 BEGIN_PROXY_MAP(DataChannel)
262 PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*) 281 PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*)
263 PROXY_METHOD0(void, UnregisterObserver) 282 PROXY_METHOD0(void, UnregisterObserver)
264 PROXY_CONSTMETHOD0(std::string, label) 283 PROXY_CONSTMETHOD0(std::string, label)
265 PROXY_CONSTMETHOD0(bool, reliable) 284 PROXY_CONSTMETHOD0(bool, reliable)
266 PROXY_CONSTMETHOD0(bool, ordered) 285 PROXY_CONSTMETHOD0(bool, ordered)
267 PROXY_CONSTMETHOD0(uint16_t, maxRetransmitTime) 286 PROXY_CONSTMETHOD0(uint16_t, maxRetransmitTime)
268 PROXY_CONSTMETHOD0(uint16_t, maxRetransmits) 287 PROXY_CONSTMETHOD0(uint16_t, maxRetransmits)
269 PROXY_CONSTMETHOD0(std::string, protocol) 288 PROXY_CONSTMETHOD0(std::string, protocol)
270 PROXY_CONSTMETHOD0(bool, negotiated) 289 PROXY_CONSTMETHOD0(bool, negotiated)
271 PROXY_CONSTMETHOD0(int, id) 290 PROXY_CONSTMETHOD0(int, id)
272 PROXY_CONSTMETHOD0(DataState, state) 291 PROXY_CONSTMETHOD0(DataState, state)
273 PROXY_CONSTMETHOD0(uint64_t, buffered_amount) 292 PROXY_CONSTMETHOD0(uint64_t, buffered_amount)
274 PROXY_METHOD0(void, Close) 293 PROXY_METHOD0(void, Close)
275 PROXY_METHOD1(bool, Send, const DataBuffer&) 294 PROXY_METHOD1(bool, Send, const DataBuffer&)
276 END_PROXY() 295 END_PROXY()
277 296
278 } // namespace webrtc 297 } // namespace webrtc
279 298
280 #endif // TALK_APP_WEBRTC_DATACHANNEL_H_ 299 #endif // TALK_APP_WEBRTC_DATACHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | talk/app/webrtc/datachannel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698