Skip to content
Permalink
Browse files
[Cocoa] Register Alternate WebM Player skeleton
https://bugs.webkit.org/show_bug.cgi?id=241769
<rdar://95542551>

Patch by Youssef Soliman <youssefdevelops@gmail.com> on 2022-06-22
Reviewed by Eric Carlson.

Added the alternate WebM player skeleton and registered it behind
the internal feature flag.

* Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml:
* Source/WebCore/PlatformMac.cmake:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/page/RuntimeEnabledFeatures.cpp:
(WebCore::RuntimeEnabledFeatures::setAlternateWebMPlayerEnabled):
* Source/WebCore/page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::alternateWebMPlayerEnabled const):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::setAlternateWebMPlayerEnabled):
(WebCore::PlatformMediaSessionManager::alternateWebMPlayerEnabled):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.h:
* Source/WebCore/platform/graphics/MediaPlayer.cpp:
(WebCore::WTF_REQUIRES_LOCK):
* Source/WebCore/platform/graphics/MediaPlayerEnums.h:
* Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.h: Added.
* Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.mm: Added.
(WebCore::MediaPlayerPrivateWebM::MediaPlayerPrivateWebM):
(WebCore::MediaPlayerPrivateWebM::~MediaPlayerPrivateWebM):
(WebCore::mimeTypeCache):
(WebCore::MediaPlayerPrivateWebM::getSupportedTypes):
(WebCore::MediaPlayerPrivateWebM::supportsType):
(WebCore::MediaPlayerPrivateWebM::load):
(WebCore::MediaPlayerPrivateWebM::cancelLoad):
(WebCore::MediaPlayerPrivateWebM::platformLayer const):
(WebCore::MediaPlayerPrivateWebM::play):
(WebCore::MediaPlayerPrivateWebM::pause):
(WebCore::MediaPlayerPrivateWebM::setPageIsVisible):
(WebCore::MediaPlayerPrivateWebM::currentMediaTime const):
(WebCore::MediaPlayerPrivateWebM::buffered const):
(WebCore::MediaPlayerPrivateWebM::didLoadingProgress const):
(WebCore::MediaPlayerPrivateWebM::logChannel const):
(WebCore::MediaPlayerPrivateWebM::registerMediaEngine):

Changes were done to the GPUProcessPreferences object to consolidate
all changes when adding a new feature to just one file.

* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::updateGPUProcessPreferences):
* Source/WebKit/GPUProcess/GPUProcessPreferences.cpp:
(WebKit::GPUProcessPreferences::GPUProcessPreferences):
(WebKit::GPUProcessPreferences::copyEnabledWebPreferences):
(WebKit::GPUProcessPreferences::encode const):
(WebKit::GPUProcessPreferences::decode):
* Source/WebKit/GPUProcess/GPUProcessPreferences.h:
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::updatePreferences):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Canonical link: https://commits.webkit.org/251767@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295762 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youssefsoli authored and webkit-commit-queue committed Jun 23, 2022
1 parent fbe4e7a commit bfe3f272a5b8cc261b68249303d357fd424ec572
Showing 14 changed files with 411 additions and 36 deletions.
@@ -666,6 +666,7 @@ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h
platform/graphics/cocoa/IOSurface.h
platform/graphics/cocoa/MediaPlaybackTargetContext.h
platform/graphics/cocoa/MediaPlayerPrivateWebM.h
platform/graphics/cocoa/SourceBufferParser.h
platform/graphics/cocoa/SourceBufferParserWebM.h
platform/graphics/cocoa/VP9UtilitiesCocoa.h
@@ -408,6 +408,7 @@ platform/graphics/cocoa/IOSurfacePoolCocoa.mm
platform/graphics/cocoa/IntRectCocoa.mm
platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp
platform/graphics/cocoa/MediaPlaybackTargetContext.mm
platform/graphics/cocoa/MediaPlayerPrivateWebM.mm
platform/graphics/cocoa/SourceBufferParser.cpp
platform/graphics/cocoa/SourceBufferParserWebM.cpp
platform/graphics/cocoa/SystemFontDatabaseCocoa.mm
@@ -10671,6 +10671,8 @@
5A67F23B284966AC00964D2E /* TrackBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TrackBuffer.cpp; sourceTree = "<group>"; };
5A67F23C284966AC00964D2E /* TrackBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TrackBuffer.h; sourceTree = "<group>"; };
5A91469E8E9F8485C37A2876 /* JSSVGGraphicsElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGGraphicsElement.cpp; sourceTree = "<group>"; };
5AEBAD8A283583AE0069741F /* MediaPlayerPrivateWebM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlayerPrivateWebM.mm; sourceTree = "<group>"; };
5AEBAD8B283583AE0069741F /* MediaPlayerPrivateWebM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateWebM.h; sourceTree = "<group>"; };
5B1E0E4325D1629B00272281 /* ScrollingEffectsController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingEffectsController.mm; sourceTree = "<group>"; };
5B30695A18B3D3450099D5E8 /* WebGLDrawBuffers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLDrawBuffers.cpp; sourceTree = "<group>"; };
5B30695B18B3D3450099D5E8 /* WebGLDrawBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLDrawBuffers.h; sourceTree = "<group>"; };
@@ -29620,6 +29622,8 @@
CDC48AC72149CF2A0024FD59 /* MediaEngineConfigurationFactoryCocoa.h */,
07F876831AD4A94500905849 /* MediaPlaybackTargetContext.h */,
1D008AA5262108C000EE3ADE /* MediaPlaybackTargetContext.mm */,
5AEBAD8B283583AE0069741F /* MediaPlayerPrivateWebM.h */,
5AEBAD8A283583AE0069741F /* MediaPlayerPrivateWebM.mm */,
31647FA8251616BD0010F8FB /* OpenGLSoftLinkCocoa.h */,
31647FA9251616BD0010F8FB /* OpenGLSoftLinkCocoa.mm */,
CDEB3D7224C41A6E001FBEEF /* SourceBufferParser.cpp */,
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2021 Apple Inc. All rights reserved.
* Copyright (C) 2013-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -47,6 +47,10 @@ bool PlatformMediaSessionManager::m_vorbisDecoderEnabled;
bool PlatformMediaSessionManager::m_opusDecoderEnabled;
#endif

