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_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 { | 179 class RtpTimestampHelper { |
|
miu
2014/05/13 01:11:56
Please make this class Chromium-style compliant, a
Alpha Left Google
2014/05/13 21:45:39
Done.
| |
| 180 public: | 180 public: |
| 181 explicit RtpSenderStatistics(int frequency) | 181 explicit RtpTimestampHelper(int frequency) |
| 182 : frequency_(frequency), | 182 : frequency_(frequency), |
| 183 rtp_timestamp_(0) { | 183 last_rtp_timestamp_(0), |
| 184 memset(&sender_info_, 0, sizeof(sender_info_)); | 184 stored_(false) { |
| 185 } | 185 } |
| 186 | 186 |
| 187 ~RtpSenderStatistics() {} | 187 ~RtpTimestampHelper() {} |
| 188 | 188 |
| 189 void UpdateInfo(const base::TimeTicks& now) { | 189 // Compute a RTP timestamp using current time, last encoded time and |
| 190 // Update RTP timestamp and return last stored statistics. | 190 // last encoded RTP timestamp. |
| 191 uint32 ntp_seconds = 0; | 191 // Return true if |rtp_timestamp| is computed. |
| 192 uint32 ntp_fraction = 0; | 192 bool GetCurrentTimeAsRtpTimestamp(const base::TimeTicks& now, |
| 193 uint32 rtp_timestamp = 0; | 193 uint32* rtp_timestamp) { |
|
miu
2014/05/13 01:11:56
Method should be const.
Alpha Left Google
2014/05/13 21:45:39
Done.
| |
| 194 if (rtp_timestamp_ > 0) { | 194 if (!stored_) |
| 195 base::TimeDelta time_since_last_send = now - time_sent_; | 195 return false; |
| 196 rtp_timestamp = rtp_timestamp_ + time_since_last_send.InMilliseconds() * | 196 base::TimeDelta elapsed_time = now - last_capture_time_; |
| 197 (frequency_ / 1000); | 197 *rtp_timestamp = last_rtp_timestamp_ + elapsed_time.InMilliseconds() * |
|
hubbe
2014/05/12 19:46:04
Is Millisecond accurate enough here?
Alpha Left Google
2014/05/12 19:49:33
I tried not to change the algorithm used here so I
| |
| 198 // Update NTP time to current time. | 198 frequency_ / base::Time::kMillisecondsPerSecond; |
| 199 ConvertTimeTicksToNtp(now, &ntp_seconds, &ntp_fraction); | 199 return true; |
| 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 } | 200 } |
| 206 | 201 |
| 207 transport::RtcpSenderInfo sender_info() const { | 202 // Store the capture time and the corresponding RTP timestamp for the |
| 208 return sender_info_; | 203 // last encoded frame. |
| 204 void StoreLatestTime(base::TimeTicks capture_time, uint32 rtp_timestamp) { | |
| 205 last_capture_time_ = capture_time; | |
| 206 last_rtp_timestamp_ = rtp_timestamp; | |
| 207 stored_ = true; | |
| 209 } | 208 } |
| 210 | 209 |
| 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: | 210 private: |
| 220 int frequency_; | 211 int frequency_; |
| 221 transport::RtcpSenderInfo sender_info_; | 212 base::TimeTicks last_capture_time_; |
| 222 base::TimeTicks time_sent_; | 213 uint32 last_rtp_timestamp_; |
| 223 uint32 rtp_timestamp_; | 214 bool stored_; |
|
miu
2014/05/13 01:11:56
You don't need this extra boolean member. Just ch
Alpha Left Google
2014/05/13 21:45:39
Done.
| |
| 224 | 215 |
| 225 DISALLOW_COPY_AND_ASSIGN(RtpSenderStatistics); | 216 DISALLOW_COPY_AND_ASSIGN(RtpTimestampHelper); |
| 226 }; | 217 }; |
| 227 | 218 |
| 228 } // namespace cast | 219 } // namespace cast |
| 229 } // namespace media | 220 } // namespace media |
| 230 | 221 |
| 231 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 222 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
| OLD | NEW |