Title: [284236] trunk/Source/WebCore
Revision
284236
Author
[email protected]
Date
2021-10-14 23:33:04 -0700 (Thu, 14 Oct 2021)

Log Message

MediaCapabilities should enqueue a task to resolve promises
https://bugs.webkit.org/show_bug.cgi?id=231569

Reviewed by Eric Carlson.

* Modules/mediacapabilities/MediaCapabilities.cpp:
We should resolve promises inside an event loop task.
To do this, instead of enqueuing a task to do some work that can be asynchronous, we do the asynchronous work and then enqueue a task to resolve the promise.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284235 => 284236)


--- trunk/Source/WebCore/ChangeLog	2021-10-15 06:24:33 UTC (rev 284235)
+++ trunk/Source/WebCore/ChangeLog	2021-10-15 06:33:04 UTC (rev 284236)
@@ -1,3 +1,14 @@
+2021-10-14  Youenn Fablet  <[email protected]>
+
+        MediaCapabilities should enqueue a task to resolve promises
+        https://bugs.webkit.org/show_bug.cgi?id=231569
+
+        Reviewed by Eric Carlson.
+
+        * Modules/mediacapabilities/MediaCapabilities.cpp:
+        We should resolve promises inside an event loop task.
+        To do this, instead of enqueuing a task to do some work that can be asynchronous, we do the asynchronous work and then enqueue a task to resolve the promise.
+
 2021-10-14  Rob Buis  <[email protected]>
 
         Fix grid-auto-repeat-dynamic-003.html

Modified: trunk/Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp (284235 => 284236)


--- trunk/Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp	2021-10-15 06:24:33 UTC (rev 284235)
+++ trunk/Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp	2021-10-15 06:33:04 UTC (rev 284236)
@@ -178,6 +178,18 @@
 
     // 1. If configuration is not a valid MediaConfiguration, return a Promise rejected with a TypeError.
     // 2. If configuration.video is present and is not a valid video configuration, return a Promise rejected with a TypeError.
+    // 2.2.3 If configuration is of type MediaDecodingConfiguration, run the following substeps:
+    // 2.2.3.1. If the user agent is able to decode the media represented by
+    // configuration, set supported to true. Otherwise set it to false.
+    // 2.2.3.2. If the user agent is able to decode the media represented by
+    // configuration at a pace that allows a smooth playback, set smooth to
+    // true. Otherwise set it to false.
+    // 2.2.3.3. If the user agent is able to decode the media represented by
+    // configuration in a power efficient manner, set powerEfficient to
+    // true. Otherwise set it to false. The user agent SHOULD NOT take into
+    // consideration the current power source in order to determine the
+    // decoding power efficiency unless the device’s power source has side
+    // effects such as enabling different decoding modules.
     // 3. If configuration.audio is present and is not a valid audio configuration, return a Promise rejected with a TypeError.
     if (!isValidMediaConfiguration(configuration)) {
 #if !RELEASE_LOG_DISABLED
@@ -197,37 +209,24 @@
     // 4. Let p be a new promise.
     // 5. In parallel, run the create a MediaCapabilitiesInfo algorithm with configuration and resolve p with its result.
     // 6. Return p.
-    document.eventLoop().queueTask(TaskSource::MediaElement, [configuration = WTFMove(configuration), promise = WTFMove(promise), logger = WTFMove(logger), identifier = WTFMove(identifier), document = Ref { document }] () mutable {
 
-        // 2.2.3 If configuration is of type MediaDecodingConfiguration, run the following substeps:
-        MediaEngineConfigurationFactory::DecodingConfigurationCallback callback = [promise = WTFMove(promise), logger = WTFMove(logger), identifier = WTFMove(identifier)] (auto info) mutable {
-            // 2.2.3.1. If the user agent is able to decode the media represented by
-            // configuration, set supported to true. Otherwise set it to false.
-            // 2.2.3.2. If the user agent is able to decode the media represented by
-            // configuration at a pace that allows a smooth playback, set smooth to
-            // true. Otherwise set it to false.
-            // 2.2.3.3. If the user agent is able to decode the media represented by
-            // configuration in a power efficient manner, set powerEfficient to
-            // true. Otherwise set it to false. The user agent SHOULD NOT take into
-            // consideration the current power source in order to determine the
-            // decoding power efficiency unless the device’s power source has side
-            // effects such as enabling different decoding modules.
+    MediaEngineConfigurationFactory::DecodingConfigurationCallback callback = [promise = WTFMove(promise), identifier = WTFMove(identifier), logger = WTFMove(logger), document = Ref { document }](auto info) mutable {
 #if !RELEASE_LOG_DISABLED
-            logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
+        logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
 #endif
+        document->eventLoop().queueTask(TaskSource::MediaElement, [promise = WTFMove(promise), info = WTFMove(info)] () mutable {
             promise->resolve<IDLDictionary<MediaCapabilitiesDecodingInfo>>(WTFMove(info));
-        };
+        });
+    };
 
 #if ENABLE(WEB_RTC)
-        if (configuration.type == MediaDecodingType::WebRTC) {
-            if (auto* page = document->page())
-                page->libWebRTCProvider().createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
-            return;
-        }
+    if (configuration.type == MediaDecodingType::WebRTC) {
+        if (auto* page = document.page())
+            page->libWebRTCProvider().createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
+        return;
+    }
 #endif
-
-        MediaEngineConfigurationFactory::createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
-    });
+    MediaEngineConfigurationFactory::createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
 }
 
 void MediaCapabilities::encodingInfo(Document& document, MediaEncodingConfiguration&& configuration, Ref<DeferredPromise>&& promise)
