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

Side by Side Diff: media/cast/rtcp/rtcp.cc

Issue 69603002: Incorporating logging into Cast (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing errors Created 7 years, 1 month 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/rtcp/rtcp.h" 5 #include "media/cast/rtcp/rtcp.h"
6 6
7 #include "base/debug/trace_event.h"
8 #include "base/rand_util.h" 7 #include "base/rand_util.h"
9 #include "media/cast/cast_config.h" 8 #include "media/cast/cast_config.h"
10 #include "media/cast/cast_defines.h" 9 #include "media/cast/cast_defines.h"
10 #include "media/cast/cast_environment.h"
11 #include "media/cast/rtcp/rtcp_defines.h" 11 #include "media/cast/rtcp/rtcp_defines.h"
12 #include "media/cast/rtcp/rtcp_receiver.h" 12 #include "media/cast/rtcp/rtcp_receiver.h"
13 #include "media/cast/rtcp/rtcp_sender.h" 13 #include "media/cast/rtcp/rtcp_sender.h"
14 #include "media/cast/rtcp/rtcp_utility.h" 14 #include "media/cast/rtcp/rtcp_utility.h"
15 #include "net/base/big_endian.h" 15 #include "net/base/big_endian.h"
16 16
17 namespace media { 17 namespace media {
18 namespace cast { 18 namespace cast {
19 19
20 static const int kMaxRttMs = 1000000; // 1000 seconds. 20 static const int kMaxRttMs = 1000000; // 1000 seconds.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 virtual void OnReceivedSendReportRequest() OVERRIDE { 79 virtual void OnReceivedSendReportRequest() OVERRIDE {
80 rtcp_->OnReceivedSendReportRequest(); 80 rtcp_->OnReceivedSendReportRequest();
81 } 81 }
82 82
83 private: 83 private:
84 Rtcp* rtcp_; 84 Rtcp* rtcp_;
85 }; 85 };
86 86
87 Rtcp::Rtcp(base::TickClock* clock, 87 Rtcp::Rtcp(scoped_refptr<CastEnvironment> cast_environment,
88 RtcpSenderFeedback* sender_feedback, 88 RtcpSenderFeedback* sender_feedback,
89 PacedPacketSender* paced_packet_sender, 89 PacedPacketSender* paced_packet_sender,
90 RtpSenderStatistics* rtp_sender_statistics, 90 RtpSenderStatistics* rtp_sender_statistics,
91 RtpReceiverStatistics* rtp_receiver_statistics, 91 RtpReceiverStatistics* rtp_receiver_statistics,
92 RtcpMode rtcp_mode, 92 RtcpMode rtcp_mode,
93 const base::TimeDelta& rtcp_interval, 93 const base::TimeDelta& rtcp_interval,
94 bool sending_media, 94 bool sending_media,
95 uint32 local_ssrc, 95 uint32 local_ssrc,
96 const std::string& c_name) 96 const std::string& c_name)
97 : rtcp_interval_(rtcp_interval), 97 : rtcp_interval_(rtcp_interval),
98 rtcp_mode_(rtcp_mode), 98 rtcp_mode_(rtcp_mode),
99 sending_media_(sending_media), 99 sending_media_(sending_media),
100 local_ssrc_(local_ssrc), 100 local_ssrc_(local_ssrc),
101 rtp_sender_statistics_(rtp_sender_statistics), 101 rtp_sender_statistics_(rtp_sender_statistics),
102 rtp_receiver_statistics_(rtp_receiver_statistics), 102 rtp_receiver_statistics_(rtp_receiver_statistics),
103 receiver_feedback_(new LocalRtcpReceiverFeedback(this)), 103 receiver_feedback_(new LocalRtcpReceiverFeedback(this)),
104 rtt_feedback_(new LocalRtcpRttFeedback(this)), 104 rtt_feedback_(new LocalRtcpRttFeedback(this)),
105 rtcp_sender_(new RtcpSender(paced_packet_sender, local_ssrc, c_name)), 105 rtcp_sender_(new RtcpSender(cast_environment, paced_packet_sender,
106 local_ssrc, c_name)),
106 last_report_sent_(0), 107 last_report_sent_(0),
107 last_report_received_(0), 108 last_report_received_(0),
108 last_received_rtp_timestamp_(0), 109 last_received_rtp_timestamp_(0),
109 last_received_ntp_seconds_(0), 110 last_received_ntp_seconds_(0),
110 last_received_ntp_fraction_(0), 111 last_received_ntp_fraction_(0),
111 min_rtt_(base::TimeDelta::FromMilliseconds(kMaxRttMs)), 112 min_rtt_(base::TimeDelta::FromMilliseconds(kMaxRttMs)),
112 number_of_rtt_in_avg_(0), 113 number_of_rtt_in_avg_(0),
113 clock_(clock) { 114 cast_environment_(cast_environment) {
114 rtcp_receiver_.reset(new RtcpReceiver(sender_feedback, 115 rtcp_receiver_.reset(new RtcpReceiver(cast_environment,
116 sender_feedback,
115 receiver_feedback_.get(), 117 receiver_feedback_.get(),
116 rtt_feedback_.get(), 118 rtt_feedback_.get(),
117 local_ssrc)); 119 local_ssrc));
118 } 120 }
119 121
120 Rtcp::~Rtcp() {} 122 Rtcp::~Rtcp() {}
121 123
122 // static 124 // static
123 bool Rtcp::IsRtcpPacket(const uint8* packet, size_t length) { 125 bool Rtcp::IsRtcpPacket(const uint8* packet, size_t length) {
124 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet"; 126 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (!rtcp_parser.IsValid()) { 159 if (!rtcp_parser.IsValid()) {
158 // Silently ignore packet. 160 // Silently ignore packet.
159 DLOG(ERROR) << "Received invalid RTCP packet"; 161 DLOG(ERROR) << "Received invalid RTCP packet";
160 return; 162 return;
161 } 163 }
162 rtcp_receiver_->IncomingRtcpPacket(&rtcp_parser); 164 rtcp_receiver_->IncomingRtcpPacket(&rtcp_parser);
163 } 165 }
164 166
165 void Rtcp::SendRtcpCast(const RtcpCastMessage& cast_message) { 167 void Rtcp::SendRtcpCast(const RtcpCastMessage& cast_message) {
166 uint32 packet_type_flags = 0; 168 uint32 packet_type_flags = 0;
167 base::TimeTicks now = clock_->NowTicks(); 169 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
168 170
169 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { 171 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) {
170 if (sending_media_) { 172 if (sending_media_) {
171 packet_type_flags = RtcpSender::kRtcpSr; 173 packet_type_flags = RtcpSender::kRtcpSr;
172 } else { 174 } else {
173 packet_type_flags = RtcpSender::kRtcpRr; 175 packet_type_flags = RtcpSender::kRtcpRr;
174 } 176 }
175 } 177 }
176 packet_type_flags |= RtcpSender::kRtcpCast; 178 packet_type_flags |= RtcpSender::kRtcpCast;
177 179
180 cast_environment_->Logging()->InsertGenericEvent(kAckSent,
181 cast_message.ack_frame_id_);
182
178 SendRtcp(now, packet_type_flags, 0, &cast_message); 183 SendRtcp(now, packet_type_flags, 0, &cast_message);
179 } 184 }
180 185
181 void Rtcp::SendRtcpPli(uint32 pli_remote_ssrc) { 186 void Rtcp::SendRtcpPli(uint32 pli_remote_ssrc) {
182 uint32 packet_type_flags = 0; 187 uint32 packet_type_flags = 0;
183 base::TimeTicks now = clock_->NowTicks(); 188 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
184 189
185 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { 190 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) {
186 if (sending_media_) { 191 if (sending_media_) {
187 packet_type_flags = RtcpSender::kRtcpSr; 192 packet_type_flags = RtcpSender::kRtcpSr;
188 } else { 193 } else {
189 packet_type_flags = RtcpSender::kRtcpRr; 194 packet_type_flags = RtcpSender::kRtcpRr;
190 } 195 }
191 } 196 }
192 packet_type_flags |= RtcpSender::kRtcpPli; 197 packet_type_flags |= RtcpSender::kRtcpPli;
193 SendRtcp(now, packet_type_flags, pli_remote_ssrc, NULL); 198 SendRtcp(now, packet_type_flags, pli_remote_ssrc, NULL);
194 } 199 }
195 200
196 void Rtcp::SendRtcpReport(uint32 media_ssrc) { 201 void Rtcp::SendRtcpReport(uint32 media_ssrc) {
197 uint32 packet_type_flags; 202 uint32 packet_type_flags;
198 base::TimeTicks now = clock_->NowTicks(); 203 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
199 if (sending_media_) { 204 if (sending_media_) {
200 packet_type_flags = RtcpSender::kRtcpSr; 205 packet_type_flags = RtcpSender::kRtcpSr;
201 } else { 206 } else {
202 packet_type_flags = RtcpSender::kRtcpRr; 207 packet_type_flags = RtcpSender::kRtcpRr;
203 } 208 }
204 SendRtcp(now, packet_type_flags, media_ssrc, NULL); 209 SendRtcp(now, packet_type_flags, media_ssrc, NULL);
205 } 210 }
206 211
207 void Rtcp::SendRtcp(const base::TimeTicks& now, 212 void Rtcp::SendRtcp(const base::TimeTicks& now,
208 uint32 packet_type_flags, 213 uint32 packet_type_flags,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } else { 253 } else {
249 RtcpReportBlock report_block; 254 RtcpReportBlock report_block;
250 report_block.remote_ssrc = 0; // Not needed to set send side. 255 report_block.remote_ssrc = 0; // Not needed to set send side.
251 report_block.media_ssrc = media_ssrc; // SSRC of the RTP packet sender. 256 report_block.media_ssrc = media_ssrc; // SSRC of the RTP packet sender.
252 if (rtp_receiver_statistics_) { 257 if (rtp_receiver_statistics_) {
253 rtp_receiver_statistics_->GetStatistics( 258 rtp_receiver_statistics_->GetStatistics(
254 &report_block.fraction_lost, 259 &report_block.fraction_lost,
255 &report_block.cumulative_lost, 260 &report_block.cumulative_lost,
256 &report_block.extended_high_sequence_number, 261 &report_block.extended_high_sequence_number,
257 &report_block.jitter); 262 &report_block.jitter);
263 cast_environment_->Logging()->InsertGenericEvent(kJitterMs,
264 report_block.jitter);
265 cast_environment_->Logging()->InsertGenericEvent(kPacketLoss,
266 report_block.fraction_lost);
267
258 } 268 }
259 269
260 report_block.last_sr = last_report_received_; 270 report_block.last_sr = last_report_received_;
261 if (!time_last_report_received_.is_null()) { 271 if (!time_last_report_received_.is_null()) {
262 uint32 delay_seconds = 0; 272 uint32 delay_seconds = 0;
263 uint32 delay_fraction = 0; 273 uint32 delay_fraction = 0;
264 base::TimeDelta delta = now - time_last_report_received_; 274 base::TimeDelta delta = now - time_last_report_received_;
265 ConvertTimeToFractions(delta.InMicroseconds(), 275 ConvertTimeToFractions(delta.InMicroseconds(),
266 &delay_seconds, 276 &delay_seconds,
267 &delay_fraction); 277 &delay_fraction);
(...skipping 16 matching lines...) Expand all
284 media_ssrc, 294 media_ssrc,
285 NULL, 295 NULL,
286 &rrtr, 296 &rrtr,
287 cast_message); 297 cast_message);
288 } 298 }
289 } 299 }
290 300
291 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { 301 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) {
292 last_report_received_ = (ntp_seconds << 16) + (ntp_fraction >> 16); 302 last_report_received_ = (ntp_seconds << 16) + (ntp_fraction >> 16);
293 303
294 base::TimeTicks now = clock_->NowTicks(); 304 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
295 time_last_report_received_ = now; 305 time_last_report_received_ = now;
296 } 306 }
297 307
298 void Rtcp::OnReceivedLipSyncInfo(uint32 rtp_timestamp, 308 void Rtcp::OnReceivedLipSyncInfo(uint32 rtp_timestamp,
299 uint32 ntp_seconds, 309 uint32 ntp_seconds,
300 uint32 ntp_fraction) { 310 uint32 ntp_fraction) {
301 last_received_rtp_timestamp_ = rtp_timestamp; 311 last_received_rtp_timestamp_ = rtp_timestamp;
302 last_received_ntp_seconds_ = ntp_seconds; 312 last_received_ntp_seconds_ = ntp_seconds;
303 last_received_ntp_fraction_ = ntp_fraction; 313 last_received_ntp_fraction_ = ntp_fraction;
304 } 314 }
305 315
306 void Rtcp::OnReceivedSendReportRequest() { 316 void Rtcp::OnReceivedSendReportRequest() {
307 base::TimeTicks now = clock_->NowTicks(); 317 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
308 318
309 // Trigger a new RTCP report at next timer. 319 // Trigger a new RTCP report at next timer.
310 next_time_to_send_rtcp_ = now; 320 next_time_to_send_rtcp_ = now;
311 } 321 }
312 322
313 bool Rtcp::RtpTimestampInSenderTime(int frequency, uint32 rtp_timestamp, 323 bool Rtcp::RtpTimestampInSenderTime(int frequency, uint32 rtp_timestamp,
314 base::TimeTicks* rtp_timestamp_in_ticks) const { 324 base::TimeTicks* rtp_timestamp_in_ticks) const {
315 if (last_received_ntp_seconds_ == 0) return false; 325 if (last_received_ntp_seconds_ == 0) return false;
316 326
317 int wrap = CheckForWrapAround(rtp_timestamp, last_received_rtp_timestamp_); 327 int wrap = CheckForWrapAround(rtp_timestamp, last_received_rtp_timestamp_);
(...skipping 22 matching lines...) Expand all
340 base::TimeDelta::FromMilliseconds(rtp_time_diff_ms); 350 base::TimeDelta::FromMilliseconds(rtp_time_diff_ms);
341 return true; 351 return true;
342 } 352 }
343 353
344 void Rtcp::OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, 354 void Rtcp::OnReceivedDelaySinceLastReport(uint32 receivers_ssrc,
345 uint32 last_report, 355 uint32 last_report,
346 uint32 delay_since_last_report) { 356 uint32 delay_since_last_report) {
347 if (last_report_sent_ != last_report) return; // Feedback on another report. 357 if (last_report_sent_ != last_report) return; // Feedback on another report.
348 if (time_last_report_sent_.is_null()) return; 358 if (time_last_report_sent_.is_null()) return;
349 359
350 base::TimeDelta sender_delay = clock_->NowTicks() - time_last_report_sent_; 360 base::TimeDelta sender_delay = cast_environment_->Clock()->NowTicks()
361 - time_last_report_sent_;
351 UpdateRtt(sender_delay, ConvertFromNtpDiff(delay_since_last_report)); 362 UpdateRtt(sender_delay, ConvertFromNtpDiff(delay_since_last_report));
352 } 363 }
353 364
354 void Rtcp::UpdateRtt(const base::TimeDelta& sender_delay, 365 void Rtcp::UpdateRtt(const base::TimeDelta& sender_delay,
355 const base::TimeDelta& receiver_delay) { 366 const base::TimeDelta& receiver_delay) {
356 base::TimeDelta rtt = sender_delay - receiver_delay; 367 base::TimeDelta rtt = sender_delay - receiver_delay;
357 rtt = std::max(rtt, base::TimeDelta::FromMilliseconds(1)); 368 rtt = std::max(rtt, base::TimeDelta::FromMilliseconds(1));
358 rtt_ = rtt; 369 rtt_ = rtt;
359 min_rtt_ = std::min(min_rtt_, rtt); 370 min_rtt_ = std::min(min_rtt_, rtt);
360 max_rtt_ = std::max(max_rtt_, rtt); 371 max_rtt_ = std::max(max_rtt_, rtt);
361 372
362 if (number_of_rtt_in_avg_ != 0) { 373 if (number_of_rtt_in_avg_ != 0) {
363 float ac = static_cast<float>(number_of_rtt_in_avg_); 374 float ac = static_cast<float>(number_of_rtt_in_avg_);
364 avg_rtt_ms_= ((ac / (ac + 1.0)) * avg_rtt_ms_) + 375 avg_rtt_ms_= ((ac / (ac + 1.0)) * avg_rtt_ms_) +
365 ((1.0 / (ac + 1.0)) * rtt.InMilliseconds()); 376 ((1.0 / (ac + 1.0)) * rtt.InMilliseconds());
366 } else { 377 } else {
367 avg_rtt_ms_ = rtt.InMilliseconds(); 378 avg_rtt_ms_ = rtt.InMilliseconds();
368 } 379 }
369 number_of_rtt_in_avg_++; 380 number_of_rtt_in_avg_++;
370 TRACE_COUNTER_ID1("cast_rtcp", "RTT", local_ssrc_, rtt.InMilliseconds());
371 } 381 }
372 382
373 bool Rtcp::Rtt(base::TimeDelta* rtt, 383 bool Rtcp::Rtt(base::TimeDelta* rtt,
374 base::TimeDelta* avg_rtt, 384 base::TimeDelta* avg_rtt,
375 base::TimeDelta* min_rtt, 385 base::TimeDelta* min_rtt,
376 base::TimeDelta* max_rtt) const { 386 base::TimeDelta* max_rtt) const {
377 DCHECK(rtt) << "Invalid argument"; 387 DCHECK(rtt) << "Invalid argument";
378 DCHECK(avg_rtt) << "Invalid argument"; 388 DCHECK(avg_rtt) << "Invalid argument";
379 DCHECK(min_rtt) << "Invalid argument"; 389 DCHECK(min_rtt) << "Invalid argument";
380 DCHECK(max_rtt) << "Invalid argument"; 390 DCHECK(max_rtt) << "Invalid argument";
381 391
382 if (number_of_rtt_in_avg_ == 0) return false; 392 if (number_of_rtt_in_avg_ == 0) return false;
393 cast_environment_->Logging()->InsertGenericEvent(kRttMs,
394 rtt->InMilliseconds());
383 395
384 *rtt = rtt_; 396 *rtt = rtt_;
385 *avg_rtt = base::TimeDelta::FromMilliseconds(avg_rtt_ms_); 397 *avg_rtt = base::TimeDelta::FromMilliseconds(avg_rtt_ms_);
386 *min_rtt = min_rtt_; 398 *min_rtt = min_rtt_;
387 *max_rtt = max_rtt_; 399 *max_rtt = max_rtt_;
388 return true; 400 return true;
389 } 401 }
390 402
391 int Rtcp::CheckForWrapAround(uint32 new_timestamp, 403 int Rtcp::CheckForWrapAround(uint32 new_timestamp,
392 uint32 old_timestamp) const { 404 uint32 old_timestamp) const {
(...skipping 10 matching lines...) Expand all
403 return -1; 415 return -1;
404 } 416 }
405 return 0; 417 return 0;
406 } 418 }
407 419
408 void Rtcp::UpdateNextTimeToSendRtcp() { 420 void Rtcp::UpdateNextTimeToSendRtcp() {
409 int random = base::RandInt(0, 999); 421 int random = base::RandInt(0, 999);
410 base::TimeDelta time_to_next = (rtcp_interval_ / 2) + 422 base::TimeDelta time_to_next = (rtcp_interval_ / 2) +
411 (rtcp_interval_ * random / 1000); 423 (rtcp_interval_ * random / 1000);
412 424
413 base::TimeTicks now = clock_->NowTicks(); 425 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
414 next_time_to_send_rtcp_ = now + time_to_next; 426 next_time_to_send_rtcp_ = now + time_to_next;
415 } 427 }
416 428
417 } // namespace cast 429 } // namespace cast
418 } // namespace media 430 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698