Title: [279375] trunk
Revision
279375
Author
[email protected]
Date
2021-06-29 10:11:34 -0700 (Tue, 29 Jun 2021)

Log Message

Loading WebM hangs if server sends only small amount of data
https://bugs.webkit.org/show_bug.cgi?id=226217
<rdar://problem/78709010>

Source/WebCore/PAL:

Reviewed by Eric Carlson.

* pal/cf/CoreMediaSoftLink.cpp:
* pal/cf/CoreMediaSoftLink.h:
* pal/spi/cf/CoreMediaSPI.h:

Source/WebKit:

Reviewed by Eric Carlson.

Test: http/tests/media/video-webm-stall.html

Adopt FigThread{Un,}RegisterAbortAction() when blocking against track parsing.

CoreMedia will attempt to abort reads during AVPlayer teardown, but because the parsing
thread is blocked on a Condition variable in WebKit code, the abort request has no effect.
Adopt methods from CoreMedia to run code during an abort request, and wrap these calls in a
stack-based object. The new AbortAction object takes a Condition variable to notify during
an abort, and its aborted() state can be queried by the Condition's predicate.

Drive-by Fix: enable running an unsigned MTFormatReaderPlugin in the GPU process for
engineering builds.

* Configurations/BaseTarget.xcconfig:
* GPUProcess/mac/GPUProcessMac.mm:
(WebKit::GPUProcess::initializeProcess):
* Shared/mac/MediaFormatReader/MediaFormatReader.cpp:
(WebKit::AbortAction::AbortAction):
(WebKit::AbortAction::~AbortAction):
(WebKit::AbortAction::aborted const):
(WebKit::AbortAction::action):
(WebKit::MediaFormatReader::copyProperty):
(WebKit::MediaFormatReader::copyTrackArray):

LayoutTests:

Reviewed by NOBODY Eric Carlson.

* http/tests/media/resources/.htaccess: Added.
* http/tests/media/video-webm-stall-expected.txt: Added.
* http/tests/media/video-webm-stall.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279374 => 279375)


--- trunk/LayoutTests/ChangeLog	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/LayoutTests/ChangeLog	2021-06-29 17:11:34 UTC (rev 279375)
@@ -1,3 +1,15 @@
+2021-06-24  Jer Noble  <[email protected]>
+
+        Loading WebM hangs if server sends only small amount of data
+        https://bugs.webkit.org/show_bug.cgi?id=226217
+        <rdar://problem/78709010>
+
+        Reviewed by Eric Carlson.
+
+        * http/tests/media/resources/.htaccess: Added.
+        * http/tests/media/video-webm-stall-expected.txt: Added.
+        * http/tests/media/video-webm-stall.html: Added.
+
 2021-06-29  Yoshiaki Jitsukawa  <[email protected]>
 
         P-384 EC public JWK key in layout tests is wrong

Added: trunk/LayoutTests/http/tests/media/resources/.htaccess (0 => 279375)


--- trunk/LayoutTests/http/tests/media/resources/.htaccess	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/resources/.htaccess	2021-06-29 17:11:34 UTC (rev 279375)
@@ -0,0 +1,4 @@
+# macOS ports currently require webm files to be served with a .webm extension, so
+# add a rewrite rule for the purposes of serving .webm files through serve_video.py.
+RewriteEngine on
+RewriteRule ^serve_video.py.webm serve_video.py [L,NS]
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/media/video-webm-stall-expected.txt (0 => 279375)


--- trunk/LayoutTests/http/tests/media/video-webm-stall-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/video-webm-stall-expected.txt	2021-06-29 17:11:34 UTC (rev 279375)
@@ -0,0 +1,10 @@
+
+RUN(video.src = '')
+EVENT(stalled)
+RUN(video.src = '')
+RUN(video.load())
+EVENT(emptied)
+RUN(video.src = '')
+EVENT(canplay)
+END OF TEST
+

Added: trunk/LayoutTests/http/tests/media/video-webm-stall.html (0 => 279375)


--- trunk/LayoutTests/http/tests/media/video-webm-stall.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/video-webm-stall.html	2021-06-29 17:11:34 UTC (rev 279375)
@@ -0,0 +1,38 @@
+<html>
+<head>
+    <script src=""
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        window.addEventListener('load', async event => {
+            findMediaElement();
+
+            if (video.canPlayType('video/webm; codecs="vp8"') == "") {
+                failTest('"video/webm" not supported');
+                return;
+            }
+
+            waitFor(video, 'error').then(event => { failTest('') });
+
+            let stallOffset = 13;
+            run(`video.src = ''`);
+            await waitFor(video, 'stalled');
+
+            run(`video.src = ''`);
+            run('video.load()');
+            await waitFor(video, 'emptied');
+
+            run(`video.src = ''`);
+            await waitFor(video, 'canplay');
+            endTest();
+        });
+
+    </script>
+</head>
+<body>
+<video id="video" playsinline muted></video>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (279374 => 279375)


