Index: media/cast/net/udp_transport.cc |
diff --git a/media/cast/net/udp_transport.cc b/media/cast/net/udp_transport.cc |
index 2560b4594c20cc0a8315d069063de0e0c7aa67fb..8a7b5a6052fb9d9e0d460db6ec58dfcc78e9521f 100644 |
--- a/media/cast/net/udp_transport.cc |
+++ b/media/cast/net/udp_transport.cc |
@@ -22,6 +22,12 @@ namespace cast { |
namespace { |
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.
|
+const char kOptionDscp[] = "DSCP"; |
+#if defined(OS_WIN) |
+const char kOptionDisableNonBlockingIO[] = "disable_non_blocking_io"; |
+#endif |
+const char kOptionSendBufferMinSize[] = "send_buffer_min_size"; |
+const char kOptionPacerMaxBurstSize[] = "pacer_max_burst_size"; |
bool IsEmpty(const net::IPEndPoint& addr) { |
net::IPAddressNumber empty_addr(addr.address().size()); |
@@ -30,6 +36,29 @@ bool IsEmpty(const net::IPEndPoint& addr) { |
!addr.port(); |
} |
+int LookupOptionWithDefault(const base::DictionaryValue& options, |
+ const std::string& path, |
+ int default_value) { |
+ int ret; |
+ if (options.GetInteger(path, &ret)) { |
+ return ret; |
+ } else { |
+ return default_value; |
+ } |
+} |
+ |
+int32_t GetTransportSendBufferSize(const base::DictionaryValue& options) { |
+ // Socket send buffer size needs to be at least greater than one burst |
+ // size. |
+ int32_t max_burst_size = |
+ LookupOptionWithDefault(options, kOptionPacerMaxBurstSize, |
+ media::cast::kMaxBurstSize) * |
+ media::cast::kMaxIpPacketSize; |
+ int32_t min_send_buffer_size = |
+ LookupOptionWithDefault(options, kOptionSendBufferMinSize, 0); |
+ return std::max(max_burst_size, min_send_buffer_size); |
+} |
+ |
miu
2016/02/22 22:38:48
nit: Need extra newline above line 24 as well.
xjz
2016/02/23 21:51:46
Done.
|
} // namespace |
UdpTransport::UdpTransport( |
@@ -37,7 +66,6 @@ UdpTransport::UdpTransport( |
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, |
const net::IPEndPoint& local_end_point, |
const net::IPEndPoint& remote_end_point, |
- int32_t send_buffer_size, |
const CastTransportStatusCallback& status_callback) |
: io_thread_proxy_(io_thread_proxy), |
local_addr_(local_end_point), |
@@ -50,7 +78,7 @@ UdpTransport::UdpTransport( |
receive_pending_(false), |
client_connected_(false), |
next_dscp_value_(net::DSCP_NO_CHANGE), |
- send_buffer_size_(send_buffer_size), |
+ send_buffer_size_(kMaxBurstSize * kMaxIpPacketSize), |
status_callback_(status_callback), |
bytes_sent_(0), |
weak_factory_(this) { |
@@ -275,5 +303,23 @@ void UdpTransport::OnSent(const scoped_refptr<net::IOBuffer>& buf, |
} |
} |
+void UdpTransport::SetUdpOptions(const base::DictionaryValue& options) { |
+ SetSendBufferSize(GetTransportSendBufferSize(options)); |
+ if (options.HasKey(kOptionDscp)) { |
+ // The default DSCP value for cast is AF41. Which gives it a higher |
+ // priority over other traffic. |
+ SetDscp(net::DSCP_AF41); |
+ } |
+#if defined(OS_WIN) |
+ if (!options.HasKey(kOptionDisableNonBlockingIO)) { |
+ UseNonBlockingIO(); |
+ } |
+#endif |
+} |
+ |
+void UdpTransport::SetSendBufferSize(int32_t send_buffer_size) { |
+ send_buffer_size_ = send_buffer_size; |
+} |
+ |
} // namespace cast |
} // namespace media |