Modified: trunk/Source/WTF/wtf/MediaTime.cpp (157834 => 157835)
--- trunk/Source/WTF/wtf/MediaTime.cpp 2013-10-23 00:14:37 UTC (rev 157834)
+++ trunk/Source/WTF/wtf/MediaTime.cpp 2013-10-23 00:18:16 UTC (rev 157835)
@@ -54,6 +54,11 @@
return safeMultiply(a, b / greatestCommonDivisor(a, b), result);
}
+static int32_t signum(int64_t val)
+{
+ return (0 < val) - (val < 0);
+}
+
const int32_t MediaTime::MaximumTimeScale = 0x7fffffffL;
MediaTime::MediaTime()
@@ -215,6 +220,40 @@
return a;
}
+MediaTime MediaTime::operator*(int32_t rhs) const
+{
+ if (isInvalid())
+ return invalidTime();
+
+ if (isIndefinite())
+ return indefiniteTime();
+
+ if (!rhs)
+ return zeroTime();
+
+ if (isPositiveInfinite()) {
+ if (rhs > 0)
+ return positiveInfiniteTime();
+ return negativeInfiniteTime();
+ }
+
+ if (isNegativeInfinite()) {
+ if (rhs > 0)
+ return negativeInfiniteTime();
+ return positiveInfiniteTime();
+ }
+
+ MediaTime a = *this;
+
+ while (!safeMultiply(a.m_timeValue, rhs, a.m_timeValue)) {
+ if (a.m_timeScale == 1)
+ return signum(a.m_timeValue) == signum(rhs) ? positiveInfiniteTime() : negativeInfiniteTime();
+ a.setTimeScale(a.m_timeScale / 2);
+ }
+
+ return a;
+}
+
bool MediaTime::operator<(const MediaTime& rhs) const
{
return compare(rhs) == LessThan;
@@ -225,6 +264,11 @@
return compare(rhs) == GreaterThan;
}
+bool MediaTime::operator!=(const MediaTime& rhs) const
+{
+ return compare(rhs) != EqualTo;
+}
+
bool MediaTime::operator==(const MediaTime& rhs) const
{
return compare(rhs) == EqualTo;
@@ -332,11 +376,6 @@
m_timeScale = timeScale;
}
-static int32_t signum(int64_t val)
-{
- return (0 < val) - (val < 0);
-}
-
MediaTime abs(const MediaTime& rhs)
{
if (rhs.isInvalid())
Modified: trunk/Source/WTF/wtf/MediaTime.h (157834 => 157835)
--- trunk/Source/WTF/wtf/MediaTime.h 2013-10-23 00:14:37 UTC (rev 157834)
+++ trunk/Source/WTF/wtf/MediaTime.h 2013-10-23 00:18:16 UTC (rev 157835)
@@ -26,6 +26,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef WTF_MediaTime_h
+#define WTF_MediaTime_h
+
#include <wtf/FastMalloc.h>
#include <cmath>
@@ -58,10 +61,14 @@
double toDouble() const;
MediaTime& operator=(const MediaTime& rhs);
+ MediaTime& operator+=(const MediaTime& rhs) { return *this = *this + rhs; }
+ MediaTime& operator-=(const MediaTime& rhs) { return *this = *this - rhs; }
MediaTime operator+(const MediaTime& rhs) const;
MediaTime operator-(const MediaTime& rhs) const;
+ MediaTime operator*(int32_t) const;
bool operator<(const MediaTime& rhs) const;
bool operator>(const MediaTime& rhs) const;
+ bool operator!=(const MediaTime& rhs) const;
bool operator==(const MediaTime& rhs) const;
bool operator>=(const MediaTime& rhs) const;
bool operator<=(const MediaTime& rhs) const;
@@ -102,8 +109,14 @@
uint32_t m_timeFlags;
};
+inline MediaTime operator*(int32_t lhs, const MediaTime& rhs) { return rhs.operator*(lhs); }
+
WTF_EXPORT_PRIVATE extern MediaTime abs(const MediaTime& rhs);
+
}
using WTF::MediaTime;
using WTF::abs;
+
+#endif
+
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp (157834 => 157835)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp 2013-10-23 00:14:37 UTC (rev 157834)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp 2013-10-23 00:18:16 UTC (rev 157835)
@@ -71,12 +71,17 @@
EXPECT_EQ(MediaTime::negativeInfiniteTime() < MediaTime::positiveInfiniteTime(), true);
EXPECT_EQ(MediaTime::negativeInfiniteTime() == MediaTime::negativeInfiniteTime(), true);
EXPECT_EQ(MediaTime::positiveInfiniteTime() == MediaTime::positiveInfiniteTime(), true);
+ EXPECT_EQ(MediaTime::positiveInfiniteTime() != MediaTime::negativeInfiniteTime(), true);
EXPECT_EQ(MediaTime::invalidTime() == MediaTime::invalidTime(), true);
+ EXPECT_EQ(MediaTime::invalidTime() != MediaTime::invalidTime(), false);
+ EXPECT_EQ(MediaTime::invalidTime() != MediaTime::zeroTime(), true);
EXPECT_EQ(MediaTime::invalidTime() > MediaTime::negativeInfiniteTime(), true);
EXPECT_EQ(MediaTime::invalidTime() > MediaTime::positiveInfiniteTime(), true);
EXPECT_EQ(MediaTime::negativeInfiniteTime() < MediaTime::invalidTime(), true);
EXPECT_EQ(MediaTime::positiveInfiniteTime() < MediaTime::invalidTime(), true);
EXPECT_EQ(MediaTime::indefiniteTime() == MediaTime::indefiniteTime(), true);
+ EXPECT_EQ(MediaTime::indefiniteTime() != MediaTime::indefiniteTime(), false);
+ EXPECT_EQ(MediaTime::indefiniteTime() != MediaTime::zeroTime(), true);
EXPECT_EQ(MediaTime::indefiniteTime() > MediaTime::negativeInfiniteTime(), true);
EXPECT_EQ(MediaTime::indefiniteTime() < MediaTime::positiveInfiniteTime(), true);
EXPECT_EQ(MediaTime::negativeInfiniteTime() < MediaTime::indefiniteTime(), true);
@@ -85,6 +90,7 @@
EXPECT_EQ(MediaTime::indefiniteTime() > MediaTime(1, 1), true);
EXPECT_EQ(MediaTime(1, 1) < MediaTime(2, 1), true);
EXPECT_EQ(MediaTime(2, 1) > MediaTime(1, 1), true);
+ EXPECT_EQ(MediaTime(1, 1) != MediaTime(2, 1), true);
EXPECT_EQ(MediaTime(2, 1) == MediaTime(2, 1), true);
EXPECT_EQ(MediaTime(2, 1) == MediaTime(4, 2), true);
@@ -122,6 +128,23 @@
EXPECT_EQ(MediaTime(1, 2) - MediaTime(1, 3), MediaTime(1, 6));
EXPECT_EQ(MediaTime(2, numeric_limits<int32_t>::max()-1) - MediaTime(1, numeric_limits<int32_t>::max()-2), MediaTime(1, numeric_limits<int32_t>::max()));
+ // Multiplication Operators
+ EXPECT_EQ(MediaTime::positiveInfiniteTime(), MediaTime::positiveInfiniteTime() * 2);
+ EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime::negativeInfiniteTime() * 2);
+ EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime::positiveInfiniteTime() * -2);
+ EXPECT_EQ(MediaTime::positiveInfiniteTime(), MediaTime::negativeInfiniteTime() * -2);
+ EXPECT_EQ(MediaTime::invalidTime(), MediaTime::invalidTime() * 2);
+ EXPECT_EQ(MediaTime::invalidTime(), MediaTime::invalidTime() * -2);
+ EXPECT_EQ(MediaTime::indefiniteTime(), MediaTime::indefiniteTime() * 2);
+ EXPECT_EQ(MediaTime::indefiniteTime(), MediaTime::indefiniteTime() * -2);
+ EXPECT_EQ(MediaTime(6, 1), MediaTime(3, 1) * 2);
+ EXPECT_EQ(MediaTime(0, 1), MediaTime(0, 1) * 2);
+ EXPECT_EQ(MediaTime(1L << 60, 1), MediaTime(1L << 60, 2) * 2);
+ EXPECT_EQ(MediaTime::positiveInfiniteTime(), MediaTime(numeric_limits<int64_t>::max(), 1) * 2);
+ EXPECT_EQ(MediaTime::positiveInfiniteTime(), MediaTime(numeric_limits<int64_t>::min(), 1) * -2);
+ EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime(numeric_limits<int64_t>::max(), 1) * -2);
+ EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime(numeric_limits<int64_t>::min(), 1) * 2);
+
// Constants
EXPECT_EQ(MediaTime::zeroTime(), MediaTime(0, 1));
EXPECT_EQ(MediaTime::invalidTime(), MediaTime(-1, 1, 0));