Skip to content

Commit 961981e

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
MediaTime spaceship operator returns the wrong order for equal negative numerators with different timescales
https://bugs.webkit.org/show_bug.cgi?id=328445 rdar://190698694 Reviewed by Eric Carlson. When both operands have the same time value but different time scales, the spaceship operator returned `b.m_timeScale <=> a.m_timeScale`. That is only correct for positive values, where a larger scale means a smaller magnitude. For negative values the relationship is reversed, so MediaTime(-1, 10) (-0.1) compared as less than MediaTime(-1, 5) (-0.2). Compare the scales in the opposite order when the shared time value is negative. Test: Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp * Source/WTF/wtf/MediaTime.cpp: (WTF::operator<=>): * Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp: (TestWebKitAPI::TEST(WTF, MediaTime)): Canonical link: https://commits.webkit.org/324514@main
1 parent 549e7aa commit 961981e

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎Source/WTF/wtf/MediaTime.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ std::partial_ordering operator<=>(const MediaTime& a, const MediaTime& b)
377377
return a.m_timeValue <=> b.m_timeValue;
378378

379379
if (a.m_timeValue == b.m_timeValue)
380-
return b.m_timeScale <=> a.m_timeScale;
380+
return a.m_timeValue < 0 ? a.m_timeScale <=> b.m_timeScale : b.m_timeScale <=> a.m_timeScale;
381381

382382
if (a.m_timeValue >= 0) {
383383
if (a.m_timeValue < b.m_timeValue && a.m_timeScale > b.m_timeScale)

‎Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ TEST(WTF, MediaTime)
168168
EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime(std::numeric_limits<int64_t>::max(), 1) * -2);
169169
EXPECT_EQ(MediaTime::negativeInfiniteTime(), MediaTime(std::numeric_limits<int64_t>::min(), 1) * 2);
170170

171+
// Comparison with equal numerators and different scales
172+
EXPECT_LT(MediaTime(1, 10), MediaTime(1, 5));
173+
EXPECT_GT(MediaTime(1, 5), MediaTime(1, 10));
174+
EXPECT_GT(MediaTime(-1, 10), MediaTime(-1, 5));
175+
EXPECT_LT(MediaTime(-1, 5), MediaTime(-1, 10));
176+
171177
// Constants
172178
EXPECT_EQ(MediaTime::zeroTime(), MediaTime(0, 1));
173179
EXPECT_EQ(MediaTime::invalidTime(), MediaTime(-1, 1, 0));

0 commit comments

Comments
 (0)