diff options
Diffstat (limited to 'media/cast/net/udp_transport.cc')
-rw-r--r-- | media/cast/net/udp_transport.cc | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/media/cast/net/udp_transport.cc b/media/cast/net/udp_transport.cc index 2560b45..bf126bc 100644 --- a/media/cast/net/udp_transport.cc +++ b/media/cast/net/udp_transport.cc @@ -21,7 +21,13 @@ namespace media { namespace cast { namespace { -const int kMaxPacketSize = 1500; + +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); +} + } // 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,8 @@ UdpTransport::UdpTransport( receive_pending_(false), client_connected_(false), next_dscp_value_(net::DSCP_NO_CHANGE), - send_buffer_size_(send_buffer_size), + send_buffer_size_(media::cast::kMaxBurstSize * + media::cast::kMaxIpPacketSize), status_callback_(status_callback), bytes_sent_(0), weak_factory_(this) { @@ -145,15 +174,13 @@ void UdpTransport::ReceiveNextPacket(int length_or_status) { // the future when a packet is ready. while (true) { if (length_or_status == net::ERR_IO_PENDING) { - next_packet_.reset(new Packet(kMaxPacketSize)); + next_packet_.reset(new Packet(media::cast::kMaxIpPacketSize)); recv_buf_ = new net::WrappedIOBuffer( reinterpret_cast<char*>(&next_packet_->front())); - length_or_status = - udp_socket_->RecvFrom(recv_buf_.get(), - kMaxPacketSize, - &recv_addr_, - base::Bind(&UdpTransport::ReceiveNextPacket, - weak_factory_.GetWeakPtr())); + length_or_status = udp_socket_->RecvFrom( + recv_buf_.get(), media::cast::kMaxIpPacketSize, &recv_addr_, + base::Bind(&UdpTransport::ReceiveNextPacket, + weak_factory_.GetWeakPtr())); if (length_or_status == net::ERR_IO_PENDING) { receive_pending_ = true; return; @@ -275,5 +302,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 |