OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. and Robin Seggelmann | 3 * Copyright 2012 Google Inc. and Robin Seggelmann |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // The highest stream ID (Sid) that SCTP allows, and the number of streams we | 57 // The highest stream ID (Sid) that SCTP allows, and the number of streams we |
58 // tell SCTP we're going to use. | 58 // tell SCTP we're going to use. |
59 const uint32 kMaxSctpSid = 1023; | 59 const uint32 kMaxSctpSid = 1023; |
60 | 60 |
61 // This is the default SCTP port to use. It is passed along the wire and the | 61 // This is the default SCTP port to use. It is passed along the wire and the |
62 // connectee and connector must be using the same port. It is not related to the | 62 // connectee and connector must be using the same port. It is not related to the |
63 // ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in | 63 // ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in |
64 // usrsctp.h) | 64 // usrsctp.h) |
65 const int kSctpDefaultPort = 5000; | 65 const int kSctpDefaultPort = 5000; |
66 | 66 |
| 67 class SctpDataMediaChannel; |
| 68 |
67 // A DataEngine that interacts with usrsctp. | 69 // A DataEngine that interacts with usrsctp. |
68 // | 70 // |
69 // From channel calls, data flows like this: | 71 // From channel calls, data flows like this: |
70 // [worker thread (although it can in princple be another thread)] | 72 // [worker thread (although it can in princple be another thread)] |
71 // 1. SctpDataMediaChannel::SendData(data) | 73 // 1. SctpDataMediaChannel::SendData(data) |
72 // 2. usrsctp_sendv(data) | 74 // 2. usrsctp_sendv(data) |
73 // [worker thread returns; sctp thread then calls the following] | 75 // [worker thread returns; sctp thread then calls the following] |
74 // 3. OnSctpOutboundPacket(wrapped_data) | 76 // 3. OnSctpOutboundPacket(wrapped_data) |
75 // [sctp thread returns having posted a message for the worker thread] | 77 // [sctp thread returns having posted a message for the worker thread] |
76 // 4. SctpDataMediaChannel::OnMessage(wrapped_data) | 78 // 4. SctpDataMediaChannel::OnMessage(wrapped_data) |
77 // 5. SctpDataMediaChannel::OnPacketFromSctpToNetwork(wrapped_data) | 79 // 5. SctpDataMediaChannel::OnPacketFromSctpToNetwork(wrapped_data) |
78 // 6. NetworkInterface::SendPacket(wrapped_data) | 80 // 6. NetworkInterface::SendPacket(wrapped_data) |
79 // 7. ... across network ... a packet is sent back ... | 81 // 7. ... across network ... a packet is sent back ... |
80 // 8. SctpDataMediaChannel::OnPacketReceived(wrapped_data) | 82 // 8. SctpDataMediaChannel::OnPacketReceived(wrapped_data) |
81 // 9. usrsctp_conninput(wrapped_data) | 83 // 9. usrsctp_conninput(wrapped_data) |
82 // [worker thread returns; sctp thread then calls the following] | 84 // [worker thread returns; sctp thread then calls the following] |
83 // 10. OnSctpInboundData(data) | 85 // 10. OnSctpInboundData(data) |
84 // [sctp thread returns having posted a message fot the worker thread] | 86 // [sctp thread returns having posted a message fot the worker thread] |
85 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) | 87 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) |
86 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) | 88 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) |
87 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) | 89 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) |
88 // 14. SctpDataMediaChannel::SignalDataReceived(data) | 90 // 14. SctpDataMediaChannel::SignalDataReceived(data) |
89 // [from the same thread, methods registered/connected to | 91 // [from the same thread, methods registered/connected to |
90 // SctpDataMediaChannel are called with the recieved data] | 92 // SctpDataMediaChannel are called with the recieved data] |
91 class SctpDataEngine : public DataEngineInterface { | 93 class SctpDataEngine : public DataEngineInterface, public sigslot::has_slots<> { |
92 public: | 94 public: |
93 SctpDataEngine(); | 95 SctpDataEngine(); |
94 virtual ~SctpDataEngine(); | 96 virtual ~SctpDataEngine(); |
95 | 97 |
96 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); | 98 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); |
97 | 99 |
98 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } | 100 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } |
99 | 101 |
| 102 static int SendThresholdCallback(struct socket* sock, uint32_t sb_free); |
| 103 |
100 private: | 104 private: |
101 static int usrsctp_engines_count; | 105 static int usrsctp_engines_count; |
102 std::vector<DataCodec> codecs_; | 106 std::vector<DataCodec> codecs_; |
| 107 |
| 108 static SctpDataMediaChannel* GetChannelFromSocket(struct socket* sock); |
103 }; | 109 }; |
104 | 110 |
105 // TODO(ldixon): Make into a special type of TypedMessageData. | 111 // TODO(ldixon): Make into a special type of TypedMessageData. |
106 // Holds data to be passed on to a channel. | 112 // Holds data to be passed on to a channel. |
107 struct SctpInboundPacket; | 113 struct SctpInboundPacket; |
108 | 114 |
109 class SctpDataMediaChannel : public DataMediaChannel, | 115 class SctpDataMediaChannel : public DataMediaChannel, |
110 public rtc::MessageHandler { | 116 public rtc::MessageHandler { |
111 public: | 117 public: |
112 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as | 118 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 virtual bool SetRecvRtpHeaderExtensions( | 182 virtual bool SetRecvRtpHeaderExtensions( |
177 const std::vector<RtpHeaderExtension>& extensions) { return true; } | 183 const std::vector<RtpHeaderExtension>& extensions) { return true; } |
178 virtual bool SetSendRtpHeaderExtensions( | 184 virtual bool SetSendRtpHeaderExtensions( |
179 const std::vector<RtpHeaderExtension>& extensions) { return true; } | 185 const std::vector<RtpHeaderExtension>& extensions) { return true; } |
180 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs); | 186 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
181 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); | 187 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
182 virtual void OnRtcpReceived(rtc::Buffer* packet, | 188 virtual void OnRtcpReceived(rtc::Buffer* packet, |
183 const rtc::PacketTime& packet_time) {} | 189 const rtc::PacketTime& packet_time) {} |
184 virtual void OnReadyToSend(bool ready) {} | 190 virtual void OnReadyToSend(bool ready) {} |
185 | 191 |
| 192 void OnSendThresholdCallback(); |
186 // Helper for debugging. | 193 // Helper for debugging. |
187 void set_debug_name(const std::string& debug_name) { | 194 void set_debug_name(const std::string& debug_name) { |
188 debug_name_ = debug_name; | 195 debug_name_ = debug_name; |
189 } | 196 } |
190 const std::string& debug_name() const { return debug_name_; } | 197 const std::string& debug_name() const { return debug_name_; } |
191 | 198 const struct socket* socket() const { return sock_; } |
192 private: | 199 private: |
193 sockaddr_conn GetSctpSockAddr(int port); | 200 sockaddr_conn GetSctpSockAddr(int port); |
194 | 201 |
195 // Creates the socket and connects. Sets sending_ to true. | 202 // Creates the socket and connects. Sets sending_ to true. |
196 bool Connect(); | 203 bool Connect(); |
197 // Closes the socket. Sets sending_ to false. | 204 // Closes the socket. Sets sending_ to false. |
198 void Disconnect(); | 205 void Disconnect(); |
199 | 206 |
200 // Returns false when openning the socket failed; when successfull sets | 207 // Returns false when openning the socket failed; when successfull sets |
201 // sending_ to true | 208 // sending_ to true |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 StreamSet queued_reset_streams_; | 256 StreamSet queued_reset_streams_; |
250 StreamSet sent_reset_streams_; | 257 StreamSet sent_reset_streams_; |
251 | 258 |
252 // A human-readable name for debugging messages. | 259 // A human-readable name for debugging messages. |
253 std::string debug_name_; | 260 std::string debug_name_; |
254 }; | 261 }; |
255 | 262 |
256 } // namespace cricket | 263 } // namespace cricket |
257 | 264 |
258 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ | 265 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ |
OLD | NEW |