| 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 | |
| 98 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } | 99 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } |
| 99 | 100 |
| 101 static int SendThresholdCallback(struct socket* sock, uint32_t sb_free); |
| 100 private: | 102 private: |
| 103 static std::vector<SctpDataMediaChannel*> channels_; |
| 101 static int usrsctp_engines_count; | 104 static int usrsctp_engines_count; |
| 102 std::vector<DataCodec> codecs_; | 105 std::vector<DataCodec> codecs_; |
| 106 |
| 107 void OnChannelDestroyed(SctpDataMediaChannel *channel); |
| 103 }; | 108 }; |
| 104 | 109 |
| 105 // TODO(ldixon): Make into a special type of TypedMessageData. | 110 // TODO(ldixon): Make into a special type of TypedMessageData. |
| 106 // Holds data to be passed on to a channel. | 111 // Holds data to be passed on to a channel. |
| 107 struct SctpInboundPacket; | 112 struct SctpInboundPacket; |
| 108 | 113 |
| 109 class SctpDataMediaChannel : public DataMediaChannel, | 114 class SctpDataMediaChannel : public DataMediaChannel, |
| 110 public rtc::MessageHandler { | 115 public rtc::MessageHandler { |
| 111 public: | 116 public: |
| 112 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as | 117 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); | 186 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 182 virtual void OnRtcpReceived(rtc::Buffer* packet, | 187 virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 183 const rtc::PacketTime& packet_time) {} | 188 const rtc::PacketTime& packet_time) {} |
| 184 virtual void OnReadyToSend(bool ready) {} | 189 virtual void OnReadyToSend(bool ready) {} |
| 185 | 190 |
| 186 // Helper for debugging. | 191 // Helper for debugging. |
| 187 void set_debug_name(const std::string& debug_name) { | 192 void set_debug_name(const std::string& debug_name) { |
| 188 debug_name_ = debug_name; | 193 debug_name_ = debug_name; |
| 189 } | 194 } |
| 190 const std::string& debug_name() const { return debug_name_; } | 195 const std::string& debug_name() const { return debug_name_; } |
| 196 const struct socket* socket() { return sock_; } |
| 197 |
| 198 sigslot::signal1<SctpDataMediaChannel*> SignalDestroyed; |
| 191 | 199 |
| 192 private: | 200 private: |
| 193 sockaddr_conn GetSctpSockAddr(int port); | 201 sockaddr_conn GetSctpSockAddr(int port); |
| 194 | 202 |
| 195 // Creates the socket and connects. Sets sending_ to true. | 203 // Creates the socket and connects. Sets sending_ to true. |
| 196 bool Connect(); | 204 bool Connect(); |
| 197 // Closes the socket. Sets sending_ to false. | 205 // Closes the socket. Sets sending_ to false. |
| 198 void Disconnect(); | 206 void Disconnect(); |
| 199 | 207 |
| 200 // Returns false when openning the socket failed; when successfull sets | 208 // Returns false when openning the socket failed; when successfull sets |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 StreamSet queued_reset_streams_; | 257 StreamSet queued_reset_streams_; |
| 250 StreamSet sent_reset_streams_; | 258 StreamSet sent_reset_streams_; |
| 251 | 259 |
| 252 // A human-readable name for debugging messages. | 260 // A human-readable name for debugging messages. |
| 253 std::string debug_name_; | 261 std::string debug_name_; |
| 254 }; | 262 }; |
| 255 | 263 |
| 256 } // namespace cricket | 264 } // namespace cricket |
| 257 | 265 |
| 258 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ | 266 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ |
| OLD | NEW |