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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" | 11 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" |
12 #include "content/common/p2p_messages.h" | 12 #include "content/common/p2p_messages.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" | |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // UDP packets cannot be bigger than 64k. | 22 // UDP packets cannot be bigger than 64k. |
22 const int kReadBufferSize = 65536; | 23 const int kReadBufferSize = 65536; |
23 // Socket receive buffer size. | 24 // Socket receive buffer size. |
24 const int kRecvSocketBufferSize = 65536; // 64K | 25 const int kRecvSocketBufferSize = 65536; // 64K |
25 | 26 |
26 // Defines set of transient errors. These errors are ignored when we get them | 27 // Defines set of transient errors. These errors are ignored when we get them |
27 // from sendto() or recvfrom() calls. | 28 // from sendto() or recvfrom() calls. |
(...skipping 29 matching lines...) Expand all Loading... | |
57 const std::vector<char>& content, | 58 const std::vector<char>& content, |
58 const talk_base::PacketOptions& options, | 59 const talk_base::PacketOptions& options, |
59 uint64 id) | 60 uint64 id) |
60 : to(to), | 61 : to(to), |
61 data(new net::IOBuffer(content.size())), | 62 data(new net::IOBuffer(content.size())), |
62 size(content.size()), | 63 size(content.size()), |
63 packet_options(options), | 64 packet_options(options), |
64 id(id) { | 65 id(id) { |
65 memcpy(data->data(), &content[0], size); | 66 memcpy(data->data(), &content[0], size); |
66 if (!options.packet_time_params.srtp_auth_key.empty()) { | 67 if (!options.packet_time_params.srtp_auth_key.empty()) { |
67 memcpy(&packet_options.packet_time_params.srtp_auth_key[0], | 68 memcpy(&packet_options.packet_time_params.srtp_auth_key[0], |
juberti2
2014/02/22 01:16:05
no need to do this copy
Mallinath (Gone from Chromium)
2014/02/25 00:20:02
Done.
| |
68 &options.packet_time_params.srtp_auth_key[0], | 69 &options.packet_time_params.srtp_auth_key[0], |
69 options.packet_time_params.srtp_auth_key.size()); | 70 options.packet_time_params.srtp_auth_key.size()); |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
73 P2PSocketHostUdp::PendingPacket::~PendingPacket() { | 74 P2PSocketHostUdp::PendingPacket::~PendingPacket() { |
74 } | 75 } |
75 | 76 |
76 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, | 77 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, |
77 int id, | 78 int id, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 int result = socket_->SetDiffServCodePoint(dscp); | 236 int result = socket_->SetDiffServCodePoint(dscp); |
236 if (result == net::OK) { | 237 if (result == net::OK) { |
237 last_dscp_ = dscp; | 238 last_dscp_ = dscp; |
238 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { | 239 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { |
239 // We receieved a non-transient error, and it seems we have | 240 // We receieved a non-transient error, and it seems we have |
240 // not changed the DSCP in the past, disable DSCP as it unlikely | 241 // not changed the DSCP in the past, disable DSCP as it unlikely |
241 // to work in the future. | 242 // to work in the future. |
242 last_dscp_ = net::DSCP_NO_CHANGE; | 243 last_dscp_ = net::DSCP_NO_CHANGE; |
243 } | 244 } |
244 } | 245 } |
246 talk_base::PacketOptions options; | |
247 MaybeUpdateRtpSendTimeExtn(packet.data->data(), packet.size, options); | |
245 int result = socket_->SendTo( | 248 int result = socket_->SendTo( |
246 packet.data.get(), | 249 packet.data.get(), |
247 packet.size, | 250 packet.size, |
248 packet.to, | 251 packet.to, |
249 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); | 252 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); |
250 | 253 |
251 // sendto() may return an error, e.g. if we've received an ICMP Destination | 254 // sendto() may return an error, e.g. if we've received an ICMP Destination |
252 // Unreachable message. When this happens try sending the same packet again, | 255 // Unreachable message. When this happens try sending the same packet again, |
253 // and just drop it if it fails again. | 256 // and just drop it if it fails again. |
254 if (IsTransientError(result)) { | 257 if (IsTransientError(result)) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 case P2P_SOCKET_OPT_DSCP: | 316 case P2P_SOCKET_OPT_DSCP: |
314 return (net::OK == socket_->SetDiffServCodePoint( | 317 return (net::OK == socket_->SetDiffServCodePoint( |
315 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 318 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
316 default: | 319 default: |
317 NOTREACHED(); | 320 NOTREACHED(); |
318 return false; | 321 return false; |
319 } | 322 } |
320 } | 323 } |
321 | 324 |
322 } // namespace content | 325 } // namespace content |
OLD | NEW |