Bug 192075 - [GStreamer][EME] CDMInstance should be shipped as a GstContext to the decryptors
Summary: [GStreamer][EME] CDMInstance should be shipped as a GstContext to the decryptors
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Xabier Rodríguez Calvar
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-11-28 03:25 PST by Xabier Rodríguez Calvar
Modified: 2018-11-30 08:22 PST (History)
5 users (show)

See Also:


Attachments
Patch (18.44 KB, patch)
2018-11-28 03:39 PST, Xabier Rodríguez Calvar
no flags Details | Formatted Diff | Diff
Patch (18.86 KB, patch)
2018-11-29 10:32 PST, Xabier Rodríguez Calvar
no flags Details | Formatted Diff | Diff
Patch (19.53 KB, patch)
2018-11-29 10:38 PST, Xabier Rodríguez Calvar
no flags Details | Formatted Diff | Diff
Patch for landing (19.61 KB, patch)
2018-11-30 07:44 PST, Xabier Rodríguez Calvar
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xabier Rodríguez Calvar 2018-11-28 03:25:33 PST
[GStreamer][EME] CDMInstance should be shipped as a GstContext to the decryptors
Comment 1 Xabier Rodríguez Calvar 2018-11-28 03:39:02 PST
Created attachment 355860 [details]
Patch
Comment 2 Philippe Normand 2018-11-28 04:04:37 PST
Comment on attachment 355860 [details]
Patch

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

> Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:313
> +        GRefPtr<GstContext> context = adoptGRef(gst_element_get_context(GST_ELEMENT(self), "drm-cdm-instance"));
> +        if (context) {

If not context is found here, maybe you can try a context query and a need-context message, like described in the GstContext docs?
Comment 3 Xabier Rodríguez Calvar 2018-11-28 10:16:23 PST
(In reply to Philippe Normand from comment #2)
> Comment on attachment 355860 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=355860&action=review
> 
> > Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:313
> > +        GRefPtr<GstContext> context = adoptGRef(gst_element_get_context(GST_ELEMENT(self), "drm-cdm-instance"));
> > +        if (context) {
> 
> If not context is found here, maybe you can try a context query and a
> need-context message, like described in the GstContext docs?

Yes, I thought of that and it could make sense in other circumstances. In our case, as soon as we get the CDMInstance from WebCore, we set it so it should be available. If it isn't a query is not going to help cause nobody is going to answer it and a message would be useless as well cause the CDMInstance is something we don't ask but we get instead.
Comment 4 Philippe Normand 2018-11-29 02:03:30 PST
Comment on attachment 355860 [details]
Patch

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

>>> Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:313
>>> +        if (context) {
>> 
>> If not context is found here, maybe you can try a context query and a need-context message, like described in the GstContext docs?
> 
> Yes, I thought of that and it could make sense in other circumstances. In our case, as soon as we get the CDMInstance from WebCore, we set it so it should be available. If it isn't a query is not going to help cause nobody is going to answer it and a message would be useless as well cause the CDMInstance is something we don't ask but we get instead.

A message sent by the decryptor could be handled in the player message handler.
Comment 5 Xabier Rodríguez Calvar 2018-11-29 03:28:22 PST
(In reply to Philippe Normand from comment #4)
> Comment on attachment 355860 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=355860&action=review
> 
> >>> Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:313
> >>> +        if (context) {
> >> 
> >> If not context is found here, maybe you can try a context query and a need-context message, like described in the GstContext docs?
> > 
> > Yes, I thought of that and it could make sense in other circumstances. In our case, as soon as we get the CDMInstance from WebCore, we set it so it should be available. If it isn't a query is not going to help cause nobody is going to answer it and a message would be useless as well cause the CDMInstance is something we don't ask but we get instead.
> 
> A message sent by the decryptor could be handled in the player message
> handler.

Obviously, but it is not going to be answered sooner, cause if we had it in the player, it would be set already in the pipeline.
Comment 6 Xabier Rodríguez Calvar 2018-11-29 03:29:26 PST
(In reply to Xabier Rodríguez Calvar from comment #5)
> (In reply to Philippe Normand from comment #4)
> > Comment on attachment 355860 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=355860&action=review
> > 
> > >>> Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:313
> > >>> +        if (context) {
> > >> 
> > >> If not context is found here, maybe you can try a context query and a need-context message, like described in the GstContext docs?
> > > 
> > > Yes, I thought of that and it could make sense in other circumstances. In our case, as soon as we get the CDMInstance from WebCore, we set it so it should be available. If it isn't a query is not going to help cause nobody is going to answer it and a message would be useless as well cause the CDMInstance is something we don't ask but we get instead.
> > 
> > A message sent by the decryptor could be handled in the player message
> > handler.
> 
> Obviously, but it is not going to be answered sooner, cause if we had it in
> the player, it would be set already in the pipeline.

It would be dead code.
Comment 7 Charlie Turner 2018-11-29 05:51:03 PST
Comment on attachment 355860 [details]
Patch

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

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:1332
> +            // FIXME: The decryptors should be able force attempt decryption after creation and being added to a pipeline as a way of trying to get they keys if needed.

This sentence needs rewording

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1218
> +    GST_LOG("CDM instance %p dispatched as context", m_cdmInstance.get());

This isn't a high frequency message, it would be better placed at the DEBUG level.

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1226
> +#ifndef NDEBUG

Could remove the macro code and put an early return in for instance != m_cdmInstance, this would also make the logic more symmetrical with cdmInstanceAttached.

> Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:912
> +void MediaPlayerPrivateGStreamerMSE::attemptToDecryptWithLocalInstance()

Since we're renaming things and don't have the distinction anymore of an argument instance vs. a class instance, this code would read nicer if the method was just called attemptToDecryptWithInstance, the local part doesn't communicate anything imo.
Comment 8 Xabier Rodríguez Calvar 2018-11-29 06:05:10 PST
(In reply to Charlie Turner from comment #7)
> Comment on attachment 355860 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=355860&action=review
> 
> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:1332
> > +            // FIXME: The decryptors should be able force attempt decryption after creation and being added to a pipeline as a way of trying to get they keys if needed.
> 
> This sentence needs rewording

Yes.

> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1218
> > +    GST_LOG("CDM instance %p dispatched as context", m_cdmInstance.get());
> 
> This isn't a high frequency message, it would be better placed at the DEBUG
> level.

Yes, I should know my logging levels better ;)

> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1226
> > +#ifndef NDEBUG
> 
> Could remove the macro code and put an early return in for instance !=
> m_cdmInstance, this would also make the logic more symmetrical with
> cdmInstanceAttached.

I'll try.

> > Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:912
> > +void MediaPlayerPrivateGStreamerMSE::attemptToDecryptWithLocalInstance()
> 
> Since we're renaming things and don't have the distinction anymore of an
> argument instance vs. a class instance, this code would read nicer if the
> method was just called attemptToDecryptWithInstance, the local part doesn't
> communicate anything imo.

There's already an attemptToDecryptWithInstance, wdym?
Comment 9 Xabier Rodríguez Calvar 2018-11-29 10:32:40 PST
Created attachment 356019 [details]
Patch
Comment 10 Xabier Rodríguez Calvar 2018-11-29 10:34:02 PST
Comment on attachment 356019 [details]
Patch

Uploaded by mistake.
Comment 11 Xabier Rodríguez Calvar 2018-11-29 10:38:47 PST
Created attachment 356023 [details]
Patch
Comment 12 Thibault Saunier 2018-11-29 11:46:35 PST
Why not simply a property on the decryptor element? As I see it, this is going through the GstContext API to simply set a property on a specific element. GstContext was designed to be able to share a common "context" on several elements in the pipeline.

To me, the "normal" way of doing that would be to have a "cdm-instance" property on the decryptor and in the MediaPlayerPrivate connect to `deep-element-added` and set the property from there.

What am I missing here? :-)
Comment 13 Xabier Rodríguez Calvar 2018-11-30 03:59:21 PST
(In reply to Thibault Saunier from comment #12)
> Why not simply a property on the decryptor element? As I see it, this is
> going through the GstContext API to simply set a property on a specific
> element. GstContext was designed to be able to share a common "context" on
> several elements in the pipeline.

For me this a common context shared by several elements in the pipeline, in this case the decryptors.

> To me, the "normal" way of doing that would be to have a "cdm-instance"
> property on the decryptor and in the MediaPlayerPrivate connect to
> `deep-element-added` and set the property from there.

Connecting to that signal would also imply inspecting the pipeline for the detach and unsetting the property when the instance is detached.

I don't have a strong opinion on GstContext vs property but in this case it looks better to me to use a context. Do you have a stronger opinion?
Comment 14 Thibault Saunier 2018-11-30 04:50:45 PST
(In reply to Xabier Rodríguez Calvar from comment #13)
> (In reply to Thibault Saunier from comment #12)
> > Why not simply a property on the decryptor element? As I see it, this is
> > going through the GstContext API to simply set a property on a specific
> > element. GstContext was designed to be able to share a common "context" on
> > several elements in the pipeline.
> 
> For me this a common context shared by several elements in the pipeline, in
> this case the decryptors.
> 
> > To me, the "normal" way of doing that would be to have a "cdm-instance"
> > property on the decryptor and in the MediaPlayerPrivate connect to
> > `deep-element-added` and set the property from there.
> 
> Connecting to that signal would also imply inspecting the pipeline for the
> detach and unsetting the property when the instance is detached.
> 
> I don't have a strong opinion on GstContext vs property but in this case it
> looks better to me to use a context. Do you have a stronger opinion?

No strong opinion no, just looked a bit odd at first sight, but I can understand your point stating that the CDMInstance is a shared context for all decryptor elements that is shared between instances.
Comment 15 Philippe Normand 2018-11-30 06:54:40 PST
Comment on attachment 356023 [details]
Patch

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

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1209
> +    if (!m_pipeline) {
> +        GST_ERROR("no pipeline yet");
> +        ASSERT_NOT_REACHED();
> +        return;
>      }

Replace this with a RELEASE_ASSERT_WITH_MESSAGE() maybe?

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1218
> +    GST_DEBUG("CDM instance %p dispatched as context", m_cdmInstance.get());

GST_DEBUG_OBJECT()

> Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1233
> +    GST_DEBUG("detaching CDM instance %p, setting empty context", m_cdmInstance.get());

GST_DEBUG_OBJECT
Comment 16 Xabier Rodríguez Calvar 2018-11-30 07:34:54 PST
(In reply to Philippe Normand from comment #15)
> Comment on attachment 356023 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=356023&action=review
> 
> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1209
> > +    if (!m_pipeline) {
> > +        GST_ERROR("no pipeline yet");
> > +        ASSERT_NOT_REACHED();
> > +        return;
> >      }
> 
> Replace this with a RELEASE_ASSERT_WITH_MESSAGE() maybe?

I think in this case it is better to stick to the GST_ERROR and the ASSERT because should this happen in real life it would be better if playback just fails and we get that message than just a crash.
 
> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1218
> > +    GST_DEBUG("CDM instance %p dispatched as context", m_cdmInstance.get());
> 
> GST_DEBUG_OBJECT()

Roger.
 
> > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:1233
> > +    GST_DEBUG("detaching CDM instance %p, setting empty context", m_cdmInstance.get());
> 
> GST_DEBUG_OBJECT

Roger.
Comment 17 Xabier Rodríguez Calvar 2018-11-30 07:44:17 PST
Created attachment 356177 [details]
Patch for landing
Comment 18 WebKit Commit Bot 2018-11-30 08:21:42 PST
Comment on attachment 356177 [details]
Patch for landing

Clearing flags on attachment: 356177

Committed r238738: <https://trac.webkit.org/changeset/238738>
Comment 19 WebKit Commit Bot 2018-11-30 08:21:44 PST
All reviewed patches have been landed.  Closing bug.
Comment 20 Radar WebKit Bug Importer 2018-11-30 08:22:40 PST
<rdar://problem/46373511>