Index: webkit/media/webmediaplayer_util.h |
diff --git a/webkit/media/webmediaplayer_util.h b/webkit/media/webmediaplayer_util.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..12d09df3cbe9c7aa3e4e6b36bdf15c1738ca33c9 |
--- /dev/null |
+++ b/webkit/media/webmediaplayer_util.h |
@@ -0,0 +1,33 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ |
+#define WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ |
+ |
+#include "base/time.h" |
+ |
+namespace { |
+ |
+// Platform independent method for converting and rounding floating point |
+// seconds to an int64 timestamp. |
+// |
+// Refer to https://bugs.webkit.org/show_bug.cgi?id=52697 for details. |
+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.
|
+ float microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
+ float integer = ceilf(microseconds); |
+ float difference = integer - microseconds; |
+ |
+ // Round down if difference is large enough. |
+ if ((microseconds > 0 && difference > 0.5f) || |
+ (microseconds <= 0 && difference >= 0.5f)) { |
+ integer -= 1.0f; |
+ } |
+ |
+ // Now we can safely cast to int64 microseconds. |
+ return base::TimeDelta::FromMicroseconds(static_cast<int64>(integer)); |
+} |
+ |
+} // namespace |
+ |
+#endif // WEBKIT_MEDIA_WEBMEDIAPLAYER_UTIL_H_ |