Title: [270841] trunk/Source
Revision
270841
Author
[email protected]
Date
2020-12-15 08:40:41 -0800 (Tue, 15 Dec 2020)

Log Message

[Mac] Numerous webgl tests time out with WebM format reader enabled
https://bugs.webkit.org/show_bug.cgi?id=219887

Reviewed by Eric Carlson.

Source/WebCore:

Covered by existing tests.

* platform/graphics/TrackPrivateBase.cpp:
(WebCore::TrackPrivateBase::trackUID const):
* platform/graphics/TrackPrivateBase.h:
* platform/graphics/cocoa/AudioTrackPrivateWebM.cpp:
(WebCore::AudioTrackPrivateWebM::id const):
(WebCore::AudioTrackPrivateWebM::trackUID const):
* platform/graphics/cocoa/AudioTrackPrivateWebM.h:
* platform/graphics/cocoa/VideoTrackPrivateWebM.cpp:
(WebCore::VideoTrackPrivateWebM::id const):
(WebCore::VideoTrackPrivateWebM::trackUID const):
* platform/graphics/cocoa/VideoTrackPrivateWebM.h:

Added a way to get the track ID as an optional uint64_t.

* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::callOnMainThreadCallback):
(WebCore::SourceBufferParserWebM::SourceBufferParserWebM):
(WebCore::SourceBufferParserWebM::appendData):
(WebCore::SourceBufferParserWebM::OnClusterBegin):
(WebCore::SourceBufferParserWebM::provideMediaData):
(WebCore::SourceBufferParserWebM::setCallOnClientThreadCallback):
* platform/graphics/cocoa/SourceBufferParserWebM.h:

Added a way for SourceBufferParserWebM clients to customize the thread on which callbacks
are invoked.

Source/WebKit:

When rendering a video frame to canvas, SampleCursor is invoked on the main thread in
order to find a sync frame to render. This triggered an ASSERT(!isMainThread()) in debug
builds, and possibly a deadlock if the cursor pointed to a sample that hadn't yet been
parsed (because SourceBufferParser calls the 'didProvideMediaData' callback on the main
thread).

Resolve this by having SourceBufferParser provide parsed samples on a background queue. To
avoid creating AtomStrings on this non-main queue, teach TrackReader to access the trackID
as a uint64_t instead.

* Shared/mac/MediaFormatReader/FormatReader.cpp:
(WebKit::FormatReader::startOnMainThread):
(WebKit::readerQueue):
(WebKit::FormatReader::parseByteSource):
(WebKit::FormatReader::didParseTracks):
(WebKit::FormatReader::didProvideMediaData):
(WebKit::FormatReader::finishParsing):
(WebKit::FormatReader::copyTrackArray):
* Shared/mac/MediaFormatReader/TrackReader.cpp:
(WebKit::MediaSampleByteRange::MediaSampleByteRange):
(WebKit::TrackReader::create):
(WebKit::TrackReader::storageQueue):
(WebKit::TrackReader::TrackReader):
(WebKit::TrackReader::addSample):
(WebKit::TrackReader::waitForSample const):
(WebKit::TrackReader::finishParsing):
(WebKit::TrackReader::finalize):
* Shared/mac/MediaFormatReader/TrackReader.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270840 => 270841)