@@ -235,9 +234,27 @@
     // 2.4 Media Capabilities Interface
     // https://wicg.github.io/media-capabilities/#media-capabilities-interface
 
+    auto identifier = WTF::Logger::LogSiteIdentifier("MediaCapabilities", __func__, this);
+    Ref<Logger> logger = document.logger();
+
     // 1. If configuration is not a valid MediaConfiguration, return a Promise rejected with a TypeError.
     // 2. If configuration.video is present and is not a valid video configuration, return a Promise rejected with a TypeError.
     // 3. If configuration.audio is present and is not a valid audio configuration, return a Promise rejected with a TypeError.
+    // 2.2.4. If configuration is of type MediaEncodingConfiguration, run the following substeps:
+    // 2.2.4.1. If the user agent is able to encode the media
+    // represented by configuration, set supported to true. Otherwise
+    // set it to false.
+    // 2.2.4.2. If the user agent is able to encode the media
+    // represented by configuration at a pace that allows encoding
+    // frames at the same pace as they are sent to the encoder, set
+    // smooth to true. Otherwise set it to false.
+    // 2.2.4.3. If the user agent is able to encode the media
+    // represented by configuration in a power efficient manner, set
+    // powerEfficient to true. Otherwise set it to false. The user agent
+    // SHOULD NOT take into consideration the current power source in
+    // order to determine the encoding power efficiency unless the
+    // device’s power source has side effects such as enabling different
+    // encoding modules.
     if (!isValidMediaConfiguration(configuration)) {
         promise->reject(TypeError);
         return;
@@ -246,37 +263,25 @@
     // 4. Let p be a new promise.
     // 5. In parallel, run the create a MediaCapabilitiesInfo algorithm with configuration and resolve p with its result.
     // 6. Return p.
-    document.eventLoop().queueTask(TaskSource::MediaElement, [configuration = WTFMove(configuration), promise = WTFMove(promise),  document = Ref { document }] () mutable {
-        // 2.2.4. If configuration is of type MediaEncodingConfiguration, run the following substeps:
-        MediaEngineConfigurationFactory::EncodingConfigurationCallback callback = [promise = WTFMove(promise)] (auto info) mutable {
-            // 2.2.4.1. If the user agent is able to encode the media
-            // represented by configuration, set supported to true. Otherwise
-            // set it to false.
-            // 2.2.4.2. If the user agent is able to encode the media
-            // represented by configuration at a pace that allows encoding
-            // frames at the same pace as they are sent to the encoder, set
-            // smooth to true. Otherwise set it to false.
-            // 2.2.4.3. If the user agent is able to encode the media
-            // represented by configuration in a power efficient manner, set
-            // powerEfficient to true. Otherwise set it to false. The user agent
-            // SHOULD NOT take into consideration the current power source in
-            // order to determine the encoding power efficiency unless the
-            // device’s power source has side effects such as enabling different
-            // encoding modules.
+
+    MediaEngineConfigurationFactory::EncodingConfigurationCallback callback = [promise = WTFMove(promise), identifier = WTFMove(identifier), logger = WTFMove(logger), document = Ref { document }](auto info) mutable {
+#if !RELEASE_LOG_DISABLED
+        logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
+#endif
+        document->eventLoop().queueTask(TaskSource::MediaElement, [promise = WTFMove(promise), info = WTFMove(info)] () mutable {
             promise->resolve<IDLDictionary<MediaCapabilitiesEncodingInfo>>(WTFMove(info));
-        };
+        });
+    };
 
 #if ENABLE(WEB_RTC)
-        if (configuration.type == MediaEncodingType::WebRTC) {
-            if (auto* page = document->page())
-                page->libWebRTCProvider().createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
-            return;
-        }
+    if (configuration.type == MediaEncodingType::WebRTC) {
+        if (auto* page = document.page())
+            page->libWebRTCProvider().createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
+        return;
+    }
 #endif
 
-        MediaEngineConfigurationFactory::createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
-
-    });
+    MediaEngineConfigurationFactory::createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to