| 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 | |
| 69 // A DataEngine that interacts with usrsctp. | 67 // A DataEngine that interacts with usrsctp. |
| 70 // | 68 // |
| 71 // From channel calls, data flows like this: | 69 // From channel calls, data flows like this: |
| 72 // [worker thread (although it can in princple be another thread)] | 70 // [worker thread (although it can in princple be another thread)] |
| 73 // 1. SctpDataMediaChannel::SendData(data) | 71 // 1. SctpDataMediaChannel::SendData(data) |
| 74 // 2. usrsctp_sendv(data) | 72 // 2. usrsctp_sendv(data) |
| 75 // [worker thread returns; sctp thread then calls the following] | 73 // [worker thread returns; sctp thread then calls the following] |
| 76 // 3. OnSctpOutboundPacket(wrapped_data) | 74 // 3. OnSctpOutboundPacket(wrapped_data) |
| 77 // [sctp thread returns having posted a message for the worker thread] | 75 // [sctp thread returns having posted a message for the worker thread] |
| 78 // 4. SctpDataMediaChannel::OnMessage(wrapped_data) | 76 // 4. SctpDataMediaChannel::OnMessage(wrapped_data) |
| 79 // 5. SctpDataMediaChannel::OnPacketFromSctpToNetwork(wrapped_data) | 77 // 5. SctpDataMediaChannel::OnPacketFromSctpToNetwork(wrapped_data) |
| 80 // 6. NetworkInterface::SendPacket(wrapped_data) | 78 // 6. NetworkInterface::SendPacket(wrapped_data) |
| 81 // 7. ... across network ... a packet is sent back ... | 79 // 7. ... across network ... a packet is sent back ... |
| 82 // 8. SctpDataMediaChannel::OnPacketReceived(wrapped_data) | 80 // 8. SctpDataMediaChannel::OnPacketReceived(wrapped_data) |
| 83 // 9. usrsctp_conninput(wrapped_data) | 81 // 9. usrsctp_conninput(wrapped_data) |
| 84 // [worker thread returns; sctp thread then calls the following] | 82 // [worker thread returns; sctp thread then calls the following] |
| 85 // 10. OnSctpInboundData(data) | 83 // 10. OnSctpInboundData(data) |
| 86 // [sctp thread returns having posted a message fot the worker thread] | 84 // [sctp thread returns having posted a message fot the worker thread] |
| 87 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) | 85 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) |
| 88 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) | 86 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) |
| 89 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) | 87 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) |
| 90 // 14. SctpDataMediaChannel::SignalDataReceived(data) | 88 // 14. SctpDataMediaChannel::SignalDataReceived(data) |
| 91 // [from the same thread, methods registered/connected to | 89 // [from the same thread, methods registered/connected to |
| 92 // SctpDataMediaChannel are called with the recieved data] | 90 // SctpDataMediaChannel are called with the recieved data] |
| 93 class SctpDataEngine : public DataEngineInterface, public sigslot::has_slots<> { | 91 class SctpDataEngine : public DataEngineInterface { |
| 94 public: | 92 public: |
| 95 SctpDataEngine(); | 93 SctpDataEngine(); |
| 96 virtual ~SctpDataEngine(); | 94 virtual ~SctpDataEngine(); |
| 97 | 95 |
| 98 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); | 96 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); |
| 99 | 97 |
| 100 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } | 98 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } |
| 101 | 99 |
| 102 static int SendThresholdCallback(struct socket* sock, uint32_t sb_free); | |
| 103 | |
| 104 private: | 100 private: |
| 105 static std::vector<SctpDataMediaChannel*> channels_; | |
| 106 static int usrsctp_engines_count; | 101 static int usrsctp_engines_count; |
| 107 std::vector<DataCodec> codecs_; | 102 std::vector<DataCodec> codecs_; |
| 108 | |
| 109 static SctpDataMediaChannel* GetChannelFromSocket(struct socket* sock); | |
| 110 void OnChannelDestroyed(SctpDataMediaChannel *channel); | |
| 111 }; | 103 }; |
| 112 | 104 |
| 113 // TODO(ldixon): Make into a special type of TypedMessageData. | 105 // TODO(ldixon): Make into a special type of TypedMessageData. |
| 114 // Holds data to be passed on to a channel. | 106 // Holds data to be passed on to a channel. |
| 115 struct SctpInboundPacket; | 107 struct SctpInboundPacket; |
| 116 | 108 |
| 117 class SctpDataMediaChannel : public DataMediaChannel, | 109 class SctpDataMediaChannel : public DataMediaChannel, |
| 118 public rtc::MessageHandler { | 110 public rtc::MessageHandler { |
| 119 public: | 111 public: |
| 120 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as | 112 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); | 181 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 190 virtual void OnRtcpReceived(rtc::Buffer* packet, | 182 virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 191 const rtc::PacketTime& packet_time) {} | 183 const rtc::PacketTime& packet_time) {} |
| 192 virtual void OnReadyToSend(bool ready) {} | 184 virtual void OnReadyToSend(bool ready) {} |
| 193 | 185 |
| 194 // Helper for debugging. | 186 // Helper for debugging. |
| 195 void set_debug_name(const std::string& debug_name) { | 187 void set_debug_name(const std::string& debug_name) { |
| 196 debug_name_ = debug_name; | 188 debug_name_ = debug_name; |
| 197 } | 189 } |
| 198 const std::string& debug_name() const { return debug_name_; } | 190 const std::string& debug_name() const { return debug_name_; } |
| 199 const struct socket* socket() { return sock_; } | |
| 200 | |
| 201 sigslot::signal1<SctpDataMediaChannel*> SignalDestroyed; | |
| 202 | 191 |
| 203 private: | 192 private: |
| 204 sockaddr_conn GetSctpSockAddr(int port); | 193 sockaddr_conn GetSctpSockAddr(int port); |
| 205 | 194 |
| 206 // Creates the socket and connects. Sets sending_ to true. | 195 // Creates the socket and connects. Sets sending_ to true. |
| 207 bool Connect(); | 196 bool Connect(); |
| 208 // Closes the socket. Sets sending_ to false. | 197 // Closes the socket. Sets sending_ to false. |
| 209 void Disconnect(); | 198 void Disconnect(); |
| 210 | 199 |
| 211 // Returns false when openning the socket failed; when successfull sets | 200 // Returns false when openning the socket failed; when successfull sets |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 StreamSet queued_reset_streams_; | 249 StreamSet queued_reset_streams_; |
| 261 StreamSet sent_reset_streams_; | 250 StreamSet sent_reset_streams_; |
| 262 | 251 |
| 263 // A human-readable name for debugging messages. | 252 // A human-readable name for debugging messages. |
| 264 std::string debug_name_; | 253 std::string debug_name_; |
| 265 }; | 254 }; |
| 266 | 255 |
| 267 } // namespace cricket | 256 } // namespace cricket |
| 268 | 257 |
| 269 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ | 258 #endif // TALK_MEDIA_SCTP_SCTPDATAENGINE_H_ |
| OLD | NEW |