Bug 232155

Summary: [Cocoa] Fairplay encrypted video fails to play when loaded in a display:none element
Product: WebKit Reporter: Eric Carlson <eric.carlson>
Component: MediaAssignee: Eric Carlson <eric.carlson>
Status: RESOLVED FIXED    
Severity: Normal CC: ews-watchlist, glenn, jer.noble, peng.liu6, philipj, sergio, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Eric Carlson 2021-10-22 10:14:35 PDT
Fairplay encrypted video can never play if it is loaded in a display:none element
Comment 1 Eric Carlson 2021-10-22 10:14:50 PDT
rdar://83419159
Comment 2 Eric Carlson 2021-10-22 10:24:50 PDT
Created attachment 442177 [details]
Patch
Comment 3 Jer Noble 2021-10-22 11:04:16 PDT
Comment on attachment 442177 [details]
Patch

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

> Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:112
> +    if (!haveBeenAskedToPaint() || (supportsAcceleratedRendering() && m_player->renderingCanBeAccelerated()))
> +        return MediaRenderingMode::MediaRenderingToLayer;

So this will just cause us to always create an AVPlayerLayer immediately after the AVAssetStatus moves to > Unknown.  Is that correct?
Comment 4 Peng Liu 2021-10-22 15:21:05 PDT
Comment on attachment 442177 [details]
Patch

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

> Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:637
> +    if (!m_avPlayer || m_videoLayer)

Just curious. Is it possible that we need a video layer with a different size (or content scale) than the existing video layer.
Before this change, this function will always create a new video layer and set some parameters (from the player).
Comment 5 Eric Carlson 2021-10-22 15:56:37 PDT
Comment on attachment 442177 [details]
Patch

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

>> Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:637
>> +    if (!m_avPlayer || m_videoLayer)
> 
> Just curious. Is it possible that we need a video layer with a different size (or content scale) than the existing video layer.
> Before this change, this function will always create a new video layer and set some parameters (from the player).

No, this function is only called when `m_videoLayer` is NULL so this change isn't necessary.
Comment 6 Eric Carlson 2021-10-22 16:08:12 PDT
Created attachment 442211 [details]
Patch
Comment 7 Jer Noble 2021-10-22 16:15:02 PDT
Comment on attachment 442211 [details]
Patch

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

r=me with nit

> Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:112
>  
> -    if (supportsAcceleratedRendering() && m_player->renderingCanBeAccelerated())
> -        return MediaRenderingToLayer;
> +    if ((m_readyState >= MediaPlayer::ReadyState::HaveMetadata && !haveBeenAskedToPaint()) || (supportsAcceleratedRendering() && m_player->renderingCanBeAccelerated()))
> +        return MediaRenderingMode::MediaRenderingToLayer;

Nit: I might break this out into two statements for readability, and a smaller diff:

if (supportsAcceleratedRendering() && m_player->renderingCanBeAccelerated())
    return MediaRenderingToLayer;

if (m_readyState >= MediaPlayer::ReadyState::HaveMetadata && !haveBeenAskedToPaint())
    return MediaRenderingToLayer;
Comment 8 Eric Carlson 2021-10-22 16:33:36 PDT
Created attachment 442219 [details]
Patch
Comment 9 Eric Carlson 2021-10-22 16:35:59 PDT
Created attachment 442221 [details]
Patch
Comment 10 EWS 2021-10-22 19:34:26 PDT
Committed r284737 (243446@main): <https://commits.webkit.org/243446@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 442221 [details].
Comment 11 Simon Fraser (smfr) 2021-10-22 20:17:25 PDT
Comment on attachment 442221 [details]
Patch

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

> Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:160
> +    enum class MediaRenderingMode : uint8_t {
> +        MediaRenderingNone,
> +        MediaRenderingToContext,
> +        MediaRenderingToLayer
> +    };

Remove "MediaRendering" from the values.