Skip to content

Commit 6c5cede

Browse files
committed
[EME] Push CDMFactory into the platform layer
https://bugs.webkit.org/show_bug.cgi?id=175129 Reviewed by Xabier Rodriguez-Calvar. This is a follow-up to r219678 that moved the majority of CDM abstraction classes into the platform layer, but missed the CDMFactory class. The CDMFactory abstraction is now also placed in the platform layer. Only change to the interface is that the createCDM() method can't accept a CDM object reference anymore since that class is cemented into the WebCore layer, and no current implementation used it anyway. Additionally, the static Vector object of registered factories is moved under the CDMFactory class, along with the register and unregister functions. The platformRegisterFactories() function is added to allow for platform-specific factory registrations to occur when the registered factories are queried for the first time. Empty implementation for this function is provided for non-GStreamer platforms, while for GStreamer the implementation is kept in CDMFactoryGStreamer.cpp. It's still empty for now, but it will register the ClearKey factory there in the near future. No new tests -- none affected, only refactoring. * CMakeLists.txt: * Modules/encryptedmedia/CDM.cpp: (WebCore::createCDMPrivateForKeySystem): (WebCore::CDM::supportsKeySystem): (WebCore::CDM::CDM): (): Deleted. (WebCore::CDM::registerCDMFactory): Deleted. (WebCore::CDM::unregisterCDMFactory): Deleted. * Modules/encryptedmedia/CDM.h: (WebCore::CDMFactory::~CDMFactory): Deleted. * PlatformWPE.cmake: * platform/GStreamer.cmake: * platform/encryptedmedia/CDMFactory.cpp: Added. (WebCore::CDMFactory::registerFactory): (WebCore::CDMFactory::unregisterFactory): (WebCore::CDMFactory::platformRegisterFactories): * platform/encryptedmedia/CDMFactory.h: Added. (WebCore::CDMFactory::~CDMFactory): * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMFactoryClearKey::createCDM): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/encryptedmedia/gstreamer/CDMFactoryGStreamer.cpp: Added. (WebCore::CDMFactory::platformRegisterFactories): * testing/MockCDMFactory.cpp: (WebCore::m_weakPtrFactory): (WebCore::MockCDMFactory::unregister): (WebCore::MockCDMFactory::createCDM): * testing/MockCDMFactory.h: Canonical link: https://commits.webkit.org/191923@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220264 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent cfe5898 commit 6c5cede

13 files changed

Lines changed: 245 additions & 48 deletions

File tree

