| 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/cast_transport_sender_impl.h" | 5 #include "media/cast/net/cast_transport_sender_impl.h" |
| 6 | 6 |
| 7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "media/cast/net/cast_transport_config.h" | 9 #include "media/cast/net/cast_transport_config.h" |
| 10 #include "media/cast/net/cast_transport_defines.h" | 10 #include "media/cast/net/cast_transport_defines.h" |
| 11 #include "media/cast/net/udp_transport.h" | 11 #include "media/cast/net/udp_transport.h" |
| 12 #include "net/base/net_errors.h" |
| 12 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 namespace cast { | 16 namespace cast { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 19 |
| 20 // See header file for what these mean. |
| 21 const char kOptionPacerTargetBurstSize[] = "pacer_target_burst_size"; |
| 22 const char kOptionPacerMaxBurstSize[] = "pacer_max_burst_size"; |
| 23 const char kOptionSendBufferMinSize[] = "send_buffer_min_size"; |
| 24 const char kOptionDscp[] = "DSCP"; |
| 25 const char kOptionWifiDisableScan[] = "disable_wifi_scan"; |
| 26 const char kOptionWifiMediaStreamingMode[] = "media_streaming_mode"; |
| 27 |
| 18 int LookupOptionWithDefault(const base::DictionaryValue& options, | 28 int LookupOptionWithDefault(const base::DictionaryValue& options, |
| 19 const std::string& path, | 29 const std::string& path, |
| 20 int default_value) { | 30 int default_value) { |
| 21 int ret; | 31 int ret; |
| 22 if (options.GetInteger(path, &ret)) { | 32 if (options.GetInteger(path, &ret)) { |
| 23 return ret; | 33 return ret; |
| 24 } else { | 34 } else { |
| 25 return default_value; | 35 return default_value; |
| 26 } | 36 } |
| 27 }; | 37 }; |
| 28 | 38 |
| 39 int32 GetTransportSendBufferSize(const base::DictionaryValue& options) { |
| 40 // Socket send buffer size needs to be at least greater than one burst |
| 41 // size. |
| 42 int32 max_burst_size = |
| 43 LookupOptionWithDefault(options, kOptionPacerMaxBurstSize, |
| 44 kMaxBurstSize) * kMaxIpPacketSize; |
| 45 int32 min_send_buffer_size = |
| 46 LookupOptionWithDefault(options, kOptionSendBufferMinSize, 0); |
| 47 return std::max(max_burst_size, min_send_buffer_size); |
| 48 } |
| 49 |
| 29 } // namespace | 50 } // namespace |
| 30 | 51 |
| 31 scoped_ptr<CastTransportSender> CastTransportSender::Create( | 52 scoped_ptr<CastTransportSender> CastTransportSender::Create( |
| 32 net::NetLog* net_log, | 53 net::NetLog* net_log, |
| 33 base::TickClock* clock, | 54 base::TickClock* clock, |
| 34 const net::IPEndPoint& remote_end_point, | 55 const net::IPEndPoint& remote_end_point, |
| 35 scoped_ptr<base::DictionaryValue> options, | 56 scoped_ptr<base::DictionaryValue> options, |
| 36 const CastTransportStatusCallback& status_callback, | 57 const CastTransportStatusCallback& status_callback, |
| 37 const BulkRawEventsCallback& raw_events_callback, | 58 const BulkRawEventsCallback& raw_events_callback, |
| 38 base::TimeDelta raw_events_callback_interval, | 59 base::TimeDelta raw_events_callback_interval, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 const net::IPEndPoint& remote_end_point, | 80 const net::IPEndPoint& remote_end_point, |
| 60 scoped_ptr<base::DictionaryValue> options, | 81 scoped_ptr<base::DictionaryValue> options, |
| 61 const CastTransportStatusCallback& status_callback, | 82 const CastTransportStatusCallback& status_callback, |
| 62 const BulkRawEventsCallback& raw_events_callback, | 83 const BulkRawEventsCallback& raw_events_callback, |
| 63 base::TimeDelta raw_events_callback_interval, | 84 base::TimeDelta raw_events_callback_interval, |
| 64 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, | 85 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, |
| 65 PacketSender* external_transport) | 86 PacketSender* external_transport) |
| 66 : clock_(clock), | 87 : clock_(clock), |
| 67 status_callback_(status_callback), | 88 status_callback_(status_callback), |
| 68 transport_task_runner_(transport_task_runner), | 89 transport_task_runner_(transport_task_runner), |
| 69 transport_(external_transport ? NULL | 90 transport_( |
| 70 : new UdpTransport(net_log, | 91 external_transport ? |
| 71 transport_task_runner, | 92 NULL : |
| 72 net::IPEndPoint(), | 93 new UdpTransport(net_log, |
| 73 remote_end_point, | 94 transport_task_runner, |
| 74 status_callback)), | 95 net::IPEndPoint(), |
| 75 pacer_(LookupOptionWithDefault(*options.get(), | 96 remote_end_point, |
| 76 "pacer_target_burst_size", | 97 GetTransportSendBufferSize(*options), |
| 98 status_callback)), |
| 99 pacer_(LookupOptionWithDefault(*options, |
| 100 kOptionPacerTargetBurstSize, |
| 77 kTargetBurstSize), | 101 kTargetBurstSize), |
| 78 LookupOptionWithDefault(*options.get(), | 102 LookupOptionWithDefault(*options, |
| 79 "pacer_max_burst_size", | 103 kOptionPacerMaxBurstSize, |
| 80 kMaxBurstSize), | 104 kMaxBurstSize), |
| 81 clock, | 105 clock, |
| 82 &logging_, | 106 &logging_, |
| 83 external_transport ? external_transport : transport_.get(), | 107 external_transport ? external_transport : transport_.get(), |
| 84 transport_task_runner), | 108 transport_task_runner), |
| 85 raw_events_callback_(raw_events_callback), | 109 raw_events_callback_(raw_events_callback), |
| 86 raw_events_callback_interval_(raw_events_callback_interval), | 110 raw_events_callback_interval_(raw_events_callback_interval), |
| 87 last_byte_acked_for_audio_(0), | 111 last_byte_acked_for_audio_(0), |
| 88 weak_factory_(this) { | 112 weak_factory_(this) { |
| 89 DCHECK(clock_); | 113 DCHECK(clock_); |
| 90 if (!raw_events_callback_.is_null()) { | 114 if (!raw_events_callback_.is_null()) { |
| 91 DCHECK(raw_events_callback_interval > base::TimeDelta()); | 115 DCHECK(raw_events_callback_interval > base::TimeDelta()); |
| 92 event_subscriber_.reset(new SimpleEventSubscriber); | 116 event_subscriber_.reset(new SimpleEventSubscriber); |
| 93 logging_.AddRawEventSubscriber(event_subscriber_.get()); | 117 logging_.AddRawEventSubscriber(event_subscriber_.get()); |
| 94 transport_task_runner->PostDelayedTask( | 118 transport_task_runner->PostDelayedTask( |
| 95 FROM_HERE, | 119 FROM_HERE, |
| 96 base::Bind(&CastTransportSenderImpl::SendRawEvents, | 120 base::Bind(&CastTransportSenderImpl::SendRawEvents, |
| 97 weak_factory_.GetWeakPtr()), | 121 weak_factory_.GetWeakPtr()), |
| 98 raw_events_callback_interval); | 122 raw_events_callback_interval); |
| 99 } | 123 } |
| 100 if (transport_) { | 124 if (transport_) { |
| 101 if (options->HasKey("DSCP")) { | 125 if (options->HasKey(kOptionDscp)) { |
| 102 // The default DSCP value for cast is AF41. Which gives it a higher | 126 // The default DSCP value for cast is AF41. Which gives it a higher |
| 103 // priority over other traffic. | 127 // priority over other traffic. |
| 104 transport_->SetDscp(net::DSCP_AF41); | 128 transport_->SetDscp(net::DSCP_AF41); |
| 105 } | 129 } |
| 106 transport_->StartReceiving( | 130 transport_->StartReceiving( |
| 107 base::Bind(&CastTransportSenderImpl::OnReceivedPacket, | 131 base::Bind(&CastTransportSenderImpl::OnReceivedPacket, |
| 108 weak_factory_.GetWeakPtr())); | 132 weak_factory_.GetWeakPtr())); |
| 109 int wifi_options = 0; | 133 int wifi_options = 0; |
| 110 if (options->HasKey("disable_wifi_scan")) { | 134 if (options->HasKey(kOptionWifiDisableScan)) { |
| 111 wifi_options |= net::WIFI_OPTIONS_DISABLE_SCAN; | 135 wifi_options |= net::WIFI_OPTIONS_DISABLE_SCAN; |
| 112 } | 136 } |
| 113 if (options->HasKey("media_streaming_mode")) { | 137 if (options->HasKey(kOptionWifiMediaStreamingMode)) { |
| 114 wifi_options |= net::WIFI_OPTIONS_MEDIA_STREAMING_MODE; | 138 wifi_options |= net::WIFI_OPTIONS_MEDIA_STREAMING_MODE; |
| 115 } | 139 } |
| 116 if (wifi_options) { | 140 if (wifi_options) { |
| 117 wifi_options_autoreset_ = net::SetWifiOptions(wifi_options); | 141 wifi_options_autoreset_ = net::SetWifiOptions(wifi_options); |
| 118 } | 142 } |
| 119 } | 143 } |
| 120 } | 144 } |
| 121 | 145 |
| 122 CastTransportSenderImpl::~CastTransportSenderImpl() { | 146 CastTransportSenderImpl::~CastTransportSenderImpl() { |
| 123 if (event_subscriber_.get()) | 147 if (event_subscriber_.get()) |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // 2. Specifies a deduplication window. For video this would be the most | 417 // 2. Specifies a deduplication window. For video this would be the most |
| 394 // recent RTT. For audio there is no deduplication. | 418 // recent RTT. For audio there is no deduplication. |
| 395 ResendPackets(ssrc, | 419 ResendPackets(ssrc, |
| 396 cast_message.missing_frames_and_packets, | 420 cast_message.missing_frames_and_packets, |
| 397 true, | 421 true, |
| 398 dedup_info); | 422 dedup_info); |
| 399 } | 423 } |
| 400 | 424 |
| 401 } // namespace cast | 425 } // namespace cast |
| 402 } // namespace media | 426 } // namespace media |
| OLD | NEW |