Changeset 254767 in webkit


Ignore:
Timestamp:
Jan 17, 2020 2:31:58 PM (4 years ago)
Author:
eric.carlson@apple.com
Message:

REGRESSION (r254483): media/track/track-cues-sorted-before-dispatch.html became very flaky
https://bugs.webkit.org/show_bug.cgi?id=206225
<rdar://problem/58634315>

Reviewed by Jer Noble.

The list of text track cues that are to fire events are sorted before events are
fired. Cue were being sorted by track, then by start time, and then by end time.
This meant that the sort order of two cues in the same track with identical start
and end times was not stable, causing this test to be flaky. The spec says to sort
by a cue's position in the track cue list when start and end times are identical,
so do that.

No new tests, this fixes a flaky test.

  • html/track/TextTrackCue.cpp:

(WebCore::TextTrackCue::cueIndex const):
(WebCore::TextTrackCue::isOrderedBefore const):

  • html/track/TextTrackCue.h:
  • html/track/TextTrackCueList.cpp:

(WebCore::cueSortsBefore):
(WebCore::TextTrackCueList::cueIndex const):
(WebCore::TextTrackCueList::add):
(WebCore::TextTrackCueList::updateCueIndex):
(WebCore::compareCues): Deleted.

  • html/track/TextTrackCueList.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r254766 r254767  
     12020-01-17  Eric Carlson  <eric.carlson@apple.com>
     2
     3        REGRESSION (r254483): media/track/track-cues-sorted-before-dispatch.html became very flaky
     4        https://bugs.webkit.org/show_bug.cgi?id=206225
     5        <rdar://problem/58634315>
     6
     7        Reviewed by Jer Noble.
     8
     9        The list of text track cues that are to fire events are sorted before events are
     10        fired. Cue were being sorted by track, then by start time, and then by end time.
     11        This meant that the sort order of two cues in the same track with identical start
     12        and end times was not stable, causing this test to be flaky. The spec says to sort
     13        by a cue's position in the track cue list when start and end times are identical,
     14        so do that.
     15
     16        No new tests, this fixes a flaky test.
     17
     18        * html/track/TextTrackCue.cpp:
     19        (WebCore::TextTrackCue::cueIndex const):
     20        (WebCore::TextTrackCue::isOrderedBefore const):
     21        * html/track/TextTrackCue.h:
     22        * html/track/TextTrackCueList.cpp:
     23        (WebCore::cueSortsBefore):
     24        (WebCore::TextTrackCueList::cueIndex const):
     25        (WebCore::TextTrackCueList::add):
     26        (WebCore::TextTrackCueList::updateCueIndex):
     27        (WebCore::compareCues): Deleted.
     28        * html/track/TextTrackCueList.h:
     29
    1302020-01-17  Andres Gonzalez  <andresg_22@apple.com>
    231
  • trunk/Source/WebCore/html/track/TextTrackCue.cpp

    r253290 r254767  
    11/*
    22 * Copyright (C) 2011, 2013 Google Inc.  All rights reserved.
    3  * Copyright (C) 2011-2017 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    5151#include "VTTCue.h"
    5252#include "VTTRegionList.h"
     53#include <limits.h>
    5354#include <wtf/HexNumber.h>
    5455#include <wtf/IsoMallocInlines.h>
     
    339340}
    340341
     342unsigned TextTrackCue::cueIndex() const
     343{
     344    ASSERT(m_track && m_track->cues());
     345    if (!m_track || !m_track->cues())
     346        return std::numeric_limits<unsigned>::max();
     347
     348    return m_track->cues()->cueIndex(*this);
     349}
     350
    341351bool TextTrackCue::isOrderedBefore(const TextTrackCue* other) const
    342352{
    343     return startMediaTime() < other->startMediaTime() || (startMediaTime() == other->startMediaTime() && endMediaTime() > other->endMediaTime());
     353    // ... cues must be sorted by their start time, earliest first;
     354    if (startMediaTime() != other->startMediaTime())
     355        return startMediaTime() < other->startMediaTime();
     356
     357    // then, any cues with the same start time must be sorted by their end time, latest first;
     358    if (endMediaTime() != other->endMediaTime())
     359        return endMediaTime() > other->endMediaTime();
     360
     361    // and finally, any cues with identical end times must be sorted in the order they were last added to
     362    // their respective text track list of cues, oldest first (so e.g. for cues from a WebVTT file, that
     363    // would initially be the order in which the cues were listed in the file)
     364    return cueIndex() < other->cueIndex();
    344365}
    345366
  • trunk/Source/WebCore/html/track/TextTrackCue.h

    r253290 r254767  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
    3  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    128128    virtual void updateDisplayTree(const MediaTime&) { };
    129129
     130    unsigned cueIndex() const;
     131
    130132protected:
    131133    TextTrackCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, DocumentFragment&&);
  • trunk/Source/WebCore/html/track/TextTrackCueList.cpp

    r221155 r254767  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     3 * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    3535
    3636#ifdef CHECK_SORTING
    37 #define ASSERT_SORTED(begin, end) ASSERT(std::is_sorted(begin, end, compareCues))
     37#define ASSERT_SORTED(begin, end) ASSERT(std::is_sorted(begin, end, cueSortsBefore))
    3838#else
    3939#define ASSERT_SORTED(begin, end) ((void)0)
     
    4242namespace WebCore {
    4343
    44 static inline bool compareCues(const RefPtr<TextTrackCue>& a, const RefPtr<TextTrackCue>& b)
     44static inline bool cueSortsBefore(const RefPtr<TextTrackCue>& a, const RefPtr<TextTrackCue>& b)
    4545{
    46     return a->isOrderedBefore(b.get());
     46    if (a->startMediaTime() < b->startMediaTime())
     47        return true;
     48
     49    return a->startMediaTime() == b->startMediaTime() && a->endMediaTime() > b->endMediaTime();
    4750}
    4851
    49 unsigned TextTrackCueList::cueIndex(TextTrackCue& cue) const
     52unsigned TextTrackCueList::cueIndex(const TextTrackCue& cue) const
    5053{
    5154    ASSERT(m_vector.contains(&cue));
     
    9497
    9598    RefPtr<TextTrackCue> cueRefPtr { WTFMove(cue) };
    96     unsigned insertionPosition = std::upper_bound(m_vector.begin(), m_vector.end(), cueRefPtr, compareCues) - m_vector.begin();
     99    unsigned insertionPosition = std::upper_bound(m_vector.begin(), m_vector.end(), cueRefPtr, cueSortsBefore) - m_vector.begin();
    97100    ASSERT_SORTED(m_vector.begin(), m_vector.end());
    98101    m_vector.insert(insertionPosition, WTFMove(cueRefPtr));
     
    114117}
    115118
    116 void TextTrackCueList::updateCueIndex(TextTrackCue& cue)
     119void TextTrackCueList::updateCueIndex(const TextTrackCue& cue)
    117120{
    118121    auto cuePosition = m_vector.begin() + cueIndex(cue);
     
    122125    ASSERT_SORTED(afterCuePosition, m_vector.end());
    123126
    124     auto reinsertionPosition = std::upper_bound(m_vector.begin(), cuePosition, *cuePosition, compareCues);
     127    auto reinsertionPosition = std::upper_bound(m_vector.begin(), cuePosition, *cuePosition, cueSortsBefore);
    125128    if (reinsertionPosition != cuePosition)
    126129        std::rotate(reinsertionPosition, cuePosition, afterCuePosition);
    127130    else {
    128         reinsertionPosition = std::upper_bound(afterCuePosition, m_vector.end(), *cuePosition, compareCues);
     131        reinsertionPosition = std::upper_bound(afterCuePosition, m_vector.end(), *cuePosition, cueSortsBefore);
    129132        if (reinsertionPosition != afterCuePosition)
    130133            std::rotate(cuePosition, afterCuePosition, reinsertionPosition);
  • trunk/Source/WebCore/html/track/TextTrackCueList.h

    r221155 r254767  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
    3  * Copyright (C) 2017 Apple Inc. All rights reserved.
     3 * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    4141    TextTrackCue* getCueById(const String&) const;
    4242
    43     unsigned cueIndex(TextTrackCue&) const;
     43    unsigned cueIndex(const TextTrackCue&) const;
    4444
    4545    void add(Ref<TextTrackCue>&&);
    4646    void remove(TextTrackCue&);
    47     void updateCueIndex(TextTrackCue&);
     47    void updateCueIndex(const TextTrackCue&);
    4848
    4949    void clear();
Note: See TracChangeset for help on using the changeset viewer.