--- trunk/Source/WebCore/ChangeLog	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/ChangeLog	2020-12-15 16:40:41 UTC (rev 270841)
@@ -1,3 +1,38 @@
+2020-12-15  Andy Estes  <[email protected]>
+
+        [Mac] Numerous webgl tests time out with WebM format reader enabled
+        https://bugs.webkit.org/show_bug.cgi?id=219887
+
+        Reviewed by Eric Carlson.
+
+        Covered by existing tests.
+
+        * platform/graphics/TrackPrivateBase.cpp:
+        (WebCore::TrackPrivateBase::trackUID const):
+        * platform/graphics/TrackPrivateBase.h:
+        * platform/graphics/cocoa/AudioTrackPrivateWebM.cpp:
+        (WebCore::AudioTrackPrivateWebM::id const):
+        (WebCore::AudioTrackPrivateWebM::trackUID const):
+        * platform/graphics/cocoa/AudioTrackPrivateWebM.h:
+        * platform/graphics/cocoa/VideoTrackPrivateWebM.cpp:
+        (WebCore::VideoTrackPrivateWebM::id const):
+        (WebCore::VideoTrackPrivateWebM::trackUID const):
+        * platform/graphics/cocoa/VideoTrackPrivateWebM.h:
+
+        Added a way to get the track ID as an optional uint64_t.
+
+        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
+        (WebCore::callOnMainThreadCallback):
+        (WebCore::SourceBufferParserWebM::SourceBufferParserWebM):
+        (WebCore::SourceBufferParserWebM::appendData):
+        (WebCore::SourceBufferParserWebM::OnClusterBegin):
+        (WebCore::SourceBufferParserWebM::provideMediaData):
+        (WebCore::SourceBufferParserWebM::setCallOnClientThreadCallback):
+        * platform/graphics/cocoa/SourceBufferParserWebM.h:
+
+        Added a way for SourceBufferParserWebM clients to customize the thread on which callbacks
+        are invoked.
+
 2020-12-15  Chris Dumez  <[email protected]>
 
         [GPUProcess] Crash under AudioDestinationCocoa::setIsPlaying(bool)