--- trunk/LayoutTests/platform/ios/TestExpectations	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2021-06-29 17:11:34 UTC (rev 279375)
@@ -3385,3 +3385,6 @@
 # Skip WebXR tests on iOS
 imported/w3c/web-platform-tests/webxr [ Skip ]
 http/wpt/webxr [ Skip ]
+
+# WebM is not supported on iOS
+http/tests/media/video-webm-stall.html [ Skip ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (279374 => 279375)


--- trunk/LayoutTests/platform/mac/TestExpectations	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2021-06-29 17:11:34 UTC (rev 279375)
@@ -2143,6 +2143,9 @@
 [ Catalina Mojave ] fast/text/system-font-width-8.html [ ImageOnlyFailure ]
 [ Catalina Mojave ] fast/text/system-font-width-9.html [ ImageOnlyFailure ]
 
+# WebM support is on Monterey and later
+[ Catalina Mojave BigSur ] http/tests/media/video-webm-stall.html [ Skip ]
+
 webkit.org/b/221152 imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html [ Pass Failure ]
 
 webkit.org/b/221491 animations/keyframe-pseudo-shadow.html [ Pass ImageOnlyFailure ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (279374 => 279375)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2021-06-29 17:11:34 UTC (rev 279375)
@@ -224,6 +224,9 @@
 platform/mac/media/media-source/media-source-change-source.html [ Skip ]
 media/now-playing-status-without-media.html [ Skip ]
 
+# WebM not supported in WK1 on macOS.
+http/tests/media/video-webm-stall.html
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End features not supported in WebKit1
 #//////////////////////////////////////////////////////////////////////////////////////////

Modified: trunk/Source/WebCore/PAL/ChangeLog (279374 => 279375)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-06-29 17:11:34 UTC (rev 279375)
@@ -1,3 +1,15 @@
+2021-06-24  Jer Noble  <[email protected]>
+
+        Loading WebM hangs if server sends only small amount of data
+        https://bugs.webkit.org/show_bug.cgi?id=226217
+        <rdar://problem/78709010>
+
+        Reviewed by Eric Carlson.
+
+        * pal/cf/CoreMediaSoftLink.cpp:
+        * pal/cf/CoreMediaSoftLink.h:
+        * pal/spi/cf/CoreMediaSPI.h:
+
 2021-06-28  Jean-Yves Avenard  <[email protected]>
 
         Not all uses of AudioToolbox framework use soft linking

Modified: trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp (279374 => 279375)


--- trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp	2021-06-29 17:11:34 UTC (rev 279375)
@@ -213,6 +213,8 @@
 SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, CMSampleBufferCallBlockForEachSample, OSStatus, (CMSampleBufferRef sbuf, OSStatus (^CMSAMPLEBUFFERCALL_NOESCAPE handler)(CMSampleBufferRef, CMItemCount)), (sbuf, handler), PAL_EXPORT)
 
 SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, CMAudioClockCreate, OSStatus, (CFAllocatorRef allocator, CMClockRef* clockOut), (allocator, clockOut), PAL_EXPORT)
+SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, FigThreadRegisterAbortAction, OSStatus, (FigThreadAbortAction action, void* refcon, FigThreadAbortActionToken* token), (action, refcon, token), PAL_EXPORT)
+SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, FigThreadUnregisterAbortAction, void, (FigThreadAbortActionToken token), (token), PAL_EXPORT)
 
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, kCMFormatDescriptionExtension_ProtectedContentOriginalFormat, CFStringRef, PAL_EXPORT)
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, CoreMedia, kCMFormatDescriptionTransferFunction_sRGB, CFStringRef, PAL_EXPORT)

Modified: trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h (279374 => 279375)


--- trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h	2021-06-29 17:11:34 UTC (rev 279375)
@@ -361,6 +361,10 @@
 
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMAudioClockCreate, OSStatus, (CFAllocatorRef allocator, CMClockRef* clockOut), (allocator, clockOut))
 #define CMAudioClockCreate softLink_CoreMedia_CMAudioClockCreate
+SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, FigThreadRegisterAbortAction, OSStatus, (FigThreadAbortAction action, void* refcon, FigThreadAbortActionToken* token), (action, refcon, token))
+#define FigThreadRegisterAbortAction softLink_CoreMedia_FigThreadRegisterAbortAction
+SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, FigThreadUnregisterAbortAction, void, (FigThreadAbortActionToken token), (token))
+#define FigThreadUnregisterAbortAction softLink_CoreMedia_FigThreadUnregisterAbortAction
 
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, CoreMedia, kCMFormatDescriptionExtension_ProtectedContentOriginalFormat, CFStringRef)
 #define kCMFormatDescriptionExtension_ProtectedContentOriginalFormat get_CoreMedia_kCMFormatDescriptionExtension_ProtectedContentOriginalFormat()

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CoreMediaSPI.h (279374 => 279375)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CoreMediaSPI.h	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CoreMediaSPI.h	2021-06-29 17:11:34 UTC (rev 279375)
@@ -35,9 +35,12 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 #include <CoreMedia/CMNotificationCenter.h>
+#include <CoreMedia/FigThreadPlatform.h>
 #else
 typedef struct opaqueCMNotificationCenter *CMNotificationCenterRef;
 typedef void (*CMNotificationCallback)(CMNotificationCenterRef inCenter, const void *inListener, CFStringRef inNotificationName, const void *inNotifyingObject, CFTypeRef inNotificationPayload);
+typedef void (*FigThreadAbortAction)(void* refcon);
+typedef struct OpaqueFigThreadAbortActionToken* FigThreadAbortActionToken;
 #endif
 
 WTF_EXTERN_C_BEGIN
@@ -44,6 +47,8 @@
 CMNotificationCenterRef CMNotificationCenterGetDefaultLocalCenter(void);
 OSStatus CMNotificationCenterAddListener(CMNotificationCenterRef inCenter, const void *inListener, CMNotificationCallback inCallBack, CFStringRef inNotificationName, const void *inObjectToObserve, UInt32 inFlags);
 OSStatus CMNotificationCenterRemoveListener(CMNotificationCenterRef inCenter, const void *inListener, CMNotificationCallback inCallBack, CFStringRef inNotificationName, const void *inObject);
+OSStatus FigThreadRegisterAbortAction(FigThreadAbortAction, void* refcon, FigThreadAbortActionToken*);
+void FigThreadUnregisterAbortAction(FigThreadAbortActionToken);
 WTF_EXTERN_C_END
 
 #endif // PLATFORM(COCOA)

Modified: trunk/Source/WebKit/ChangeLog (279374 => 279375)


--- trunk/Source/WebKit/ChangeLog	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebKit/ChangeLog	2021-06-29 17:11:34 UTC (rev 279375)
@@ -1,3 +1,35 @@
+2021-06-24  Jer Noble  <[email protected]>
+
+        Loading WebM hangs if server sends only small amount of data
+        https://bugs.webkit.org/show_bug.cgi?id=226217
+        <rdar://problem/78709010>
+
+        Reviewed by Eric Carlson.
+
+        Test: http/tests/media/video-webm-stall.html
+
+        Adopt FigThread{Un,}RegisterAbortAction() when blocking against track parsing.
+
+        CoreMedia will attempt to abort reads during AVPlayer teardown, but because the parsing
+        thread is blocked on a Condition variable in WebKit code, the abort request has no effect.
+        Adopt methods from CoreMedia to run code during an abort request, and wrap these calls in a
+        stack-based object. The new AbortAction object takes a Condition variable to notify during
+        an abort, and its aborted() state can be queried by the Condition's predicate.
+
+        Drive-by Fix: enable running an unsigned MTFormatReaderPlugin in the GPU process for 
+        engineering builds.
+
+        * Configurations/BaseTarget.xcconfig:
+        * GPUProcess/mac/GPUProcessMac.mm:
+        (WebKit::GPUProcess::initializeProcess):
+        * Shared/mac/MediaFormatReader/MediaFormatReader.cpp:
+        (WebKit::AbortAction::AbortAction):
+        (WebKit::AbortAction::~AbortAction):
+        (WebKit::AbortAction::aborted const):
+        (WebKit::AbortAction::action):
+        (WebKit::MediaFormatReader::copyProperty):
+        (WebKit::MediaFormatReader::copyTrackArray):
+
 2021-06-29  Carlos Garcia Campos  <[email protected]>
 
         [GTK][WPE] Check GApplication has a valid ID before trying to create the flatpack info

Modified: trunk/Source/WebKit/Configurations/BaseTarget.xcconfig (279374 => 279375)


--- trunk/Source/WebKit/Configurations/BaseTarget.xcconfig	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebKit/Configurations/BaseTarget.xcconfig	2021-06-29 17:11:34 UTC (rev 279375)
@@ -39,8 +39,11 @@
 WK_ENABLE_EXPERIMENTAL_FEATURES = $(WK_ENABLE_EXPERIMENTAL_FEATURES_$(WK_RELOCATABLE_FRAMEWORKS));
 WK_ENABLE_EXPERIMENTAL_FEATURES_YES = ENABLE_EXPERIMENTAL_FEATURES;
 
