| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 if (later <= earlier) { | 186 if (later <= earlier) { |
| 187 return -static_cast<long>(earlier - later); | 187 return -static_cast<long>(earlier - later); |
| 188 } else { | 188 } else { |
| 189 return -static_cast<long>(earlier + (UINT32_MAX - later) + 1); | 189 return -static_cast<long>(earlier + (UINT32_MAX - later) + 1); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 #endif | 192 #endif |
| 193 } | 193 } |
| 194 | 194 |
| 195 TimestampWrapAroundHandler::TimestampWrapAroundHandler() | 195 TimestampWrapAroundHandler::TimestampWrapAroundHandler() |
| 196 : last_ts_(0), num_wrap_(0) {} | 196 : last_ts_(0), num_wrap_(-1) {} |
| 197 | 197 |
| 198 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) { | 198 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) { |
| 199 if (num_wrap_ == -1) { |
| 200 last_ts_ = ts; |
| 201 num_wrap_ = 0; |
| 202 return ts; |
| 203 } |
| 204 |
| 199 if (ts < last_ts_) { | 205 if (ts < last_ts_) { |
| 200 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { | 206 if (last_ts_ >= 0xf0000000 && ts < 0x0fffffff) |
| 201 ++num_wrap_; | 207 ++num_wrap_; |
| 202 } | 208 } else if ((ts - last_ts_) > 0xf0000000) { |
| 209 // Backwards wrap. Unwrap with last wrap count and don't update last_ts_. |
| 210 return ts + ((num_wrap_ - 1) << 32); |
| 203 } | 211 } |
| 212 |
| 204 last_ts_ = ts; | 213 last_ts_ = ts; |
| 205 int64_t unwrapped_ts = ts + (num_wrap_ << 32); | 214 return ts + (num_wrap_ << 32); |
| 206 return unwrapped_ts; | |
| 207 } | 215 } |
| 208 | 216 |
| 209 int64_t TmToSeconds(const std::tm& tm) { | 217 int64_t TmToSeconds(const std::tm& tm) { |
| 210 static short int mdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 218 static short int mdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
| 211 static short int cumul_mdays[12] = {0, 31, 59, 90, 120, 151, | 219 static short int cumul_mdays[12] = {0, 31, 59, 90, 120, 151, |
| 212 181, 212, 243, 273, 304, 334}; | 220 181, 212, 243, 273, 304, 334}; |
| 213 int year = tm.tm_year + 1900; | 221 int year = tm.tm_year + 1900; |
| 214 int month = tm.tm_mon; | 222 int month = tm.tm_mon; |
| 215 int day = tm.tm_mday - 1; // Make 0-based like the rest. | 223 int day = tm.tm_mday - 1; // Make 0-based like the rest. |
| 216 int hour = tm.tm_hour; | 224 int hour = tm.tm_hour; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 244 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. | 252 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. |
| 245 day -= 1; | 253 day -= 1; |
| 246 | 254 |
| 247 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | 255 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| |
| 248 // which was accumulated into |day| above). | 256 // which was accumulated into |day| above). |
| 249 return (((static_cast<int64_t> | 257 return (((static_cast<int64_t> |
| 250 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | 258 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; |
| 251 } | 259 } |
| 252 | 260 |
| 253 } // namespace rtc | 261 } // namespace rtc |
| OLD | NEW |