Title: [239797] branches/safari-607-branch
Revision
239797
Author
[email protected]
Date
2019-01-09 17:37:59 -0800 (Wed, 09 Jan 2019)

Log Message

Cherry-pick r239688. rdar://problem/47158770

    A MediaTime timescale must never be zero
    https://bugs.webkit.org/show_bug.cgi?id=193156
    <rdar://problem/32504501>

    Reviewed by Jer Noble.

    Source/WTF:

    * wtf/MediaTime.cpp:
    (WTF::greatestCommonDivisor): ASSERT if either parameter or return value is zero.
    (WTF::MediaTime::MediaTime): Create +/- infinity if passed zero timescale.
    (WTF::MediaTime::createWithFloat): Ditto.
    (WTF::MediaTime::createWithDouble): Ditto.
    (WTF::MediaTime::setTimeScale): Ditto.

    Tools:

    * TestWebKitAPI/Tests/WTF/MediaTime.cpp:
    (TestWebKitAPI::TEST): Add tests for zero timescale.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239688 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WTF/ChangeLog (239796 => 239797)


--- branches/safari-607-branch/Source/WTF/ChangeLog	2019-01-10 01:37:56 UTC (rev 239796)
+++ branches/safari-607-branch/Source/WTF/ChangeLog	2019-01-10 01:37:59 UTC (rev 239797)
@@ -1,3 +1,45 @@
+2019-01-09  Kocsen Chung  <[email protected]>
+
+        Cherry-pick r239688. rdar://problem/47158770
+
+    A MediaTime timescale must never be zero
+    https://bugs.webkit.org/show_bug.cgi?id=193156
+    <rdar://problem/32504501>
+    
+    Reviewed by Jer Noble.
+    
+    Source/WTF:
+    
+    * wtf/MediaTime.cpp:
+    (WTF::greatestCommonDivisor): ASSERT if either parameter or return value is zero.
+    (WTF::MediaTime::MediaTime): Create +/- infinity if passed zero timescale.
+    (WTF::MediaTime::createWithFloat): Ditto.
+    (WTF::MediaTime::createWithDouble): Ditto.
+    (WTF::MediaTime::setTimeScale): Ditto.
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WTF/MediaTime.cpp:
+    (TestWebKitAPI::TEST): Add tests for zero timescale.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-01-07  Eric Carlson  <[email protected]>
+
+            A MediaTime timescale must never be zero
+            https://bugs.webkit.org/show_bug.cgi?id=193156
+            <rdar://problem/32504501>
+
+            Reviewed by Jer Noble.
+
+            * wtf/MediaTime.cpp:
+            (WTF::greatestCommonDivisor): ASSERT if either parameter or return value is zero.
+            (WTF::MediaTime::MediaTime): Create +/- infinity if passed zero timescale.
+            (WTF::MediaTime::createWithFloat): Ditto.
+            (WTF::MediaTime::createWithDouble): Ditto.
+            (WTF::MediaTime::setTimeScale): Ditto.
+
 2019-01-02  Alex Christensen  <[email protected]>
 
         Homograph with LATIN SMALL LETTER R WITH FISHHOOK

Modified: branches/safari-607-branch/Source/WTF/wtf/MediaTime.cpp (239796 => 239797)


--- branches/safari-607-branch/Source/WTF/wtf/MediaTime.cpp	2019-01-10 01:37:56 UTC (rev 239796)
+++ branches/safari-607-branch/Source/WTF/wtf/MediaTime.cpp	2019-01-10 01:37:59 UTC (rev 239797)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,6 +31,7 @@
 
 #include <algorithm>
 #include <cstdlib>
+#include <wtf/Assertions.h>
 #include <wtf/CheckedArithmetic.h>
 #include <wtf/JSONValues.h>
 #include <wtf/MathExtras.h>
@@ -41,6 +42,9 @@
 
 static uint32_t greatestCommonDivisor(uint32_t a, uint32_t b)
 {
+    ASSERT(a);
+    ASSERT(b);
+
     // Euclid's Algorithm
     uint32_t temp = 0;
     while (b) {
@@ -48,6 +52,8 @@
         b = a % b;
         a = temp;
     }
+
+    ASSERT(a);
     return a;
 }
 
@@ -75,6 +81,10 @@
     , m_timeScale(scale)
     , m_timeFlags(flags)
 {
+    if (scale || isInvalid())
+        return;
+
+    *this = value < 0 ? negativeInfiniteTime() : positiveInfiniteTime();
 }
 
 MediaTime::~MediaTime()