Modified: trunk/Source/WebCore/platform/graphics/TrackPrivateBase.cpp (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/TrackPrivateBase.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/TrackPrivateBase.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -33,6 +33,11 @@
 
 namespace WebCore {
 
+Optional<uint64_t> TrackPrivateBase::trackUID() const
+{
+    return WTF::nullopt;
+}
+
 #if !RELEASE_LOG_DISABLED
 
 static uint64_t s_uniqueId = 0;

Modified: trunk/Source/WebCore/platform/graphics/TrackPrivateBase.h (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/TrackPrivateBase.h	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/TrackPrivateBase.h	2020-12-15 16:40:41 UTC (rev 270841)
@@ -63,6 +63,7 @@
     virtual AtomString language() const { return emptyAtom(); }
 
     virtual int trackIndex() const { return 0; }
+    virtual Optional<uint64_t> trackUID() const;
 
     virtual MediaTime startTimeVariance() const { return MediaTime::zeroTime(); }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.cpp (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -44,11 +44,20 @@
 
 AtomString AudioTrackPrivateWebM::id() const
 {
-    if (m_trackID.isNull())
-        m_trackID = m_track.track_uid.is_present() ? AtomString::number(m_track.track_uid.value()) : emptyAtom();
+    if (m_trackID.isNull()) {
+        auto uid = trackUID();
+        m_trackID = uid ? AtomString::number(*uid) : emptyAtom();
+    }
     return m_trackID;
 }
 
+Optional<uint64_t> AudioTrackPrivateWebM::trackUID() const
+{
+    if (m_track.track_uid.is_present())
+        return m_track.track_uid.value();
+    return WTF::nullopt;
+}
+
 AtomString AudioTrackPrivateWebM::label() const
 {
     if (m_label.isNull())

Modified: trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.h (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.h	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.h	2020-12-15 16:40:41 UTC (rev 270841)
@@ -41,6 +41,7 @@
     AtomString label() const final;
     AtomString language() const final;
     int trackIndex() const final;
+    Optional<uint64_t> trackUID() const final;
 
 private:
     AudioTrackPrivateWebM(webm::TrackEntry&&);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -529,9 +529,24 @@
 #endif // ENABLE(VP9) || ENABLE(VORBIS) || ENABLE(OPUS)
 }
 
+RefPtr<SourceBufferParserWebM> SourceBufferParserWebM::create(const ContentType& type)
+{
+    if (isContentTypeSupported(type) != MediaPlayerEnums::SupportsType::IsNotSupported)
+        return adoptRef(new SourceBufferParserWebM());
+    return nullptr;
+}
+
+static SourceBufferParserWebM::CallOnClientThreadCallback callOnMainThreadCallback()
+{
+    return [](Function<void()>&& function) {
+        callOnMainThread(WTFMove(function));
+    };
+}
+
 SourceBufferParserWebM::SourceBufferParserWebM()
     : m_reader(WTF::makeUniqueRef<StreamingVectorReader>())
     , m_initializationSegmentIsHandledSemaphore(Box<BinarySemaphore>::create())
+    , m_callOnClientThreadCallback(callOnMainThreadCallback())
 {
     if (isWebmParserAvailable())
         m_parser = WTF::makeUniqueWithoutFastMallocCheck<WebmParser>();
@@ -585,7 +600,7 @@
     }
 
     ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "status.code(", m_status.code, ")");
-    callOnMainThread([this, protectedThis = makeRef(*this), code = m_status.code] {
+    m_callOnClientThreadCallback([this, protectedThis = makeRef(*this), code = m_status.code] {
         if (m_didEncounterErrorDuringParsingCallback)
             m_didEncounterErrorDuringParsingCallback(code);
     });
@@ -766,7 +781,7 @@
         return Status(Status::kNotEnoughMemory);
 
     if (m_initializationSegmentEncountered && m_didParseInitializationDataCallback) {
-        callOnMainThread([this, protectedThis = makeRef(*this), initializationSegment = WTFMove(*m_initializationSegment)]() mutable {
+        m_callOnClientThreadCallback([this, protectedThis = makeRef(*this), initializationSegment = WTFMove(*m_initializationSegment)]() mutable {
             m_didParseInitializationDataCallback(WTFMove(initializationSegment), [this, protectedThis = makeRef(*this)] {
                 m_initializationSegmentIsHandledSemaphore->signal();
             });
@@ -946,7 +961,7 @@
 
 void SourceBufferParserWebM::provideMediaData(RetainPtr<CMSampleBufferRef> sampleBuffer, uint64_t trackID, Optional<size_t> byteRangeOffset)
 {
-    callOnMainThread([this, protectedThis = makeRef(*this), sampleBuffer = WTFMove(sampleBuffer), trackID, byteRangeOffset] () mutable {
+    m_callOnClientThreadCallback([this, protectedThis = makeRef(*this), sampleBuffer = WTFMove(sampleBuffer), trackID, byteRangeOffset] () mutable {
         if (!m_didProvideMediaDataCallback)
             return;
 
@@ -1211,6 +1226,12 @@
     m_minimumAudioSampleDuration = duration;
 }
 
+void SourceBufferParserWebM::setCallOnClientThreadCallback(CallOnClientThreadCallback&& callback)
+{
+    ASSERT(callback);
+    m_callOnClientThreadCallback = WTFMove(callback);
+}
+
 const HashSet<String>& SourceBufferParserWebM::supportedVideoCodecs()
 {
     static auto codecs = makeNeverDestroyed<HashSet<String>>({ "V_VP8", "V_VP9" });

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2020-12-15 16:40:41 UTC (rev 270841)
@@ -61,6 +61,7 @@
     class StreamingVectorReader;
 
     static MediaPlayerEnums::SupportsType isContentTypeSupported(const ContentType&);
+    static RefPtr<SourceBufferParserWebM> create(const ContentType&);
 
     SourceBufferParserWebM();
     ~SourceBufferParserWebM();
@@ -79,6 +80,9 @@
 
     void flushPendingAudioBuffers();
     void setMinimumAudioSampleDuration(float);
+    
+    using CallOnClientThreadCallback = WTF::Function<void(WTF::Function<void()>&&)>;
+    void setCallOnClientThreadCallback(CallOnClientThreadCallback&&);
 
     void setLogger(const WTF::Logger&, const void* identifier) final;
 
@@ -260,6 +264,7 @@
     float m_minimumAudioSampleDuration { 2 };
 
     Box<BinarySemaphore> m_initializationSegmentIsHandledSemaphore;
+    CallOnClientThreadCallback m_callOnClientThreadCallback;
 
     RefPtr<const WTF::Logger> m_logger;
     const void* m_logIdentifier { nullptr };

Modified: trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.cpp (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -44,11 +44,20 @@
 
 AtomString VideoTrackPrivateWebM::id() const
 {
-    if (m_trackID.isNull())
-        m_trackID = m_track.track_uid.is_present() ? AtomString::number(m_track.track_uid.value()) : emptyAtom();
+    if (m_trackID.isNull()) {
+        auto uid = trackUID();
+        m_trackID = uid ? AtomString::number(*uid) : emptyAtom();
+    }
     return m_trackID;
 }
 
+Optional<uint64_t> VideoTrackPrivateWebM::trackUID() const
+{
+    if (m_track.track_uid.is_present())
+        return m_track.track_uid.value();
+    return WTF::nullopt;
+}
+
 AtomString VideoTrackPrivateWebM::label() const
 {
     if (m_label.isNull())

Modified: trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.h (270840 => 270841)


--- trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.h	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.h	2020-12-15 16:40:41 UTC (rev 270841)
@@ -41,6 +41,7 @@
     AtomString label() const final;
     AtomString language() const final;
     int trackIndex() const final;
+    Optional<uint64_t> trackUID() const final;
 
 private:
     VideoTrackPrivateWebM(webm::TrackEntry&&);

Modified: trunk/Source/WebKit/ChangeLog (270840 => 270841)


--- trunk/Source/WebKit/ChangeLog	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebKit/ChangeLog	2020-12-15 16:40:41 UTC (rev 270841)
@@ -1,3 +1,39 @@
+2020-12-15  Andy Estes  <[email protected]>
+
+        [Mac] Numerous webgl tests time out with WebM format reader enabled
+        https://bugs.webkit.org/show_bug.cgi?id=219887
+
+        Reviewed by Eric Carlson.
+
+        When rendering a video frame to canvas, SampleCursor is invoked on the main thread in
+        order to find a sync frame to render. This triggered an ASSERT(!isMainThread()) in debug
+        builds, and possibly a deadlock if the cursor pointed to a sample that hadn't yet been
+        parsed (because SourceBufferParser calls the 'didProvideMediaData' callback on the main
+        thread).
+
+        Resolve this by having SourceBufferParser provide parsed samples on a background queue. To
+        avoid creating AtomStrings on this non-main queue, teach TrackReader to access the trackID
+        as a uint64_t instead.
+
+        * Shared/mac/MediaFormatReader/FormatReader.cpp:
+        (WebKit::FormatReader::startOnMainThread):
+        (WebKit::readerQueue):
+        (WebKit::FormatReader::parseByteSource):
+        (WebKit::FormatReader::didParseTracks):
+        (WebKit::FormatReader::didProvideMediaData):
+        (WebKit::FormatReader::finishParsing):
+        (WebKit::FormatReader::copyTrackArray):
+        * Shared/mac/MediaFormatReader/TrackReader.cpp:
+        (WebKit::MediaSampleByteRange::MediaSampleByteRange):
+        (WebKit::TrackReader::create):
+        (WebKit::TrackReader::storageQueue):
+        (WebKit::TrackReader::TrackReader):
+        (WebKit::TrackReader::addSample):
+        (WebKit::TrackReader::waitForSample const):
+        (WebKit::TrackReader::finishParsing):
+        (WebKit::TrackReader::finalize):
+        * Shared/mac/MediaFormatReader/TrackReader.h:
+
 2020-12-15  Chris Dumez  <[email protected]>
 
         [GPUProcess] Crash under AudioDestinationCocoa::setIsPlaying(bool)

Modified: trunk/Source/WebKit/Shared/mac/MediaFormatReader/FormatReader.cpp (270840 => 270841)


--- trunk/Source/WebKit/Shared/mac/MediaFormatReader/FormatReader.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebKit/Shared/mac/MediaFormatReader/FormatReader.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -33,7 +33,7 @@
 #include <WebCore/ContentType.h>
 #include <WebCore/InbandTextTrackPrivate.h>
 #include <WebCore/MediaSample.h>
-#include <WebCore/SourceBufferParser.h>
+#include <WebCore/SourceBufferParserWebM.h>
 #include <WebCore/VideoTrackPrivate.h>
 #include <pal/avfoundation/MediaTimeAVFoundation.h>
 #include <wtf/WorkQueue.h>
@@ -70,7 +70,11 @@
 
 void FormatReader::startOnMainThread(MTPluginByteSourceRef byteSource)
 {
-    ASSERT(!isMainThread());
+    if (isMainThread()) {
+        parseByteSource(WTFMove(byteSource));
+        return;
+    }
+
     callOnMainThread([this, protectedThis = makeRef(*this), byteSource = retainPtr(byteSource)]() mutable {
         parseByteSource(WTFMove(byteSource));
     });
@@ -78,7 +82,7 @@
 
 static WorkQueue& readerQueue()
 {
-    static auto& queue = WorkQueue::create("WebKit FormatReader Queue", WorkQueue::Type::Concurrent).leakRef();
+    static auto& queue = WorkQueue::create("WebKit::FormatReader Queue", WorkQueue::Type::Concurrent).leakRef();
     return queue;
 }
 
@@ -87,7 +91,7 @@
     ASSERT(isMainThread());
 
     static NeverDestroyed<ContentType> contentType("video/webm"_s);
-    auto parser = SourceBufferParser::create(contentType, true);
+    auto parser = SourceBufferParserWebM::create(contentType);
     if (!parser) {
         m_parseTracksStatus = kMTPluginFormatReaderError_AllocationFailure;
         return;
@@ -96,13 +100,10 @@
     // Set a minimum audio sample duration of 0 so the parser creates indivisible samples with byte source ranges.
     parser->setMinimumAudioSampleDuration(0);
 
-    auto locker = holdLock(m_parseTracksLock);
+    parser->setCallOnClientThreadCallback([](Function<void()>&& function) {
+        TrackReader::storageQueue().dispatch(WTFMove(function));
+    });
 
-    m_byteSource = WTFMove(byteSource);
-    m_parseTracksStatus = WTF::nullopt;
-    m_duration = MediaTime::invalidTime();
-    m_trackReaders.clear();
-
     parser->setDidParseInitializationDataCallback([this, protectedThis = makeRef(*this)](SourceBufferParser::InitializationSegment&& initializationSegment, CompletionHandler<void()>&& completionHandler) {
         didParseTracks(WTFMove(initializationSegment), noErr);
         completionHandler();
@@ -116,9 +117,15 @@
         didProvideMediaData(WTFMove(mediaSample), trackID, mediaType);
     });
 
+    auto locker = holdLock(m_parseTracksLock);
+    m_byteSource = WTFMove(byteSource);
+    m_parseTracksStatus = WTF::nullopt;
+    m_duration = MediaTime::invalidTime();
+    m_trackReaders.clear();
+
     readerQueue().dispatch([this, protectedThis = makeRef(*this), byteSource = m_byteSource, parser = parser.releaseNonNull()]() mutable {
         parser->appendData(WTFMove(byteSource));
-        callOnMainThread([this, protectedThis = makeRef(*this), parser = WTFMove(parser)]() mutable {
+        TrackReader::storageQueue().dispatch([this, protectedThis = makeRef(*this), parser = WTFMove(parser)]() mutable {
             finishParsing(WTFMove(parser));
         });
     });
@@ -126,7 +133,7 @@
 
 void FormatReader::didParseTracks(SourceBufferPrivateClient::InitializationSegment&& segment, uint64_t errorCode)
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
 
     auto locker = holdLock(m_parseTracksLock);
     ASSERT(!m_parseTracksStatus);
@@ -162,7 +169,7 @@
 
 void FormatReader::didProvideMediaData(Ref<MediaSample>&& mediaSample, uint64_t trackID, const String&)
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
 
     auto locker = holdLock(m_parseTracksLock);
     auto trackIndex = m_trackReaders.findMatching([&](auto& track) {
@@ -175,7 +182,7 @@
 
 void FormatReader::finishParsing(Ref<SourceBufferParser>&& parser)
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
 
     auto locker = holdLock(m_parseTracksLock);
     ASSERT(m_parseTracksStatus.hasValue());
@@ -208,8 +215,6 @@
 
 OSStatus FormatReader::copyTrackArray(CFArrayRef* trackArrayCopy)
 {
-    ASSERT(!isMainThread());
-
     auto locker = holdLock(m_parseTracksLock);
     m_parseTracksCondition.wait(m_parseTracksLock, [&] {
         return m_parseTracksStatus.hasValue();

Modified: trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.cpp (270840 => 270841)


--- trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.cpp	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.cpp	2020-12-15 16:40:41 UTC (rev 270841)
@@ -92,6 +92,7 @@
     , m_byteRange(sample.byteRange())
     , m_byteSource(byteSource)
 {
+    ASSERT(!isMainThread());
     auto platformSample = sample.platformSample();
     switch (platformSample.type) {
     case PlatformSample::CMSampleBufferType:
@@ -139,7 +140,7 @@
 {
     if (!track)
         return nullptr;
-    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, *track, kCMMediaType_Video));
+    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Video, *track->trackUID()));
 }
 
 RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, const AudioTrackPrivate* track)
@@ -146,7 +147,7 @@
 {
     if (!track)
         return nullptr;
-    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, *track, kCMMediaType_Audio));
+    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Audio, *track->trackUID()));
 }
 
 RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, const InbandTextTrackPrivate* track)
@@ -153,22 +154,27 @@
 {
     if (!track)
         return nullptr;
-    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, *track, kCMMediaType_Text));
+    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Text, *track->trackUID()));
 }
 
-TrackReader::TrackReader(Allocator&& allocator, const FormatReader& formatReader, const TrackPrivateBase& track, CMMediaType mediaType)
+WorkQueue& TrackReader::storageQueue()
+{
+    static auto& queue = WorkQueue::create("WebKit::TrackReader Storage Queue", WorkQueue::Type::Serial).leakRef();
+    return queue;
+}
+
+TrackReader::TrackReader(Allocator&& allocator, const FormatReader& formatReader, CMMediaType mediaType, uint64_t trackID)
     : CoreMediaWrapped(WTFMove(allocator))
-    , m_trackID(track.id().string().toUInt64())
+    , m_trackID(trackID)
     , m_mediaType(mediaType)
     , m_duration(formatReader.duration())
 {
-    ASSERT(isMainThread());
-    ASSERT(m_trackID > 0);
+    ASSERT(!isMainThread());
 }
 
 void TrackReader::addSample(Ref<MediaSample>&& sample, MTPluginByteSourceRef byteSource)
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
     auto locker = holdLock(m_sampleStorageLock);
     if (!m_sampleStorage)
         m_sampleStorage = makeUnique<SampleStorage>();
@@ -187,7 +193,6 @@
 
 void TrackReader::waitForSample(Function<bool(SampleMap&, bool)>&& predicate) const
 {
-    ASSERT(!isMainThread());
     auto locker = holdLock(m_sampleStorageLock);
     if (!m_sampleStorage)
         m_sampleStorage = makeUnique<SampleStorage>();
@@ -198,7 +203,7 @@
 
 void TrackReader::finishParsing()
 {
-    ASSERT(isMainThread());
+    ASSERT(!isMainThread());
     auto locker = holdLock(m_sampleStorageLock);
     if (!m_sampleStorage)
         m_sampleStorage = makeUnique<SampleStorage>();
@@ -243,7 +248,7 @@
 void TrackReader::finalize()
 {
     auto locker = holdLock(m_sampleStorageLock);
-    callOnMainThread([sampleStorage = std::exchange(m_sampleStorage, nullptr)] { });
+    storageQueue().dispatch([sampleStorage = std::exchange(m_sampleStorage, nullptr)] { });
     CoreMediaWrapped<TrackReader>::finalize();
 }
 

Modified: trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.h (270840 => 270841)


--- trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.h	2020-12-15 16:36:04 UTC (rev 270840)
+++ trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.h	2020-12-15 16:40:41 UTC (rev 270841)
@@ -33,6 +33,10 @@
 
 DECLARE_CORE_MEDIA_TRAITS(TrackReader);
 
+namespace WTF {
+class WorkQueue;
+}
+
 namespace WebCore {
 class AudioTrackPrivate;
 class InbandTextTrackPrivate;
@@ -55,6 +59,8 @@
     static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, const WebCore::AudioTrackPrivate*);
     static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, const WebCore::InbandTextTrackPrivate*);
 
+    static WTF::WorkQueue& storageQueue();
+
     uint64_t trackID() const { return m_trackID; }
     void addSample(Ref<WebCore::MediaSample>&&, MTPluginByteSourceRef);
     void waitForSample(Function<bool(WebCore::SampleMap&, bool)>&&) const;
@@ -67,7 +73,7 @@
 private:
     using CoreMediaWrapped<TrackReader>::unwrap;
 
-    TrackReader(Allocator&&, const FormatReader&, const WebCore::TrackPrivateBase&, CMMediaType);
+    TrackReader(Allocator&&, const FormatReader&, CMMediaType, uint64_t);
 
     // CMBaseClass
     String debugDescription() const final { return "WebKit::TrackReader"_s; }
@@ -82,7 +88,7 @@
 
     struct SampleStorage {
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
-        ~SampleStorage() { ASSERT(isMainThread()); }
+        ~SampleStorage() { ASSERT(!isMainThread()); }
         WebCore::SampleMap sampleMap;
         bool hasAllSamples { false };
     };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to