OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ | 11 #ifndef WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ |
12 #define WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ | 12 #define WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ |
13 | 13 |
14 #include <errno.h> | 14 #include <errno.h> |
15 | 15 |
16 #include <memory> // for unique_ptr. | 16 #include <memory> // for unique_ptr. |
17 #include <set> | 17 #include <set> |
18 #include <string> | 18 #include <string> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "webrtc/base/asyncinvoker.h" | 21 #include "webrtc/base/asyncinvoker.h" |
22 #include "webrtc/base/constructormagic.h" | 22 #include "webrtc/base/constructormagic.h" |
23 #include "webrtc/base/copyonwritebuffer.h" | 23 #include "webrtc/base/copyonwritebuffer.h" |
24 #include "webrtc/base/sigslot.h" | 24 #include "webrtc/base/sigslot.h" |
25 #include "webrtc/base/thread.h" | 25 #include "webrtc/base/thread.h" |
26 // For SendDataParams/ReceiveDataParams. | 26 // For SendDataParams/ReceiveDataParams. |
27 #include "webrtc/media/base/mediachannel.h" | 27 #include "webrtc/media/base/mediachannel.h" |
28 #include "webrtc/media/sctp/sctptransportinternal.h" | 28 #include "webrtc/media/sctp/sctptransportinternal.h" |
| 29 #include "webrtc/p2p/base/transportchannel.h" |
29 | 30 |
30 // Defined by "usrsctplib/usrsctp.h" | 31 // Defined by "usrsctplib/usrsctp.h" |
31 struct sockaddr_conn; | 32 struct sockaddr_conn; |
32 struct sctp_assoc_change; | 33 struct sctp_assoc_change; |
33 struct sctp_stream_reset_event; | 34 struct sctp_stream_reset_event; |
34 // Defined by <sys/socket.h> | 35 // Defined by <sys/socket.h> |
35 struct socket; | 36 struct socket; |
36 namespace cricket { | 37 namespace cricket { |
37 | 38 |
38 // Holds data to be passed on to a channel. | 39 // Holds data to be passed on to a channel. |
(...skipping 12 matching lines...) Expand all Loading... |
51 // 7. SctpTransport::OnPacketReceived(wrapped_data) | 52 // 7. SctpTransport::OnPacketReceived(wrapped_data) |
52 // 8. usrsctp_conninput(wrapped_data) | 53 // 8. usrsctp_conninput(wrapped_data) |
53 // [network thread returns; sctp thread then calls the following] | 54 // [network thread returns; sctp thread then calls the following] |
54 // 9. OnSctpInboundData(data) | 55 // 9. OnSctpInboundData(data) |
55 // [sctp thread returns having async invoked on the network thread] | 56 // [sctp thread returns having async invoked on the network thread] |
56 // 10. SctpTransport::OnInboundPacketFromSctpToChannel(inboundpacket) | 57 // 10. SctpTransport::OnInboundPacketFromSctpToChannel(inboundpacket) |
57 // 11. SctpTransport::OnDataFromSctpToChannel(data) | 58 // 11. SctpTransport::OnDataFromSctpToChannel(data) |
58 // 12. SctpTransport::SignalDataReceived(data) | 59 // 12. SctpTransport::SignalDataReceived(data) |
59 // [from the same thread, methods registered/connected to | 60 // [from the same thread, methods registered/connected to |
60 // SctpTransport are called with the recieved data] | 61 // SctpTransport are called with the recieved data] |
61 // TODO(zhihuang): Rename "channel" to "transport" on network-level. | |
62 class SctpTransport : public SctpTransportInternal, | 62 class SctpTransport : public SctpTransportInternal, |
63 public sigslot::has_slots<> { | 63 public sigslot::has_slots<> { |
64 public: | 64 public: |
65 // |network_thread| is where packets will be processed and callbacks from | 65 // |network_thread| is where packets will be processed and callbacks from |
66 // this transport will be posted, and is the only thread on which public | 66 // this transport will be posted, and is the only thread on which public |
67 // methods can be called. | 67 // methods can be called. |
68 // |channel| is required (must not be null). | 68 // |channel| is required (must not be null). |
69 SctpTransport(rtc::Thread* network_thread, | 69 SctpTransport(rtc::Thread* network_thread, |
70 rtc::PacketTransportInterface* channel); | 70 cricket::TransportChannel* channel); |
71 ~SctpTransport() override; | 71 ~SctpTransport() override; |
72 | 72 |
73 // SctpTransportInternal overrides (see sctptransportinternal.h for comments). | 73 // SctpTransportInternal overrides (see sctptransportinternal.h for comments). |
74 void SetTransportChannel(rtc::PacketTransportInterface* channel) override; | 74 void SetTransportChannel(cricket::TransportChannel* channel) override; |
75 bool Start(int local_port, int remote_port) override; | 75 bool Start(int local_port, int remote_port) override; |
76 bool OpenStream(int sid) override; | 76 bool OpenStream(int sid) override; |
77 bool ResetStream(int sid) override; | 77 bool ResetStream(int sid) override; |
78 bool SendData(const SendDataParams& params, | 78 bool SendData(const SendDataParams& params, |
79 const rtc::CopyOnWriteBuffer& payload, | 79 const rtc::CopyOnWriteBuffer& payload, |
80 SendDataResult* result = nullptr) override; | 80 SendDataResult* result = nullptr) override; |
81 bool ReadyToSendData() override; | 81 bool ReadyToSendData() override; |
82 void set_debug_name_for_testing(const char* debug_name) override { | 82 void set_debug_name_for_testing(const char* debug_name) override { |
83 debug_name_ = debug_name; | 83 debug_name_ = debug_name; |
84 } | 84 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void OnNotificationAssocChange(const sctp_assoc_change& change); | 133 void OnNotificationAssocChange(const sctp_assoc_change& change); |
134 | 134 |
135 void OnStreamResetEvent(const struct sctp_stream_reset_event* evt); | 135 void OnStreamResetEvent(const struct sctp_stream_reset_event* evt); |
136 | 136 |
137 // Responsible for marshalling incoming data to the channels listeners, and | 137 // Responsible for marshalling incoming data to the channels listeners, and |
138 // outgoing data to the network interface. | 138 // outgoing data to the network interface. |
139 rtc::Thread* network_thread_; | 139 rtc::Thread* network_thread_; |
140 // Helps pass inbound/outbound packets asynchronously to the network thread. | 140 // Helps pass inbound/outbound packets asynchronously to the network thread. |
141 rtc::AsyncInvoker invoker_; | 141 rtc::AsyncInvoker invoker_; |
142 // Underlying DTLS channel. | 142 // Underlying DTLS channel. |
143 rtc::PacketTransportInterface* transport_channel_; | 143 TransportChannel* transport_channel_; |
144 bool was_ever_writable_ = false; | 144 bool was_ever_writable_ = false; |
145 int local_port_ = kSctpDefaultPort; | 145 int local_port_ = kSctpDefaultPort; |
146 int remote_port_ = kSctpDefaultPort; | 146 int remote_port_ = kSctpDefaultPort; |
147 struct socket* sock_ = nullptr; // The socket created by usrsctp_socket(...). | 147 struct socket* sock_ = nullptr; // The socket created by usrsctp_socket(...). |
148 | 148 |
149 // Has Start been called? Don't create SCTP socket until it has. | 149 // Has Start been called? Don't create SCTP socket until it has. |
150 bool started_ = false; | 150 bool started_ = false; |
151 // Are we ready to queue data (SCTP socket created, and not blocked due to | 151 // Are we ready to queue data (SCTP socket created, and not blocked due to |
152 // congestion control)? Different than |transport_channel_|'s "ready to | 152 // congestion control)? Different than |transport_channel_|'s "ready to |
153 // send". | 153 // send". |
(...skipping 18 matching lines...) Expand all Loading... |
172 | 172 |
173 RTC_DISALLOW_COPY_AND_ASSIGN(SctpTransport); | 173 RTC_DISALLOW_COPY_AND_ASSIGN(SctpTransport); |
174 }; | 174 }; |
175 | 175 |
176 class SctpTransportFactory : public SctpTransportInternalFactory { | 176 class SctpTransportFactory : public SctpTransportInternalFactory { |
177 public: | 177 public: |
178 explicit SctpTransportFactory(rtc::Thread* network_thread) | 178 explicit SctpTransportFactory(rtc::Thread* network_thread) |
179 : network_thread_(network_thread) {} | 179 : network_thread_(network_thread) {} |
180 | 180 |
181 std::unique_ptr<SctpTransportInternal> CreateSctpTransport( | 181 std::unique_ptr<SctpTransportInternal> CreateSctpTransport( |
182 rtc::PacketTransportInterface* channel) override { | 182 TransportChannel* channel) override { |
183 return std::unique_ptr<SctpTransportInternal>( | 183 return std::unique_ptr<SctpTransportInternal>( |
184 new SctpTransport(network_thread_, channel)); | 184 new SctpTransport(network_thread_, channel)); |
185 } | 185 } |
186 | 186 |
187 private: | 187 private: |
188 rtc::Thread* network_thread_; | 188 rtc::Thread* network_thread_; |
189 }; | 189 }; |
190 | 190 |
191 } // namespace cricket | 191 } // namespace cricket |
192 | 192 |
193 #endif // WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ | 193 #endif // WEBRTC_MEDIA_SCTP_SCTPTRANSPORT_H_ |
OLD | NEW |