Skip to content

CDMInstanceProxy: Use weak ptr for keeping player#900

Closed
asurdej-comcast wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.28from
asurdej-comcast:cdm_crashfix
Closed

CDMInstanceProxy: Use weak ptr for keeping player#900
asurdej-comcast wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.28from
asurdej-comcast:cdm_crashfix

Conversation

@asurdej-comcast

Copy link
Copy Markdown

Use WeakPtr for keeping media player ptr as it can be used after
player is destroyed.
The media player can be removed by HTMLMediaElement::load() request
while still waiting for decryption key. CDM is not aware of such case
and tries to use m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load()
as the player will be re-created.

Use WeakPtr for keeping media player ptr as it can be used after
player is destroyed.
The media player can be removed by HTMLMediaElement::load() request
while still waiting for decryption key. CDM is not aware of such case
and tries to use m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load()
as the player will be re-created.
@woutermeek
woutermeek requested a review from calvaris June 28, 2022 09:14
@calvaris calvaris self-assigned this Jun 29, 2022
@calvaris

Copy link
Copy Markdown
Member

I keep this on my radar, will need to upstream this.

@woutermeek woutermeek added wpe-2.28 Only for PR affecting 2.28 upstream Related to an upstream bug (or should be at some point) labels Jun 30, 2022
@asurdej-comcast

Copy link
Copy Markdown
Author

Hi @calvaris any update here? Is there anything needed from my side?

@calvaris

calvaris commented Jul 8, 2022

Copy link
Copy Markdown
Member

Now that you ask, a use case would be nice.

Regarding updates, I have a lot of work and other priorities. This is not just merging, it meens submitting upstream, studying it, etc. It is not just a shallow review, so I will do it as soon as I can.

@asurdej-comcast

Copy link
Copy Markdown
Author

Sure, take your time

The case here was that there was no key for decryption. Decryptor was waiting in tryWaitForKeyHandle() and this function was timeouted (after 7.0sec timeout). stoppedWaitingForKey() was scheduled to be called on main thread but decryptor recognized that there is no key and issued and error on pipeline and media element. JavaScript reloaded the player (vidoe.load()) that caused the new player to be created. Now the stoppedWaitingForKey was invoked on the main thread but the player is already gone. It was crashing sometimes if the memory was already overwritten but in most cases this was surprisingly working and the callback was even reaching HTMLMediaElement (that has new player already)

webkit-commit-queue pushed a commit to calvaris/WebKit that referenced this pull request Nov 18, 2022
https://bugs.webkit.org/show_bug.cgi?id=247977

Reviewed by Philippe Normand.

Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

Patch by Andrzej Surdej <Andrzej_Surdej@comcast.com> coming from
WebPlatformForEmbedded/WPEWebKit#900.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::prepareForLoad):
* Source/WebCore/platform/encryptedmedia/CDMProxy.h:
(WebCore::CDMInstanceProxy::setPlayer):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

Canonical link: https://commits.webkit.org/256823@main
calvaris pushed a commit that referenced this pull request Nov 18, 2022
https://bugs.webkit.org/show_bug.cgi?id=247977

Reviewed by Philippe Normand.

Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

Coming from #900.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::prepareForLoad):
* Source/WebCore/platform/encryptedmedia/CDMProxy.h:
(WebCore::CDMInstanceProxy::setPlayer):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

Canonical link: https://commits.webkit.org/256823@main

Signed-off-by: Xabier Rodriguez Calvar <calvaris@igalia.com>
@calvaris

Copy link
Copy Markdown
Member

Landed this PR as 683cfd9 on wpe-2.28. Closing.

@calvaris calvaris closed this Nov 18, 2022
mnutt pushed a commit to movableink/webkit that referenced this pull request Dec 6, 2022
https://bugs.webkit.org/show_bug.cgi?id=247977

Reviewed by Philippe Normand.

Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

Patch by Andrzej Surdej <Andrzej_Surdej@comcast.com> coming from
WebPlatformForEmbedded#900.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::prepareForLoad):
* Source/WebCore/platform/encryptedmedia/CDMProxy.h:
(WebCore::CDMInstanceProxy::setPlayer):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

Canonical link: https://commits.webkit.org/256823@main
aperezdc pushed a commit to WebKit/WebKit that referenced this pull request Jan 25, 2023
…gi?id=247977

    [EME] CDMInstanceProxy: Use weak ptr for keeping player
    https://bugs.webkit.org/show_bug.cgi?id=247977

    Reviewed by Philippe Normand.

    Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
    HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
    m_player ptr anyway that resuts with crash.

    Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

    Patch by Andrzej Surdej <Andrzej_Surdej@comcast.com> coming from
    WebPlatformForEmbedded/WPEWebKit#900.

    * Source/WebCore/html/HTMLMediaElement.cpp:
    (WebCore::HTMLMediaElement::prepareForLoad):
    * Source/WebCore/platform/encryptedmedia/CDMProxy.h:
    (WebCore::CDMInstanceProxy::setPlayer):
    * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
    (WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

    Canonical link: https://commits.webkit.org/256823@main
calvaris added a commit that referenced this pull request Jan 31, 2023
https://bugs.webkit.org/show_bug.cgi?id=247977

Reviewed by Philippe Normand.

Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

Patch by Andrzej Surdej <Andrzej_Surdej@comcast.com> coming from
#900.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::prepareForLoad):
* Source/WebCore/platform/encryptedmedia/CDMProxy.h:
(WebCore::CDMInstanceProxy::setPlayer):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

Canonical link: https://commits.webkit.org/256823@main
calvaris added a commit that referenced this pull request Feb 1, 2023
https://bugs.webkit.org/show_bug.cgi?id=247977

Reviewed by Philippe Normand.

Use WeakPtr for keeping media player ptr as it can be used after player is destroyed. The media player can be removed by
HTMLMediaElement::load() request while still waiting for decryption key. CDM is not aware of such case and tries to use
m_player ptr anyway that resuts with crash.

Also reset m_playbackBlockedWaitingForKey when calling load() as the player will be re-created.

Patch by Andrzej Surdej <Andrzej_Surdej@comcast.com> coming from
#900.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::prepareForLoad):
* Source/WebCore/platform/encryptedmedia/CDMProxy.h:
(WebCore::CDMInstanceProxy::setPlayer):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::cdmInstanceAttached):

Canonical link: https://commits.webkit.org/256823@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream Related to an upstream bug (or should be at some point) wpe-2.28 Only for PR affecting 2.28

Development

Successfully merging this pull request may close these issues.

3 participants