OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" | 14 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" |
15 #include "content/common/p2p_messages.h" | 15 #include "content/common/p2p_messages.h" |
16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "ipc/ipc_sender.h" | 18 #include "ipc/ipc_sender.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
22 #include "third_party/webrtc/base/asyncpacketsocket.h" | 22 #include "third_party/libjingle/source/talk/media/base/rtputils.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // UDP packets cannot be bigger than 64k. | 26 // UDP packets cannot be bigger than 64k. |
27 const int kReadBufferSize = 65536; | 27 const int kReadBufferSize = 65536; |
28 // Socket receive buffer size. | 28 // Socket receive buffer size. |
29 const int kRecvSocketBufferSize = 65536; // 64K | 29 const int kRecvSocketBufferSize = 65536; // 64K |
30 | 30 |
31 // Defines set of transient errors. These errors are ignored when we get them | 31 // Defines set of transient errors. These errors are ignored when we get them |
32 // from sendto() or recvfrom() calls. | 32 // from sendto() or recvfrom() calls. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 last_dscp_ = dscp; | 287 last_dscp_ = dscp; |
288 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { | 288 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { |
289 // We receieved a non-transient error, and it seems we have | 289 // We receieved a non-transient error, and it seems we have |
290 // not changed the DSCP in the past, disable DSCP as it unlikely | 290 // not changed the DSCP in the past, disable DSCP as it unlikely |
291 // to work in the future. | 291 // to work in the future. |
292 last_dscp_ = net::DSCP_NO_CHANGE; | 292 last_dscp_ = net::DSCP_NO_CHANGE; |
293 } | 293 } |
294 } | 294 } |
295 | 295 |
296 base::TimeTicks send_time = base::TimeTicks::Now(); | 296 base::TimeTicks send_time = base::TimeTicks::Now(); |
297 | 297 cricket::ApplyPacketOptions(reinterpret_cast<uint8_t*>(packet.data->data()), |
298 packet_processing_helpers::ApplyPacketOptions( | 298 packet.size, |
299 packet.data->data(), packet.size, packet.packet_options, 0); | 299 packet.packet_options.packet_time_params, |
| 300 (send_time - base::TimeTicks()).InMicroseconds()); |
300 auto callback_binding = | 301 auto callback_binding = |
301 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id, | 302 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id, |
302 packet.packet_options.packet_id, send_time); | 303 packet.packet_options.packet_id, send_time); |
303 int result = socket_->SendTo(packet.data.get(), packet.size, packet.to, | 304 int result = socket_->SendTo(packet.data.get(), packet.size, packet.to, |
304 callback_binding); | 305 callback_binding); |
305 | 306 |
306 // sendto() may return an error, e.g. if we've received an ICMP Destination | 307 // sendto() may return an error, e.g. if we've received an ICMP Destination |
307 // Unreachable message. When this happens try sending the same packet again, | 308 // Unreachable message. When this happens try sending the same packet again, |
308 // and just drop it if it fails again. | 309 // and just drop it if it fails again. |
309 if (IsTransientError(result)) { | 310 if (IsTransientError(result)) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 case P2P_SOCKET_OPT_DSCP: | 392 case P2P_SOCKET_OPT_DSCP: |
392 return (net::OK == socket_->SetDiffServCodePoint( | 393 return (net::OK == socket_->SetDiffServCodePoint( |
393 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 394 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
394 default: | 395 default: |
395 NOTREACHED(); | 396 NOTREACHED(); |
396 return false; | 397 return false; |
397 } | 398 } |
398 } | 399 } |
399 | 400 |
400 } // namespace content | 401 } // namespace content |
OLD | NEW |