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 // Maps a frame's |rtp_timestamp| to its approximate capture time, based on |
106 base::TimeTicks* rtp_timestamp_in_ticks) const; | 104 // the latest "lip sync" info gleaned from the sender reports. The returned |
105 // TimeTicks value is relative to the local CastEnvironment clock. Returns a | |
106 // null TimeTicks value to indicate no lip sync info was available. | |
107 // |rtp_timebase| is the number of units of |rtp_timestamp| that elapse per | |
108 // one second (e.g., for audio, this is usually the sampling frequency). | |
109 // | |
110 // Note: The values returned are not guaranteed to be monotonically increasing | |
111 // for monotonically increasing rtp_timestamps. In fact, it's possible that | |
112 // calling this method more than once with the same arguments will return | |
113 // different results. | |
114 base::TimeTicks ToApproximateCaptureTime(uint32 rtp_timestamp, | |
hubbe
2014/05/19 17:52:20
I'm not sure "Capture Time" is the terminology we
miu
2014/05/23 03:09:01
Done. After fixing the logic, I moved the code ar
| |
115 int rtp_timebase) const; | |
107 | 116 |
108 // Set the history size to record Cast receiver events. The event history is | 117 // 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. | 118 // used to remove duplicates. The history will store at most |size| events. |
110 void SetCastReceiverEventHistorySize(size_t size); | 119 void SetCastReceiverEventHistorySize(size_t size); |
111 | 120 |
112 // Update the target delay. Will be added to every sender report. | 121 // Update the target delay. Will be added to every report sent back to the |
122 // sender. | |
123 // TODO(miu): Remove this deprecated functionality. The sender ignores this. | |
113 void SetTargetDelay(base::TimeDelta target_delay); | 124 void SetTargetDelay(base::TimeDelta target_delay); |
114 | 125 |
115 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); | 126 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); |
116 | 127 |
117 protected: | 128 protected: |
118 int CheckForWrapAround(uint32 new_timestamp, uint32 old_timestamp) const; | 129 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); |
119 | |
120 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, | 130 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, |
121 uint32 ntp_seconds, | 131 uint32 ntp_seconds, |
122 uint32 ntp_fraction); | 132 uint32 ntp_fraction); |
123 | 133 |
124 private: | 134 private: |
125 friend class LocalRtcpRttFeedback; | 135 friend class LocalRtcpRttFeedback; |
126 friend class LocalRtcpReceiverFeedback; | 136 friend class LocalRtcpReceiverFeedback; |
127 | 137 |
128 void SendRtcp(const base::TimeTicks& now, | 138 // Uses recent reports from the remote to translate remote-provided NTP |
129 uint32 packet_type_flags, | 139 // timestamps into TimeTicks values relative to the local clock. Returns a |
130 uint32 media_ssrc, | 140 // null TimeTicks value to indicate a usable report has not yet been received. |
131 const RtcpCastMessage* cast_message); | 141 base::TimeTicks ToApproximateLocalTime(uint32 remote_ntp_seconds, |
132 | 142 uint32 remote_ntp_fraction) const; |
133 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); | |
134 | 143 |
135 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, | 144 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, |
136 uint32 last_report, | 145 uint32 last_report, |
137 uint32 delay_since_last_report); | 146 uint32 delay_since_last_report); |
138 | 147 |
139 void OnReceivedSendReportRequest(); | 148 void OnReceivedSendReportRequest(); |
140 | 149 |
141 void UpdateRtt(const base::TimeDelta& sender_delay, | 150 void UpdateRtt(const base::TimeDelta& sender_delay, |
142 const base::TimeDelta& receiver_delay); | 151 const base::TimeDelta& receiver_delay); |
143 | 152 |
144 void UpdateNextTimeToSendRtcp(); | 153 void UpdateNextTimeToSendRtcp(); |
145 | 154 |
146 void SaveLastSentNtpTime(const base::TimeTicks& now, | 155 void SaveLastSentNtpTime(const base::TimeTicks& now, |
147 uint32 last_ntp_seconds, | 156 uint32 last_ntp_seconds, |
148 uint32 last_ntp_fraction); | 157 uint32 last_ntp_fraction); |
149 | 158 |
159 // Returns a truncated 16+16-bit NTP timestamp, computed from the full | |
160 // 32+32-bit NTP timestamp in |last_report_ntp_time_|. | |
161 uint32 GetTruncatedLastNtpReportTime() const; | |
162 | |
150 scoped_refptr<CastEnvironment> cast_environment_; | 163 scoped_refptr<CastEnvironment> cast_environment_; |
151 transport::CastTransportSender* const transport_sender_; | 164 transport::CastTransportSender* const transport_sender_; |
152 const base::TimeDelta rtcp_interval_; | 165 const base::TimeDelta rtcp_interval_; |
153 const RtcpMode rtcp_mode_; | 166 const RtcpMode rtcp_mode_; |
154 const uint32 local_ssrc_; | 167 const uint32 local_ssrc_; |
155 const uint32 remote_ssrc_; | 168 const uint32 remote_ssrc_; |
156 const std::string c_name_; | 169 const std::string c_name_; |
157 | 170 |
158 // Not owned by this class. | 171 // Not owned by this class. |
159 RtpReceiverStatistics* const rtp_receiver_statistics_; | 172 RtpReceiverStatistics* const rtp_receiver_statistics_; |
160 | 173 |
161 scoped_ptr<LocalRtcpRttFeedback> rtt_feedback_; | 174 scoped_ptr<LocalRtcpRttFeedback> rtt_feedback_; |
162 scoped_ptr<LocalRtcpReceiverFeedback> receiver_feedback_; | 175 scoped_ptr<LocalRtcpReceiverFeedback> receiver_feedback_; |
163 scoped_ptr<RtcpSender> rtcp_sender_; | 176 scoped_ptr<RtcpSender> rtcp_sender_; |
164 scoped_ptr<RtcpReceiver> rtcp_receiver_; | 177 scoped_ptr<RtcpReceiver> rtcp_receiver_; |
165 | 178 |
166 base::TimeTicks next_time_to_send_rtcp_; | 179 base::TimeTicks next_time_to_send_rtcp_; |
167 RtcpSendTimeMap last_reports_sent_map_; | 180 RtcpSendTimeMap last_reports_sent_map_; |
168 RtcpSendTimeQueue last_reports_sent_queue_; | 181 RtcpSendTimeQueue last_reports_sent_queue_; |
182 | |
183 // The NTP timestamp provided in the last report from the remote peer, along | |
184 // with the local time at which the report was received. These two values are | |
185 // used both for: 1) ping-pong'ing NTP timestamps between the peers; and 2) | |
186 // computing the local clock's offset from the remote clock. | |
187 uint64 last_report_ntp_time_; | |
169 base::TimeTicks time_last_report_received_; | 188 base::TimeTicks time_last_report_received_; |
170 uint32 last_report_received_; | |
171 | 189 |
172 uint32 last_received_rtp_timestamp_; | 190 // Latest "lip sync" info from the sender. The sender provides the RTP |
173 uint32 last_received_ntp_seconds_; | 191 // timestamp of some frame of its choosing and also the frame's capture time. |
174 uint32 last_received_ntp_fraction_; | 192 // This allows the receiver to approximate the capture times of other frames |
193 // based on their RTP timestamp. It is expected that the sender will update | |
194 // this data regularly and in a timely manner (e.g., about once per second). | |
195 uint32 lip_sync_rtp_timestamp_; | |
196 base::TimeTicks lip_sync_capture_time_; | |
175 | 197 |
176 base::TimeDelta rtt_; | 198 base::TimeDelta rtt_; |
177 base::TimeDelta min_rtt_; | 199 base::TimeDelta min_rtt_; |
178 base::TimeDelta max_rtt_; | 200 base::TimeDelta max_rtt_; |
179 int number_of_rtt_in_avg_; | 201 int number_of_rtt_in_avg_; |
180 float avg_rtt_ms_; | 202 double avg_rtt_ms_; |
181 uint16 target_delay_ms_; | 203 uint16 target_delay_ms_; |
182 bool is_audio_; | 204 bool is_audio_; |
183 | 205 |
184 DISALLOW_COPY_AND_ASSIGN(Rtcp); | 206 DISALLOW_COPY_AND_ASSIGN(Rtcp); |
185 }; | 207 }; |
186 | 208 |
187 } // namespace cast | 209 } // namespace cast |
188 } // namespace media | 210 } // namespace media |
189 | 211 |
190 #endif // MEDIA_CAST_RTCP_RTCP_H_ | 212 #endif // MEDIA_CAST_RTCP_RTCP_H_ |
OLD | NEW |