OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/cast/net/udp_transport.h" | 5 #include "media/cast/net/udp_transport.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/base/rand_callback.h" | 18 #include "net/base/rand_callback.h" |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 namespace cast { | 21 namespace cast { |
22 | 22 |
23 namespace { | 23 namespace { |
24 const int kMaxPacketSize = 1500; | 24 const int kMaxPacketSize = 1500; |
25 | 25 |
26 bool IsEmpty(const net::IPEndPoint& addr) { | 26 bool IsEmpty(const net::IPEndPoint& addr) { |
27 net::IPAddressNumber empty_addr(addr.address().size()); | 27 net::IPAddressNumber empty_addr(addr.address().size()); |
28 return std::equal( | 28 return std::equal(empty_addr.begin(), empty_addr.end(), |
29 empty_addr.begin(), empty_addr.end(), addr.address().begin()) && | 29 addr.address().bytes().begin()) && |
30 !addr.port(); | 30 !addr.port(); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 UdpTransport::UdpTransport( | 35 UdpTransport::UdpTransport( |
36 net::NetLog* net_log, | 36 net::NetLog* net_log, |
37 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, | 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, |
38 const net::IPEndPoint& local_end_point, | 38 const net::IPEndPoint& local_end_point, |
39 const net::IPEndPoint& remote_end_point, | 39 const net::IPEndPoint& remote_end_point, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 // TODO(hubbe): We should only do this if the caller used a valid ssrc. | 175 // TODO(hubbe): We should only do this if the caller used a valid ssrc. |
176 if (IsEmpty(remote_addr_)) { | 176 if (IsEmpty(remote_addr_)) { |
177 remote_addr_ = recv_addr_; | 177 remote_addr_ = recv_addr_; |
178 VLOG(1) << "Setting remote address from first received packet: " | 178 VLOG(1) << "Setting remote address from first received packet: " |
179 << remote_addr_.ToString(); | 179 << remote_addr_.ToString(); |
180 next_packet_->resize(length_or_status); | 180 next_packet_->resize(length_or_status); |
181 if (!packet_receiver_.Run(std::move(next_packet_))) { | 181 if (!packet_receiver_.Run(std::move(next_packet_))) { |
182 VLOG(1) << "Packet was not valid, resetting remote address."; | 182 VLOG(1) << "Packet was not valid, resetting remote address."; |
183 remote_addr_ = net::IPEndPoint(); | 183 remote_addr_ = net::IPEndPoint(); |
184 } | 184 } |
185 } else if (!(remote_addr_ == recv_addr_)) { | 185 } else if (!(remote_addr_ == recv_addr_)) { |
miu
2016/01/21 00:57:50
Since you added the != operator, can you please ch
martijnc
2016/01/21 21:28:57
remote_addr_ and recv_addr_ are net::IPEndpoint in
miu
2016/01/21 23:34:31
Ah, my mistake. Never mind.
| |
186 VLOG(1) << "Ignoring packet received from an unrecognized address: " | 186 VLOG(1) << "Ignoring packet received from an unrecognized address: " |
187 << recv_addr_.ToString() << "."; | 187 << recv_addr_.ToString() << "."; |
188 } else { | 188 } else { |
189 next_packet_->resize(length_or_status); | 189 next_packet_->resize(length_or_status); |
190 packet_receiver_.Run(std::move(next_packet_)); | 190 packet_receiver_.Run(std::move(next_packet_)); |
191 } | 191 } |
192 length_or_status = net::ERR_IO_PENDING; | 192 length_or_status = net::ERR_IO_PENDING; |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 } | 270 } |
271 ScheduleReceiveNextPacket(); | 271 ScheduleReceiveNextPacket(); |
272 | 272 |
273 if (!cb.is_null()) { | 273 if (!cb.is_null()) { |
274 cb.Run(); | 274 cb.Run(); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 } // namespace cast | 278 } // namespace cast |
279 } // namespace media | 279 } // namespace media |
OLD | NEW |