Changeset 284236 in webkit


Ignore:
Timestamp:
Oct 14, 2021 11:33:04 PM (9 months ago)
Author:
youenn@apple.com
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.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284235 r284236  
     12021-10-14  Youenn Fablet  <youenn@apple.com>
     2
     3        MediaCapabilities should enqueue a task to resolve promises
     4        https://bugs.webkit.org/show_bug.cgi?id=231569
     5
     6        Reviewed by Eric Carlson.
     7
     8        * Modules/mediacapabilities/MediaCapabilities.cpp:
     9        We should resolve promises inside an event loop task.
     10        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.
     11
    1122021-10-14  Rob Buis  <rbuis@igalia.com>
    213
  • trunk/Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp

    r284085 r284236  
    179179    // 1. If configuration is not a valid MediaConfiguration, return a Promise rejected with a TypeError.
    180180    // 2. If configuration.video is present and is not a valid video configuration, return a Promise rejected with a TypeError.
     181    // 2.2.3 If configuration is of type MediaDecodingConfiguration, run the following substeps:
     182    // 2.2.3.1. If the user agent is able to decode the media represented by
     183    // configuration, set supported to true. Otherwise set it to false.
     184    // 2.2.3.2. If the user agent is able to decode the media represented by
     185    // configuration at a pace that allows a smooth playback, set smooth to
     186    // true. Otherwise set it to false.
     187    // 2.2.3.3. If the user agent is able to decode the media represented by
     188    // configuration in a power efficient manner, set powerEfficient to
     189    // true. Otherwise set it to false. The user agent SHOULD NOT take into
     190    // consideration the current power source in order to determine the
     191    // decoding power efficiency unless the device’s power source has side
     192    // effects such as enabling different decoding modules.
    181193    // 3. If configuration.audio is present and is not a valid audio configuration, return a Promise rejected with a TypeError.
    182194    if (!isValidMediaConfiguration(configuration)) {
     
    198210    // 5. In parallel, run the create a MediaCapabilitiesInfo algorithm with configuration and resolve p with its result.
    199211    // 6. Return p.
    200     document.eventLoop().queueTask(TaskSource::MediaElement, [configuration = WTFMove(configuration), promise = WTFMove(promise), logger = WTFMove(logger), identifier = WTFMove(identifier), document = Ref { document }] () mutable {
    201 
    202         // 2.2.3 If configuration is of type MediaDecodingConfiguration, run the following substeps:
    203         MediaEngineConfigurationFactory::DecodingConfigurationCallback callback = [promise = WTFMove(promise), logger = WTFMove(logger), identifier = WTFMove(identifier)] (auto info) mutable {
    204             // 2.2.3.1. If the user agent is able to decode the media represented by
    205             // configuration, set supported to true. Otherwise set it to false.
    206             // 2.2.3.2. If the user agent is able to decode the media represented by
    207             // configuration at a pace that allows a smooth playback, set smooth to
    208             // true. Otherwise set it to false.
    209             // 2.2.3.3. If the user agent is able to decode the media represented by
    210             // configuration in a power efficient manner, set powerEfficient to
    211             // true. Otherwise set it to false. The user agent SHOULD NOT take into
    212             // consideration the current power source in order to determine the
    213             // decoding power efficiency unless the device’s power source has side
    214             // effects such as enabling different decoding modules.
     212
     213    MediaEngineConfigurationFactory::DecodingConfigurationCallback callback = [promise = WTFMove(promise), identifier = WTFMove(identifier), logger = WTFMove(logger), document = Ref { document }](auto info) mutable {
    215214#if !RELEASE_LOG_DISABLED
    216             logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
    217 #endif
     215        logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
     216#endif
     217        document->eventLoop().queueTask(TaskSource::MediaElement, [promise = WTFMove(promise), info = WTFMove(info)] () mutable {
    218218            promise->resolve<IDLDictionary<MediaCapabilitiesDecodingInfo>>(WTFMove(info));
    219         };
     219        });
     220    };
    220221
    221222#if ENABLE(WEB_RTC)
    222         if (configuration.type == MediaDecodingType::WebRTC) {
    223             if (auto* page = document->page())
    224                 page->libWebRTCProvider().createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
    225             return;
    226         }
    227 #endif
    228 
    229         MediaEngineConfigurationFactory::createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
    230     });
     223    if (configuration.type == MediaDecodingType::WebRTC) {
     224        if (auto* page = document.page())
     225            page->libWebRTCProvider().createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
     226        return;
     227    }
     228#endif
     229    MediaEngineConfigurationFactory::createDecodingConfiguration(WTFMove(configuration), WTFMove(callback));
    231230}
    232231
     
    235234    // 2.4 Media Capabilities Interface
    236235    // https://wicg.github.io/media-capabilities/#media-capabilities-interface
     236
     237    auto identifier = WTF::Logger::LogSiteIdentifier("MediaCapabilities", __func__, this);
     238    Ref<Logger> logger = document.logger();
    237239
    238240    // 1. If configuration is not a valid MediaConfiguration, return a Promise rejected with a TypeError.
    239241    // 2. If configuration.video is present and is not a valid video configuration, return a Promise rejected with a TypeError.
    240242    // 3. If configuration.audio is present and is not a valid audio configuration, return a Promise rejected with a TypeError.
     243    // 2.2.4. If configuration is of type MediaEncodingConfiguration, run the following substeps:
     244    // 2.2.4.1. If the user agent is able to encode the media
     245    // represented by configuration, set supported to true. Otherwise
     246    // set it to false.
     247    // 2.2.4.2. If the user agent is able to encode the media
     248    // represented by configuration at a pace that allows encoding
     249    // frames at the same pace as they are sent to the encoder, set
     250    // smooth to true. Otherwise set it to false.
     251    // 2.2.4.3. If the user agent is able to encode the media
     252    // represented by configuration in a power efficient manner, set
     253    // powerEfficient to true. Otherwise set it to false. The user agent
     254    // SHOULD NOT take into consideration the current power source in
     255    // order to determine the encoding power efficiency unless the
     256    // device’s power source has side effects such as enabling different
     257    // encoding modules.
    241258    if (!isValidMediaConfiguration(configuration)) {
    242259        promise->reject(TypeError);
     
    247264    // 5. In parallel, run the create a MediaCapabilitiesInfo algorithm with configuration and resolve p with its result.
    248265    // 6. Return p.
    249     document.eventLoop().queueTask(TaskSource::MediaElement, [configuration = WTFMove(configuration), promise = WTFMove(promise),  document = Ref { document }] () mutable {
    250         // 2.2.4. If configuration is of type MediaEncodingConfiguration, run the following substeps:
    251         MediaEngineConfigurationFactory::EncodingConfigurationCallback callback = [promise = WTFMove(promise)] (auto info) mutable {
    252             // 2.2.4.1. If the user agent is able to encode the media
    253             // represented by configuration, set supported to true. Otherwise
    254             // set it to false.
    255             // 2.2.4.2. If the user agent is able to encode the media
    256             // represented by configuration at a pace that allows encoding
    257             // frames at the same pace as they are sent to the encoder, set
    258             // smooth to true. Otherwise set it to false.
    259             // 2.2.4.3. If the user agent is able to encode the media
    260             // represented by configuration in a power efficient manner, set
    261             // powerEfficient to true. Otherwise set it to false. The user agent
    262             // SHOULD NOT take into consideration the current power source in
    263             // order to determine the encoding power efficiency unless the
    264             // device’s power source has side effects such as enabling different
    265             // encoding modules.
     266
     267    MediaEngineConfigurationFactory::EncodingConfigurationCallback callback = [promise = WTFMove(promise), identifier = WTFMove(identifier), logger = WTFMove(logger), document = Ref { document }](auto info) mutable {
     268#if !RELEASE_LOG_DISABLED
     269        logger->info(LogMedia, identifier, "::callback() - Resolved. info: ", info);
     270#endif
     271        document->eventLoop().queueTask(TaskSource::MediaElement, [promise = WTFMove(promise), info = WTFMove(info)] () mutable {
    266272            promise->resolve<IDLDictionary<MediaCapabilitiesEncodingInfo>>(WTFMove(info));
    267         };
     273        });
     274    };
    268275
    269276#if ENABLE(WEB_RTC)
    270         if (configuration.type == MediaEncodingType::WebRTC) {
    271             if (auto* page = document->page())
    272                 page->libWebRTCProvider().createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
    273             return;
    274         }
    275 #endif
    276 
    277         MediaEngineConfigurationFactory::createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
    278 
    279     });
    280 }
    281 
    282 }
     277    if (configuration.type == MediaEncodingType::WebRTC) {
     278        if (auto* page = document.page())
     279            page->libWebRTCProvider().createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
     280        return;
     281    }
     282#endif
     283
     284    MediaEngineConfigurationFactory::createEncodingConfiguration(WTFMove(configuration), WTFMove(callback));
     285}
     286
     287}
Note: See TracChangeset for help on using the changeset viewer.