Changeset 254200 in webkit


Ignore:
Timestamp:
Jan 8, 2020 7:57:03 AM (4 years ago)
Author:
aboya@igalia.com
Message:

[WTF] Allow MediaTime static constants
https://bugs.webkit.org/show_bug.cgi?id=205723

Reviewed by Darin Adler.

Source/WebCore:

Since MediaTime no longer has a non-trivial destructor, declaring
MediaTime variables no longer has potential side effects as far as the
compiler is concerned and it can therefore print "unused variable"
errors where that is the case.

This patch marks one of such variable as intentionally unused, since
it's only used in Debug and would otherwise break the Release build.
Actually unused variables are also removed.

  • platform/graphics/cocoa/WebCoreDecompressionSession.mm:

(WebCore::WebCoreDecompressionSession::imageForTime):

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::sourceBufferPrivateFastSeekTimeForMediaTime):

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::removeCodedFrames):

Source/WTF:

Despite all its convenience methods, at its core MediaTime is a rather
trivial class with only integral members. Despite this, since it had a
destructor declared, this made the class non-trivially destructible
even if the implementation was empty, and therefore clang did not
allow to use it for static variables unless done in form of a pointer.

By removing the destructor this restriction is lifted and we don't
need heap allocations for static MediaTime objects.

Previous usages of heap allocation for static MediaTime objects have
been rewritten to take advantage of this. Test coverage is provided by
successful compilation without [-Werror,-Wexit-time-destructors]
errors and existing tests.

  • wtf/MediaTime.cpp:

(WTF::MediaTime::zeroTime):
(WTF::MediaTime::invalidTime):
(WTF::MediaTime::positiveInfiniteTime):
(WTF::MediaTime::negativeInfiniteTime):
(WTF::MediaTime::indefiniteTime):
(WTF::MediaTime::~MediaTime): Deleted.

  • wtf/MediaTime.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r254187 r254200  
     12020-01-08  Alicia Boya García  <aboya@igalia.com>
     2
     3        [WTF] Allow MediaTime static constants
     4        https://bugs.webkit.org/show_bug.cgi?id=205723
     5
     6        Reviewed by Darin Adler.
     7
     8        Despite all its convenience methods, at its core MediaTime is a rather
     9        trivial class with only integral members. Despite this, since it had a
     10        destructor declared, this made the class non-trivially destructible
     11        even if the implementation was empty, and therefore clang did not
     12        allow to use it for static variables unless done in form of a pointer.
     13
     14        By removing the destructor this restriction is lifted and we don't
     15        need heap allocations for static MediaTime objects.
     16
     17        Previous usages of heap allocation for static MediaTime objects have
     18        been rewritten to take advantage of this. Test coverage is provided by
     19        successful compilation without [-Werror,-Wexit-time-destructors]
     20        errors and existing tests.
     21
     22        * wtf/MediaTime.cpp:
     23        (WTF::MediaTime::zeroTime):
     24        (WTF::MediaTime::invalidTime):
     25        (WTF::MediaTime::positiveInfiniteTime):
     26        (WTF::MediaTime::negativeInfiniteTime):
     27        (WTF::MediaTime::indefiniteTime):
     28        (WTF::MediaTime::~MediaTime): Deleted.
     29        * wtf/MediaTime.h:
     30
    1312020-01-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
    232
  • trunk/Source/WTF/wtf/MediaTime.cpp

    r253975 r254200  
    4242namespace WTF {
    4343
     44static_assert(std::is_trivially_destructible_v<MediaTime>, "MediaTime should be trivially destructible.");
     45
    4446static uint32_t greatestCommonDivisor(uint32_t a, uint32_t b)
    4547{
     
    8789
    8890    *this = value < 0 ? negativeInfiniteTime() : positiveInfiniteTime();
    89 }
    90 
    91 MediaTime::~MediaTime()
    92 {
    9391}
    9492
     
    458456const MediaTime& MediaTime::zeroTime()
    459457{
    460     static const MediaTime* time = new MediaTime(0, 1, Valid);
    461     return *time;
     458    static const MediaTime time(0, 1, Valid);
     459    return time;
    462460}
    463461
    464462const MediaTime& MediaTime::invalidTime()
    465463{
    466     static const MediaTime* time = new MediaTime(-1, 1, 0);
    467     return *time;
     464    static const MediaTime time(-1, 1, 0);
     465    return time;
    468466}
    469467
    470468const MediaTime& MediaTime::positiveInfiniteTime()
    471469{
    472     static const MediaTime* time = new MediaTime(0, 1, PositiveInfinite | Valid);
    473     return *time;
     470    static const MediaTime time(0, 1, PositiveInfinite | Valid);
     471    return time;
    474472}
    475473
    476474const MediaTime& MediaTime::negativeInfiniteTime()
    477475{
    478     static const MediaTime* time = new MediaTime(-1, 1, NegativeInfinite | Valid);
    479     return *time;
     476    static const MediaTime time(-1, 1, NegativeInfinite | Valid);
     477    return time;
    480478}
    481479
    482480const MediaTime& MediaTime::indefiniteTime()
    483481{
    484     static const MediaTime* time = new MediaTime(0, 1, Indefinite | Valid);
    485     return *time;
     482    static const MediaTime time(0, 1, Indefinite | Valid);
     483    return time;
    486484}
    487485
  • trunk/Source/WTF/wtf/MediaTime.h

    r253290 r254200  
    5757    MediaTime(int64_t value, uint32_t scale, uint8_t flags = Valid);
    5858    MediaTime(const MediaTime& rhs);
    59     ~MediaTime();
    6059
    6160    static MediaTime createWithFloat(float floatTime);
  • trunk/Source/WebCore/ChangeLog

    r254198 r254200  
     12020-01-08  Alicia Boya García  <aboya@igalia.com>
     2
     3        [WTF] Allow MediaTime static constants
     4        https://bugs.webkit.org/show_bug.cgi?id=205723
     5
     6        Reviewed by Darin Adler.
     7
     8        Since MediaTime no longer has a non-trivial destructor, declaring
     9        MediaTime variables no longer has potential side effects as far as the
     10        compiler is concerned and it can therefore print "unused variable"
     11        errors where that is the case.
     12
     13        This patch marks one of such variable as intentionally unused, since
     14        it's only used in Debug and would otherwise break the Release build.
     15        Actually unused variables are also removed.
     16
     17        * platform/graphics/cocoa/WebCoreDecompressionSession.mm:
     18        (WebCore::WebCoreDecompressionSession::imageForTime):
     19        * Modules/mediasource/SourceBuffer.cpp:
     20        (WebCore::SourceBuffer::sourceBufferPrivateFastSeekTimeForMediaTime):
     21        * Modules/mediasource/SourceBuffer.cpp:
     22        (WebCore::SourceBuffer::removeCodedFrames):
     23
    1242020-01-08  Diego Pino Garcia  <dpino@igalia.com>
    225
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp

    r253809 r254200  
    496496{
    497497    MediaTime seekTime = targetTime;
    498     MediaTime lowerBoundTime = targetTime - negativeThreshold;
    499     MediaTime upperBoundTime = targetTime + positiveThreshold;
    500498
    501499    for (auto& trackBuffer : m_trackBufferMap.values()) {
     
    811809
    812810    // 1. Let start be the starting presentation timestamp for the removal range.
    813     MediaTime durationMediaTime = m_source->duration();
    814811    MediaTime currentMediaTime = m_source->currentTime();
    815812
  • trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm

    r251454 r254200  
    475475
    476476    MediaTime startTime = PAL::toMediaTime(CMBufferQueueGetFirstPresentationTimeStamp(m_producerQueue.get()));
     477#if !LOG_DISABLED
    477478    MediaTime endTime = PAL::toMediaTime(CMBufferQueueGetEndPresentationTimeStamp(m_producerQueue.get()));
     479#endif
    478480    if (!allowLater && time < startTime) {
    479481        LOG(Media, "WebCoreDecompressionSession::imageForTime(%p) - time(%s) too early for queue(%s -> %s)", this, toString(time).utf8().data(), toString(startTime).utf8().data(), toString(endTime).utf8().data());
Note: See TracChangeset for help on using the changeset viewer.