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 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "webrtc/base/logging.h" | 25 #include "webrtc/base/logging.h" |
26 #include "webrtc/base/safe_conversions.h" | 26 #include "webrtc/base/safe_conversions.h" |
27 #include "webrtc/media/base/codec.h" | 27 #include "webrtc/media/base/codec.h" |
28 #include "webrtc/media/base/mediaconstants.h" | 28 #include "webrtc/media/base/mediaconstants.h" |
29 #include "webrtc/media/base/streamparams.h" | 29 #include "webrtc/media/base/streamparams.h" |
30 | 30 |
31 namespace cricket { | 31 namespace cricket { |
32 // The biggest SCTP packet. Starting from a 'safe' wire MTU value of 1280, | 32 // The biggest SCTP packet. Starting from a 'safe' wire MTU value of 1280, |
33 // take off 80 bytes for DTLS/TURN/TCP/IP overhead. | 33 // take off 80 bytes for DTLS/TURN/TCP/IP overhead. |
34 static const size_t kSctpMtu = 1200; | 34 static const size_t kSctpMtu = 1200; |
35 // usrsctp seems to interpret the MTU we give it strangely -- it seems to | |
36 // give us back packets bigger than that MTU, if only by a fixed amount. | |
37 // This is that amount that we've observed. | |
38 const int kSctpOverhead = 80; | |
honghaiz3
2016/08/10 19:25:42
Make it static if it is not used outside of this f
Taylor Brandstetter
2016/08/10 20:55:05
I went to investigate where the 80 is coming from,
| |
35 | 39 |
36 // The size of the SCTP association send buffer. 256kB, the usrsctp default. | 40 // The size of the SCTP association send buffer. 256kB, the usrsctp default. |
37 static const int kSendBufferSize = 262144; | 41 static const int kSendBufferSize = 262144; |
38 | 42 |
39 struct SctpInboundPacket { | 43 struct SctpInboundPacket { |
40 rtc::CopyOnWriteBuffer buffer; | 44 rtc::CopyOnWriteBuffer buffer; |
41 ReceiveDataParams params; | 45 ReceiveDataParams params; |
42 // The |flags| parameter is used by SCTP to distinguish notification packets | 46 // The |flags| parameter is used by SCTP to distinguish notification packets |
43 // from other types of packets. | 47 // from other types of packets. |
44 int flags; | 48 int flags; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, | 474 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, |
471 sizeof(nodelay))) { | 475 sizeof(nodelay))) { |
472 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SCTP_NODELAY."; | 476 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SCTP_NODELAY."; |
473 return false; | 477 return false; |
474 } | 478 } |
475 | 479 |
476 // Disable MTU discovery | 480 // Disable MTU discovery |
477 sctp_paddrparams params = {{0}}; | 481 sctp_paddrparams params = {{0}}; |
478 params.spp_assoc_id = 0; | 482 params.spp_assoc_id = 0; |
479 params.spp_flags = SPP_PMTUD_DISABLE; | 483 params.spp_flags = SPP_PMTUD_DISABLE; |
480 params.spp_pathmtu = kSctpMtu; | 484 params.spp_pathmtu = kSctpMtu - kSctpOverhead; |
481 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, ¶ms, | 485 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, ¶ms, |
482 sizeof(params))) { | 486 sizeof(params))) { |
483 LOG_ERRNO(LS_ERROR) << debug_name_ | 487 LOG_ERRNO(LS_ERROR) << debug_name_ |
484 << "Failed to set SCTP_PEER_ADDR_PARAMS."; | 488 << "Failed to set SCTP_PEER_ADDR_PARAMS."; |
485 return false; | 489 return false; |
486 } | 490 } |
487 | 491 |
488 // Subscribe to SCTP event notifications. | 492 // Subscribe to SCTP event notifications. |
489 int event_types[] = {SCTP_ASSOC_CHANGE, | 493 int event_types[] = {SCTP_ASSOC_CHANGE, |
490 SCTP_PEER_ADDR_CHANGE, | 494 SCTP_PEER_ADDR_CHANGE, |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 } | 999 } |
996 | 1000 |
997 bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) { | 1001 bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) { |
998 return GetCodecIntParameter( | 1002 return GetCodecIntParameter( |
999 codecs, kGoogleSctpDataCodecId, kGoogleSctpDataCodecName, kCodecParamPort, | 1003 codecs, kGoogleSctpDataCodecId, kGoogleSctpDataCodecName, kCodecParamPort, |
1000 &local_port_); | 1004 &local_port_); |
1001 } | 1005 } |
1002 | 1006 |
1003 void SctpDataMediaChannel::OnPacketFromSctpToNetwork( | 1007 void SctpDataMediaChannel::OnPacketFromSctpToNetwork( |
1004 rtc::CopyOnWriteBuffer* buffer) { | 1008 rtc::CopyOnWriteBuffer* buffer) { |
1005 // usrsctp seems to interpret the MTU we give it strangely -- it seems to | 1009 if (buffer->size() > (kSctpMtu)) { |
1006 // give us back packets bigger than that MTU, if only by a fixed amount. | |
1007 // This is that amount that we've observed. | |
1008 const int kSctpOverhead = 76; | |
1009 if (buffer->size() > (kSctpOverhead + kSctpMtu)) { | |
1010 LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): " | 1010 LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): " |
1011 << "SCTP seems to have made a packet that is bigger " | 1011 << "SCTP seems to have made a packet that is bigger " |
1012 << "than its official MTU: " << buffer->size() | 1012 << "than its official MTU: " << buffer->size() |
1013 << " vs max of " << kSctpMtu | 1013 << " vs max of " << kSctpMtu - kSctpOverhead |
1014 << " even after adding " << kSctpOverhead | 1014 << " even after adding " << kSctpOverhead |
1015 << " extra SCTP overhead"; | 1015 << " extra SCTP overhead"; |
1016 } | 1016 } |
1017 MediaChannel::SendPacket(buffer, rtc::PacketOptions()); | 1017 MediaChannel::SendPacket(buffer, rtc::PacketOptions()); |
1018 } | 1018 } |
1019 | 1019 |
1020 bool SctpDataMediaChannel::SendQueuedStreamResets() { | 1020 bool SctpDataMediaChannel::SendQueuedStreamResets() { |
1021 if (!sent_reset_streams_.empty() || queued_reset_streams_.empty()) { | 1021 if (!sent_reset_streams_.empty() || queued_reset_streams_.empty()) { |
1022 return true; | 1022 return true; |
1023 } | 1023 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 } | 1068 } |
1069 case MSG_SCTPOUTBOUNDPACKET: { | 1069 case MSG_SCTPOUTBOUNDPACKET: { |
1070 std::unique_ptr<OutboundPacketMessage> pdata( | 1070 std::unique_ptr<OutboundPacketMessage> pdata( |
1071 static_cast<OutboundPacketMessage*>(msg->pdata)); | 1071 static_cast<OutboundPacketMessage*>(msg->pdata)); |
1072 OnPacketFromSctpToNetwork(pdata->data().get()); | 1072 OnPacketFromSctpToNetwork(pdata->data().get()); |
1073 break; | 1073 break; |
1074 } | 1074 } |
1075 } | 1075 } |
1076 } | 1076 } |
1077 } // namespace cricket | 1077 } // namespace cricket |
OLD | NEW |