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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 size(content.size()), | 59 size(content.size()), |
60 packet_options(options), | 60 packet_options(options), |
61 id(id) { | 61 id(id) { |
62 memcpy(data->data(), &content[0], size); | 62 memcpy(data->data(), &content[0], size); |
63 } | 63 } |
64 | 64 |
65 P2PSocketHostUdp::PendingPacket::~PendingPacket() { | 65 P2PSocketHostUdp::PendingPacket::~PendingPacket() { |
66 } | 66 } |
67 | 67 |
68 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, | 68 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, |
69 int id, | 69 int socket_id, |
70 P2PMessageThrottler* throttler) | 70 P2PMessageThrottler* throttler) |
71 : P2PSocketHost(message_sender, id), | 71 : P2PSocketHost(message_sender, socket_id), |
72 socket_(new net::UDPServerSocket( | 72 socket_( |
73 GetContentClient()->browser()->GetNetLog(), | 73 new net::UDPServerSocket(GetContentClient()->browser()->GetNetLog(), |
74 net::NetLog::Source())), | 74 net::NetLog::Source())), |
75 send_pending_(false), | 75 send_pending_(false), |
76 last_dscp_(net::DSCP_CS0), | 76 last_dscp_(net::DSCP_CS0), |
77 throttler_(throttler) { | 77 throttler_(throttler) { |
78 } | 78 } |
79 | 79 |
80 P2PSocketHostUdp::~P2PSocketHostUdp() { | 80 P2PSocketHostUdp::~P2PSocketHostUdp() { |
81 if (state_ == STATE_OPEN) { | 81 if (state_ == STATE_OPEN) { |
82 DCHECK(socket_.get()); | 82 DCHECK(socket_.get()); |
83 socket_.reset(); | 83 socket_.reset(); |
84 } | 84 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } else if (!stun || type == STUN_DATA_INDICATION) { | 166 } else if (!stun || type == STUN_DATA_INDICATION) { |
167 LOG(ERROR) << "Received unexpected data packet from " | 167 LOG(ERROR) << "Received unexpected data packet from " |
168 << recv_address_.ToString() | 168 << recv_address_.ToString() |
169 << " before STUN binding is finished."; | 169 << " before STUN binding is finished."; |
170 return; | 170 return; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 message_sender_->Send(new P2PMsg_OnDataReceived( | 174 message_sender_->Send(new P2PMsg_OnDataReceived( |
175 id_, recv_address_, data, base::TimeTicks::Now())); | 175 id_, recv_address_, data, base::TimeTicks::Now())); |
| 176 |
| 177 if (dump_incoming_rtp_packet_) |
| 178 DumpRtpPacket(&data[0], data.size(), true); |
176 } else if (result < 0 && !IsTransientError(result)) { | 179 } else if (result < 0 && !IsTransientError(result)) { |
177 LOG(ERROR) << "Error when reading from UDP socket: " << result; | 180 LOG(ERROR) << "Error when reading from UDP socket: " << result; |
178 OnError(); | 181 OnError(); |
179 } | 182 } |
180 } | 183 } |
181 | 184 |
182 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, | 185 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, |
183 const std::vector<char>& data, | 186 const std::vector<char>& data, |
184 const talk_base::PacketOptions& options, | 187 const talk_base::PacketOptions& options, |
185 uint64 packet_id) { | 188 uint64 packet_id) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 packet.to, | 257 packet.to, |
255 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), | 258 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), |
256 packet.id)); | 259 packet.id)); |
257 } | 260 } |
258 | 261 |
259 if (result == net::ERR_IO_PENDING) { | 262 if (result == net::ERR_IO_PENDING) { |
260 send_pending_ = true; | 263 send_pending_ = true; |
261 } else { | 264 } else { |
262 HandleSendResult(packet.id, result); | 265 HandleSendResult(packet.id, result); |
263 } | 266 } |
| 267 |
| 268 if (dump_outgoing_rtp_packet_) |
| 269 DumpRtpPacket(packet.data->data(), packet.size, false); |
264 } | 270 } |
265 | 271 |
266 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { | 272 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { |
267 DCHECK(send_pending_); | 273 DCHECK(send_pending_); |
268 DCHECK_NE(result, net::ERR_IO_PENDING); | 274 DCHECK_NE(result, net::ERR_IO_PENDING); |
269 | 275 |
270 send_pending_ = false; | 276 send_pending_ = false; |
271 | 277 |
272 HandleSendResult(packet_id, result); | 278 HandleSendResult(packet_id, result); |
273 | 279 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 case P2P_SOCKET_OPT_DSCP: | 316 case P2P_SOCKET_OPT_DSCP: |
311 return (net::OK == socket_->SetDiffServCodePoint( | 317 return (net::OK == socket_->SetDiffServCodePoint( |
312 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 318 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
313 default: | 319 default: |
314 NOTREACHED(); | 320 NOTREACHED(); |
315 return false; | 321 return false; |
316 } | 322 } |
317 } | 323 } |
318 | 324 |
319 } // namespace content | 325 } // namespace content |
OLD | NEW |