WebKit Bugzilla
Attachment 358442 Details for
Bug 193156
: A MediaTime timescale must never be zero
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-193156-20190106094558.patch (text/plain), 6.00 KB, created by
Eric Carlson
on 2019-01-05 12:45:59 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Eric Carlson
Created:
2019-01-05 12:45:59 PST
Size:
6.00 KB
patch
obsolete
>Subversion Revision: 239461 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 36a3eae2a209273ab1e71cd3aa7a8aeb32e0ea66..df919adcd6c9706a3dba5b823b8fe02da2f03c4d 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,18 @@ >+2019-01-04 Eric Carlson <eric.carlson@apple.com> >+ >+ A MediaTime timescale must never be zero >+ https://bugs.webkit.org/show_bug.cgi?id=193156 >+ <rdar://problem/32504501> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * 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. >+ > 2018-12-20 Chris Dumez <cdumez@apple.com> > > Use Optional::valueOr() instead of Optional::value_or() >diff --git a/Source/WTF/wtf/MediaTime.cpp b/Source/WTF/wtf/MediaTime.cpp >index 94712ea3c7d2a256a4c0f66fa0d528c83449fbee..276cf9c97bfbd5c7aa1bb345989561549b8fef97 100644 >--- a/Source/WTF/wtf/MediaTime.cpp >+++ b/Source/WTF/wtf/MediaTime.cpp >@@ -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 @@ namespace WTF { > > 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 @@ static uint32_t greatestCommonDivisor(uint32_t a, uint32_t b) > b = a % b; > a = temp; > } >+ >+ ASSERT(a); > return a; > } > >@@ -75,6 +81,13 @@ MediaTime::MediaTime(int64_t value, uint32_t scale, uint8_t flags) > , m_timeScale(scale) > , m_timeFlags(flags) > { >+ if (scale || isInvalid()) >+ return; >+ >+ if (value < 0) >+ *this = negativeInfiniteTime(); >+ else >+ *this = positiveInfiniteTime(); > } > > MediaTime::~MediaTime() >@@ -108,6 +121,8 @@ MediaTime MediaTime::createWithFloat(float floatTime, uint32_t timeScale) > 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 +151,8 @@ MediaTime MediaTime::createWithDouble(double doubleTime, uint32_t timeScale) > 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 +501,11 @@ void MediaTime::setTimeScale(uint32_t timeScale, RoundingFlags flags) > return; > } > >+ if (!timeScale) { >+ *this = m_timeValue < 0 ? negativeInfiniteTime() : positiveInfiniteTime(); >+ return; >+ } >+ > if (timeScale == m_timeScale) > return; > >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 2b84345254b15ef3f8898761303091a3678d9e33..b49a5cd94cdd4c57c6c40c420aecb9680637ecca 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,14 @@ >+2019-01-04 Eric Carlson <eric.carlson@apple.com> >+ >+ A MediaTime timescale must never be zero >+ https://bugs.webkit.org/show_bug.cgi?id=193156 >+ <rdar://problem/32504501> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/Tests/WTF/MediaTime.cpp: >+ (TestWebKitAPI::TEST): Add tests for zero timescale. >+ > 2018-12-20 Chris Dumez <cdumez@apple.com> > > Use Optional::valueOr() instead of Optional::value_or() >diff --git a/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp b/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp >index 703ab125f3668a461568770dbc5e04761b8e49a2..961bc26f20d96e6d2bba5d1fa0c17386a214d8d1 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp >@@ -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 @@ TEST(WTF, MediaTime) > 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()); > } > > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193156
:
358385
|
358398
|
358406
|
358407
|
358417
|
358420
|
358442
|
358510