#if ENABLE(ALTERNATE_WEBM_PLAYER)
bool PlatformMediaSessionManager::m_alternateWebMPlayerEnabled;
#endif

#if ENABLE(VP9)
bool PlatformMediaSessionManager::m_vp9DecoderEnabled;
bool PlatformMediaSessionManager::m_vp8DecoderEnabled;
@@ -695,6 +699,24 @@ void PlatformMediaSessionManager::setOpusDecoderEnabled(bool enabled)
#endif
}

void PlatformMediaSessionManager::setAlternateWebMPlayerEnabled(bool enabled)
{
#if ENABLE(ALTERNATE_WEBM_PLAYER)
m_alternateWebMPlayerEnabled = enabled;
#else
UNUSED_PARAM(enabled);
#endif
}

bool PlatformMediaSessionManager::alternateWebMPlayerEnabled()
{
#if ENABLE(ALTERNATE_WEBM_PLAYER)
return m_alternateWebMPlayerEnabled;
#else
return false;
#endif
}

#if ENABLE(VP9)
void PlatformMediaSessionManager::setShouldEnableVP9Decoder(bool vp9DecoderEnabled)
{
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2021 Apple Inc. All rights reserved.
* Copyright (C) 2013-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -60,6 +60,8 @@ class PlatformMediaSessionManager
WEBCORE_EXPORT static bool vorbisDecoderEnabled();
WEBCORE_EXPORT static void setOpusDecoderEnabled(bool);
WEBCORE_EXPORT static bool opusDecoderEnabled();
WEBCORE_EXPORT static void setAlternateWebMPlayerEnabled(bool);
WEBCORE_EXPORT static bool alternateWebMPlayerEnabled();

#if ENABLE(VP9)
WEBCORE_EXPORT static void setShouldEnableVP9Decoder(bool);
@@ -231,6 +233,9 @@ class PlatformMediaSessionManager
#if ENABLE(OPUS)
static bool m_opusDecoderEnabled;
#endif
#if ENABLE(ALTERNATE_WEBM_PLAYER)
static bool m_alternateWebMPlayerEnabled;
#endif

#if ENABLE(VP9)
static bool m_vp9DecoderEnabled;
@@ -39,6 +39,7 @@
#include "MIMETypeRegistry.h"
#include "MediaPlayerPrivate.h"
#include "PlatformMediaResourceLoader.h"
#include "PlatformMediaSessionManager.h"
#include "PlatformScreen.h"
#include "PlatformTextTrack.h"
#include "PlatformTimeRanges.h"
@@ -82,6 +83,10 @@
#include "MediaPlayerPrivateMediaStreamAVFObjC.h"
#endif

#if ENABLE(ALTERNATE_WEBM_PLAYER)
#include "MediaPlayerPrivateWebM.h"
#endif

#endif // PLATFORM(COCOA)

#if PLATFORM(WIN) && USE(AVFOUNDATION) && !USE(GSTREAMER)
@@ -266,6 +271,15 @@ static void buildMediaEnginesVector() WTF_REQUIRES_LOCK(mediaEngineVectorLock)
if (DeprecatedGlobalSettings::isAVFoundationEnabled()) {
auto& registerRemoteEngine = registerRemotePlayerCallback();

#if ENABLE(ALTERNATE_WEBM_PLAYER)
if (PlatformMediaSessionManager::alternateWebMPlayerEnabled()) {
if (registerRemoteEngine)
registerRemoteEngine(addMediaEngine, MediaPlayerEnums::MediaEngineIdentifier::CocoaWebM);
else
MediaPlayerPrivateWebM::registerMediaEngine(addMediaEngine);
}
#endif

#if PLATFORM(COCOA)
if (registerRemoteEngine)
registerRemoteEngine(addMediaEngine, MediaPlayerEnums::MediaEngineIdentifier::AVFoundation);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2020 Apple Inc. All rights reserved.
* Copyright (C) 2015-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -98,6 +98,7 @@ class MediaPlayerEnums {
HolePunch,
MediaFoundation,
MockMSE,
CocoaWebM
};

enum class WirelessPlaybackTargetType : uint8_t {
@@ -232,7 +233,8 @@ template<> struct EnumTraits<WebCore::MediaPlayerEnums::MediaEngineIdentifier> {
WebCore::MediaPlayerEnums::MediaEngineIdentifier::GStreamerMSE,
WebCore::MediaPlayerEnums::MediaEngineIdentifier::HolePunch,
WebCore::MediaPlayerEnums::MediaEngineIdentifier::MediaFoundation,
WebCore::MediaPlayerEnums::MediaEngineIdentifier::MockMSE
WebCore::MediaPlayerEnums::MediaEngineIdentifier::MockMSE,
WebCore::MediaPlayerEnums::MediaEngineIdentifier::CocoaWebM
>;
};

@@ -0,0 +1,119 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(ALTERNATE_WEBM_PLAYER)

#include "MediaPlayerPrivate.h"
#include "PlatformLayer.h"
#include <wtf/LoggerHelper.h>
#include <wtf/WeakPtr.h>

namespace WebCore {

class MediaPlayerPrivateWebM
: public MediaPlayerPrivateInterface
, private LoggerHelper {
WTF_MAKE_FAST_ALLOCATED;
public:
MediaPlayerPrivateWebM(MediaPlayer*);
~MediaPlayerPrivateWebM();

static void registerMediaEngine(MediaEngineRegistrar);

void load(const String&) final;

#if ENABLE(MEDIA_SOURCE)
void load(const URL&, const ContentType&, MediaSourcePrivateClient&) final;
#endif
#if ENABLE(MEDIA_STREAM)
void load(MediaStreamPrivate&) final;
#endif

void cancelLoad() final;

PlatformLayer* platformLayer() const final;

void play() final;
void pause() final;

FloatSize naturalSize() const final { return m_naturalSize; };

bool hasAudio() const final { return m_hasAudio; };
bool hasVideo() const final { return m_hasVideo; };

void setPageIsVisible(bool) final;

MediaTime currentMediaTime() const final;
MediaTime durationMediaTime() const final { return m_duration; };

bool seeking() const final { return m_seeking; };

bool paused() const final { return m_paused; };

MediaPlayer::NetworkState networkState() const final { return m_networkState; };
MediaPlayer::ReadyState readyState() const final { return m_readyState; };

std::unique_ptr<PlatformTimeRanges> buffered() const final;

bool didLoadingProgress() const final;

void paint(GraphicsContext&, const FloatRect&) final { };

DestinationColorSpace colorSpace() final { return DestinationColorSpace::SRGB(); };

bool supportsAcceleratedRendering() const final { return false; };

const Logger& logger() const final { return m_logger.get(); }
const char* logClassName() const final { return "MediaPlayerPrivateWebM"; }
const void* logIdentifier() const final { return reinterpret_cast<const void*>(m_logIdentifier); }
WTFLogChannel& logChannel() const final;

private:
friend class MediaPlayerFactoryWebM;
static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>&);
static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);

MediaPlayer* m_player;

MediaPlayer::NetworkState m_networkState { MediaPlayer::NetworkState::Empty };
MediaPlayer::ReadyState m_readyState { MediaPlayer::ReadyState::HaveNothing };

Ref<const Logger> m_logger;
const void* m_logIdentifier;

FloatSize m_naturalSize;
bool m_hasAudio { false };
bool m_hasVideo { false };
MediaTime m_currentTime;
MediaTime m_duration;
bool m_seeking { false };
bool m_paused { false };
};

} // namespace WebCore

#endif // ENABLE(ALTERNATE_WEBM_PLAYER)

0 comments on commit bfe3f27

Please sign in to comment.