@@ -108,6 +118,8 @@
         return positiveInfiniteTime();
     if (floatTime < std::numeric_limits<int64_t>::min())
         return negativeInfiniteTime();
+    if (!timeScale)
+        return std::signbit(floatTime) ? negativeInfiniteTime() : positiveInfiniteTime();
 
     while (floatTime * timeScale > std::numeric_limits<int64_t>::max())
         timeScale /= 2;
@@ -136,6 +148,8 @@
         return positiveInfiniteTime();
     if (doubleTime < std::numeric_limits<int64_t>::min())
         return negativeInfiniteTime();
+    if (!timeScale)
+        return std::signbit(doubleTime) ? negativeInfiniteTime() : positiveInfiniteTime();
 
     while (doubleTime * timeScale > std::numeric_limits<int64_t>::max())
         timeScale /= 2;
@@ -484,6 +498,11 @@
         return;
     }
 
+    if (!timeScale) {
+        *this = m_timeValue < 0 ? negativeInfiniteTime() : positiveInfiniteTime();
+        return;
+    }
+
     if (timeScale == m_timeScale)
         return;
 

Modified: branches/safari-607-branch/Tools/ChangeLog (239796 => 239797)


--- branches/safari-607-branch/Tools/ChangeLog	2019-01-10 01:37:56 UTC (rev 239796)
+++ branches/safari-607-branch/Tools/ChangeLog	2019-01-10 01:37:59 UTC (rev 239797)
@@ -1,5 +1,43 @@
 2019-01-09  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r239688. rdar://problem/47158770
+
+    A MediaTime timescale must never be zero
+    https://bugs.webkit.org/show_bug.cgi?id=193156
+    <rdar://problem/32504501>
+    
+    Reviewed by Jer Noble.
+    
+    Source/WTF:
+    
+    * wtf/MediaTime.cpp:
+    (WTF::greatestCommonDivisor): ASSERT if either parameter or return value is zero.
+    (WTF::MediaTime::MediaTime): Create +/- infinity if passed zero timescale.
+    (WTF::MediaTime::createWithFloat): Ditto.
+    (WTF::MediaTime::createWithDouble): Ditto.
+    (WTF::MediaTime::setTimeScale): Ditto.
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WTF/MediaTime.cpp:
+    (TestWebKitAPI::TEST): Add tests for zero timescale.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-01-07  Eric Carlson  <[email protected]>
+
+            A MediaTime timescale must never be zero
+            https://bugs.webkit.org/show_bug.cgi?id=193156
+            <rdar://problem/32504501>
+
+            Reviewed by Jer Noble.
+
+            * TestWebKitAPI/Tests/WTF/MediaTime.cpp:
+            (TestWebKitAPI::TEST): Add tests for zero timescale.
+
+2019-01-09  Kocsen Chung  <[email protected]>
+
         Cherry-pick r239676. rdar://problem/47158606
 
     API test broken: TestWebKitAPI.WebKit.CustomDataStorePathsVersusCompletionHandlers

Modified: branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp (239796 => 239797)


--- branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp	2019-01-10 01:37:56 UTC (rev 239796)
+++ branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp	2019-01-10 01:37:59 UTC (rev 239797)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -309,6 +309,18 @@
     EXPECT_EQ(MediaTime(bigInt - 2, MediaTime::MaximumTimeScale).toTimeScale(MediaTime::MaximumTimeScale - 1).hasBeenRounded(), true);
     EXPECT_EQ(MediaTime(bigInt, 1).toTimeScale(MediaTime::MaximumTimeScale), MediaTime::positiveInfiniteTime());
     EXPECT_EQ(MediaTime(-bigInt, 1).toTimeScale(MediaTime::MaximumTimeScale), MediaTime::negativeInfiniteTime());
+
+    // Non-zero timescale
+    EXPECT_EQ(MediaTime(102, 0), MediaTime::positiveInfiniteTime());
+    EXPECT_EQ(MediaTime(-102, 0), MediaTime::negativeInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithDouble(99, 0), MediaTime::positiveInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithDouble(-99, 0), MediaTime::negativeInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithDouble(99).toTimeScale(0), MediaTime::positiveInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithDouble(-99).toTimeScale(0), MediaTime::negativeInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithFloat(909, 0), MediaTime::positiveInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithFloat(-909, 0), MediaTime::negativeInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithFloat(999).toTimeScale(0), MediaTime::positiveInfiniteTime());
+    EXPECT_EQ(MediaTime::createWithFloat(-999).toTimeScale(0), MediaTime::negativeInfiniteTime());
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to