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

Side by Side Diff: trunk/src/media/cast/pacing/paced_sender.cc

Issue 25546003: Revert 226264 "Be able to build cast_unittest and related target..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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/pacing/paced_sender.h" 5 #include "media/cast/pacing/paced_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 10
(...skipping 24 matching lines...) Expand all
35 UpdateBurstSize(num_of_packets_in_frame); 35 UpdateBurstSize(num_of_packets_in_frame);
36 return true; 36 return true;
37 } 37 }
38 UpdateBurstSize(num_of_packets_in_frame); 38 UpdateBurstSize(num_of_packets_in_frame);
39 39
40 if (packets_sent_in_burst_ >= burst_size_) { 40 if (packets_sent_in_burst_ >= burst_size_) {
41 packet_list_.push_back(packet); 41 packet_list_.push_back(packet);
42 return true; 42 return true;
43 } 43 }
44 ++packets_sent_in_burst_; 44 ++packets_sent_in_burst_;
45 return transport_->SendPacket(packet); 45 return transport_->SendPacket(&(packet[0]), packet.size());
46 } 46 }
47 47
48 bool PacedSender::ResendPacket(const std::vector<uint8>& packet, 48 bool PacedSender::ResendPacket(const std::vector<uint8>& packet,
49 int num_of_packets_to_resend) { 49 int num_of_packets_to_resend) {
50 if (!packet_list_.empty() || !resend_packet_list_.empty()) { 50 if (!packet_list_.empty() || !resend_packet_list_.empty()) {
51 // We have a queue put the resend packets in the list. 51 // We have a queue put the resend packets in the list.
52 resend_packet_list_.push_back(packet); 52 resend_packet_list_.push_back(packet);
53 UpdateBurstSize(num_of_packets_to_resend); 53 UpdateBurstSize(num_of_packets_to_resend);
54 return true; 54 return true;
55 } 55 }
56 UpdateBurstSize(num_of_packets_to_resend); 56 UpdateBurstSize(num_of_packets_to_resend);
57 57
58 if (packets_sent_in_burst_ >= burst_size_) { 58 if (packets_sent_in_burst_ >= burst_size_) {
59 resend_packet_list_.push_back(packet); 59 resend_packet_list_.push_back(packet);
60 return true; 60 return true;
61 } 61 }
62 ++packets_sent_in_burst_; 62 ++packets_sent_in_burst_;
63 return transport_->SendPacket(packet); 63 return transport_->SendPacket(&(packet[0]), packet.size());
64 } 64 }
65 65
66 bool PacedSender::SendRtcpPacket(const std::vector<uint8>& packet) { 66 bool PacedSender::SendRtcpPacket(const std::vector<uint8>& packet) {
67 // We pass the RTCP packets straight through. 67 // We pass the RTCP packets straight through.
68 return transport_->SendPacket(packet); 68 return transport_->SendPacket(&(packet[0]), packet.size());
69 } 69 }
70 70
71 void PacedSender::ScheduleNextSend() { 71 void PacedSender::ScheduleNextSend() {
72 base::TimeDelta time_to_next = time_last_process_ - clock_->NowTicks() + 72 base::TimeDelta time_to_next = time_last_process_ - clock_->NowTicks() +
73 base::TimeDelta::FromMilliseconds(kPacingIntervalMs); 73 base::TimeDelta::FromMilliseconds(kPacingIntervalMs);
74 74
75 time_to_next = std::max(time_to_next, 75 time_to_next = std::max(time_to_next,
76 base::TimeDelta::FromMilliseconds(0)); 76 base::TimeDelta::FromMilliseconds(0));
77 77
78 cast_thread_->PostDelayedTask(CastThread::MAIN, FROM_HERE, 78 cast_thread_->PostDelayedTask(CastThread::MAIN, FROM_HERE,
79 base::Bind(&PacedSender::SendNextPacketBurst, weak_factory_.GetWeakPtr()), 79 base::Bind(&PacedSender::SendNextPacketBurst, weak_factory_.GetWeakPtr()),
80 time_to_next); 80 time_to_next);
81 } 81 }
82 82
83 void PacedSender::SendNextPacketBurst() { 83 void PacedSender::SendNextPacketBurst() {
84 int packets_to_send = burst_size_; 84 int packets_to_send = burst_size_;
85 time_last_process_ = clock_->NowTicks(); 85 time_last_process_ = clock_->NowTicks();
86 for (int i = 0; i < packets_to_send; ++i) { 86 for (int i = 0; i < packets_to_send; ++i) {
87 SendStoredPacket(); 87 SendStoredPacket();
88 } 88 }
89 ScheduleNextSend(); 89 ScheduleNextSend();
90 } 90 }
91 91
92 void PacedSender::SendStoredPacket() { 92 void PacedSender::SendStoredPacket() {
93 if (packet_list_.empty() && resend_packet_list_.empty()) return; 93 if (packet_list_.empty() && resend_packet_list_.empty()) return;
94 94
95 if (!resend_packet_list_.empty()) { 95 if (!resend_packet_list_.empty()) {
96 // Send our re-send packets first. 96 // Send our re-send packets first.
97 const std::vector<uint8>& packet = resend_packet_list_.front(); 97 const std::vector<uint8>& packet = resend_packet_list_.front();
98 transport_->SendPacket(packet); 98 transport_->SendPacket(&(packet[0]), packet.size());
99 resend_packet_list_.pop_front(); 99 resend_packet_list_.pop_front();
100 } else { 100 } else {
101 const std::vector<uint8>& packet = packet_list_.front(); 101 const std::vector<uint8>& packet = packet_list_.front();
102 transport_->SendPacket(packet); 102 transport_->SendPacket(&(packet[0]), packet.size());
103 packet_list_.pop_front(); 103 packet_list_.pop_front();
104 104
105 if (packet_list_.empty()) { 105 if (packet_list_.empty()) {
106 burst_size_ = 1; // Reset burst size after we sent the last stored packet 106 burst_size_ = 1; // Reset burst size after we sent the last stored packet
107 packets_sent_in_burst_ = 0; 107 packets_sent_in_burst_ = 0;
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 void PacedSender::UpdateBurstSize(int packets_to_send) { 112 void PacedSender::UpdateBurstSize(int packets_to_send) {
113 packets_to_send = std::max(packets_to_send, 113 packets_to_send = std::max(packets_to_send,
114 static_cast<int>(resend_packet_list_.size() + packet_list_.size())); 114 static_cast<int>(resend_packet_list_.size() + packet_list_.size()));
115 115
116 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. 116 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up.
117 117
118 burst_size_ = std::max(packets_to_send / kPacingMaxBurstsPerFrame, 118 burst_size_ = std::max(packets_to_send / kPacingMaxBurstsPerFrame,
119 burst_size_); 119 burst_size_);
120 } 120 }
121 121
122 } // namespace cast 122 } // namespace cast
123 } // namespace media 123 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/media/cast/pacing/mock_packet_sender.cc ('k') | trunk/src/media/cast/pacing/paced_sender.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698