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

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

Issue 196433002: Cast: Log sender side packet events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 9 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/big_endian.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 10
10 namespace media { 11 namespace media {
11 namespace cast { 12 namespace cast {
12 namespace transport { 13 namespace transport {
13 14
14 namespace { 15 namespace {
15 static const int64 kPacingIntervalMs = 10; 16 static const int64 kPacingIntervalMs = 10;
16 // Each frame will be split into no more than kPacingMaxBurstsPerFrame 17 // Each frame will be split into no more than kPacingMaxBurstsPerFrame
17 // bursts of packets. 18 // bursts of packets.
18 static const size_t kPacingMaxBurstsPerFrame = 3; 19 static const size_t kPacingMaxBurstsPerFrame = 3;
19 20
21 using media::cast::CastLoggingEvent;
22
23 CastLoggingEvent GetLoggingEvent(bool is_audio, bool retransmit) {
24 if (retransmit) {
25 return is_audio ? media::cast::kAudioPacketRetransmitted
26 : media::cast::kVideoPacketRetransmitted;
27 } else {
28 return is_audio ? media::cast::kAudioPacketSentToNetwork
29 : media::cast::kVideoPacketSentToNetwork;
30 }
31 }
32
20 } // namespace 33 } // namespace
21 34
22 PacedSender::PacedSender( 35 PacedSender::PacedSender(
23 base::TickClock* clock, 36 base::TickClock* clock,
37 LoggingImpl* logging,
24 PacketSender* transport, 38 PacketSender* transport,
25 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner) 39 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner)
26 : clock_(clock), 40 : clock_(clock),
41 logging_(logging),
27 transport_(transport), 42 transport_(transport),
28 transport_task_runner_(transport_task_runner), 43 transport_task_runner_(transport_task_runner),
44 audio_ssrc_(0),
45 video_ssrc_(0),
29 burst_size_(1), 46 burst_size_(1),
30 packets_sent_in_burst_(0), 47 packets_sent_in_burst_(0),
31 weak_factory_(this) { 48 weak_factory_(this) {
32 ScheduleNextSend(); 49 ScheduleNextSend();
33 } 50 }
34 51
35 PacedSender::~PacedSender() {} 52 PacedSender::~PacedSender() {}
36 53
54 void PacedSender::RegisterAudioSsrc(uint32 audio_ssrc) {
55 audio_ssrc_ = audio_ssrc;
56 }
57
58 void PacedSender::RegisterVideoSsrc(uint32 video_ssrc) {
59 video_ssrc_ = video_ssrc;
60 }
61
37 bool PacedSender::SendPackets(const PacketList& packets) { 62 bool PacedSender::SendPackets(const PacketList& packets) {
38 return SendPacketsToTransport(packets, &packet_list_); 63 return SendPacketsToTransport(packets, &packet_list_, false);
39 } 64 }
40 65
41 bool PacedSender::ResendPackets(const PacketList& packets) { 66 bool PacedSender::ResendPackets(const PacketList& packets) {
42 return SendPacketsToTransport(packets, &resend_packet_list_); 67 return SendPacketsToTransport(packets, &resend_packet_list_, true);
43 } 68 }
44 69
45 bool PacedSender::SendPacketsToTransport(const PacketList& packets, 70 bool PacedSender::SendPacketsToTransport(const PacketList& packets,
46 PacketList* packets_not_sent) { 71 PacketList* packets_not_sent,
72 bool retransmit) {
47 UpdateBurstSize(packets.size()); 73 UpdateBurstSize(packets.size());
48 74
49 if (!packets_not_sent->empty()) { 75 if (!packets_not_sent->empty()) {
50 packets_not_sent->insert( 76 packets_not_sent->insert(
51 packets_not_sent->end(), packets.begin(), packets.end()); 77 packets_not_sent->end(), packets.begin(), packets.end());
52 return true; 78 return true;
53 } 79 }
54 80
55 PacketList packets_to_send; 81 PacketList packets_to_send;
56 PacketList::const_iterator first_to_store_it = packets.begin(); 82 PacketList::const_iterator first_to_store_it = packets.begin();
57 83
58 size_t max_packets_to_send_now = burst_size_ - packets_sent_in_burst_; 84 size_t max_packets_to_send_now = burst_size_ - packets_sent_in_burst_;
59 85
60 if (max_packets_to_send_now > 0) { 86 if (max_packets_to_send_now > 0) {
61 size_t packets_to_send_now = 87 size_t packets_to_send_now =
62 std::min(max_packets_to_send_now, packets.size()); 88 std::min(max_packets_to_send_now, packets.size());
63 89
64 std::advance(first_to_store_it, packets_to_send_now); 90 std::advance(first_to_store_it, packets_to_send_now);
65 packets_to_send.insert( 91 packets_to_send.insert(
66 packets_to_send.begin(), packets.begin(), first_to_store_it); 92 packets_to_send.begin(), packets.begin(), first_to_store_it);
67 } 93 }
68 packets_not_sent->insert( 94 packets_not_sent->insert(
69 packets_not_sent->end(), first_to_store_it, packets.end()); 95 packets_not_sent->end(), first_to_store_it, packets.end());
70 packets_sent_in_burst_ = packets_to_send.size(); 96 packets_sent_in_burst_ = packets_to_send.size();
71 if (packets_to_send.empty()) 97 if (packets_to_send.empty())
72 return true; 98 return true;
73 99
100 for (PacketList::iterator it = packets_to_send.begin();
101 it != packets_to_send.end();
102 ++it) {
103 LogPacketEvent(*it, retransmit);
104 }
105
74 return TransmitPackets(packets_to_send); 106 return TransmitPackets(packets_to_send);
75 } 107 }
76 108
77 bool PacedSender::SendRtcpPacket(const Packet& packet) { 109 bool PacedSender::SendRtcpPacket(const Packet& packet) {
78 // We pass the RTCP packets straight through. 110 // We pass the RTCP packets straight through.
79 return transport_->SendPacket(packet); 111 return transport_->SendPacket(packet);
80 } 112 }
81 113
82 void PacedSender::ScheduleNextSend() { 114 void PacedSender::ScheduleNextSend() {
83 base::TimeDelta time_to_next = 115 base::TimeDelta time_to_next =
(...skipping 20 matching lines...) Expand all
104 136
105 size_t packets_to_send = burst_size_; 137 size_t packets_to_send = burst_size_;
106 PacketList packets_to_resend; 138 PacketList packets_to_resend;
107 139
108 // Send our re-send packets first. 140 // Send our re-send packets first.
109 if (!resend_packet_list_.empty()) { 141 if (!resend_packet_list_.empty()) {
110 PacketList::iterator it = resend_packet_list_.begin(); 142 PacketList::iterator it = resend_packet_list_.begin();
111 size_t packets_to_send_now = 143 size_t packets_to_send_now =
112 std::min(packets_to_send, resend_packet_list_.size()); 144 std::min(packets_to_send, resend_packet_list_.size());
113 std::advance(it, packets_to_send_now); 145 std::advance(it, packets_to_send_now);
146
147 for (PacketList::iterator log_it = resend_packet_list_.begin();
148 log_it != it;
149 ++log_it) {
150 LogPacketEvent(*log_it, true);
151 }
114 packets_to_resend.insert( 152 packets_to_resend.insert(
115 packets_to_resend.begin(), resend_packet_list_.begin(), it); 153 packets_to_resend.begin(), resend_packet_list_.begin(), it);
116 resend_packet_list_.erase(resend_packet_list_.begin(), it); 154 resend_packet_list_.erase(resend_packet_list_.begin(), it);
117 packets_to_send -= packets_to_resend.size(); 155 packets_to_send -= packets_to_resend.size();
118 } 156 }
119 if (!packet_list_.empty() && packets_to_send > 0) { 157 if (!packet_list_.empty() && packets_to_send > 0) {
120 PacketList::iterator it = packet_list_.begin(); 158 PacketList::iterator it = packet_list_.begin();
121 size_t packets_to_send_now = std::min(packets_to_send, packet_list_.size()); 159 size_t packets_to_send_now = std::min(packets_to_send, packet_list_.size());
160 std::advance(it, packets_to_send_now);
122 161
123 std::advance(it, packets_to_send_now); 162 for (PacketList::iterator log_it = packet_list_.begin(); log_it != it;
163 ++log_it) {
164 LogPacketEvent(*log_it, false);
165 }
166
124 packets_to_resend.insert(packets_to_resend.end(), packet_list_.begin(), it); 167 packets_to_resend.insert(packets_to_resend.end(), packet_list_.begin(), it);
125 packet_list_.erase(packet_list_.begin(), it); 168 packet_list_.erase(packet_list_.begin(), it);
126 169
127 if (packet_list_.empty()) { 170 if (packet_list_.empty()) {
128 burst_size_ = 1; // Reset burst size after we sent the last stored packet 171 burst_size_ = 1; // Reset burst size after we sent the last stored packet
129 packets_sent_in_burst_ = 0; 172 packets_sent_in_burst_ = 0;
130 } else { 173 } else {
131 packets_sent_in_burst_ = packets_to_resend.size(); 174 packets_sent_in_burst_ = packets_to_resend.size();
132 } 175 }
133 } 176 }
(...skipping 10 matching lines...) Expand all
144 187
145 void PacedSender::UpdateBurstSize(size_t packets_to_send) { 188 void PacedSender::UpdateBurstSize(size_t packets_to_send) {
146 packets_to_send = std::max(packets_to_send, 189 packets_to_send = std::max(packets_to_send,
147 resend_packet_list_.size() + packet_list_.size()); 190 resend_packet_list_.size() + packet_list_.size());
148 191
149 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up. 192 packets_to_send += (kPacingMaxBurstsPerFrame - 1); // Round up.
150 burst_size_ = 193 burst_size_ =
151 std::max(packets_to_send / kPacingMaxBurstsPerFrame, burst_size_); 194 std::max(packets_to_send / kPacingMaxBurstsPerFrame, burst_size_);
152 } 195 }
153 196
197 void PacedSender::LogPacketEvent(const Packet& packet, bool retransmit) {
198 // Get SSRC from packet and compare with the audio_ssrc / video_ssrc to see
199 // if the packet is audio or video.
200 DCHECK_GE(packet.size(), 12u);
201 base::BigEndianReader reader(reinterpret_cast<const char*>(&packet[8]), 4);
202 uint32 ssrc;
203 bool success = reader.ReadU32(&ssrc);
204 DCHECK(success);
205 bool is_audio;
Alpha Left Google 2014/03/13 19:56:14 This can be simplified as: DCHECK(ssrc == audio_s
imcheng 2014/03/13 21:48:58 This changes the behavior though. If we get a pack
206 if (ssrc == audio_ssrc_) {
207 is_audio = true;
208 } else if (ssrc == video_ssrc_) {
209 is_audio = false;
210 } else {
211 DVLOG(3) << "Got unknown ssrc " << ssrc << " when logging packet event";
212 return;
213 }
214
215 CastLoggingEvent event = GetLoggingEvent(is_audio, retransmit);
216
217 logging_->InsertSinglePacketEvent(clock_->NowTicks(), event, packet);
218 }
219
154 } // namespace transport 220 } // namespace transport
155 } // namespace cast 221 } // namespace cast
156 } // namespace media 222 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698