| OLD | NEW |
| 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 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 if (max_packets_to_send_now > 0) { | 60 if (max_packets_to_send_now > 0) { |
| 61 size_t packets_to_send_now = | 61 size_t packets_to_send_now = |
| 62 std::min(max_packets_to_send_now, packets.size()); | 62 std::min(max_packets_to_send_now, packets.size()); |
| 63 | 63 |
| 64 std::advance(first_to_store_it, packets_to_send_now); | 64 std::advance(first_to_store_it, packets_to_send_now); |
| 65 packets_to_send.insert( | 65 packets_to_send.insert( |
| 66 packets_to_send.begin(), packets.begin(), first_to_store_it); | 66 packets_to_send.begin(), packets.begin(), first_to_store_it); |
| 67 } | 67 } |
| 68 packets_not_sent->insert( | 68 packets_not_sent->insert( |
| 69 packets_not_sent->end(), first_to_store_it, packets.end()); | 69 packets_not_sent->end(), first_to_store_it, packets.end()); |
| 70 packets_sent_in_burst_ += packets_to_send.size(); | 70 packets_sent_in_burst_ = packets_to_send.size(); |
| 71 if (packets_to_send.empty()) | 71 if (packets_to_send.empty()) |
| 72 return true; | 72 return true; |
| 73 | 73 |
| 74 return TransmitPackets(packets_to_send); | 74 return TransmitPackets(packets_to_send); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool PacedSender::SendRtcpPacket(const Packet& packet) { | 77 bool PacedSender::SendRtcpPacket(const Packet& packet) { |
| 78 // We pass the RTCP packets straight through. | 78 // We pass the RTCP packets straight through. |
| 79 return transport_->SendPacket(packet); | 79 return transport_->SendPacket(packet); |
| 80 } | 80 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 PacketList::iterator it = packet_list_.begin(); | 120 PacketList::iterator it = packet_list_.begin(); |
| 121 size_t packets_to_send_now = std::min(packets_to_send, packet_list_.size()); | 121 size_t packets_to_send_now = std::min(packets_to_send, packet_list_.size()); |
| 122 | 122 |
| 123 std::advance(it, packets_to_send_now); | 123 std::advance(it, packets_to_send_now); |
| 124 packets_to_resend.insert(packets_to_resend.end(), packet_list_.begin(), it); | 124 packets_to_resend.insert(packets_to_resend.end(), packet_list_.begin(), it); |
| 125 packet_list_.erase(packet_list_.begin(), it); | 125 packet_list_.erase(packet_list_.begin(), it); |
| 126 | 126 |
| 127 if (packet_list_.empty()) { | 127 if (packet_list_.empty()) { |
| 128 burst_size_ = 1; // Reset burst size after we sent the last stored packet | 128 burst_size_ = 1; // Reset burst size after we sent the last stored packet |
| 129 packets_sent_in_burst_ = 0; | 129 packets_sent_in_burst_ = 0; |
| 130 } else { |
| 131 packets_sent_in_burst_ = packets_to_resend.size(); |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 TransmitPackets(packets_to_resend); | 134 TransmitPackets(packets_to_resend); |
| 133 } | 135 } |
| 134 | 136 |
| 135 bool PacedSender::TransmitPackets(const PacketList& packets) { | 137 bool PacedSender::TransmitPackets(const PacketList& packets) { |
| 136 bool ret = true; | 138 bool ret = true; |
| 137 for (size_t i = 0; i < packets.size(); i++) { | 139 for (size_t i = 0; i < packets.size(); i++) { |
| 138 ret &= transport_->SendPacket(packets[i]); | 140 ret &= transport_->SendPacket(packets[i]); |
| 139 } | 141 } |
| 140 return ret; | 142 return ret; |
| 141 } | 143 } |
| 142 | 144 |
| 143 void PacedSender::UpdateBurstSize(size_t packets_to_send) { | 145 void PacedSender::UpdateBurstSize(size_t packets_to_send) { |
| 144 packets_to_send = std::max(packets_to_send, | 146 packets_to_send = std::max(packets_to_send, |
| 145 resend_packet_list_.size() + packet_list_.size()); | 147 resend_packet_list_.size() + packet_list_.size()); |
| 146 | 148 |
| 147 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. | 149 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. |
| 148 burst_size_ = | 150 burst_size_ = |
| 149 std::max(packets_to_send / kPacingMaxBurstsPerFrame, burst_size_); | 151 std::max(packets_to_send / kPacingMaxBurstsPerFrame, burst_size_); |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace transport | 154 } // namespace transport |
| 153 } // namespace cast | 155 } // namespace cast |
| 154 } // namespace media | 156 } // namespace media |
| OLD | NEW |