Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: media/cast/net/udp_transport.cc

Issue 1515023002: Simplify interface for media/cast: CastTransportSenderImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add changes on tests. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
miu 2016/02/22 22:38:48 Let's delete this, since it's identical to kMaxIpP
xjz 2016/02/23 21:51:46 Done.
25 const char kOptionDscp[] = "DSCP";
26 #if defined(OS_WIN)
27 const char kOptionDisableNonBlockingIO[] = "disable_non_blocking_io";
28 #endif
29 const char kOptionSendBufferMinSize[] = "send_buffer_min_size";
30 const char kOptionPacerMaxBurstSize[] = "pacer_max_burst_size";
25 31
26 bool IsEmpty(const net::IPEndPoint& addr) { 32 bool IsEmpty(const net::IPEndPoint& addr) {
27 net::IPAddressNumber empty_addr(addr.address().size()); 33 net::IPAddressNumber empty_addr(addr.address().size());
28 return std::equal(empty_addr.begin(), empty_addr.end(), 34 return std::equal(empty_addr.begin(), empty_addr.end(),
29 addr.address().bytes().begin()) && 35 addr.address().bytes().begin()) &&
30 !addr.port(); 36 !addr.port();
31 } 37 }
32 38
39 int LookupOptionWithDefault(const base::DictionaryValue& options,
40 const std::string& path,
41 int default_value) {
42 int ret;
43 if (options.GetInteger(path, &ret)) {
44 return ret;
45 } else {
46 return default_value;
47 }
48 }
49
50 int32_t GetTransportSendBufferSize(const base::DictionaryValue& options) {
51 // Socket send buffer size needs to be at least greater than one burst
52 // size.
53 int32_t max_burst_size =
54 LookupOptionWithDefault(options, kOptionPacerMaxBurstSize,
55 media::cast::kMaxBurstSize) *
56 media::cast::kMaxIpPacketSize;
57 int32_t min_send_buffer_size =
58 LookupOptionWithDefault(options, kOptionSendBufferMinSize, 0);
59 return std::max(max_burst_size, min_send_buffer_size);
60 }
61
miu 2016/02/22 22:38:48 nit: Need extra newline above line 24 as well.
xjz 2016/02/23 21:51:46 Done.
33 } // namespace 62 } // namespace
34 63
35 UdpTransport::UdpTransport( 64 UdpTransport::UdpTransport(
36 net::NetLog* net_log, 65 net::NetLog* net_log,
37 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, 66 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy,
38 const net::IPEndPoint& local_end_point, 67 const net::IPEndPoint& local_end_point,
39 const net::IPEndPoint& remote_end_point, 68 const net::IPEndPoint& remote_end_point,
40 int32_t send_buffer_size,
41 const CastTransportStatusCallback& status_callback) 69 const CastTransportStatusCallback& status_callback)
42 : io_thread_proxy_(io_thread_proxy), 70 : io_thread_proxy_(io_thread_proxy),
43 local_addr_(local_end_point), 71 local_addr_(local_end_point),
44 remote_addr_(remote_end_point), 72 remote_addr_(remote_end_point),
45 udp_socket_(new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND, 73 udp_socket_(new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND,
46 net::RandIntCallback(), 74 net::RandIntCallback(),
47 net_log, 75 net_log,
48 net::NetLog::Source())), 76 net::NetLog::Source())),
49 send_pending_(false), 77 send_pending_(false),
50 receive_pending_(false), 78 receive_pending_(false),
51 client_connected_(false), 79 client_connected_(false),
52 next_dscp_value_(net::DSCP_NO_CHANGE), 80 next_dscp_value_(net::DSCP_NO_CHANGE),
53 send_buffer_size_(send_buffer_size), 81 send_buffer_size_(kMaxBurstSize * kMaxIpPacketSize),
54 status_callback_(status_callback), 82 status_callback_(status_callback),
55 bytes_sent_(0), 83 bytes_sent_(0),
56 weak_factory_(this) { 84 weak_factory_(this) {
57 DCHECK(!IsEmpty(local_end_point) || !IsEmpty(remote_end_point)); 85 DCHECK(!IsEmpty(local_end_point) || !IsEmpty(remote_end_point));
58 } 86 }
59 87
60 UdpTransport::~UdpTransport() {} 88 UdpTransport::~UdpTransport() {}
61 89
62 void UdpTransport::StartReceiving( 90 void UdpTransport::StartReceiving(
63 const PacketReceiverCallbackWithStatus& packet_receiver) { 91 const PacketReceiverCallbackWithStatus& packet_receiver) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (result < 0) { 296 if (result < 0) {
269 VLOG(1) << "Failed to send packet: " << result << "."; 297 VLOG(1) << "Failed to send packet: " << result << ".";
270 } 298 }
271 ScheduleReceiveNextPacket(); 299 ScheduleReceiveNextPacket();
272 300
273 if (!cb.is_null()) { 301 if (!cb.is_null()) {
274 cb.Run(); 302 cb.Run();
275 } 303 }
276 } 304 }
277 305
306 void UdpTransport::SetUdpOptions(const base::DictionaryValue& options) {
307 SetSendBufferSize(GetTransportSendBufferSize(options));
308 if (options.HasKey(kOptionDscp)) {
309 // The default DSCP value for cast is AF41. Which gives it a higher
310 // priority over other traffic.
311 SetDscp(net::DSCP_AF41);
312 }
313 #if defined(OS_WIN)
314 if (!options.HasKey(kOptionDisableNonBlockingIO)) {
315 UseNonBlockingIO();
316 }
317 #endif
318 }
319
320 void UdpTransport::SetSendBufferSize(int32_t send_buffer_size) {
321 send_buffer_size_ = send_buffer_size;
322 }
323
278 } // namespace cast 324 } // namespace cast
279 } // namespace media 325 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698