⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 271194 in webkit


Ignore:
Timestamp:
Jan 5, 2021, 11:26:14 PM (6 years ago)
Author:
eric.carlson@apple.com
Message:

[Cocoa] WebM format reader doesn't work with a url in a <source> element
https://bugs.webkit.org/show_bug.cgi?id=219961
<rdar://problem/72399014>

Reviewed by Andy Estes.

Source/WebCore:

Work around a CoreMedia bug that makes the format reader fail to load when the
AVURLAssetOutOfBandMIMETypeKeyis included in the AVURLAsset options dictionary.
Also include some cleanup:

  • Move the code to check for WebM MIME types from MediaPlayerPrivateAVFoundationObjC to AVAssetMIMETypeCache.
  • Don't use RuntimeEnabledFeatures in MediaPlayerPrivateAVFoundationObjC.
  • Register the WebM format reader when creating an AVURLAsset for a WebM url instead of when checking the MIME type.
  • Cleanup WebM "codecs" parameter parsing.
  • It is a layering violation to use RuntimeSettings from inside of /platform.
  • platform/audio/PlatformMediaSessionManager.cpp:

(WebCore::PlatformMediaSessionManager::webMFormatReaderEnabled):
(WebCore::PlatformMediaSessionManager::setWebMFormatReaderEnabled):
(WebCore::PlatformMediaSessionManager::vorbisDecoderEnabled):
(WebCore::PlatformMediaSessionManager::setVorbisDecoderEnabled):

  • platform/audio/PlatformMediaSessionManager.h:
  • platform/graphics/TrackPrivateBase.cpp:

(WebCore::TrackPrivateBase::defaultEnabled const):

  • platform/graphics/TrackPrivateBase.h:
  • platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm:

(WebCore::AVAssetMIMETypeCache::canDecodeExtendedType):
(WebCore::AVAssetMIMETypeCache::initializeCache):

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::registerFormatReaderIfNecessary):
(WebCore::willUseWebMFormatReaderForType):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsTypeAndCodecs):
(WebCore::ensureFormatReaderIsRegistered): Deleted.
(WebCore::isFormatReaderAvailable): Deleted.

  • platform/graphics/cocoa/AudioTrackPrivateWebM.cpp:

(WebCore::AudioTrackPrivateWebM::defaultEnabled const):

  • platform/graphics/cocoa/AudioTrackPrivateWebM.h:
  • platform/graphics/cocoa/SourceBufferParserWebM.cpp:

(WebCore::SourceBufferParserWebM::webmMIMETypes):
(WebCore::canLoadFormatReader):
(WebCore::SourceBufferParserWebM::isWebMFormatReaderAvailable):
(WebCore::SourceBufferParserWebM::isContentTypeSupported):

  • platform/graphics/cocoa/SourceBufferParserWebM.h:
  • platform/graphics/cocoa/VideoTrackPrivateWebM.cpp:

(WebCore::VideoTrackPrivateWebM::defaultEnabled const):

  • platform/graphics/cocoa/VideoTrackPrivateWebM.h:
  • platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm:

(WebCore::isVorbisDecoderAvailable):

Source/WebKit:

Only enable a WebM track when the it has FlagEnabled element, or when we see that
it has media samples. This is necessary because there are WebM files with empty tracks,
and CoreMedia won't play a file if any enabled track doesn't have samples.

  • Shared/mac/MediaFormatReader/FormatReader.cpp:

(WebKit::FormatReader::didParseTracks):

  • Shared/mac/MediaFormatReader/TrackReader.cpp:

