| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "webkit/media/webmediaplayer_util.h" | 5 #include "webkit/media/webmediaplayer_util.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 namespace webkit_media { | 9 namespace webkit_media { |
| 10 | 10 |
| 11 base::TimeDelta ConvertSecondsToTimestamp(float seconds) { | 11 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { |
| 12 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; | 12 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
| 13 float integer = ceilf(microseconds); | 13 return base::TimeDelta::FromMicroseconds( |
| 14 float difference = integer - microseconds; | 14 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); |
| 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 } | 15 } |
| 25 | 16 |
| 26 } // namespace webkit_media | 17 } // namespace webkit_media |
| OLD | NEW |