Source/WebCore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,8 @@ set(WebCore_SOURCES
23032303
platform/audio/VectorMath.cpp
23042304
platform/audio/ZeroPole.cpp
23052305

2306+
platform/encryptedmedia/CDMFactory.cpp
2307+
23062308
platform/graphics/BitmapImage.cpp
23072309
platform/graphics/Color.cpp
23082310
platform/graphics/ComplexTextController.cpp

Source/WebCore/ChangeLog

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
2017-08-04 Zan Dobersek <[email protected]>
2+
3+
[EME] Push CDMFactory into the platform layer
4+
https://bugs.webkit.org/show_bug.cgi?id=175129
5+
6+
Reviewed by Xabier Rodriguez-Calvar.
7+
8+
This is a follow-up to r219678 that moved the majority of CDM abstraction
9+
classes into the platform layer, but missed the CDMFactory class.
10+
11+
The CDMFactory abstraction is now also placed in the platform layer. Only
12+
change to the interface is that the createCDM() method can't accept a CDM
13+
object reference anymore since that class is cemented into the WebCore
14+
layer, and no current implementation used it anyway.
15+
16+
Additionally, the static Vector object of registered factories is moved
17+
under the CDMFactory class, along with the register and unregister
18+
functions. The platformRegisterFactories() function is added to allow for
19+
platform-specific factory registrations to occur when the registered
20+
factories are queried for the first time. Empty implementation for this
21+
function is provided for non-GStreamer platforms, while for GStreamer
22+
the implementation is kept in CDMFactoryGStreamer.cpp. It's still empty
23+
for now, but it will register the ClearKey factory there in the near
24+
future.
25+
26+
No new tests -- none affected, only refactoring.
27+
28+
* CMakeLists.txt:
29+
* Modules/encryptedmedia/CDM.cpp:
30+
(WebCore::createCDMPrivateForKeySystem):
31+
(WebCore::CDM::supportsKeySystem):
32+
(WebCore::CDM::CDM):
33+
(): Deleted.
34+
(WebCore::CDM::registerCDMFactory): Deleted.
35+
(WebCore::CDM::unregisterCDMFactory): Deleted.
36+
* Modules/encryptedmedia/CDM.h:
37+
(WebCore::CDMFactory::~CDMFactory): Deleted.
38+
* PlatformWPE.cmake:
39+
* platform/GStreamer.cmake:
40+
* platform/encryptedmedia/CDMFactory.cpp: Added.
41+
(WebCore::CDMFactory::registerFactory):
42+
(WebCore::CDMFactory::unregisterFactory):
43+
(WebCore::CDMFactory::platformRegisterFactories):
44+
* platform/encryptedmedia/CDMFactory.h: Added.
45+
(WebCore::CDMFactory::~CDMFactory):
46+
* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
47+
(WebCore::CDMFactoryClearKey::createCDM):
48+
* platform/encryptedmedia/clearkey/CDMClearKey.h:
49+
* platform/encryptedmedia/gstreamer/CDMFactoryGStreamer.cpp: Added.
50+
(WebCore::CDMFactory::platformRegisterFactories):
51+
* testing/MockCDMFactory.cpp:
52+
(WebCore::m_weakPtrFactory):
53+
(WebCore::MockCDMFactory::unregister):
54+
(WebCore::MockCDMFactory::createCDM):
55+
* testing/MockCDMFactory.h:
56+
157
2017-08-04 Frederic Wang <[email protected]>
258

359
ScrollingTreeOverflowScrollingNodeIOS uses the wrong fixed position rectangle

Source/WebCore/Modules/encryptedmedia/CDM.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#if ENABLE(ENCRYPTED_MEDIA)
3030

31+
#include "CDMFactory.h"
3132
#include "CDMPrivate.h"
3233
#include "Document.h"
3334
#include "InitDataRegistry.h"
@@ -41,27 +42,9 @@
4142

4243
namespace WebCore {
4344

44-
static Vector<CDMFactory*>& cdmFactories()
45-
{
46-
static NeverDestroyed<Vector<CDMFactory*>> factories;
47-
return factories;
48-
}
49-
50-
void CDM::registerCDMFactory(CDMFactory& factory)
51-
{
52-
ASSERT(!cdmFactories().contains(&factory));
53-
cdmFactories().append(&factory);
54-
}
55-
56-
void CDM::unregisterCDMFactory(CDMFactory& factory)
57-
{
58-
ASSERT(cdmFactories().contains(&factory));
59-
cdmFactories().removeAll(&factory);
60-
}
61-
6245
bool CDM::supportsKeySystem(const String& keySystem)
6346
{
64-
for (auto* factory : cdmFactories()) {
47+
for (auto* factory : CDMFactory::registeredFactories()) {
6548
if (factory->supportsKeySystem(keySystem))
6649
return true;
6750
}
@@ -79,9 +62,9 @@ CDM::CDM(Document& document, const String& keySystem)
7962
, m_weakPtrFactory(this)
8063
{
8164
ASSERT(supportsKeySystem(keySystem));
82-
for (auto* factory : cdmFactories()) {
65+
for (auto* factory : CDMFactory::registeredFactories()) {
8366
if (factory->supportsKeySystem(keySystem)) {
84-
m_private = factory->createCDM(*this);
67+
m_private = factory->createCDM();
8568
break;
8669
}
8770
}

Source/WebCore/Modules/encryptedmedia/CDM.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,15 @@
4242

4343
namespace WebCore {
4444

45-
class CDM;
45+
class CDMFactory;
4646
class CDMInstance;
4747
class CDMPrivate;
4848
class Document;
4949
class ScriptExecutionContext;
5050
class SharedBuffer;
5151

52-
class CDMFactory {
53-
public:
54-
virtual ~CDMFactory() { };
55-
virtual std::unique_ptr<CDMPrivate> createCDM(CDM&) = 0;
56-
virtual bool supportsKeySystem(const String&) = 0;
57-
};
58-
5952
class CDM : public RefCounted<CDM>, private ContextDestructionObserver {
6053
public:
61-
WEBCORE_EXPORT static void registerCDMFactory(CDMFactory&);
62-
WEBCORE_EXPORT static void unregisterCDMFactory(CDMFactory&);
63-
6454
static bool supportsKeySystem(const String&);
6555
static bool isPersistentType(MediaKeySessionType);
6656

Source/WebCore/PlatformWPE.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,6 @@ list(APPEND WebCorePlatformWPE_SOURCES
150150
platform/wpe/WidgetWPE.cpp
151151
)
152152

153-
if (ENABLE_ENCRYPTED_MEDIA)
154-
list(APPEND WebCore_INCLUDE_DIRECTORIES
155-
"${WEBCORE_DIR}/platform/encryptedmedia/clearkey"
156-
)
157-
list(APPEND WebCore_SOURCES
158-
platform/encryptedmedia/clearkey/CDMClearKey.cpp
159-
)
160-
endif ()
161-
162153
list(APPEND WebCore_USER_AGENT_STYLE_SHEETS
163154
${WEBCORE_DIR}/Modules/mediacontrols/mediaControlsBase.css
164155
)

Source/WebCore/platform/GStreamer.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,14 @@ endif ()
133133

134134
if (ENABLE_ENCRYPTED_MEDIA)
135135
list(APPEND WebCore_INCLUDE_DIRECTORIES
136+
"${WEBCORE_DIR}/platform/encryptedmedia/clearkey"
136137
${LIBGCRYPT_INCLUDE_DIRS}
137138
)
139+
list(APPEND WebCore_SOURCES
140+
platform/encryptedmedia/clearkey/CDMClearKey.cpp
141+
142+
platform/graphics/gstreamer/eme/CDMFactoryGStreamer.cpp
143+
)
138144
list(APPEND WebCore_LIBRARIES
139145
${LIBGCRYPT_LIBRARIES} -lgpg-error
140146
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2016 Apple Inc. All rights reserved.
3+
* Copyright (C) 2017 Metrological Group B.V.
4+
* Copyright (C) 2017 Igalia S.L.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25+
* THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#include "config.h"
29+
#include "CDMFactory.h"
30+
31+
#if ENABLE(ENCRYPTED_MEDIA)
32+
33+
#include <mutex>
34+
#include <wtf/NeverDestroyed.h>
35+
36+
namespace WebCore {
37+
38+
Vector<CDMFactory*>& CDMFactory::registeredFactories()
39+
{
40+
static NeverDestroyed<Vector<CDMFactory*>> factories;
41+
static std::once_flag once;
42+
std::call_once(once, [&] { platformRegisterFactories(factories); });
43+
44+
return factories;
45+
}
46+
47+
void CDMFactory::registerFactory(CDMFactory& factory)
48+
{
49+
ASSERT(!registeredFactories().contains(&factory));
50+
registeredFactories().append(&factory);
51+
}
52+
53+
void CDMFactory::unregisterFactory(CDMFactory& factory)
54+
{
55+
ASSERT(registeredFactories().contains(&factory));
56+
registeredFactories().removeAll(&factory);
57+
}
58+
59+
#if !USE(GSTREAMER)
60+
void CDMFactory::platformRegisterFactories()
61+
{
62+
}
63+
#endif
64+
65+
} // namespace WebCore
66+
67+
#endif // ENABLE(ENCRYPTED_MEDIA)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2016 Apple Inc. All rights reserved.
3+
* Copyright (C) 2017 Metrological Group B.V.
4+
* Copyright (C) 2017 Igalia S.L.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25+
* THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#pragma once
29+
30+
#if ENABLE(ENCRYPTED_MEDIA)
31+
32+
#include <memory>
33+
#include <wtf/Forward.h>
34+
#include <wtf/Vector.h>
35+
36+
namespace WebCore {
37+
38+
class CDMPrivate;
39+
40+
class CDMFactory {
41+
public:
42+
virtual ~CDMFactory() { };
43+
virtual std::unique_ptr<CDMPrivate> createCDM() = 0;
44+
virtual bool supportsKeySystem(const String&) = 0;
45+
46+
static Vector<CDMFactory*>& registeredFactories();
47+
WEBCORE_EXPORT static void registerFactory(CDMFactory&);
48+
WEBCORE_EXPORT static void unregisterFactory(CDMFactory&);
49+
50+
// Platform-specific function that's called when the list of
51+
// registered CDMFactory objects is queried for the first time.
52+
static void platformRegisterFactories(Vector<CDMFactory*>&);
53+
};
54+
55+
} // namespace WebCore
56+
57+
#endif // ENABLE(ENCRYPTED_MEDIA)

Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131

3232
#if ENABLE(ENCRYPTED_MEDIA)
3333

34+
#include "SharedBuffer.h"
35+
3436
namespace WebCore {
3537

3638
CDMFactoryClearKey::CDMFactoryClearKey() = default;
3739
CDMFactoryClearKey::~CDMFactoryClearKey() = default;
3840

39-
std::unique_ptr<CDMPrivate> CDMFactoryClearKey::createCDM(CDM&)
41+
std::unique_ptr<CDMPrivate> CDMFactoryClearKey::createCDM()
4042
{
4143
return std::unique_ptr<CDMPrivate>(new CDMPrivateClearKey);
4244
}

Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#if ENABLE(ENCRYPTED_MEDIA)
3232

33-
#include "CDM.h"
33+
#include "CDMFactory.h"
3434
#include "CDMInstance.h"
3535
#include "CDMPrivate.h"
3636

@@ -41,7 +41,7 @@ class CDMFactoryClearKey final : public CDMFactory {
4141
CDMFactoryClearKey();
4242
virtual ~CDMFactoryClearKey();
4343

44-
std::unique_ptr<CDMPrivate> createCDM(CDM&) override;
44+
std::unique_ptr<CDMPrivate> createCDM() override;
4545
bool supportsKeySystem(const String&) override;
4646
};
4747

0 commit comments

Comments
 (0)