| OLD | NEW |
| 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/net/rtcp/rtcp.h" |
| 6 | 6 |
| 7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
| 8 #include "media/cast/cast_config.h" | 8 #include "media/cast/cast_config.h" |
| 9 #include "media/cast/cast_defines.h" | 9 #include "media/cast/cast_defines.h" |
| 10 #include "media/cast/cast_environment.h" | 10 #include "media/cast/cast_environment.h" |
| 11 #include "media/cast/rtcp/rtcp_defines.h" | 11 #include "media/cast/net/cast_transport_defines.h" |
| 12 #include "media/cast/rtcp/rtcp_receiver.h" | 12 #include "media/cast/net/rtcp/rtcp_defines.h" |
| 13 #include "media/cast/rtcp/rtcp_sender.h" | 13 #include "media/cast/net/rtcp/rtcp_receiver.h" |
| 14 #include "media/cast/rtcp/rtcp_utility.h" | 14 #include "media/cast/net/rtcp/rtcp_sender.h" |
| 15 #include "media/cast/transport/cast_transport_defines.h" | 15 #include "media/cast/net/rtcp/rtcp_utility.h" |
| 16 | 16 |
| 17 using base::TimeDelta; | 17 using base::TimeDelta; |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 namespace cast { | 20 namespace cast { |
| 21 | 21 |
| 22 static const int32 kMaxRttMs = 10000; // 10 seconds. | 22 static const int32 kMaxRttMs = 10000; // 10 seconds. |
| 23 static const int32 kMaxDelayMs = 2000; // 2 seconds. | 23 static const int32 kMaxDelayMs = 2000; // 2 seconds. |
| 24 | 24 |
| 25 class LocalRtcpRttFeedback : public RtcpRttFeedback { | 25 class LocalRtcpRttFeedback : public RtcpRttFeedback { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 Rtcp* rtcp_; | 37 Rtcp* rtcp_; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class LocalRtcpReceiverFeedback : public RtcpReceiverFeedback { | 40 class LocalRtcpReceiverFeedback : public RtcpReceiverFeedback { |
| 41 public: | 41 public: |
| 42 LocalRtcpReceiverFeedback(Rtcp* rtcp, | 42 LocalRtcpReceiverFeedback(Rtcp* rtcp, |
| 43 scoped_refptr<CastEnvironment> cast_environment) | 43 scoped_refptr<CastEnvironment> cast_environment) |
| 44 : rtcp_(rtcp), cast_environment_(cast_environment) {} | 44 : rtcp_(rtcp), cast_environment_(cast_environment) {} |
| 45 | 45 |
| 46 virtual void OnReceivedSenderReport( | 46 virtual void OnReceivedSenderReport( |
| 47 const transport::RtcpSenderInfo& remote_sender_info) OVERRIDE { | 47 const RtcpSenderInfo& remote_sender_info) OVERRIDE { |
| 48 rtcp_->OnReceivedNtp(remote_sender_info.ntp_seconds, | 48 rtcp_->OnReceivedNtp(remote_sender_info.ntp_seconds, |
| 49 remote_sender_info.ntp_fraction); | 49 remote_sender_info.ntp_fraction); |
| 50 if (remote_sender_info.send_packet_count != 0) { | 50 if (remote_sender_info.send_packet_count != 0) { |
| 51 rtcp_->OnReceivedLipSyncInfo(remote_sender_info.rtp_timestamp, | 51 rtcp_->OnReceivedLipSyncInfo(remote_sender_info.rtp_timestamp, |
| 52 remote_sender_info.ntp_seconds, | 52 remote_sender_info.ntp_seconds, |
| 53 remote_sender_info.ntp_fraction); | 53 remote_sender_info.ntp_fraction); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void OnReceiverReferenceTimeReport( | 57 virtual void OnReceiverReferenceTimeReport( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 rtcp_->OnReceivedReceiverLog(receiver_log); | 69 rtcp_->OnReceivedReceiverLog(receiver_log); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 Rtcp* rtcp_; | 73 Rtcp* rtcp_; |
| 74 scoped_refptr<CastEnvironment> cast_environment_; | 74 scoped_refptr<CastEnvironment> cast_environment_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 Rtcp::Rtcp(scoped_refptr<CastEnvironment> cast_environment, | 77 Rtcp::Rtcp(scoped_refptr<CastEnvironment> cast_environment, |
| 78 RtcpSenderFeedback* sender_feedback, | 78 RtcpSenderFeedback* sender_feedback, |
| 79 transport::CastTransportSender* const transport_sender, | 79 CastTransportSender* const transport_sender, |
| 80 transport::PacedPacketSender* paced_packet_sender, | 80 PacedPacketSender* paced_packet_sender, |
| 81 RtpReceiverStatistics* rtp_receiver_statistics, RtcpMode rtcp_mode, | 81 RtpReceiverStatistics* rtp_receiver_statistics, RtcpMode rtcp_mode, |
| 82 const base::TimeDelta& rtcp_interval, uint32 local_ssrc, | 82 const base::TimeDelta& rtcp_interval, uint32 local_ssrc, |
| 83 uint32 remote_ssrc, const std::string& c_name, | 83 uint32 remote_ssrc, const std::string& c_name, |
| 84 EventMediaType event_media_type) | 84 EventMediaType event_media_type) |
| 85 : cast_environment_(cast_environment), | 85 : cast_environment_(cast_environment), |
| 86 transport_sender_(transport_sender), | 86 transport_sender_(transport_sender), |
| 87 rtcp_interval_(rtcp_interval), | 87 rtcp_interval_(rtcp_interval), |
| 88 rtcp_mode_(rtcp_mode), | 88 rtcp_mode_(rtcp_mode), |
| 89 local_ssrc_(local_ssrc), | 89 local_ssrc_(local_ssrc), |
| 90 remote_ssrc_(remote_ssrc), | 90 remote_ssrc_(remote_ssrc), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 Rtcp::~Rtcp() {} | 110 Rtcp::~Rtcp() {} |
| 111 | 111 |
| 112 // static | 112 // static |
| 113 bool Rtcp::IsRtcpPacket(const uint8* packet, size_t length) { | 113 bool Rtcp::IsRtcpPacket(const uint8* packet, size_t length) { |
| 114 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet"; | 114 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet"; |
| 115 if (length < kMinLengthOfRtcp) return false; | 115 if (length < kMinLengthOfRtcp) return false; |
| 116 | 116 |
| 117 uint8 packet_type = packet[1]; | 117 uint8 packet_type = packet[1]; |
| 118 if (packet_type >= transport::kPacketTypeLow && | 118 if (packet_type >= kPacketTypeLow && |
| 119 packet_type <= transport::kPacketTypeHigh) { | 119 packet_type <= kPacketTypeHigh) { |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 return false; | 122 return false; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // static | 125 // static |
| 126 uint32 Rtcp::GetSsrcOfSender(const uint8* rtcp_buffer, size_t length) { | 126 uint32 Rtcp::GetSsrcOfSender(const uint8* rtcp_buffer, size_t length) { |
| 127 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet"; | 127 DCHECK_GE(length, kMinLengthOfRtcp) << "Invalid RTCP packet"; |
| 128 uint32 ssrc_of_sender; | 128 uint32 ssrc_of_sender; |
| 129 base::BigEndianReader big_endian_reader( | 129 base::BigEndianReader big_endian_reader( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 150 rtcp_receiver_->IncomingRtcpPacket(&rtcp_parser); | 150 rtcp_receiver_->IncomingRtcpPacket(&rtcp_parser); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void Rtcp::SendRtcpFromRtpReceiver( | 153 void Rtcp::SendRtcpFromRtpReceiver( |
| 154 const RtcpCastMessage* cast_message, | 154 const RtcpCastMessage* cast_message, |
| 155 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events) { | 155 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events) { |
| 156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 156 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 157 uint32 packet_type_flags = 0; | 157 uint32 packet_type_flags = 0; |
| 158 | 158 |
| 159 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 159 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 160 transport::RtcpReportBlock report_block; | 160 RtcpReportBlock report_block; |
| 161 RtcpReceiverReferenceTimeReport rrtr; | 161 RtcpReceiverReferenceTimeReport rrtr; |
| 162 | 162 |
| 163 // Attach our NTP to all RTCP packets; with this information a "smart" sender | 163 // Attach our NTP to all RTCP packets; with this information a "smart" sender |
| 164 // can make decisions based on how old the RTCP message is. | 164 // can make decisions based on how old the RTCP message is. |
| 165 packet_type_flags |= transport::kRtcpRrtr; | 165 packet_type_flags |= kRtcpRrtr; |
| 166 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); | 166 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); |
| 167 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); | 167 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); |
| 168 | 168 |
| 169 if (cast_message) { | 169 if (cast_message) { |
| 170 packet_type_flags |= transport::kRtcpCast; | 170 packet_type_flags |= kRtcpCast; |
| 171 } | 171 } |
| 172 if (rtcp_events) { | 172 if (rtcp_events) { |
| 173 packet_type_flags |= transport::kRtcpReceiverLog; | 173 packet_type_flags |= kRtcpReceiverLog; |
| 174 } | 174 } |
| 175 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { | 175 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { |
| 176 packet_type_flags |= transport::kRtcpRr; | 176 packet_type_flags |= kRtcpRr; |
| 177 | 177 |
| 178 report_block.remote_ssrc = 0; // Not needed to set send side. | 178 report_block.remote_ssrc = 0; // Not needed to set send side. |
| 179 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. | 179 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. |
| 180 if (rtp_receiver_statistics_) { | 180 if (rtp_receiver_statistics_) { |
| 181 rtp_receiver_statistics_->GetStatistics( | 181 rtp_receiver_statistics_->GetStatistics( |
| 182 &report_block.fraction_lost, &report_block.cumulative_lost, | 182 &report_block.fraction_lost, &report_block.cumulative_lost, |
| 183 &report_block.extended_high_sequence_number, &report_block.jitter); | 183 &report_block.extended_high_sequence_number, &report_block.jitter); |
| 184 } | 184 } |
| 185 | 185 |
| 186 report_block.last_sr = last_report_truncated_ntp_; | 186 report_block.last_sr = last_report_truncated_ntp_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 201 &report_block, | 201 &report_block, |
| 202 &rrtr, | 202 &rrtr, |
| 203 cast_message, | 203 cast_message, |
| 204 rtcp_events, | 204 rtcp_events, |
| 205 target_delay_); | 205 target_delay_); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, | 208 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, |
| 209 uint32 current_time_as_rtp_timestamp) { | 209 uint32 current_time_as_rtp_timestamp) { |
| 210 DCHECK(transport_sender_); | 210 DCHECK(transport_sender_); |
| 211 uint32 packet_type_flags = transport::kRtcpSr; | 211 uint32 packet_type_flags = kRtcpSr; |
| 212 uint32 current_ntp_seconds = 0; | 212 uint32 current_ntp_seconds = 0; |
| 213 uint32 current_ntp_fractions = 0; | 213 uint32 current_ntp_fractions = 0; |
| 214 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, | 214 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, |
| 215 ¤t_ntp_fractions); | 215 ¤t_ntp_fractions); |
| 216 SaveLastSentNtpTime(current_time, current_ntp_seconds, | 216 SaveLastSentNtpTime(current_time, current_ntp_seconds, |
| 217 current_ntp_fractions); | 217 current_ntp_fractions); |
| 218 | 218 |
| 219 transport::RtcpDlrrReportBlock dlrr; | 219 RtcpDlrrReportBlock dlrr; |
| 220 if (!time_last_report_received_.is_null()) { | 220 if (!time_last_report_received_.is_null()) { |
| 221 packet_type_flags |= transport::kRtcpDlrr; | 221 packet_type_flags |= kRtcpDlrr; |
| 222 dlrr.last_rr = last_report_truncated_ntp_; | 222 dlrr.last_rr = last_report_truncated_ntp_; |
| 223 uint32 delay_seconds = 0; | 223 uint32 delay_seconds = 0; |
| 224 uint32 delay_fraction = 0; | 224 uint32 delay_fraction = 0; |
| 225 base::TimeDelta delta = current_time - time_last_report_received_; | 225 base::TimeDelta delta = current_time - time_last_report_received_; |
| 226 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 226 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
| 227 &delay_fraction); | 227 &delay_fraction); |
| 228 | 228 |
| 229 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); | 229 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); |
| 230 } | 230 } |
| 231 | 231 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 VLOG(2) << "Received log message via RTCP that we did not expect: " | 421 VLOG(2) << "Received log message via RTCP that we did not expect: " |
| 422 << static_cast<int>(event_it->type); | 422 << static_cast<int>(event_it->type); |
| 423 break; | 423 break; |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace cast | 429 } // namespace cast |
| 430 } // namespace media | 430 } // namespace media |
| OLD | NEW |