| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 value1 <<= 16; | 46 value1 <<= 16; |
| 47 value1 |= packet_id_or_zero; | 47 value1 |= packet_id_or_zero; |
| 48 value1 <<= 32; | 48 value1 <<= 32; |
| 49 value1 |= frame_rtp_timestamp; | 49 value1 |= frame_rtp_timestamp; |
| 50 return std::make_pair( | 50 return std::make_pair( |
| 51 value1, static_cast<uint64>(event_timestamp.ToInternalValue())); | 51 value1, static_cast<uint64>(event_timestamp.ToInternalValue())); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 RtpReceiverStatistics::RtpReceiverStatistics() : | |
| 57 fraction_lost(0), | |
| 58 cumulative_lost(0), | |
| 59 extended_high_sequence_number(0), | |
| 60 jitter(0) { | |
| 61 } | |
| 62 | |
| 63 Rtcp::Rtcp(const RtcpCastMessageCallback& cast_callback, | 56 Rtcp::Rtcp(const RtcpCastMessageCallback& cast_callback, |
| 64 const RtcpRttCallback& rtt_callback, | 57 const RtcpRttCallback& rtt_callback, |
| 65 const RtcpLogMessageCallback& log_callback, | 58 const RtcpLogMessageCallback& log_callback, |
| 66 base::TickClock* clock, | 59 base::TickClock* clock, |
| 67 PacedPacketSender* packet_sender, | 60 PacedPacketSender* packet_sender, |
| 68 uint32 local_ssrc, | 61 uint32 local_ssrc, |
| 69 uint32 remote_ssrc) | 62 uint32 remote_ssrc) |
| 70 : cast_callback_(cast_callback), | 63 : cast_callback_(cast_callback), |
| 71 rtt_callback_(rtt_callback), | 64 rtt_callback_(rtt_callback), |
| 72 log_callback_(log_callback), | 65 log_callback_(log_callback), |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 184 |
| 192 RtcpReceiverLogMessage::iterator tmp = i; | 185 RtcpReceiverLogMessage::iterator tmp = i; |
| 193 ++i; | 186 ++i; |
| 194 if (messages->empty()) { | 187 if (messages->empty()) { |
| 195 receiver_log->erase(tmp); | 188 receiver_log->erase(tmp); |
| 196 } | 189 } |
| 197 } | 190 } |
| 198 return !receiver_log->empty(); | 191 return !receiver_log->empty(); |
| 199 } | 192 } |
| 200 | 193 |
| 201 void Rtcp::SendRtcpFromRtpReceiver( | 194 RtcpTimeData Rtcp::ConvertToNTPAndSave(base::TimeTicks now) { |
| 202 const RtcpCastMessage* cast_message, | 195 RtcpTimeData ret; |
| 203 base::TimeDelta target_delay, | 196 ret.t = now; |
| 204 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events, | |
| 205 RtpReceiverStatistics* rtp_receiver_statistics) { | |
| 206 base::TimeTicks now = clock_->NowTicks(); | |
| 207 RtcpReportBlock report_block; | |
| 208 RtcpReceiverReferenceTimeReport rrtr; | |
| 209 | 197 |
| 210 // Attach our NTP to all RTCP packets; with this information a "smart" sender | 198 // Attach our NTP to all RTCP packets; with this information a "smart" sender |
| 211 // can make decisions based on how old the RTCP message is. | 199 // can make decisions based on how old the RTCP message is. |
| 212 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); | 200 ConvertTimeTicksToNtp(now, &ret.ntp_seconds, &ret.ntp_fraction); |
| 213 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); | 201 SaveLastSentNtpTime(now, ret.ntp_seconds, ret.ntp_fraction); |
| 202 return ret; |
| 203 } |
| 204 |
| 205 void Rtcp::SendRtcpFromRtpReceiver( |
| 206 RtcpTimeData time_data, |
| 207 const RtcpCastMessage* cast_message, |
| 208 base::TimeDelta target_delay, |
| 209 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
| 210 const RtpReceiverStatistics* rtp_receiver_statistics) const { |
| 211 RtcpReportBlock report_block; |
| 212 RtcpReceiverReferenceTimeReport rrtr; |
| 213 rrtr.ntp_seconds = time_data.ntp_seconds; |
| 214 rrtr.ntp_fraction = time_data.ntp_fraction; |
| 214 | 215 |
| 215 if (rtp_receiver_statistics) { | 216 if (rtp_receiver_statistics) { |
| 216 report_block.remote_ssrc = 0; // Not needed to set send side. | 217 report_block.remote_ssrc = 0; // Not needed to set send side. |
| 217 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. | 218 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. |
| 218 report_block.fraction_lost = rtp_receiver_statistics->fraction_lost; | 219 report_block.fraction_lost = rtp_receiver_statistics->fraction_lost; |
| 219 report_block.cumulative_lost = rtp_receiver_statistics->cumulative_lost; | 220 report_block.cumulative_lost = rtp_receiver_statistics->cumulative_lost; |
| 220 report_block.extended_high_sequence_number = | 221 report_block.extended_high_sequence_number = |
| 221 rtp_receiver_statistics->extended_high_sequence_number; | 222 rtp_receiver_statistics->extended_high_sequence_number; |
| 222 report_block.jitter = rtp_receiver_statistics->jitter; | 223 report_block.jitter = rtp_receiver_statistics->jitter; |
| 223 report_block.last_sr = last_report_truncated_ntp_; | 224 report_block.last_sr = last_report_truncated_ntp_; |
| 224 if (!time_last_report_received_.is_null()) { | 225 if (!time_last_report_received_.is_null()) { |
| 225 uint32 delay_seconds = 0; | 226 uint32 delay_seconds = 0; |
| 226 uint32 delay_fraction = 0; | 227 uint32 delay_fraction = 0; |
| 227 base::TimeDelta delta = now - time_last_report_received_; | 228 base::TimeDelta delta = time_data.t - time_last_report_received_; |
| 228 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 229 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
| 229 &delay_fraction); | 230 &delay_fraction); |
| 230 report_block.delay_since_last_sr = | 231 report_block.delay_since_last_sr = |
| 231 ConvertToNtpDiff(delay_seconds, delay_fraction); | 232 ConvertToNtpDiff(delay_seconds, delay_fraction); |
| 232 } else { | 233 } else { |
| 233 report_block.delay_since_last_sr = 0; | 234 report_block.delay_since_last_sr = 0; |
| 234 } | 235 } |
| 235 } | 236 } |
| 237 RtcpBuilder rtcp_builder(local_ssrc_); |
| 236 packet_sender_->SendRtcpPacket( | 238 packet_sender_->SendRtcpPacket( |
| 237 local_ssrc_, | 239 local_ssrc_, |
| 238 rtcp_builder_.BuildRtcpFromReceiver( | 240 rtcp_builder.BuildRtcpFromReceiver( |
| 239 rtp_receiver_statistics ? &report_block : NULL, | 241 rtp_receiver_statistics ? &report_block : NULL, |
| 240 &rrtr, | 242 &rrtr, |
| 241 cast_message, | 243 cast_message, |
| 242 rtcp_events, | 244 rtcp_events, |
| 243 target_delay)); | 245 target_delay)); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, | 248 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, |
| 247 uint32 current_time_as_rtp_timestamp, | 249 uint32 current_time_as_rtp_timestamp, |
| 248 uint32 send_packet_count, | 250 uint32 send_packet_count, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 382 } |
| 381 | 383 |
| 382 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { | 384 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { |
| 383 if (log_callback_.is_null()) | 385 if (log_callback_.is_null()) |
| 384 return; | 386 return; |
| 385 log_callback_.Run(receiver_log); | 387 log_callback_.Run(receiver_log); |
| 386 } | 388 } |
| 387 | 389 |
| 388 } // namespace cast | 390 } // namespace cast |
| 389 } // namespace media | 391 } // namespace media |
| OLD | NEW |