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 #include "net/log/net_log_source.h" | 19 #include "net/log/net_log_source.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 namespace cast { | 22 namespace cast { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kOptionDscp[] = "DSCP"; | 26 const char kOptionDscp[] = "DSCP"; |
27 #if defined(OS_WIN) | |
28 const char kOptionDisableNonBlockingIO[] = "disable_non_blocking_io"; | |
29 #endif | |
30 const char kOptionSendBufferMinSize[] = "send_buffer_min_size"; | 27 const char kOptionSendBufferMinSize[] = "send_buffer_min_size"; |
31 const char kOptionPacerMaxBurstSize[] = "pacer_max_burst_size"; | 28 const char kOptionPacerMaxBurstSize[] = "pacer_max_burst_size"; |
32 | 29 |
33 bool IsEmpty(const net::IPEndPoint& addr) { | 30 bool IsEmpty(const net::IPEndPoint& addr) { |
34 return (addr.address().empty() || addr.address().IsZero()) && !addr.port(); | 31 return (addr.address().empty() || addr.address().IsZero()) && !addr.port(); |
35 } | 32 } |
36 | 33 |
37 int LookupOptionWithDefault(const base::DictionaryValue& options, | 34 int LookupOptionWithDefault(const base::DictionaryValue& options, |
38 const std::string& path, | 35 const std::string& path, |
39 int default_value) { | 36 int default_value) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 129 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); |
133 packet_receiver_ = PacketReceiverCallbackWithStatus(); | 130 packet_receiver_ = PacketReceiverCallbackWithStatus(); |
134 } | 131 } |
135 | 132 |
136 | 133 |
137 void UdpTransport::SetDscp(net::DiffServCodePoint dscp) { | 134 void UdpTransport::SetDscp(net::DiffServCodePoint dscp) { |
138 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 135 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); |
139 next_dscp_value_ = dscp; | 136 next_dscp_value_ = dscp; |
140 } | 137 } |
141 | 138 |
142 #if defined(OS_WIN) | |
143 void UdpTransport::UseNonBlockingIO() { | |
144 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | |
145 if (!udp_socket_) | |
146 return; | |
147 udp_socket_->UseNonBlockingIO(); | |
148 } | |
149 #endif | |
150 | |
151 void UdpTransport::ScheduleReceiveNextPacket() { | 139 void UdpTransport::ScheduleReceiveNextPacket() { |
152 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 140 DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); |
153 if (!packet_receiver_.is_null() && !receive_pending_) { | 141 if (!packet_receiver_.is_null() && !receive_pending_) { |
154 receive_pending_ = true; | 142 receive_pending_ = true; |
155 io_thread_proxy_->PostTask(FROM_HERE, | 143 io_thread_proxy_->PostTask(FROM_HERE, |
156 base::Bind(&UdpTransport::ReceiveNextPacket, | 144 base::Bind(&UdpTransport::ReceiveNextPacket, |
157 weak_factory_.GetWeakPtr(), | 145 weak_factory_.GetWeakPtr(), |
158 net::ERR_IO_PENDING)); | 146 net::ERR_IO_PENDING)); |
159 } | 147 } |
160 } | 148 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 288 } |
301 } | 289 } |
302 | 290 |
303 void UdpTransport::SetUdpOptions(const base::DictionaryValue& options) { | 291 void UdpTransport::SetUdpOptions(const base::DictionaryValue& options) { |
304 SetSendBufferSize(GetTransportSendBufferSize(options)); | 292 SetSendBufferSize(GetTransportSendBufferSize(options)); |
305 if (options.HasKey(kOptionDscp)) { | 293 if (options.HasKey(kOptionDscp)) { |
306 // The default DSCP value for cast is AF41. Which gives it a higher | 294 // The default DSCP value for cast is AF41. Which gives it a higher |
307 // priority over other traffic. | 295 // priority over other traffic. |
308 SetDscp(net::DSCP_AF41); | 296 SetDscp(net::DSCP_AF41); |
309 } | 297 } |
310 #if defined(OS_WIN) | |
311 if (!options.HasKey(kOptionDisableNonBlockingIO)) { | |
312 UseNonBlockingIO(); | |
313 } | |
314 #endif | |
315 } | 298 } |
316 | 299 |
317 void UdpTransport::SetSendBufferSize(int32_t send_buffer_size) { | 300 void UdpTransport::SetSendBufferSize(int32_t send_buffer_size) { |
318 send_buffer_size_ = send_buffer_size; | 301 send_buffer_size_ = send_buffer_size; |
319 } | 302 } |
320 | 303 |
321 } // namespace cast | 304 } // namespace cast |
322 } // namespace media | 305 } // namespace media |
OLD | NEW |