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

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

Issue 499433002: Minor code redundancy cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | media/cast/net/rtcp/rtcp_sender.h » ('j') | media/cast/net/rtcp/rtcp_sender.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/net/rtcp/rtcp.h" 5 #include "media/cast/net/rtcp/rtcp.h"
6 6
7 #include "media/cast/cast_config.h" 7 #include "media/cast/cast_config.h"
8 #include "media/cast/cast_defines.h" 8 #include "media/cast/cast_defines.h"
9 #include "media/cast/cast_environment.h" 9 #include "media/cast/cast_environment.h"
10 #include "media/cast/net/cast_transport_defines.h" 10 #include "media/cast/net/cast_transport_defines.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 } 191 }
192 return !receiver_log->empty(); 192 return !receiver_log->empty();
193 } 193 }
194 194
195 void Rtcp::SendRtcpFromRtpReceiver( 195 void Rtcp::SendRtcpFromRtpReceiver(
196 const RtcpCastMessage* cast_message, 196 const RtcpCastMessage* cast_message,
197 base::TimeDelta target_delay, 197 base::TimeDelta target_delay,
198 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events, 198 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events,
199 RtpReceiverStatistics* rtp_receiver_statistics) { 199 RtpReceiverStatistics* rtp_receiver_statistics) {
200 uint32 packet_type_flags = 0;
201
202 base::TimeTicks now = clock_->NowTicks(); 200 base::TimeTicks now = clock_->NowTicks();
203 RtcpReportBlock report_block; 201 RtcpReportBlock report_block;
204 RtcpReceiverReferenceTimeReport rrtr; 202 RtcpReceiverReferenceTimeReport rrtr;
205 203
206 // Attach our NTP to all RTCP packets; with this information a "smart" sender 204 // Attach our NTP to all RTCP packets; with this information a "smart" sender
207 // can make decisions based on how old the RTCP message is. 205 // can make decisions based on how old the RTCP message is.
208 packet_type_flags |= kRtcpRrtr;
209 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); 206 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction);
210 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); 207 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction);
211 208
212 if (cast_message) {
213 packet_type_flags |= kRtcpCast;
214 }
215 if (rtcp_events) {
216 packet_type_flags |= kRtcpReceiverLog;
217 }
218 // If RTCP is in compound mode then we always send a RR. 209 // If RTCP is in compound mode then we always send a RR.
Alpha Left Google 2014/08/21 20:18:23 This comment is invalid.
hubbe 2014/08/21 21:34:14 Removed.
219 if (rtp_receiver_statistics) { 210 if (rtp_receiver_statistics) {
220 packet_type_flags |= kRtcpRr;
221
222 report_block.remote_ssrc = 0; // Not needed to set send side. 211 report_block.remote_ssrc = 0; // Not needed to set send side.
223 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. 212 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender.
224 if (rtp_receiver_statistics) { 213 if (rtp_receiver_statistics) {
225 rtp_receiver_statistics->GetStatistics( 214 rtp_receiver_statistics->GetStatistics(
226 &report_block.fraction_lost, &report_block.cumulative_lost, 215 &report_block.fraction_lost, &report_block.cumulative_lost,
227 &report_block.extended_high_sequence_number, &report_block.jitter); 216 &report_block.extended_high_sequence_number, &report_block.jitter);
228 } 217 }
229 218
230 report_block.last_sr = last_report_truncated_ntp_; 219 report_block.last_sr = last_report_truncated_ntp_;
231 if (!time_last_report_received_.is_null()) { 220 if (!time_last_report_received_.is_null()) {
232 uint32 delay_seconds = 0; 221 uint32 delay_seconds = 0;
233 uint32 delay_fraction = 0; 222 uint32 delay_fraction = 0;
234 base::TimeDelta delta = now - time_last_report_received_; 223 base::TimeDelta delta = now - time_last_report_received_;
235 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, 224 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds,
236 &delay_fraction); 225 &delay_fraction);
237 report_block.delay_since_last_sr = 226 report_block.delay_since_last_sr =
238 ConvertToNtpDiff(delay_seconds, delay_fraction); 227 ConvertToNtpDiff(delay_seconds, delay_fraction);
239 } else { 228 } else {
240 report_block.delay_since_last_sr = 0; 229 report_block.delay_since_last_sr = 0;
241 } 230 }
242 } 231 }
243 rtcp_sender_->SendRtcpFromRtpReceiver(packet_type_flags, 232 rtcp_sender_->SendRtcpFromRtpReceiver(
244 &report_block, 233 rtp_receiver_statistics ? &report_block : NULL,
245 &rrtr, 234 &rrtr,
246 cast_message, 235 cast_message,
247 rtcp_events, 236 rtcp_events,
248 target_delay); 237 target_delay);
249 } 238 }
250 239
251 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, 240 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time,
252 uint32 current_time_as_rtp_timestamp, 241 uint32 current_time_as_rtp_timestamp,
253 uint32 send_packet_count, 242 uint32 send_packet_count,
254 size_t send_octet_count) { 243 size_t send_octet_count) {
255 uint32 packet_type_flags = kRtcpSr;
256 uint32 current_ntp_seconds = 0; 244 uint32 current_ntp_seconds = 0;
257 uint32 current_ntp_fractions = 0; 245 uint32 current_ntp_fractions = 0;
258 ConvertTimeTicksToNtp(current_time, &current_ntp_seconds, 246 ConvertTimeTicksToNtp(current_time, &current_ntp_seconds,
259 &current_ntp_fractions); 247 &current_ntp_fractions);
260 SaveLastSentNtpTime(current_time, current_ntp_seconds, 248 SaveLastSentNtpTime(current_time, current_ntp_seconds,
261 current_ntp_fractions); 249 current_ntp_fractions);
262 250
263 RtcpDlrrReportBlock dlrr; 251 RtcpDlrrReportBlock dlrr;
Alpha Left Google 2014/08/21 20:18:23 DLRR can be removed from the code. It's not mandat
hubbe 2014/08/21 21:34:14 Done.
252 RtcpDlrrReportBlock* dlrr_ptr = NULL;
264 if (!time_last_report_received_.is_null()) { 253 if (!time_last_report_received_.is_null()) {
265 packet_type_flags |= kRtcpDlrr; 254 dlrr_ptr = &dlrr;
266 dlrr.last_rr = last_report_truncated_ntp_; 255 dlrr.last_rr = last_report_truncated_ntp_;
267 uint32 delay_seconds = 0; 256 uint32 delay_seconds = 0;
268 uint32 delay_fraction = 0; 257 uint32 delay_fraction = 0;
269 base::TimeDelta delta = current_time - time_last_report_received_; 258 base::TimeDelta delta = current_time - time_last_report_received_;
270 // TODO(hclam): DLRR is not used by any receiver. Consider removing 259 // TODO(hclam): DLRR is not used by any receiver. Consider removing
271 // it. There is one race condition in the computation of the time for 260 // it. There is one race condition in the computation of the time for
272 // DLRR: current time is submitted to this method while 261 // DLRR: current time is submitted to this method while
273 // |time_last_report_received_| is updated just before that. This can 262 // |time_last_report_received_| is updated just before that. This can
274 // happen if current time is not submitted synchronously. 263 // happen if current time is not submitted synchronously.
275 if (delta < base::TimeDelta()) 264 if (delta < base::TimeDelta())
276 delta = base::TimeDelta(); 265 delta = base::TimeDelta();
277 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, 266 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds,
278 &delay_fraction); 267 &delay_fraction);
279 268
280 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); 269 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction);
281 } 270 }
282 271
283 RtcpSenderInfo sender_info; 272 RtcpSenderInfo sender_info;
284 sender_info.ntp_seconds = current_ntp_seconds; 273 sender_info.ntp_seconds = current_ntp_seconds;
285 sender_info.ntp_fraction = current_ntp_fractions; 274 sender_info.ntp_fraction = current_ntp_fractions;
286 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; 275 sender_info.rtp_timestamp = current_time_as_rtp_timestamp;
287 sender_info.send_packet_count = send_packet_count; 276 sender_info.send_packet_count = send_packet_count;
288 sender_info.send_octet_count = send_octet_count; 277 sender_info.send_octet_count = send_octet_count;
289 278
290 rtcp_sender_->SendRtcpFromRtpSender(packet_type_flags, sender_info, dlrr); 279 rtcp_sender_->SendRtcpFromRtpSender(&sender_info, dlrr_ptr);
291 } 280 }
292 281
293 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { 282 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) {
294 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); 283 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction);
295 284
296 const base::TimeTicks now = clock_->NowTicks(); 285 const base::TimeTicks now = clock_->NowTicks();
297 time_last_report_received_ = now; 286 time_last_report_received_ = now;
298 287
299 // TODO(miu): This clock offset calculation does not account for packet 288 // TODO(miu): This clock offset calculation does not account for packet
300 // transit time over the network. End2EndTest.EvilNetwork confirms that this 289 // transit time over the network. End2EndTest.EvilNetwork confirms that this
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 421 }
433 422
434 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { 423 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) {
435 if (log_callback_.is_null()) 424 if (log_callback_.is_null())
436 return; 425 return;
437 log_callback_.Run(receiver_log); 426 log_callback_.Run(receiver_log);
438 } 427 }
439 428
440 } // namespace cast 429 } // namespace cast
441 } // namespace media 430 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/cast/net/rtcp/rtcp_sender.h » ('j') | media/cast/net/rtcp/rtcp_sender.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698