Chromium Code Reviews| 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 #ifndef MEDIA_CAST_RTCP_RTCP_H_ | 5 #ifndef MEDIA_CAST_RTCP_RTCP_H_ |
| 6 #define MEDIA_CAST_RTCP_RTCP_H_ | 6 #define MEDIA_CAST_RTCP_RTCP_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <map> | 8 #include <map> |
| 10 #include <queue> | 9 #include <queue> |
| 11 #include <set> | |
| 12 #include <string> | 10 #include <string> |
| 13 | 11 |
| 14 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 15 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time/tick_clock.h" | 14 #include "base/time/tick_clock.h" |
| 17 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 18 #include "media/cast/cast_config.h" | 16 #include "media/cast/cast_config.h" |
| 19 #include "media/cast/cast_defines.h" | 17 #include "media/cast/cast_defines.h" |
| 20 #include "media/cast/cast_environment.h" | 18 #include "media/cast/cast_environment.h" |
| 21 #include "media/cast/rtcp/receiver_rtcp_event_subscriber.h" | 19 #include "media/cast/rtcp/receiver_rtcp_event_subscriber.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 // will append the log messages. | 92 // will append the log messages. |
| 95 void SendRtcpFromRtpReceiver( | 93 void SendRtcpFromRtpReceiver( |
| 96 const RtcpCastMessage* cast_message, | 94 const RtcpCastMessage* cast_message, |
| 97 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events); | 95 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events); |
| 98 | 96 |
| 99 void IncomingRtcpPacket(const uint8* rtcp_buffer, size_t length); | 97 void IncomingRtcpPacket(const uint8* rtcp_buffer, size_t length); |
| 100 bool Rtt(base::TimeDelta* rtt, | 98 bool Rtt(base::TimeDelta* rtt, |
| 101 base::TimeDelta* avg_rtt, | 99 base::TimeDelta* avg_rtt, |
| 102 base::TimeDelta* min_rtt, | 100 base::TimeDelta* min_rtt, |
| 103 base::TimeDelta* max_rtt) const; | 101 base::TimeDelta* max_rtt) const; |
| 104 bool RtpTimestampInSenderTime(int frequency, | 102 |
| 105 uint32 rtp_timestamp, | 103 // Uses recent reports from the remote to translate remote-provided NTP |
| 106 base::TimeTicks* rtp_timestamp_in_ticks) const; | 104 // timestamps into TimeTicks values relative to the local clock. Returns a |
| 105 // null TimeTicks value to indicate a usable report has not yet been received. | |
| 106 // | |
| 107 // Note: The values returned are not guaranteed to be monotonically increasing | |
| 108 // for monotonically increasing NTP timestamps. In fact, it's possible that | |
| 109 // calling this method more than once with the same arguments will return | |
| 110 // different results. | |
| 111 base::TimeTicks ToApproximateLocalTime(uint32 remote_ntp_seconds, | |
|
hubbe
2014/05/14 23:12:23
Can this be made private?
miu
2014/05/16 22:45:47
Done.
| |
| 112 uint32 remote_ntp_fraction) const; | |
| 113 | |
| 114 // Maps a frame's |rtp_timestamp| to its approximate capture time, based on | |
| 115 // the latest "lip sync" info gleaned from the sender reports. The returned | |
| 116 // TimeTicks value is relative to the local CastEnvironment clock. Returns a | |
| 117 // null TimeTicks value to indicate no lip sync info was available. | |
| 118 // |rtp_timebase| is the number of units of |rtp_timestamp| that elapse per | |
| 119 // one second (e.g., for audio, this is usually the sampling frequency). | |
| 120 // | |
| 121 // Note: The values returned are not guaranteed to be monotonically increasing | |
| 122 // for monotonically increasing rtp_timestamps. In fact, it's possible that | |
| 123 // calling this method more than once with the same arguments will return | |
| 124 // different results. | |
| 125 base::TimeTicks ToApproximateCaptureTime(uint32 rtp_timestamp, | |
| 126 int rtp_timebase) const; | |
| 107 | 127 |
| 108 // Set the history size to record Cast receiver events. The event history is | 128 // Set the history size to record Cast receiver events. The event history is |
| 109 // used to remove duplicates. The history will store at most |size| events. | 129 // used to remove duplicates. The history will store at most |size| events. |
| 110 void SetCastReceiverEventHistorySize(size_t size); | 130 void SetCastReceiverEventHistorySize(size_t size); |
| 111 | 131 |
| 112 // Update the target delay. Will be added to every sender report. | 132 // Update the target delay. Will be added to every report sent back to the |
| 133 // sender. | |
| 134 // TODO(miu): Remove this deprecated functionality. The sender ignores this. | |
| 113 void SetTargetDelay(base::TimeDelta target_delay); | 135 void SetTargetDelay(base::TimeDelta target_delay); |
| 114 | 136 |
| 115 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); | 137 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); |
| 116 | 138 |
| 117 protected: | 139 protected: |
| 118 int CheckForWrapAround(uint32 new_timestamp, uint32 old_timestamp) const; | 140 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); |
| 119 | |
| 120 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, | 141 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, |
| 121 uint32 ntp_seconds, | 142 uint32 ntp_seconds, |
| 122 uint32 ntp_fraction); | 143 uint32 ntp_fraction); |
| 123 | 144 |
| 124 private: | 145 private: |
| 125 friend class LocalRtcpRttFeedback; | 146 friend class LocalRtcpRttFeedback; |
| 126 friend class LocalRtcpReceiverFeedback; | 147 friend class LocalRtcpReceiverFeedback; |
| 127 | 148 |
| 128 void SendRtcp(const base::TimeTicks& now, | 149 void SendRtcp(const base::TimeTicks& now, |
| 129 uint32 packet_type_flags, | 150 uint32 packet_type_flags, |
| 130 uint32 media_ssrc, | 151 uint32 media_ssrc, |
| 131 const RtcpCastMessage* cast_message); | 152 const RtcpCastMessage* cast_message); |
| 132 | 153 |
| 133 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); | |
| 134 | |
| 135 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, | 154 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, |
| 136 uint32 last_report, | 155 uint32 last_report, |
| 137 uint32 delay_since_last_report); | 156 uint32 delay_since_last_report); |
| 138 | 157 |
| 139 void OnReceivedSendReportRequest(); | 158 void OnReceivedSendReportRequest(); |
| 140 | 159 |
| 141 void UpdateRtt(const base::TimeDelta& sender_delay, | 160 void UpdateRtt(const base::TimeDelta& sender_delay, |
| 142 const base::TimeDelta& receiver_delay); | 161 const base::TimeDelta& receiver_delay); |
| 143 | 162 |
| 144 void UpdateNextTimeToSendRtcp(); | 163 void UpdateNextTimeToSendRtcp(); |
| 145 | 164 |
| 146 void SaveLastSentNtpTime(const base::TimeTicks& now, | 165 void SaveLastSentNtpTime(const base::TimeTicks& now, |
| 147 uint32 last_ntp_seconds, | 166 uint32 last_ntp_seconds, |
| 148 uint32 last_ntp_fraction); | 167 uint32 last_ntp_fraction); |
| 149 | 168 |
| 169 // Returns a truncated 16+16-bit NTP timestamp, computed from the full | |
| 170 // 32+32-bit NTP timestamp in |last_report_ntp_time_|. | |
| 171 uint32 GetTruncatedLastNtpReportTime() const; | |
|
hubbe
2014/05/14 23:12:23
Where is the inverse of this function?
miu
2014/05/16 22:45:47
Not implemented. It appears to be parsed and deli
| |
| 172 | |
| 150 scoped_refptr<CastEnvironment> cast_environment_; | 173 scoped_refptr<CastEnvironment> cast_environment_; |
| 151 transport::CastTransportSender* const transport_sender_; | 174 transport::CastTransportSender* const transport_sender_; |
| 152 const base::TimeDelta rtcp_interval_; | 175 const base::TimeDelta rtcp_interval_; |
| 153 const RtcpMode rtcp_mode_; | 176 const RtcpMode rtcp_mode_; |
| 154 const uint32 local_ssrc_; | 177 const uint32 local_ssrc_; |
| 155 const uint32 remote_ssrc_; | 178 const uint32 remote_ssrc_; |
| 156 const std::string c_name_; | 179 const std::string c_name_; |
| 157 | 180 |
| 158 // Not owned by this class. | 181 // Not owned by this class. |
| 159 RtpReceiverStatistics* const rtp_receiver_statistics_; | 182 RtpReceiverStatistics* const rtp_receiver_statistics_; |
| 160 | 183 |
| 161 scoped_ptr<LocalRtcpRttFeedback> rtt_feedback_; | 184 scoped_ptr<LocalRtcpRttFeedback> rtt_feedback_; |
| 162 scoped_ptr<LocalRtcpReceiverFeedback> receiver_feedback_; | 185 scoped_ptr<LocalRtcpReceiverFeedback> receiver_feedback_; |
| 163 scoped_ptr<RtcpSender> rtcp_sender_; | 186 scoped_ptr<RtcpSender> rtcp_sender_; |
| 164 scoped_ptr<RtcpReceiver> rtcp_receiver_; | 187 scoped_ptr<RtcpReceiver> rtcp_receiver_; |
| 165 | 188 |
| 166 base::TimeTicks next_time_to_send_rtcp_; | 189 base::TimeTicks next_time_to_send_rtcp_; |
| 167 RtcpSendTimeMap last_reports_sent_map_; | 190 RtcpSendTimeMap last_reports_sent_map_; |
| 168 RtcpSendTimeQueue last_reports_sent_queue_; | 191 RtcpSendTimeQueue last_reports_sent_queue_; |
| 192 | |
| 193 // The NTP timestamp provided in the last report from the remote peer, along | |
| 194 // with the local time at which the report was received. These two values are | |
| 195 // used both for: 1) ping-pong'ing NTP timestamps between the peers; and 2) | |
| 196 // computing the local clock's offset from the remote clock. | |
| 197 uint64 last_report_ntp_time_; | |
|
hubbe
2014/05/14 23:12:23
Don't we need some sort of min() calculation for t
miu
2014/05/16 22:45:47
Nope. These are just snapshots from the latest se
hubbe
2014/05/19 17:52:20
Hmm, maybe I'm missing something. Isn't this used
miu
2014/05/23 03:09:00
Done. Created a ClockDriftSmoother, and incorpora
| |
| 169 base::TimeTicks time_last_report_received_; | 198 base::TimeTicks time_last_report_received_; |
| 170 uint32 last_report_received_; | |
| 171 | 199 |
| 172 uint32 last_received_rtp_timestamp_; | 200 // Latest "lip sync" info from the sender. The sender provides the RTP |
| 173 uint32 last_received_ntp_seconds_; | 201 // timestamp of some frame of its choosing and also the frame's capture time. |
| 174 uint32 last_received_ntp_fraction_; | 202 // This allows the receiver to approximate the capture times of other frames |
| 203 // based on their RTP timestamp. It is expected that the sender will update | |
| 204 // this data regularly and in a timely manner (i.e., about once per second). | |
|
hubbe
2014/05/14 23:12:23
i.e. -> e.g.
miu
2014/05/16 22:45:47
Done.
| |
| 205 uint32 lip_sync_rtp_timestamp_; | |
| 206 base::TimeTicks lip_sync_capture_time_; | |
| 175 | 207 |
| 176 base::TimeDelta rtt_; | 208 base::TimeDelta rtt_; |
| 177 base::TimeDelta min_rtt_; | 209 base::TimeDelta min_rtt_; |
| 178 base::TimeDelta max_rtt_; | 210 base::TimeDelta max_rtt_; |
| 179 int number_of_rtt_in_avg_; | 211 int number_of_rtt_in_avg_; |
| 180 float avg_rtt_ms_; | 212 double avg_rtt_ms_; |
| 181 uint16 target_delay_ms_; | 213 uint16 target_delay_ms_; |
| 182 bool is_audio_; | 214 bool is_audio_; |
| 183 | 215 |
| 184 DISALLOW_COPY_AND_ASSIGN(Rtcp); | 216 DISALLOW_COPY_AND_ASSIGN(Rtcp); |
| 185 }; | 217 }; |
| 186 | 218 |
| 187 } // namespace cast | 219 } // namespace cast |
| 188 } // namespace media | 220 } // namespace media |
| 189 | 221 |
| 190 #endif // MEDIA_CAST_RTCP_RTCP_H_ | 222 #endif // MEDIA_CAST_RTCP_RTCP_H_ |
| OLD | NEW |