| 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_SCTPDATAENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_SCTP_SCTPDATAENGINE_H_ |
| 12 #define WEBRTC_MEDIA_SCTP_SCTPDATAENGINE_H_ | 12 #define WEBRTC_MEDIA_SCTP_SCTPDATAENGINE_H_ |
| 13 | 13 |
| 14 #include <errno.h> | 14 #include <errno.h> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 namespace cricket { | 18 namespace cricket { |
| 19 // Some ERRNO values get re-#defined to WSA* equivalents in some talk/ | 19 // Some ERRNO values get re-#defined to WSA* equivalents in some talk/ |
| 20 // headers. We save the original ones in an enum. | 20 // headers. We save the original ones in an enum. |
| 21 enum PreservedErrno { | 21 enum PreservedErrno { |
| 22 SCTP_EINPROGRESS = EINPROGRESS, | 22 SCTP_EINPROGRESS = EINPROGRESS, |
| 23 SCTP_EWOULDBLOCK = EWOULDBLOCK | 23 SCTP_EWOULDBLOCK = EWOULDBLOCK |
| 24 }; | 24 }; |
| 25 } // namespace cricket | 25 } // namespace cricket |
| 26 | 26 |
| 27 #include "webrtc/base/copyonwritebuffer.h" | 27 #include "webrtc/base/copyonwritebuffer.h" |
| 28 #include "webrtc/base/gtest_prod_util.h" |
| 29 #include "webrtc/base/thread_checker.h" |
| 28 #include "webrtc/media/base/codec.h" | 30 #include "webrtc/media/base/codec.h" |
| 29 #include "webrtc/media/base/mediachannel.h" | 31 #include "webrtc/media/base/mediachannel.h" |
| 30 #include "webrtc/media/base/mediaengine.h" | 32 #include "webrtc/media/base/mediaengine.h" |
| 31 | 33 |
| 32 // Defined by "usrsctplib/usrsctp.h" | 34 // Defined by "usrsctplib/usrsctp.h" |
| 33 struct sockaddr_conn; | 35 struct sockaddr_conn; |
| 34 struct sctp_assoc_change; | 36 struct sctp_assoc_change; |
| 35 struct sctp_stream_reset_event; | 37 struct sctp_stream_reset_event; |
| 36 // Defined by <sys/socket.h> | 38 // Defined by <sys/socket.h> |
| 37 struct socket; | 39 struct socket; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 68 // [sctp thread returns having posted a message fot the worker thread] | 70 // [sctp thread returns having posted a message fot the worker thread] |
| 69 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) | 71 // 11. SctpDataMediaChannel::OnMessage(inboundpacket) |
| 70 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) | 72 // 12. SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(inboundpacket) |
| 71 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) | 73 // 13. SctpDataMediaChannel::OnDataFromSctpToChannel(data) |
| 72 // 14. SctpDataMediaChannel::SignalDataReceived(data) | 74 // 14. SctpDataMediaChannel::SignalDataReceived(data) |
| 73 // [from the same thread, methods registered/connected to | 75 // [from the same thread, methods registered/connected to |
| 74 // SctpDataMediaChannel are called with the recieved data] | 76 // SctpDataMediaChannel are called with the recieved data] |
| 75 class SctpDataEngine : public DataEngineInterface, public sigslot::has_slots<> { | 77 class SctpDataEngine : public DataEngineInterface, public sigslot::has_slots<> { |
| 76 public: | 78 public: |
| 77 SctpDataEngine(); | 79 SctpDataEngine(); |
| 78 virtual ~SctpDataEngine(); | 80 ~SctpDataEngine() override; |
| 79 | 81 |
| 80 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); | 82 DataMediaChannel* CreateChannel(DataChannelType data_channel_type) override; |
| 81 | 83 const std::vector<DataCodec>& data_codecs() override; |
| 82 virtual const std::vector<DataCodec>& data_codecs() { return codecs_; } | |
| 83 | |
| 84 static int SendThresholdCallback(struct socket* sock, uint32_t sb_free); | |
| 85 | 84 |
| 86 private: | 85 private: |
| 87 static int usrsctp_engines_count; | 86 rtc::ThreadChecker thread_checker_; |
| 88 std::vector<DataCodec> codecs_; | 87 const std::vector<DataCodec> codecs_; |
| 89 | |
| 90 static SctpDataMediaChannel* GetChannelFromSocket(struct socket* sock); | |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 // TODO(ldixon): Make into a special type of TypedMessageData. | 90 // TODO(ldixon): Make into a special type of TypedMessageData. |
| 94 // Holds data to be passed on to a channel. | 91 // Holds data to be passed on to a channel. |
| 95 struct SctpInboundPacket; | 92 struct SctpInboundPacket; |
| 96 | 93 |
| 97 class SctpDataMediaChannel : public DataMediaChannel, | 94 class SctpDataMediaChannel : public DataMediaChannel, |
| 98 public rtc::MessageHandler { | 95 public rtc::MessageHandler { |
| 99 public: | 96 public: |
| 100 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as | 97 // DataMessageType is used for the SCTP "Payload Protocol Identifier", as |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 rtc::Thread* worker_thread() const { return worker_thread_; } | 151 rtc::Thread* worker_thread() const { return worker_thread_; } |
| 155 | 152 |
| 156 // Many of these things are unused by SCTP, but are needed to fulfill | 153 // Many of these things are unused by SCTP, but are needed to fulfill |
| 157 // the MediaChannel interface. | 154 // the MediaChannel interface. |
| 158 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, | 155 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
| 159 const rtc::PacketTime& packet_time) {} | 156 const rtc::PacketTime& packet_time) {} |
| 160 virtual void OnReadyToSend(bool ready) {} | 157 virtual void OnReadyToSend(bool ready) {} |
| 161 | 158 |
| 162 void OnSendThresholdCallback(); | 159 void OnSendThresholdCallback(); |
| 163 // Helper for debugging. | 160 // Helper for debugging. |
| 164 void set_debug_name(const std::string& debug_name) { | 161 void set_debug_name_for_testing(const char* debug_name) { |
| 165 debug_name_ = debug_name; | 162 debug_name_ = debug_name; |
| 166 } | 163 } |
| 167 const std::string& debug_name() const { return debug_name_; } | |
| 168 const struct socket* socket() const { return sock_; } | 164 const struct socket* socket() const { return sock_; } |
| 165 |
| 166 private: |
| 167 FRIEND_TEST_ALL_PREFIXES(SctpDataMediaChannelTest, EngineSignalsRightChannel); |
| 168 static int SendThresholdCallback(struct socket* sock, uint32_t sb_free); |
| 169 static SctpDataMediaChannel* GetChannelFromSocket(struct socket* sock); |
| 170 |
| 169 private: | 171 private: |
| 170 sockaddr_conn GetSctpSockAddr(int port); | 172 sockaddr_conn GetSctpSockAddr(int port); |
| 171 | 173 |
| 172 bool SetSendCodecs(const std::vector<DataCodec>& codecs); | 174 bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
| 173 bool SetRecvCodecs(const std::vector<DataCodec>& codecs); | 175 bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 174 | 176 |
| 175 // Creates the socket and connects. Sets sending_ to true. | 177 // Creates the socket and connects. Sets sending_ to true. |
| 176 bool Connect(); | 178 bool Connect(); |
| 177 // Closes the socket. Sets sending_ to false. | 179 // Closes the socket. Sets sending_ to false. |
| 178 void Disconnect(); | 180 void Disconnect(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // want to close it, the stream's ID goes into queued_reset_streams_. When | 224 // want to close it, the stream's ID goes into queued_reset_streams_. When |
| 223 // we actually transmit a RE-CONFIG chunk with that stream ID, the ID goes | 225 // we actually transmit a RE-CONFIG chunk with that stream ID, the ID goes |
| 224 // into sent_reset_streams_. When we get a response RE-CONFIG chunk back | 226 // into sent_reset_streams_. When we get a response RE-CONFIG chunk back |
| 225 // acknowledging the reset, we remove the stream ID from | 227 // acknowledging the reset, we remove the stream ID from |
| 226 // sent_reset_streams_. We use sent_reset_streams_ to differentiate | 228 // sent_reset_streams_. We use sent_reset_streams_ to differentiate |
| 227 // between acknowledgment RE-CONFIG and peer-initiated RE-CONFIGs. | 229 // between acknowledgment RE-CONFIG and peer-initiated RE-CONFIGs. |
| 228 StreamSet open_streams_; | 230 StreamSet open_streams_; |
| 229 StreamSet queued_reset_streams_; | 231 StreamSet queued_reset_streams_; |
| 230 StreamSet sent_reset_streams_; | 232 StreamSet sent_reset_streams_; |
| 231 | 233 |
| 232 // A human-readable name for debugging messages. | 234 // A static human-readable name for debugging messages. |
| 233 std::string debug_name_; | 235 const char* debug_name_; |
| 234 }; | 236 }; |
| 235 | 237 |
| 236 } // namespace cricket | 238 } // namespace cricket |
| 237 | 239 |
| 238 #endif // WEBRTC_MEDIA_SCTP_SCTPDATAENGINE_H_ | 240 #endif // WEBRTC_MEDIA_SCTP_SCTPDATAENGINE_H_ |
| OLD | NEW |