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

Side by Side Diff: webrtc/media/sctp/sctptransportinternal.h

Issue 2564333002: Reland of: Separating SCTP code from BaseChannel/MediaChannel. (Closed)
Patch Set: Merge with master. Created 3 years, 11 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 | « webrtc/media/sctp/sctptransport_unittest.cc ('k') | webrtc/pc/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_
12 #define WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_
13
14 // TODO(deadbeef): Move SCTP code out of media/, and make it not depend on
15 // anything in media/.
16
17 #include <memory> // for unique_ptr
18 #include <string>
19 #include <vector>
20
21 #include "webrtc/base/copyonwritebuffer.h"
22 #include "webrtc/base/thread.h"
23 // For SendDataParams/ReceiveDataParams.
24 // TODO(deadbeef): Use something else for SCTP. It's confusing that we use an
25 // SSRC field for SID.
26 #include "webrtc/media/base/mediachannel.h"
27 #include "webrtc/p2p/base/transportchannel.h"
28
29 namespace cricket {
30
31 // The number of outgoing streams that we'll negotiate. Since stream IDs (SIDs)
32 // are 0-based, the highest usable SID is 1023.
33 //
34 // It's recommended to use the maximum of 65535 in:
35 // https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.2
36 // However, we use 1024 in order to save memory. usrsctp allocates 104 bytes
37 // for each pair of incoming/outgoing streams (on a 64-bit system), so 65535
38 // streams would waste ~6MB.
39 //
40 // Note: "max" and "min" here are inclusive.
41 constexpr uint16_t kMaxSctpStreams = 1024;
42 constexpr uint16_t kMaxSctpSid = kMaxSctpStreams - 1;
43 constexpr uint16_t kMinSctpSid = 0;
44
45 // This is the default SCTP port to use. It is passed along the wire and the
46 // connectee and connector must be using the same port. It is not related to the
47 // ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in
48 // usrsctp.h)
49 const int kSctpDefaultPort = 5000;
50
51 // Abstract SctpTransport interface for use internally (by
52 // PeerConnection/WebRtcSession/etc.). Exists to allow mock/fake SctpTransports
53 // to be created.
54 class SctpTransportInternal {
55 public:
56 virtual ~SctpTransportInternal() {}
57
58 // Changes what underlying DTLS channel is uses. Used when switching which
59 // bundled transport the SctpTransport uses.
60 // Assumes |channel| is non-null.
61 virtual void SetTransportChannel(TransportChannel* channel) = 0;
62
63 // When Start is called, connects as soon as possible; this can be called
64 // before DTLS completes, in which case the connection will begin when DTLS
65 // completes. This method can be called multiple times, though not if either
66 // of the ports are changed.
67 //
68 // |local_sctp_port| and |remote_sctp_port| are passed along the wire and the
69 // listener and connector must be using the same port. They are not related
70 // to the ports at the IP level. If set to -1, we default to
71 // kSctpDefaultPort.
72 //
73 // TODO(deadbeef): Add remote max message size as parameter to Start, once we
74 // start supporting it.
75 // TODO(deadbeef): Support calling Start with different local/remote ports
76 // and create a new association? Not clear if this is something we need to
77 // support though. See: https://github.com/w3c/webrtc-pc/issues/979
78 virtual bool Start(int local_sctp_port, int remote_sctp_port) = 0;
79
80 // NOTE: Initially there was a "Stop" method here, but it was never used, so
81 // it was removed.
82
83 // Informs SctpTransport that |sid| will start being used. Returns false if
84 // it is impossible to use |sid|, or if it's already in use.
85 // Until calling this, can't send data using |sid|.
86 // TODO(deadbeef): Actually implement the "returns false if |sid| can't be
87 // used" part. See:
88 // https://bugs.chromium.org/p/chromium/issues/detail?id=619849
89 virtual bool OpenStream(int sid) = 0;
90 // The inverse of OpenStream. When this method returns, the reset process may
91 // have not finished but it will have begun.
92 // TODO(deadbeef): We need a way to tell when it's done. See:
93 // https://bugs.chromium.org/p/webrtc/issues/detail?id=4453
94 virtual bool ResetStream(int sid) = 0;
95 // Send data down this channel (will be wrapped as SCTP packets then given to
96 // usrsctp that will then post the network interface).
97 // Returns true iff successful data somewhere on the send-queue/network.
98 // Uses |params.ssrc| as the SCTP sid.
99 virtual bool SendData(const SendDataParams& params,
100 const rtc::CopyOnWriteBuffer& payload,
101 SendDataResult* result = nullptr) = 0;
102
103 // Indicates when the SCTP socket is created and not blocked by congestion
104 // control. This changes to false when SDR_BLOCK is returned from SendData,
105 // and
106 // changes to true when SignalReadyToSendData is fired. The underlying DTLS/
107 // ICE channels may be unwritable while ReadyToSendData is true, because data
108 // can still be queued in usrsctp.
109 virtual bool ReadyToSendData() = 0;
110
111 sigslot::signal0<> SignalReadyToSendData;
112 // ReceiveDataParams includes SID, seq num, timestamp, etc. CopyOnWriteBuffer
113 // contains message payload.
114 sigslot::signal2<const ReceiveDataParams&, const rtc::CopyOnWriteBuffer&>
115 SignalDataReceived;
116 // Parameter is SID of closed stream.
117 sigslot::signal1<int> SignalStreamClosedRemotely;
118
119 // Helper for debugging.
120 virtual void set_debug_name_for_testing(const char* debug_name) = 0;
121 };
122
123 // Factory class which can be used to allow fake SctpTransports to be injected
124 // for testing. Or, theoretically, SctpTransportInternal implementations that
125 // use something other than usrsctp.
126 class SctpTransportInternalFactory {
127 public:
128 virtual ~SctpTransportInternalFactory() {}
129
130 // Create an SCTP transport using |channel| for the underlying transport.
131 virtual std::unique_ptr<SctpTransportInternal> CreateSctpTransport(
132 TransportChannel* channel) = 0;
133 };
134
135 } // namespace cricket
136
137 #endif // WEBRTC_MEDIA_SCTP_SCTPTRANSPORTINTERNAL_H_
OLDNEW
« no previous file with comments | « webrtc/media/sctp/sctptransport_unittest.cc ('k') | webrtc/pc/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698