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_CAST_DEFINES_H_ | 5 #ifndef MEDIA_CAST_CAST_DEFINES_H_ |
6 #define MEDIA_CAST_CAST_DEFINES_H_ | 6 #define MEDIA_CAST_CAST_DEFINES_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; | 169 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
170 } | 170 } |
171 | 171 |
172 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { | 172 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { |
173 base::TimeTicks zero_time; | 173 base::TimeTicks zero_time; |
174 base::TimeDelta recorded_delta = time_ticks - zero_time; | 174 base::TimeDelta recorded_delta = time_ticks - zero_time; |
175 // Timestamp is in 90 KHz for video. | 175 // Timestamp is in 90 KHz for video. |
176 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); | 176 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); |
177 } | 177 } |
178 | 178 |
179 class RtpSenderStatistics { | |
180 public: | |
181 explicit RtpSenderStatistics(int frequency) | |
182 : frequency_(frequency), | |
183 rtp_timestamp_(0) { | |
184 memset(&sender_info_, 0, sizeof(sender_info_)); | |
185 } | |
186 | |
187 ~RtpSenderStatistics() {} | |
188 | |
189 void UpdateInfo(const base::TimeTicks& now) { | |
190 // Update RTP timestamp and return last stored statistics. | |
191 uint32 ntp_seconds = 0; | |
192 uint32 ntp_fraction = 0; | |
193 uint32 rtp_timestamp = 0; | |
194 if (rtp_timestamp_ > 0) { | |
195 base::TimeDelta time_since_last_send = now - time_sent_; | |
196 rtp_timestamp = rtp_timestamp_ + time_since_last_send.InMilliseconds() * | |
197 (frequency_ / 1000); | |
198 // Update NTP time to current time. | |
199 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); | |
200 } | |
201 // Populate sender info. | |
202 sender_info_.rtp_timestamp = rtp_timestamp; | |
203 sender_info_.ntp_seconds = ntp_seconds; | |
204 sender_info_.ntp_fraction = ntp_fraction; | |
205 } | |
206 | |
207 transport::RtcpSenderInfo sender_info() const { | |
208 return sender_info_; | |
209 } | |
210 | |
211 void Store(transport::RtcpSenderInfo sender_info, | |
212 base::TimeTicks time_sent, | |
213 uint32 rtp_timestamp) { | |
214 sender_info_ = sender_info; | |
215 time_sent_ = time_sent; | |
216 rtp_timestamp_ = rtp_timestamp; | |
217 } | |
218 | |
219 private: | |
220 int frequency_; | |
221 transport::RtcpSenderInfo sender_info_; | |
222 base::TimeTicks time_sent_; | |
223 uint32 rtp_timestamp_; | |
224 | |
225 DISALLOW_COPY_AND_ASSIGN(RtpSenderStatistics); | |
226 }; | |
227 | |
228 } // namespace cast | 179 } // namespace cast |
229 } // namespace media | 180 } // namespace media |
230 | 181 |
231 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 182 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
OLD | NEW |