From d9cdfeebd9eb6a067b97316daa149c7f58e1c7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 29 Nov 2021 14:53:59 +0100 Subject: Use AVPlayerItemVideoOutput to generate video frames This fixes rendering problems on M1 based Macs. It also unifies the rendering pipeline between macOS and iOS as much as possible, and avoids an intermediate copy to an FBO, Since AVPlayerItemVideoOutput produces GL_TEXTURE_RECTANGLE textures on macOS a new QAbstractVideoBuffer handle has been added that explicitly maps to GL_TEXTURE_RECTANGLE. We use this handle type internally in QSGVideoMaterial_Texture where we know how to blit GL_TEXTURE_RECTANGLE textures. To maintain compatibility for QAbstractVideoSurface consumers who expect GL_TEXTURE_2D textures we blit the rectangle texture to an FBO returned as QAbstractVideoBuffer::GLTextureHandle. Fixes: QTBUG-89803 Done-with: Lars Knoll Change-Id: I36d22eafb63902ecc1097e138705812ef6a8cb71 Reviewed-by: Lars Knoll Reviewed-by: Doris Verria --- .../mediaplayer/avfmediaplayersession.mm | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm') diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index ea54fe6be..ae2234764 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -110,6 +110,12 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext self->m_session = session; self->m_bufferIsLikelyToKeepUp = FALSE; + + m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:nil]; + [m_playerLayer retain]; + m_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; + m_playerLayer.anchorPoint = CGPointMake(0.0f, 0.0f); + return self; } @@ -172,10 +178,6 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext [m_player release]; m_player = 0; } - if (m_playerLayer) { - [m_playerLayer release]; - m_playerLayer = 0; - } } - (void) prepareToPlayAsset:(AVURLAsset *)asset @@ -260,14 +262,8 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext [m_player setMuted:m_session->isMuted()]; } - //Create a new player layer if we don't have one already - if (!m_playerLayer) - { - m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:m_player]; - [m_playerLayer retain]; - m_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; - m_playerLayer.anchorPoint = CGPointMake(0.0f, 0.0f); - } + //Assign the output layer to the new player + m_playerLayer.player = m_player; //Observe the AVPlayer "currentItem" property to find out when any //AVPlayer replaceCurrentItemWithPlayerItem: replacement will/did @@ -413,6 +409,7 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext } [m_mimeType release]; + [m_playerLayer release]; [super dealloc]; } -- cgit v1.2.3