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 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/base/rand_callback.h" | 18 #include "net/base/rand_callback.h" |
18 | 19 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Confirm the packet has come from the expected remote address; otherwise, | 176 // Confirm the packet has come from the expected remote address; otherwise, |
176 // ignore it. If this is the first packet being received and no remote | 177 // ignore it. If this is the first packet being received and no remote |
177 // address has been set, set the remote address and expect all future | 178 // address has been set, set the remote address and expect all future |
178 // packets to come from the same one. | 179 // packets to come from the same one. |
179 // TODO(hubbe): We should only do this if the caller used a valid ssrc. | 180 // TODO(hubbe): We should only do this if the caller used a valid ssrc. |
180 if (IsEmpty(remote_addr_)) { | 181 if (IsEmpty(remote_addr_)) { |
181 remote_addr_ = recv_addr_; | 182 remote_addr_ = recv_addr_; |
182 VLOG(1) << "Setting remote address from first received packet: " | 183 VLOG(1) << "Setting remote address from first received packet: " |
183 << remote_addr_.ToString(); | 184 << remote_addr_.ToString(); |
184 next_packet_->resize(length_or_status); | 185 next_packet_->resize(length_or_status); |
185 if (!packet_receiver_.Run(next_packet_.Pass())) { | 186 if (!packet_receiver_.Run(std::move(next_packet_))) { |
186 VLOG(1) << "Packet was not valid, resetting remote address."; | 187 VLOG(1) << "Packet was not valid, resetting remote address."; |
187 remote_addr_ = net::IPEndPoint(); | 188 remote_addr_ = net::IPEndPoint(); |
188 } | 189 } |
189 } else if (!IsEqual(remote_addr_, recv_addr_)) { | 190 } else if (!IsEqual(remote_addr_, recv_addr_)) { |
190 VLOG(1) << "Ignoring packet received from an unrecognized address: " | 191 VLOG(1) << "Ignoring packet received from an unrecognized address: " |
191 << recv_addr_.ToString() << "."; | 192 << recv_addr_.ToString() << "."; |
192 } else { | 193 } else { |
193 next_packet_->resize(length_or_status); | 194 next_packet_->resize(length_or_status); |
194 packet_receiver_.Run(next_packet_.Pass()); | 195 packet_receiver_.Run(std::move(next_packet_)); |
195 } | 196 } |
196 length_or_status = net::ERR_IO_PENDING; | 197 length_or_status = net::ERR_IO_PENDING; |
197 } | 198 } |
198 } | 199 } |
199 | 200 |
200 bool UdpTransport::SendPacket(PacketRef packet, const base::Closure& cb) { | 201 bool UdpTransport::SendPacket(PacketRef packet, const base::Closure& cb) { |
201 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 202 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); |
202 if (!udp_socket_) | 203 if (!udp_socket_) |
203 return true; | 204 return true; |
204 | 205 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 275 } |
275 ScheduleReceiveNextPacket(); | 276 ScheduleReceiveNextPacket(); |
276 | 277 |
277 if (!cb.is_null()) { | 278 if (!cb.is_null()) { |
278 cb.Run(); | 279 cb.Run(); |
279 } | 280 } |
280 } | 281 } |
281 | 282 |
282 } // namespace cast | 283 } // namespace cast |
283 } // namespace media | 284 } // namespace media |
OLD | NEW |