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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cast/net/udp_transport.h ('k') | media/cast/net/udp_transport_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..bf126bc6c5877684bdc80773a668bf8878954dd0 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
« no previous file with comments | « media/cast/net/udp_transport.h ('k') | media/cast/net/udp_transport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698