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

Side by Side Diff: media/cast/transport/pacing/paced_sender.cc

Issue 131233007: Cast: Clean up injection of transport into PacedPacketSender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/transport/pacing/paced_sender.h" 5 #include "media/cast/transport/pacing/paced_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 9
10 namespace media { 10 namespace media {
11 namespace cast { 11 namespace cast {
12 namespace transport { 12 namespace transport {
13 13
14 namespace { 14 namespace {
15 static const int64 kPacingIntervalMs = 10; 15 static const int64 kPacingIntervalMs = 10;
16 // Each frame will be split into no more than kPacingMaxBurstsPerFrame 16 // Each frame will be split into no more than kPacingMaxBurstsPerFrame
17 // bursts of packets. 17 // bursts of packets.
18 static const size_t kPacingMaxBurstsPerFrame = 3; 18 static const size_t kPacingMaxBurstsPerFrame = 3;
19 19
20 } // namespace 20 } // namespace
21 21
22 PacedSender::PacedSender( 22 PacedSender::PacedSender(
23 base::TickClock* clock, 23 base::TickClock* clock,
24 const CastTransportConfig* const config, 24 PacketSender* transport,
25 PacketSender* external_transport, 25 const scoped_refptr<base::TaskRunner>& transport_task_runner)
26 const scoped_refptr<base::TaskRunner>& transport_task_runner,
27 const CastTransportStatusCallback& status_callback)
28 : clock_(clock), 26 : clock_(clock),
29 external_transport_(external_transport), 27 transport_(transport),
30 config_(config),
31 transport_task_runner_(transport_task_runner), 28 transport_task_runner_(transport_task_runner),
32 burst_size_(1), 29 burst_size_(1),
33 packets_sent_in_burst_(0), 30 packets_sent_in_burst_(0),
34 weak_factory_(this) { 31 weak_factory_(this) {
35 if (!external_transport) {
36 net::IPEndPoint local_end_point;
37 net::IPEndPoint receiver_end_point;
38 // Set up transport in the absence of an external transport.
39 transport_.reset(new UdpTransport(transport_task_runner,
40 config_->local_endpoint,
41 config_->receiver_endpoint,
42 status_callback));
43 }
44 ScheduleNextSend(); 32 ScheduleNextSend();
45 } 33 }
46 34
47 PacedSender::~PacedSender() {} 35 PacedSender::~PacedSender() {}
48 36
49 void PacedSender::SetPacketReceiver(
50 const PacketReceiverCallback& packet_receiver) {
51 DCHECK(!external_transport_);
52 transport_->StartReceiving(packet_receiver);
53 }
54
55 bool PacedSender::SendPackets(const PacketList& packets) { 37 bool PacedSender::SendPackets(const PacketList& packets) {
56 return SendPacketsToTransport(packets, &packet_list_); 38 return SendPacketsToTransport(packets, &packet_list_);
57 } 39 }
58 40
59 bool PacedSender::ResendPackets(const PacketList& packets) { 41 bool PacedSender::ResendPackets(const PacketList& packets) {
60 return SendPacketsToTransport(packets, &resend_packet_list_); 42 return SendPacketsToTransport(packets, &resend_packet_list_);
61 } 43 }
62 44
63 bool PacedSender::SendPacketsToTransport(const PacketList& packets, 45 bool PacedSender::SendPacketsToTransport(const PacketList& packets,
64 PacketList* packets_not_sent) { 46 PacketList* packets_not_sent) {
(...skipping 20 matching lines...) Expand all
85 } 67 }
86 packets_not_sent->insert(packets_not_sent->end(), 68 packets_not_sent->insert(packets_not_sent->end(),
87 first_to_store_it, packets.end()); 69 first_to_store_it, packets.end());
88 packets_sent_in_burst_ += packets_to_send.size(); 70 packets_sent_in_burst_ += packets_to_send.size();
89 if (packets_to_send.empty()) return true; 71 if (packets_to_send.empty()) return true;
90 72
91 return TransmitPackets(packets_to_send); 73 return TransmitPackets(packets_to_send);
92 } 74 }
93 75
94 bool PacedSender::SendRtcpPacket(const Packet& packet) { 76 bool PacedSender::SendRtcpPacket(const Packet& packet) {
95 if (external_transport_) {
96 return external_transport_->SendPacket(packet);
97 }
98 // We pass the RTCP packets straight through. 77 // We pass the RTCP packets straight through.
99 return transport_->SendPacket(packet); 78 return transport_->SendPacket(packet);
100 } 79 }
101 80
102 void PacedSender::ScheduleNextSend() { 81 void PacedSender::ScheduleNextSend() {
103 base::TimeDelta time_to_next = time_last_process_ - 82 base::TimeDelta time_to_next = time_last_process_ -
104 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(kPacingIntervalMs); 83 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(kPacingIntervalMs);
105 84
106 time_to_next = std::max(time_to_next, base::TimeDelta()); 85 time_to_next = std::max(time_to_next, base::TimeDelta());
107 86
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 burst_size_ = 1; // Reset burst size after we sent the last stored packet 126 burst_size_ = 1; // Reset burst size after we sent the last stored packet
148 packets_sent_in_burst_ = 0; 127 packets_sent_in_burst_ = 0;
149 } 128 }
150 } 129 }
151 TransmitPackets(packets_to_resend); 130 TransmitPackets(packets_to_resend);
152 } 131 }
153 132
154 bool PacedSender::TransmitPackets(const PacketList& packets) { 133 bool PacedSender::TransmitPackets(const PacketList& packets) {
155 bool ret = true; 134 bool ret = true;
156 for (size_t i = 0; i < packets.size(); i++) { 135 for (size_t i = 0; i < packets.size(); i++) {
157 if (external_transport_) { 136 ret &= transport_->SendPacket(packets[i]);
158 ret &= external_transport_->SendPacket(packets[i]);
159 } else {
160 ret &= transport_->SendPacket(packets[i]);
161 }
162 } 137 }
163 return ret; 138 return ret;
164 } 139 }
165 140
166 void PacedSender::UpdateBurstSize(size_t packets_to_send) { 141 void PacedSender::UpdateBurstSize(size_t packets_to_send) {
167 packets_to_send = std::max(packets_to_send, 142 packets_to_send = std::max(packets_to_send,
168 resend_packet_list_.size() + packet_list_.size()); 143 resend_packet_list_.size() + packet_list_.size());
169 144
170 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. 145 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up.
171 burst_size_ = std::max(packets_to_send / kPacingMaxBurstsPerFrame, 146 burst_size_ = std::max(packets_to_send / kPacingMaxBurstsPerFrame,
172 burst_size_); 147 burst_size_);
173 } 148 }
174 149
175 void PacedSender::InsertFakeTransportForTesting(PacketSender* fake_transport) {
176 external_transport_ = fake_transport;
177 }
178
179 } // namespace transport 150 } // namespace transport
180 } // namespace cast 151 } // namespace cast
181 } // namespace media 152 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/transport/pacing/paced_sender.h ('k') | media/cast/transport/pacing/paced_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698