Bug 201339 - [EME] Introduce a Proxy CDM for thread-safe access to CDM instances from background decryption threads
Summary: [EME] Introduce a Proxy CDM for thread-safe access to CDM instances from back...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Charlie Turner
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-08-30 05:20 PDT by Charlie Turner
Modified: 2019-09-05 15:00 PDT (History)
4 users (show)

See Also:


Attachments
Patch (16.98 KB, patch)
2019-08-30 05:20 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff
Patch (19.89 KB, patch)
2019-09-04 11:04 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff
Patch (19.90 KB, patch)
2019-09-05 01:08 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff
Patch (19.34 KB, patch)
2019-09-05 10:56 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff
Patch for landing (19.34 KB, patch)
2019-09-05 14:42 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff
Patch for landing (19.34 KB, patch)
2019-09-05 14:43 PDT, Charlie Turner
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Charlie Turner 2019-08-30 05:20:01 PDT
[EME] Introduce a Proxy CDM for thread-safe access to CDM instances from background decryption threads
Comment 1 Charlie Turner 2019-08-30 05:20:50 PDT
Created attachment 377700 [details]
Patch

This won't build on Mac ports because I haven't modifieded the CDM instance there. Review on the approach is appreciated, the ClearKey proxy CDM in the future should contain all the GCrypt code in my opinion, right now it wastes a lot of copies shoving all the keys into the background decryptor threads
Comment 2 Charlie Turner 2019-08-30 05:32:40 PDT
CC Jer, this is a spin-off from https://bugs.webkit.org/show_bug.cgi?id=192229#c25

Again it might seem quite pointless, but such a ProxyCDM will be used more heavily with Widevine / Playready.

It also seems like a good idea to move the GCrypt code from our GStreamer-specific decryptor into the cross-platform ClearKey CDM.

The patch is not for landing as it, the comments need tidying, and the approached needs to be blessed.
Comment 3 Xabier Rodríguez Calvar 2019-09-02 08:29:09 PDT
Comment on attachment 377700 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=377700&action=review

LGTM as a WIP patch.

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1323
> +    GST_DEBUG_OBJECT(m_pipeline.get(), "CDM proxy instance %p dispatched as context", m_cdmInstance->proxyCDM().get());

I'd say ProxyCDM instance...

> Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:298
> +                GST_DEBUG_OBJECT(self, "received a new CDM proxy instance %p, refcount %u", priv->proxyCDM.get(), priv->proxyCDM->refCount());

ProxyCDM
Comment 4 Charlie Turner 2019-09-04 11:04:51 PDT
Created attachment 377988 [details]
Patch

Attempt #1 to get the build green for Mac ports.
Comment 5 Charlie Turner 2019-09-05 00:42:34 PDT
I don't understand the iOS build failures,

In file included from /Volumes/Data/worker/iOS-12-Build-EWS/build/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:30:
/Volumes/Data/worker/iOS-12-Build-EWS/build/Source/WebCore/platform/encryptedmedia/CDMInstance.h:80:30: note: unimplemented pure virtual method 'proxyCDM' in 'CDMInstanceFairPlayStreamingAVFObjC'
    virtual RefPtr<ProxyCDM> proxyCDM() const = 0;

That method is implemented in CDMInstanceFairPlayStreamingAVFObjC,

+    RefPtr<ProxyCDM> proxyCDM() final { return adoptRef(*new ProxyCDMFairPlayStreamingAVFObjC()); }

And builds on Mac ports.
Comment 6 Charlie Turner 2019-09-05 01:08:41 PDT
Created attachment 378056 [details]
Patch

Sneaky method signature diff, Mac port attempt #2
Comment 7 Xabier Rodríguez Calvar 2019-09-05 03:04:36 PDT
Comment on attachment 378056 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378056&action=review

LGTM, Jer, Eric, any objections?

> Source/WebCore/platform/encryptedmedia/CDMInstance.h:47
> +// from background threads (I.e. decryptors)

.
Comment 8 Jer Noble 2019-09-05 09:44:53 PDT
Comment on attachment 378056 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378056&action=review

> Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:52
> +class ProxyCDMFairPlayStreamingAVFObjC final : public ProxyCDM {
> +    virtual ~ProxyCDMFairPlayStreamingAVFObjC() = default;
> +};
> +

This...

> Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:70
> +    RefPtr<ProxyCDM> proxyCDM() const final { return adoptRef(*new ProxyCDMFairPlayStreamingAVFObjC()); }

...and this seem unnecessary. Can this just return null?
Comment 9 Charlie Turner 2019-09-05 10:56:21 PDT
Created attachment 378096 [details]
Patch

Do not provide scaffolding for ProxyCDM on Mac ports
Comment 10 Jer Noble 2019-09-05 11:31:10 PDT
(In reply to Charlie Turner from comment #9)
> Created attachment 378096 [details]
> Patch
> 
> Do not provide scaffolding for ProxyCDM on Mac ports

LGTM
Comment 11 Charlie Turner 2019-09-05 14:42:52 PDT
Created attachment 378124 [details]
Patch for landing
Comment 12 Charlie Turner 2019-09-05 14:43:21 PDT
Created attachment 378125 [details]
Patch for landing
Comment 13 WebKit Commit Bot 2019-09-05 14:59:04 PDT
Comment on attachment 378125 [details]
Patch for landing

Clearing flags on attachment: 378125

Committed r249548: <https://trac.webkit.org/changeset/249548>
Comment 14 WebKit Commit Bot 2019-09-05 14:59:05 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 Radar WebKit Bug Importer 2019-09-05 15:00:19 PDT
<rdar://problem/55086095>