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 #include "webkit/media/webmediaplayer_util.h" |
| 6 |
| 7 #include <math.h> |
| 8 |
| 9 namespace webkit_media { |
| 10 |
| 11 base::TimeDelta ConvertSecondsToTimestamp(float seconds) { |
| 12 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
| 13 float integer = ceilf(microseconds); |
| 14 float difference = integer - microseconds; |
| 15 |
| 16 // Round down if difference is large enough. |
| 17 if ((microseconds > 0 && difference > 0.5f) || |
| 18 (microseconds <= 0 && difference >= 0.5f)) { |
| 19 integer -= 1.0f; |
| 20 } |
| 21 |
| 22 // Now we can safely cast to int64 microseconds. |
| 23 return base::TimeDelta::FromMicroseconds(static_cast<int64>(integer)); |
| 24 } |
| 25 |
| 26 } // namespace webkit_media |
OLD | NEW |