Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ | |
| 6 #define WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ | |
| 7 | |
| 8 #include "base/time.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // Platform independent method for converting and rounding floating point | |
| 13 // seconds to an int64 timestamp. | |
| 14 // | |
| 15 // Refer to https://bugs.webkit.org/show_bug.cgi?id=52697 for details. | |
| 16 base::TimeDelta ConvertSecondsToTimestamp(float seconds) { | |
|
scherkus (not reviewing)
2012/04/21 03:02:05
let's get a .cc for this
qinmin
2012/04/23 18:57:04
Done.
| |
| 17 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; | |
| 18 float integer = ceilf(microseconds); | |
| 19 float difference = integer - microseconds; | |
| 20 | |
| 21 // Round down if difference is large enough. | |
| 22 if ((microseconds > 0 && difference > 0.5f) || | |
| 23 (microseconds <= 0 && difference >= 0.5f)) { | |
| 24 integer -= 1.0f; | |
| 25 } | |
| 26 | |
| 27 // Now we can safely cast to int64 microseconds. | |
| 28 return base::TimeDelta::FromMicroseconds(static_cast<int64>(integer)); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 #endif // WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ | |
| OLD | NEW |