(WebKit::TrackReader::create):
(WebKit::TrackReader::TrackReader):
(WebKit::TrackReader::finishParsing):
(WebKit::TrackReader::isEnabled const):
(WebKit::TrackReader::copyProperty):

  • Shared/mac/MediaFormatReader/TrackReader.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::updatePreferences):

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess):

Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271191 r271194  
     12021-01-05  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Cocoa] WebM format reader doesn't work with a url in a <source> element
     4        https://bugs.webkit.org/show_bug.cgi?id=219961
     5        <rdar://problem/72399014>
     6
     7        Reviewed by Andy Estes.
     8
     9        Work around a CoreMedia bug that makes the format reader fail to load when the
     10        AVURLAssetOutOfBandMIMETypeKeyis included in the AVURLAsset options dictionary.
     11        Also include some cleanup:
     12        - Move the code to check for WebM MIME types from MediaPlayerPrivateAVFoundationObjC
     13          to AVAssetMIMETypeCache.
     14        - Don't use RuntimeEnabledFeatures in MediaPlayerPrivateAVFoundationObjC.
     15        - Register the WebM format reader when creating an AVURLAsset for a WebM url instead
     16          of when checking the MIME type.
     17        - Cleanup WebM "codecs" parameter parsing.
     18        - It is a layering violation to use RuntimeSettings from inside of /platform.
     19
     20        * platform/audio/PlatformMediaSessionManager.cpp:
     21        (WebCore::PlatformMediaSessionManager::webMFormatReaderEnabled):
     22        (WebCore::PlatformMediaSessionManager::setWebMFormatReaderEnabled):
     23        (WebCore::PlatformMediaSessionManager::vorbisDecoderEnabled):
     24        (WebCore::PlatformMediaSessionManager::setVorbisDecoderEnabled):
     25        * platform/audio/PlatformMediaSessionManager.h:
     26        * platform/graphics/TrackPrivateBase.cpp:
     27        (WebCore::TrackPrivateBase::defaultEnabled const):
     28        * platform/graphics/TrackPrivateBase.h:
     29        * platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm:
     30        (WebCore::AVAssetMIMETypeCache::canDecodeExtendedType):
     31        (WebCore::AVAssetMIMETypeCache::initializeCache):
     32        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     33        (WebCore::registerFormatReaderIfNecessary):
     34        (WebCore::willUseWebMFormatReaderForType):
     35        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
     36        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsTypeAndCodecs):
     37        (WebCore::ensureFormatReaderIsRegistered): Deleted.
     38        (WebCore::isFormatReaderAvailable): Deleted.
     39        * platform/graphics/cocoa/AudioTrackPrivateWebM.cpp:
     40        (WebCore::AudioTrackPrivateWebM::defaultEnabled const):
     41        * platform/graphics/cocoa/AudioTrackPrivateWebM.h:
     42        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
     43        (WebCore::SourceBufferParserWebM::webmMIMETypes):
     44        (WebCore::canLoadFormatReader):
     45        (WebCore::SourceBufferParserWebM::isWebMFormatReaderAvailable):
     46        (WebCore::SourceBufferParserWebM::isContentTypeSupported):
     47        * platform/graphics/cocoa/SourceBufferParserWebM.h:
     48        * platform/graphics/cocoa/VideoTrackPrivateWebM.cpp:
     49        (WebCore::VideoTrackPrivateWebM::defaultEnabled const):
     50        * platform/graphics/cocoa/VideoTrackPrivateWebM.h:
     51        * platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm:
     52        (WebCore::isVorbisDecoderAvailable):
     53
    1542021-01-05  Simon Fraser  <simon.fraser@apple.com>
    255
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp

    r269077 r271194  
    3636#if ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
    3737
     38#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     39bool PlatformMediaSessionManager::m_webMFormatReaderEnabled;
     40#endif
     41
     42#if ENABLE(VORBIS) && PLATFORM(MAC)
     43bool PlatformMediaSessionManager::m_vorbisDecoderEnabled;
     44#endif
     45
    3846static std::unique_ptr<PlatformMediaSessionManager>& sharedPlatformMediaSessionManager()
    3947{
     
    611619}
    612620
     621bool PlatformMediaSessionManager::webMFormatReaderEnabled()
     622{
     623#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     624    return m_webMFormatReaderEnabled;
     625#else
     626    return false;
     627#endif
     628}
     629
     630void PlatformMediaSessionManager::setWebMFormatReaderEnabled(bool enabled)
     631{
     632#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     633    m_webMFormatReaderEnabled = enabled;
     634#else
     635    UNUSED_PARAM(enabled);
     636#endif
     637}
     638
     639bool PlatformMediaSessionManager::vorbisDecoderEnabled()
     640{
     641#if ENABLE(VORBIS) && PLATFORM(MAC)
     642    return m_vorbisDecoderEnabled;
     643#else
     644    return false;
     645#endif
     646}
     647
     648void PlatformMediaSessionManager::setVorbisDecoderEnabled(bool enabled)
     649{
     650#if ENABLE(VORBIS) && PLATFORM(MAC)
     651    m_vorbisDecoderEnabled = enabled;
     652#else
     653    UNUSED_PARAM(enabled);
     654#endif
     655}
     656
    613657#else // ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
    614658
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h

    r269077 r271194  
    5959    WEBCORE_EXPORT static bool shouldDeactivateAudioSession();
    6060
     61    WEBCORE_EXPORT static void setWebMFormatReaderEnabled(bool);
     62    WEBCORE_EXPORT static bool webMFormatReaderEnabled();
     63    WEBCORE_EXPORT static void setVorbisDecoderEnabled(bool);
     64    WEBCORE_EXPORT static bool vorbisDecoderEnabled();
     65
    6166    virtual ~PlatformMediaSessionManager() = default;
    6267
     
    202207    GenericTaskQueue<Timer> updateSessionStateQueue;
    203208
     209#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     210    static bool m_webMFormatReaderEnabled;
     211#endif
     212#if ENABLE(VORBIS) && PLATFORM(MAC)
     213    static bool m_vorbisDecoderEnabled;
     214#endif
     215
    204216#if !RELEASE_LOG_DISABLED
    205217    Ref<AggregateLogger> m_logger;
  • trunk/Source/WebCore/platform/graphics/TrackPrivateBase.cpp

    r270841 r271194  
    3939}
    4040
     41Optional<bool> TrackPrivateBase::defaultEnabled() const
     42{
     43    return WTF::nullopt;
     44}
     45
    4146#if !RELEASE_LOG_DISABLED
    4247
  • trunk/Source/WebCore/platform/graphics/TrackPrivateBase.h

    r270841 r271194  
    6565    virtual int trackIndex() const { return 0; }
    6666    virtual Optional<uint64_t> trackUID() const;
     67    virtual Optional<bool> defaultEnabled() const;
    6768
    6869    virtual MediaTime startTimeVariance() const { return MediaTime::zeroTime(); }
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm

    r271038 r271194  
    3030
    3131#import "ContentType.h"
     32#import "SourceBufferParserWebM.h"
    3233#import <pal/cf/CoreMediaSoftLink.h>
    3334#import <pal/cocoa/AVFoundationSoftLink.h>
     
    6465#if ENABLE(VIDEO) && USE(AVFOUNDATION)
    6566    ASSERT(isAvailable());
    66     return [PAL::getAVURLAssetClass() isPlayableExtendedMIMEType:type.raw()];
     67    if ([PAL::getAVURLAssetClass() isPlayableExtendedMIMEType:type.raw()])
     68        return true;
     69
     70#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     71    if (SourceBufferParserWebM::isContentTypeSupported(type) == MediaPlayerEnums::SupportsType::IsSupported)
     72        return true;
    6773#endif
     74
     75#endif // ENABLE(VIDEO) && USE(AVFOUNDATION)
    6876
    6977    return false;
     
    149157        cache.add(type);
    150158
     159#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     160    if (SourceBufferParserWebM::isWebMFormatReaderAvailable()) {
     161        auto webmTypes = SourceBufferParserWebM::webmMIMETypes();
     162        cache.add(webmTypes.begin(), webmTypes.end());
     163    }
     164#endif
     165
    151166    if (m_cacheTypeCallback)
    152167        m_cacheTypeCallback(copyToVector(cache));
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r271038 r271194  
    5757#import "PlatformTimeRanges.h"
    5858#import "RuntimeApplicationChecks.h"
    59 #import "RuntimeEnabledFeatures.h"
    6059#import "SecurityOrigin.h"
    6160#import "SerializedPlatformDataCueMac.h"
     
    101100#import <wtf/URL.h>
    102101#import <wtf/cocoa/VectorCocoa.h>
    103 #import <wtf/spi/darwin/OSVariantSPI.h>
    104102#import <wtf/text/CString.h>
    105103#import <wtf/threads/BinarySemaphore.h>
     
    269267    });
    270268    return globalQueue;
     269}
     270
     271static void registerFormatReaderIfNecessary()
     272{
     273#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     274    static dispatch_once_t onceToken;
     275    dispatch_once(&onceToken, ^{
     276        // Like we do for other media formats, allow the format reader to run in the WebContent or GPU process
     277        // (which is already appropriately sandboxed) rather than in a separate MediaToolbox XPC service.
     278        RELEASE_ASSERT(isInGPUProcess() || isInWebProcess());
     279        MTRegisterPluginFormatReaderBundleDirectory((__bridge CFURLRef)NSBundle.mainBundle.builtInPlugInsURL);
     280        MTPluginFormatReaderDisableSandboxing();
     281    });
     282#endif
    271283}
    272284
     
    793805}
    794806
     807static bool willUseWebMFormatReaderForType(const String& type)
     808{
     809#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     810    if (!SourceBufferParserWebM::isWebMFormatReaderAvailable())
     811        return false;
     812
     813    return equalIgnoringASCIICase(type, "video/webm") || equalIgnoringASCIICase(type, "audio/webm");
     814#else
     815    UNUSED_PARAM(type);
     816    return false;
     817#endif
     818}
     819
    795820void MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL(const URL& url, RetainPtr<NSMutableDictionary> options)
    796821{
     
    834859
    835860    auto type = player()->contentMIMEType();
    836     if (PAL::canLoad_AVFoundation_AVURLAssetOutOfBandMIMETypeKey() && !type.isEmpty() && !player()->contentMIMETypeWasInferredFromExtension()) {
     861
     862    // Don't advertise WebM MIME types or the format reader won't be loaded until rdar://72405127 is fixed.
     863    auto willUseWebMFormatReader = willUseWebMFormatReaderForType(type);
     864
     865    if (PAL::canLoad_AVFoundation_AVURLAssetOutOfBandMIMETypeKey() && !type.isEmpty() && !player()->contentMIMETypeWasInferredFromExtension() && !willUseWebMFormatReader) {
    837866        auto codecs = player()->contentTypeCodecs();
    838867        if (!codecs.isEmpty()) {
     
    876905            [options setObject:@NO forKey:AVURLAssetUsesNoPersistentCacheKey];
    877906    }
     907
     908    if (willUseWebMFormatReader)
     909        registerFormatReaderIfNecessary();
    878910
    879911    NSURL *cocoaURL = canonicalURL(url);
     
    16681700#endif
    16691701
    1670 #if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
    1671 static void ensureFormatReaderIsRegistered()
    1672 {
    1673     static dispatch_once_t onceToken;
    1674     dispatch_once(&onceToken, ^{
    1675         // Like we do for other media formats, allow the format reader to run in the WebContent or GPU process
    1676         // (which is already appropriately sandboxed) rather than in a separate MediaToolbox XPC service.
    1677         RELEASE_ASSERT(isInGPUProcess() || isInWebProcess());
    1678         MTRegisterPluginFormatReaderBundleDirectory((__bridge CFURLRef)NSBundle.mainBundle.builtInPlugInsURL);
    1679         MTPluginFormatReaderDisableSandboxing();
    1680     });
    1681 }
    1682 #endif
    1683 
    1684 #if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
    1685 static bool isFormatReaderAvailable()
    1686 {
    1687     if (!RuntimeEnabledFeatures::sharedFeatures().webMFormatReaderEnabled())
    1688         return false;
    1689 
    1690 #if !USE(APPLE_INTERNAL_SDK)
    1691     // FIXME (rdar://72320419): If WebKit was built with ad-hoc code-signing,
    1692     // CoreMedia will only load the format reader plug-in when a user default
    1693     // is set on Apple internal OSs. That means we cannot currently support WebM
    1694     // in public SDK builds on customer OSs.
    1695     if (!os_variant_allows_internal_security_policies("com.apple.WebKit"))
    1696         return false;
    1697 #endif
    1698 
    1699     return true;
    1700 }
    1701 #endif
    1702 
    17031702MediaPlayer::SupportsType MediaPlayerPrivateAVFoundationObjC::supportsTypeAndCodecs(const MediaEngineSupportParameters& parameters)
    17041703{
     
    17101709    if (parameters.isMediaStream)
    17111710        return MediaPlayer::SupportsType::IsNotSupported;
    1712 #endif
    1713 
    1714 #if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
    1715     if (isFormatReaderAvailable()) {
    1716         auto supported = SourceBufferParserWebM::isContentTypeSupported(parameters.type);
    1717         if (supported != MediaPlayer::SupportsType::IsNotSupported) {
    1718             ensureFormatReaderIsRegistered();
    1719             if (supported == MediaPlayer::SupportsType::MayBeSupported)
    1720                 return supported;
    1721             if (contentTypeMeetsHardwareDecodeRequirements(parameters.type, parameters.contentTypesRequiringHardwareSupport))
    1722                 return MediaPlayer::SupportsType::IsSupported;
    1723         }
    1724     }
    17251711#endif
    17261712
  • trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.cpp

    r270841 r271194  
    5959}
    6060
     61Optional<bool> AudioTrackPrivateWebM::defaultEnabled() const
     62{
     63    if (m_track.is_enabled.is_present())
     64        return m_track.is_enabled.value();
     65    return WTF::nullopt;
     66}
     67
    6168AtomString AudioTrackPrivateWebM::label() const
    6269{
  • trunk/Source/WebCore/platform/graphics/cocoa/AudioTrackPrivateWebM.h

    r270841 r271194  
    4343    int trackIndex() const final;
    4444    Optional<uint64_t> trackUID() const final;
     45    Optional<bool> defaultEnabled() const final;
    4546
    4647private:
  • trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp

    r271086 r271194  
    3636#include "MediaSampleAVFObjC.h"
    3737#include "NotImplemented.h"
     38#include "PlatformMediaSessionManager.h"
    3839#include "SharedBuffer.h"
    3940#include "VP9UtilitiesCocoa.h"
     
    4950#include <wtf/cf/TypeCastsCF.h>
    5051#include <wtf/darwin/WeakLinking.h>
     52#include <wtf/spi/darwin/OSVariantSPI.h>
    5153
    5254#include "CoreVideoSoftLink.h"
     
    444446};
    445447
     448const HashSet<String, ASCIICaseInsensitiveHash>& SourceBufferParserWebM::webmMIMETypes()
     449{
     450    static auto types = makeNeverDestroyed([] {
     451
     452        HashSet<String, ASCIICaseInsensitiveHash> types;
     453
     454#if ENABLE(VP9)
     455        types.add("video/webm");
     456#endif
     457#if ENABLE(VORBIS) || ENABLE(OPUS)
     458        types.add("audio/webm");
     459#endif
     460
     461        return types;
     462    }());
     463
     464    return types;
     465}
     466
     467static bool canLoadFormatReader()
     468{
     469#if !HAVE(MT_PLUGIN_FORMAT_READER)
     470    return false;
     471#elif USE(APPLE_INTERNAL_SDK)
     472    return true;
     473#else
     474    // FIXME (rdar://72320419): If WebKit was built with ad-hoc code-signing,
     475    // CoreMedia will only load the format reader plug-in when a user default
     476    // is set on Apple internal OSs. That means we cannot currently support WebM
     477    // in public SDK builds on customer OSs.
     478    static bool allowsInternalSecurityPolicies = os_variant_allows_internal_security_policies("com.apple.WebKit");
     479    return allowsInternalSecurityPolicies;
     480#endif // !USE(APPLE_INTERNAL_SDK)
     481}
     482
     483bool SourceBufferParserWebM::isWebMFormatReaderAvailable()
     484{
     485    return PlatformMediaSessionManager::webMFormatReaderEnabled() && canLoadFormatReader() && isWebmParserAvailable();
     486}
     487
    446488MediaPlayerEnums::SupportsType SourceBufferParserWebM::isContentTypeSupported(const ContentType& type)
    447489{
     
    450492        return MediaPlayerEnums::SupportsType::IsNotSupported;
    451493
    452     bool isAudioContainerType = WTF::equalIgnoringASCIICase(type.containerType(), "audio/webm");
    453     bool isVideoContainerType = WTF::equalIgnoringASCIICase(type.containerType(), "video/webm");
     494    auto containerType = type.containerType();
     495    bool isAudioContainerType = WTF::equalIgnoringASCIICase(containerType, "audio/webm");
     496    bool isVideoContainerType = WTF::equalIgnoringASCIICase(containerType, "video/webm");
    454497    if (!isAudioContainerType && !isVideoContainerType)
    455498        return MediaPlayerEnums::SupportsType::IsNotSupported;
     
    474517        return MediaPlayerEnums::SupportsType::IsNotSupported;
    475518
    476     String codecsParameter = type.parameter(ContentType::codecsParameter());
    477     if (!codecsParameter)
     519    auto codecs = type.codecs();
     520    if (codecs.isEmpty())
    478521        return MediaPlayerEnums::SupportsType::MayBeSupported;
    479522
    480     auto splitResults = StringView(codecsParameter).split(',');
    481     if (splitResults.begin() == splitResults.end())
    482         return MediaPlayerEnums::SupportsType::MayBeSupported;
    483 
    484     for (auto split : splitResults) {
     523    for (auto& codec : codecs) {
    485524#if ENABLE(VP9)
    486         if (split.startsWith("vp09") || split.startsWith("vp08") || equal(split, "vp8") || equal(split, "vp9")) {
     525        if (codec.startsWith("vp09") || codec.startsWith("vp08") || equal(codec, "vp8") || equal(codec, "vp9")) {
    487526
    488527            if (!isVP9DecoderAvailable())
    489528                return MediaPlayerEnums::SupportsType::IsNotSupported;
    490529
    491             auto codecParameters = parseVPCodecParameters(split);
     530            auto codecParameters = parseVPCodecParameters(codec);
    492531            if (!codecParameters)
    493532                return MediaPlayerEnums::SupportsType::IsNotSupported;
     
    501540
    502541#if ENABLE(VORBIS)
    503         if (split == "vorbis") {
     542        if (codec == "vorbis") {
    504543            if (!isVorbisDecoderAvailable())
    505544                return MediaPlayerEnums::SupportsType::IsNotSupported;
     
    510549
    511550#if ENABLE(OPUS)
    512         if (split == "opus") {
     551        if (codec == "opus") {
    513552            if (!isOpusDecoderAvailable())
    514553                return MediaPlayerEnums::SupportsType::IsNotSupported;
  • trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h

    r271038 r271194  
    6161    class StreamingVectorReader;
    6262
     63    static bool isWebMFormatReaderAvailable();
    6364    static MediaPlayerEnums::SupportsType isContentTypeSupported(const ContentType&);
     65    static const HashSet<String, ASCIICaseInsensitiveHash>& webmMIMETypes();
    6466    static RefPtr<SourceBufferParserWebM> create(const ContentType&);
    6567
  • trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.cpp

    r270841 r271194  
    5959}
    6060
     61Optional<bool> VideoTrackPrivateWebM::defaultEnabled() const
     62{
     63    if (m_track.is_enabled.is_present())
     64        return m_track.is_enabled.value();
     65    return WTF::nullopt;
     66}
     67
    6168AtomString VideoTrackPrivateWebM::label() const
    6269{
  • trunk/Source/WebCore/platform/graphics/cocoa/VideoTrackPrivateWebM.h

    r270841 r271194  
    4343    int trackIndex() const final;
    4444    Optional<uint64_t> trackUID() const final;
     45    Optional<bool> defaultEnabled() const final;
    4546
    4647private:
  • trunk/Source/WebCore/platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm

    r270722 r271194  
    3232#import "Logging.h"
    3333#import "MediaUtilities.h"
    34 #import "RuntimeEnabledFeatures.h"
     34#import "PlatformMediaSessionManager.h"
    3535#import <AudioToolbox/AudioComponent.h>
    3636#import <AudioToolbox/AudioFormat.h>
     
    178178
    179179#if ENABLE(VORBIS) && PLATFORM(MAC)
    180     if (!RuntimeEnabledFeatures::sharedFeatures().vorbisDecoderEnabled())
     180    if (!PlatformMediaSessionManager::vorbisDecoderEnabled())
    181181        return false;
    182182
  • trunk/Source/WebKit/ChangeLog

    r271193 r271194  
     12021-01-05  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Cocoa] WebM format reader doesn't work with a url in a <source> element
     4        https://bugs.webkit.org/show_bug.cgi?id=219961
     5        <rdar://problem/72399014>
     6
     7        Reviewed by Andy Estes.
     8
     9        Only enable a WebM track when the it has FlagEnabled element, or when we see that
     10        it has media samples. This is necessary because there are WebM files with empty tracks,
     11        and CoreMedia won't play a file if any enabled track doesn't have samples.
     12
     13        * Shared/mac/MediaFormatReader/FormatReader.cpp:
     14        (WebKit::FormatReader::didParseTracks):
     15        * Shared/mac/MediaFormatReader/TrackReader.cpp:
     16        (WebKit::TrackReader::create):
     17        (WebKit::TrackReader::TrackReader):
     18        (WebKit::TrackReader::finishParsing):
     19        (WebKit::TrackReader::isEnabled const):
     20        (WebKit::TrackReader::copyProperty):
     21        * Shared/mac/MediaFormatReader/TrackReader.h:
     22        * WebProcess/WebPage/WebPage.cpp:
     23        (WebKit::WebPage::updatePreferences):
     24        * WebProcess/cocoa/WebProcessCocoa.mm:
     25        (WebKit::WebProcess::platformInitializeWebProcess):
     26
    1272021-01-05  Wenson Hsieh  <wenson_hsieh@apple.com>
    228
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/FormatReader.cpp

    r270841 r271194  
    145145
    146146    for (auto& videoTrack : segment.videoTracks) {
    147         if (auto trackReader = TrackReader::create(allocator(), *this, videoTrack.track.get()))
     147        auto track = videoTrack.track.get();
     148        auto trackReader = TrackReader::create(allocator(), *this, kCMMediaType_Video, *track->trackUID(), track->defaultEnabled());
     149        if (!trackReader)
     150            continue;
     151
     152        m_trackReaders.append(trackReader.releaseNonNull());
     153    }
     154
     155    for (auto& audioTrack : segment.audioTracks) {
     156        auto track = audioTrack.track.get();
     157        auto trackReader = TrackReader::create(allocator(), *this, kCMMediaType_Audio, *track->trackUID(), track->defaultEnabled());
     158        if (!trackReader)
     159            continue;
     160
     161        m_trackReaders.append(trackReader.releaseNonNull());
     162    }
     163
     164    for (auto& textTrack : segment.textTracks) {
     165        auto track = textTrack.track.get();
     166        if (auto trackReader = TrackReader::create(allocator(), *this, kCMMediaType_Text, *track->trackUID(), track->defaultEnabled()))
    148167            m_trackReaders.append(trackReader.releaseNonNull());
    149         // FIXME: How do we know which tracks should be enabled?
    150         if (m_trackReaders.size() == 1)
    151             m_trackReaders[0]->setEnabled(true);
    152     }
    153 
    154     for (auto& audioTrack : segment.audioTracks) {
    155         if (auto trackReader = TrackReader::create(allocator(), *this, audioTrack.track.get()))
    156             m_trackReaders.append(trackReader.releaseNonNull());
    157         // FIXME: How do we know which tracks should be enabled?
    158         if (m_trackReaders.size() == segment.videoTracks.size() + 1)
    159             m_trackReaders[segment.videoTracks.size()]->setEnabled(true);
    160     }
    161 
    162     for (auto& textTrack : segment.textTracks) {
    163         if (auto trackReader = TrackReader::create(allocator(), *this, textTrack.track.get()))
    164             m_trackReaders.append(trackReader.releaseNonNull());
    165     }
    166    
     168    }
     169
    167170    m_parseTracksCondition.notifyAll();
    168171}
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.cpp

    r270876 r271194  
    145145}
    146146
    147 RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, const VideoTrackPrivate* track)
    148 {
    149     if (!track)
    150         return nullptr;
    151     return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Video, *track->trackUID()));
    152 }
    153 
    154 RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, const AudioTrackPrivate* track)
    155 {
    156     if (!track)
    157         return nullptr;
    158     return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Audio, *track->trackUID()));
    159 }
    160 
    161 RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, const InbandTextTrackPrivate* track)
    162 {
    163     if (!track)
    164         return nullptr;
    165     return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, kCMMediaType_Text, *track->trackUID()));
     147RefPtr<TrackReader> TrackReader::create(Allocator&& allocator, const FormatReader& formatReader, CMMediaType mediaType, uint64_t trackID, Optional<bool> enabled)
     148{
     149    return adoptRef(new (allocator) TrackReader(WTFMove(allocator), formatReader, mediaType, trackID, enabled));
    166150}
    167151
     
    172156}
    173157
    174 TrackReader::TrackReader(Allocator&& allocator, const FormatReader& formatReader, CMMediaType mediaType, uint64_t trackID)
     158TrackReader::TrackReader(Allocator&& allocator, const FormatReader& formatReader, CMMediaType mediaType, uint64_t trackID, Optional<bool> enabled)
    175159    : CoreMediaWrapped(WTFMove(allocator))
    176160    , m_trackID(trackID)
     
    179163{
    180164    ASSERT(!isMainThread());
     165
     166    if (enabled)
     167        m_isEnabled = enabled.value() ? Enabled::True : Enabled::False;
    181168}
    182169
     
    217204        m_sampleStorage = makeUnique<SampleStorage>();
    218205    m_sampleStorage->hasAllSamples = true;
     206    if (m_isEnabled == Enabled::Unknown)
     207        m_isEnabled = m_sampleStorage->sampleMap.empty() ? Enabled::False : Enabled::True;
    219208    m_sampleStorageCondition.notifyAll();
    220209}
     
    222211OSStatus TrackReader::copyProperty(CFStringRef key, CFAllocatorRef allocator, void* copiedValue)
    223212{
    224     if (CFEqual(key, PAL::get_MediaToolbox_kMTPluginTrackReaderProperty_Enabled())) {
    225         *reinterpret_cast<CFBooleanRef*>(copiedValue) = retainPtr(m_isEnabled ? kCFBooleanTrue : kCFBooleanFalse).leakRef();
     213    // Don't block waiting for media if the we know the enabled state.
     214    if (CFEqual(key, PAL::get_MediaToolbox_kMTPluginTrackReaderProperty_Enabled()) && m_isEnabled != Enabled::Unknown) {
     215        *reinterpret_cast<CFBooleanRef*>(copiedValue) = retainPtr(m_isEnabled == Enabled::True ? kCFBooleanTrue : kCFBooleanFalse).leakRef();
    226216        return noErr;
    227217    }
     
    233223
    234224    auto& sampleMap = m_sampleStorage->sampleMap;
     225
     226    if (CFEqual(key, PAL::get_MediaToolbox_kMTPluginTrackReaderProperty_Enabled())) {
     227        if (m_isEnabled == Enabled::Unknown)
     228            m_isEnabled = sampleMap.empty() ? Enabled::False : Enabled::True;
     229
     230        *reinterpret_cast<CFBooleanRef*>(copiedValue) = retainPtr(m_isEnabled == Enabled::True ? kCFBooleanTrue : kCFBooleanFalse).leakRef();
     231        return noErr;
     232    }
     233
    235234    if (sampleMap.empty())
    236235        return kCMBaseObjectError_ValueNotAvailable;
  • trunk/Source/WebKit/Shared/mac/MediaFormatReader/TrackReader.h

    r270841 r271194  
    5555    static CMBaseClassID wrapperClassID();
    5656    static CoreMediaWrapped<TrackReader>* unwrap(CMBaseObjectRef);
     57    static WTF::WorkQueue& storageQueue();
    5758
    58     static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, const WebCore::VideoTrackPrivate*);
    59     static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, const WebCore::AudioTrackPrivate*);
    60     static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, const WebCore::InbandTextTrackPrivate*);
    61 
    62     static WTF::WorkQueue& storageQueue();
     59    static RefPtr<TrackReader> create(Allocator&&, const FormatReader&, CMMediaType, uint64_t, Optional<bool>);
    6360
    6461    uint64_t trackID() const { return m_trackID; }
     
    6663    void waitForSample(Function<bool(WebCore::SampleMap&, bool)>&&) const;
    6764
    68     bool isEnabled() const { return m_isEnabled; }
    69     void setEnabled(bool enabled) { m_isEnabled = enabled; }
     65    void setEnabled(bool enabled) { m_isEnabled = enabled ? Enabled::True : Enabled::False; }
     66    CMMediaType mediaType() const { return m_mediaType; }
    7067
    7168    void finishParsing();
     
    7471    using CoreMediaWrapped<TrackReader>::unwrap;
    7572
    76     TrackReader(Allocator&&, const FormatReader&, CMMediaType, uint64_t);
     73    TrackReader(Allocator&&, const FormatReader&, CMMediaType, uint64_t, Optional<bool>);
    7774
    7875    // CMBaseClass
     
    9491    };
    9592
     93    enum Enabled : uint8_t { Unknown, False, True };
     94
    9695    const uint64_t m_trackID;
    9796    const CMMediaType m_mediaType;
    9897    const MediaTime m_duration;
    99     std::atomic<bool> m_isEnabled { false };
     98    std::atomic<Enabled> m_isEnabled { Enabled::Unknown };
    10099    mutable Condition m_sampleStorageCondition;
    101100    mutable Lock m_sampleStorageLock;
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r271171 r271194  
    38393839    }
    38403840#endif
     3841
     3842#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     3843    PlatformMediaSessionManager::setWebMFormatReaderEnabled(RuntimeEnabledFeatures::sharedFeatures().webMFormatReaderEnabled());
     3844#endif
     3845
     3846#if ENABLE(VORBIS) && PLATFORM(MAC)
     3847    PlatformMediaSessionManager::setVorbisDecoderEnabled(RuntimeEnabledFeatures::sharedFeatures().vorbisDecoderEnabled());
     3848#endif
    38413849}
    38423850
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r271190 r271194  
    6969#import <WebCore/PerformanceLogging.h>
    7070#import <WebCore/PictureInPictureSupport.h>
     71#import <WebCore/PlatformMediaSessionManager.h>
    7172#import <WebCore/RuntimeApplicationChecks.h>
     73#import <WebCore/RuntimeEnabledFeatures.h>
    7274#import <WebCore/SWContextManager.h>
    7375#import <WebCore/SystemBattery.h>
     
    329331#endif
    330332
     333#if ENABLE(MEDIA_SOURCE) && HAVE(MT_PLUGIN_FORMAT_READER)
     334    PlatformMediaSessionManager::setWebMFormatReaderEnabled(RuntimeEnabledFeatures::sharedFeatures().webMFormatReaderEnabled());
     335#endif
     336
     337#if ENABLE(VORBIS) && PLATFORM(MAC)
     338    PlatformMediaSessionManager::setVorbisDecoderEnabled(RuntimeEnabledFeatures::sharedFeatures().vorbisDecoderEnabled());
     339#endif
     340
    331341    if (!parameters.mediaMIMETypes.isEmpty())
    332342        setMediaMIMETypes(parameters.mediaMIMETypes);
Note: See TracChangeset for help on using the changeset viewer.