+WK_FORMATREADERBUNDLE_CODESIGNING_DEFINES = ENABLE_LOWER_FORMATREADERBUNDLE_CODESIGNING_REQUIREMENTS;
+WK_FORMATREADERBUNDLE_CODESIGNING_DEFINES[config=Production] = ;
+
 GCC_PREFIX_HEADER = WebKit2Prefix.h;
-GCC_PREPROCESSOR_DEFINITIONS = $(DEBUG_DEFINES) $(WK_ENABLE_EXPERIMENTAL_FEATURES) $(WK_CORE_PREDICTION_DEFINES) FRAMEWORK_NAME=WebKit;
+GCC_PREPROCESSOR_DEFINITIONS = $(DEBUG_DEFINES) $(WK_ENABLE_EXPERIMENTAL_FEATURES) $(WK_CORE_PREDICTION_DEFINES) $(WK_FORMATREADERBUNDLE_CODESIGNING_DEFINES) FRAMEWORK_NAME=WebKit;
 WEBKITADDITIONS_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/usr/local/include/WebKitAdditions $(SDKROOT)/usr/local/include/WebKitAdditions;
 LIBWEBRTC_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/usr/local/include/webrtc $(SDKROOT)/usr/local/include/webrtc;
 

Modified: trunk/Source/WebKit/GPUProcess/mac/GPUProcessMac.mm (279374 => 279375)


--- trunk/Source/WebKit/GPUProcess/mac/GPUProcessMac.mm	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebKit/GPUProcess/mac/GPUProcessMac.mm	2021-06-29 17:11:34 UTC (rev 279375)
@@ -49,6 +49,12 @@
     ASSERT_UNUSED(error, error == noErr);
 #endif
 
+#if ENABLE(LOWER_FORMATREADERBUNDLE_CODESIGNING_REQUIREMENTS)
+    // For testing in engineering builds, allow CoreMedia to load the MediaFormatReader bundle no matter its code signature.
+    auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:@"com.apple.coremedia"]);
+    [userDefaults registerDefaults:@{ @"pluginformatreader_unsigned": @YES }];
+#endif
+
     launchServicesCheckIn();
 }
 

Modified: trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaFormatReader.cpp (279374 => 279375)


--- trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaFormatReader.cpp	2021-06-29 15:19:46 UTC (rev 279374)
+++ trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaFormatReader.cpp	2021-06-29 17:11:34 UTC (rev 279375)
@@ -58,6 +58,36 @@
 static WTFLogChannel& logChannel() { return WebCore::LogMedia; }
 static const char* logClassName() { return "MediaFormatReader"; }
 
+class AbortAction {
+public:
+    AbortAction(Condition& condition)
+        : m_condition(condition)
+    {
+        if (noErr != PAL::FigThreadRegisterAbortAction(action, this, &m_token))
+            m_token = nullptr;
+    }
+
+    ~AbortAction()
+    {
+        if (m_token)
+            PAL::FigThreadUnregisterAbortAction(m_token);
+    }
+
+    bool aborted() const { return m_aborted; }
+
+private:
+    static void action(void* refcon)
+    {
+        auto thisPtr = static_cast<AbortAction*>(refcon);
+        thisPtr->m_aborted = true;
+        thisPtr->m_condition.notifyAll();
+    }
+
+    Condition& m_condition;
+    FigThreadAbortActionToken m_token { nullptr };
+    bool m_aborted { false };
+};
+
 CMBaseClassID MediaFormatReader::wrapperClassID()
 {
     return MTPluginFormatReaderGetClassID();
@@ -235,10 +265,12 @@
         return kCMBaseObjectError_ValueNotAvailable;
     }
 
+    AbortAction action { m_parseTracksCondition };
+
     Locker locker { m_parseTracksLock };
     m_parseTracksCondition.wait(m_parseTracksLock, [&] {
         assertIsHeld(m_parseTracksLock);
-        return m_parseTracksStatus.has_value();
+        return m_parseTracksStatus.has_value() || action.aborted();
     });
 
     if (m_duration.isIndefinite())
@@ -255,10 +287,12 @@
 
 OSStatus MediaFormatReader::copyTrackArray(CFArrayRef* trackArrayCopy)
 {
+    AbortAction action { m_parseTracksCondition };
+
     Locker locker { m_parseTracksLock };
     m_parseTracksCondition.wait(m_parseTracksLock, [&] {
         assertIsHeld(m_parseTracksLock);
-        return m_parseTracksStatus.has_value();
+        return m_parseTracksStatus.has_value() || action.aborted();
     });
 
     if (*m_parseTracksStatus != noErr)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to