Skip to content
Permalink
Browse files
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.


Canonical link: https://commits.webkit.org/243045@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284236 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf committed Oct 15, 2021
1 parent f256927 commit 7cb2f6909952ddafade8c78618d5316ca2aa3cc5
Showing 2 changed files with 67 additions and 51 deletions.
@@ -1,3 +1,14 @@
2021-10-14 Youenn Fablet <youenn@apple.com>

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 <rbuis@igalia.com>

Fix grid-auto-repeat-dynamic-003.html
@@ -178,6 +178,18 @@ void MediaCapabilities::decodingInfo(Document& document, MediaDecodingConfigurat

// 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,47 +209,52 @@ void MediaCapabilities::decodingInfo(Document& document, MediaDecodingConfigurat
// 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)
{
// 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 @@ void MediaCapabilities::encodingInfo(Document& document, MediaEncodingConfigurat
// 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));
}

}

0 comments on commit 7cb2f69

Please sign in to comment.