diff options
Diffstat (limited to 'src/plugins/multimedia/darwin/mediaplayer')
6 files changed, 123 insertions, 303 deletions
diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm index 64b625f0e..8c6561f37 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm +++ b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink.mm @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "avfdisplaylink_p.h" #include <QtCore/qcoreapplication.h> @@ -239,3 +203,5 @@ bool AVFDisplayLink::event(QEvent *event) } return QObject::event(event); } + +#include "moc_avfdisplaylink_p.cpp" diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h index 6b95e1e07..c4eb504a5 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h +++ b/src/plugins/multimedia/darwin/mediaplayer/avfdisplaylink_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef AVFDISPLAYLINK_H #define AVFDISPLAYLINK_H diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm index 86b7ce0a2..694cc0e3d 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm +++ b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "avfmediaplayer_p.h" #include "avfvideorenderercontrol_p.h" @@ -48,6 +12,7 @@ #include <qpointer.h> #include <QFileInfo> #include <QtCore/qmath.h> +#include <QtCore/qmutex.h> #import <AVFoundation/AVFoundation.h> @@ -95,6 +60,12 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM - (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest; @end +#ifdef Q_OS_IOS +// Alas, no such thing as 'class variable', hence globals: +static unsigned sessionActivationCount; +static QMutex sessionMutex; +#endif // Q_OS_IOS + @implementation AVFMediaPlayerObserver { @private @@ -106,10 +77,39 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM BOOL m_bufferIsLikelyToKeepUp; NSData *m_data; NSString *m_mimeType; +#ifdef Q_OS_IOS + BOOL m_activated; +#endif } @synthesize m_player, m_playerItem, m_playerLayer, m_session; +#ifdef Q_OS_IOS +- (void)setSessionActive:(BOOL)active +{ + const QMutexLocker lock(&sessionMutex); + if (active) { + // Don't count the same player twice if already activated, + // unless it tried to deactivate first: + if (m_activated) + return; + if (!sessionActivationCount) + [AVAudioSession.sharedInstance setActive:YES error:nil]; + ++sessionActivationCount; + m_activated = YES; + } else { + if (!sessionActivationCount || !m_activated) { + qWarning("Unbalanced audio session deactivation, ignoring."); + return; + } + --sessionActivationCount; + m_activated = NO; + if (!sessionActivationCount) + [AVAudioSession.sharedInstance setActive:NO error:nil]; + } +} +#endif // Q_OS_IOS + - (AVFMediaPlayerObserver *) initWithMediaPlayerSession:(AVFMediaPlayer *)session { if (!(self = [super init])) @@ -127,6 +127,9 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM - (void) setURL:(NSURL *)url mimeType:(NSString *)mimeType { + if (!m_session) + return; + [m_mimeType release]; m_mimeType = [mimeType retain]; @@ -140,23 +143,29 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM // use __block to avoid maintaining strong references on variables captured by the // following block callback +#if defined(Q_OS_IOS) + BOOL isAccessing = [m_URL startAccessingSecurityScopedResource]; +#endif __block AVURLAsset *asset = [[AVURLAsset URLAssetWithURL:m_URL options:nil] retain]; [asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()]; __block NSArray *requestedKeys = [[NSArray arrayWithObjects:AVF_TRACKS_KEY, AVF_PLAYABLE_KEY, nil] retain]; - __block AVFMediaPlayerObserver *blockSelf = self; - QPointer<AVFMediaPlayer> session(m_session); + __block AVFMediaPlayerObserver *blockSelf = [self retain]; // Tells the asset to load the values of any of the specified keys that are not already loaded. [asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler: ^{ dispatch_async( dispatch_get_main_queue(), ^{ - if (session) - [blockSelf prepareToPlayAsset:asset withKeys:requestedKeys]; +#if defined(Q_OS_IOS) + if (isAccessing) + [m_URL stopAccessingSecurityScopedResource]; +#endif + [blockSelf prepareToPlayAsset:asset withKeys:requestedKeys]; [asset release]; [requestedKeys release]; + [blockSelf release]; }); }]; } @@ -186,13 +195,16 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM if (m_playerLayer) m_playerLayer.player = nil; #if defined(Q_OS_IOS) - [[AVAudioSession sharedInstance] setActive:NO error:nil]; + [self setSessionActive:NO]; #endif } - (void) prepareToPlayAsset:(AVURLAsset *)asset withKeys:(NSArray *)requestedKeys { + if (!m_session) + return; + //Make sure that the value of each key has loaded successfully. for (NSString *thisKey in requestedKeys) { @@ -213,10 +225,23 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM qDebug() << Q_FUNC_INFO << "isPlayable: " << [asset isPlayable]; #endif if (!asset.playable) + qWarning() << "Asset reported to be not playable. Playback of this asset may not be possible."; + + //At this point we're ready to set up for playback of the asset. + //Stop observing our prior AVPlayerItem, if we have one. + if (m_playerItem) { + //Remove existing player item key value observers and notifications. + [self unloadMedia]; + } + + //Create a new instance of AVPlayerItem from the now successfully loaded AVAsset. + m_playerItem = [AVPlayerItem playerItemWithAsset:asset]; + if (!m_playerItem) { + qWarning() << "Failed to create player item"; //Generate an error describing the failure. NSString *localizedDescription = NSLocalizedString(@"Item cannot be played", @"Item cannot be played description"); - NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but could not be made playable.", @"Item cannot be played failure reason"); + NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but couldn't create player item.", @"Item cannot be played failure reason"); NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys: localizedDescription, NSLocalizedDescriptionKey, localizedFailureReason, NSLocalizedFailureReasonErrorKey, @@ -224,21 +249,9 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM NSError *assetCannotBePlayedError = [NSError errorWithDomain:@"StitchedStreamPlayer" code:0 userInfo:errorDict]; [self assetFailedToPrepareForPlayback:assetCannotBePlayedError]; - return; } - //At this point we're ready to set up for playback of the asset. - //Stop observing our prior AVPlayerItem, if we have one. - if (m_playerItem) - { - //Remove existing player item key value observers and notifications. - [self unloadMedia]; - } - - //Create a new instance of AVPlayerItem from the now successfully loaded AVAsset. - m_playerItem = [AVPlayerItem playerItemWithAsset:asset]; - //Observe the player item "status" key to determine when it is ready to play. [m_playerItem addObserver:self forKeyPath:AVF_STATUS_KEY @@ -271,11 +284,12 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM m_player = [AVPlayer playerWithPlayerItem:m_playerItem]; [m_player retain]; - //Set the initial volume on new player object + //Set the initial audio ouptut settings on new player object if (self.session) { auto *audioOutput = m_session->m_audioOutput; m_player.volume = (audioOutput ? audioOutput->volume : 1.); m_player.muted = (audioOutput ? audioOutput->muted : true); + m_session->updateAudioOutputDevice(); } //Assign the output layer to the new player @@ -302,7 +316,7 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM context:AVFMediaPlayerObserverCurrentItemDurationObservationContext]; #if defined(Q_OS_IOS) [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; - [[AVAudioSession sharedInstance] setActive:YES error:nil]; + [self setSessionActive:YES]; #endif } @@ -472,19 +486,18 @@ static void *AVFMediaPlayerObserverCurrentItemDurationObservationContext = &AVFM @end AVFMediaPlayer::AVFMediaPlayer(QMediaPlayer *player) - : QObject(player) - , QPlatformMediaPlayer(player) - , m_state(QMediaPlayer::StoppedState) - , m_mediaStatus(QMediaPlayer::NoMedia) - , m_mediaStream(nullptr) - , m_tryingAsync(false) - , m_rate(1.0) - , m_requestedPosition(-1) - , m_duration(0) - , m_bufferProgress(0) - , m_videoAvailable(false) - , m_audioAvailable(false) - , m_seekable(false) + : QObject(player), + QPlatformMediaPlayer(player), + m_state(QMediaPlayer::StoppedState), + m_mediaStatus(QMediaPlayer::NoMedia), + m_mediaStream(nullptr), + m_rate(1.0), + m_requestedPosition(-1), + m_duration(0), + m_bufferProgress(0), + m_videoAvailable(false), + m_audioAvailable(false), + m_seekable(false) { m_observer = [[AVFMediaPlayerObserver alloc] initWithMediaPlayerSession:this]; connect(&m_playbackTimer, &QTimer::timeout, this, &AVFMediaPlayer::processPositionChange); @@ -583,7 +596,7 @@ void AVFMediaPlayer::setMedia(const QUrl &content, QIODevice *stream) setVideoAvailable(false); setSeekable(false); m_requestedPosition = -1; - orientationChanged(QVideoFrame::Rotation0, false); + orientationChanged(QtVideo::Rotation::None, false); Q_EMIT positionChanged(position()); if (m_duration != 0) { m_duration = 0; @@ -738,12 +751,12 @@ void AVFMediaPlayer::setAudioOutput(QPlatformAudioOutput *output) m_audioOutput->q->disconnect(this); m_audioOutput = output; if (m_audioOutput) { - connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &AVFMediaPlayer::audioOutputChanged); + connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, &AVFMediaPlayer::updateAudioOutputDevice); connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &AVFMediaPlayer::setVolume); connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &AVFMediaPlayer::setMuted); //connect(m_audioOutput->q, &QAudioOutput::audioRoleChanged, this, &AVFMediaPlayer::setAudioRole); } - audioOutputChanged(); + updateAudioOutputDevice(); setMuted(m_audioOutput ? m_audioOutput->muted : true); setVolume(m_audioOutput ? m_audioOutput->volume : 1.); } @@ -924,7 +937,7 @@ void AVFMediaPlayer::setMuted(bool muted) player.muted = muted; } -void AVFMediaPlayer::audioOutputChanged() +void AVFMediaPlayer::updateAudioOutputDevice() { #ifdef Q_OS_MACOS AVPlayer *player = [static_cast<AVFMediaPlayerObserver*>(m_observer) player]; @@ -1120,7 +1133,7 @@ void AVFMediaPlayer::updateTracks() if (m_observer.videoTrack != track) { m_observer.videoTrack = track; bool isMirrored = false; - QVideoFrame::RotationAngle orientation = QVideoFrame::Rotation0; + QtVideo::Rotation orientation = QtVideo::Rotation::None; videoOrientationForAssetTrack(assetTrack, orientation, isMirrored); orientationChanged(orientation, isMirrored); } @@ -1210,7 +1223,7 @@ void AVFMediaPlayer::nativeSizeChanged(QSize size) m_videoSink->setNativeSize(size); } -void AVFMediaPlayer::orientationChanged(QVideoFrame::RotationAngle rotation, bool mirrored) +void AVFMediaPlayer::orientationChanged(QtVideo::Rotation rotation, bool mirrored) { if (!m_videoOutput) return; @@ -1220,10 +1233,10 @@ void AVFMediaPlayer::orientationChanged(QVideoFrame::RotationAngle rotation, boo } void AVFMediaPlayer::videoOrientationForAssetTrack(AVAssetTrack *videoTrack, - QVideoFrame::RotationAngle &angle, + QtVideo::Rotation &angle, bool &mirrored) { - angle = QVideoFrame::Rotation0; + angle = QtVideo::Rotation::None; if (videoTrack) { CGAffineTransform transform = videoTrack.preferredTransform; if (CGAffineTransformIsIdentity(transform)) @@ -1246,11 +1259,13 @@ void AVFMediaPlayer::videoOrientationForAssetTrack(AVAssetTrack *videoTrack, } if (qFuzzyCompare(degrees, qreal(90)) || qFuzzyCompare(degrees, qreal(-270))) { - angle = QVideoFrame::Rotation90; + angle = QtVideo::Rotation::Clockwise90; } else if (qFuzzyCompare(degrees, qreal(-90)) || qFuzzyCompare(degrees, qreal(270))) { - angle = QVideoFrame::Rotation270; + angle = QtVideo::Rotation::Clockwise270; } else if (qFuzzyCompare(degrees, qreal(180)) || qFuzzyCompare(degrees, qreal(-180))) { - angle = QVideoFrame::Rotation180; + angle = QtVideo::Rotation::Clockwise180; } } } + +#include "moc_avfmediaplayer_p.cpp" diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h index 6993a28d7..6ac3aef46 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h +++ b/src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef AVFMEDIAPLAYER_H #define AVFMEDIAPLAYER_H @@ -110,7 +74,7 @@ public: QMediaMetaData metaData() const override; static void videoOrientationForAssetTrack(AVAssetTrack *track, - QVideoFrame::RotationAngle &angle, + QtVideo::Rotation &angle, bool &mirrored); public Q_SLOTS: @@ -125,7 +89,7 @@ public Q_SLOTS: void setVolume(float volume); void setMuted(bool muted); - void audioOutputChanged(); + void updateAudioOutputDevice(); void processEOS(); void processLoadStateChange(QMediaPlayer::PlaybackState newState); @@ -157,7 +121,7 @@ private: void setSeekable(bool seekable); void resetStream(QIODevice *stream = nullptr); - void orientationChanged(QVideoFrame::RotationAngle rotation, bool mirrored); + void orientationChanged(QtVideo::Rotation rotation, bool mirrored); AVFVideoRendererControl *m_videoOutput = nullptr; AVFVideoSink *m_videoSink = nullptr; @@ -168,7 +132,6 @@ private: QUrl m_resources; QMediaMetaData m_metaData; - bool m_tryingAsync; qreal m_rate; qint64 m_requestedPosition; diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm index 0a59708f2..66687c931 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm +++ b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol.mm @@ -1,51 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "avfvideorenderercontrol_p.h" #include "avfdisplaylink_p.h" #include <avfvideobuffer_p.h> #include "qavfhelpers_p.h" +#include "private/qvideoframe_p.h" #include <QtMultimedia/qvideoframeformat.h> #include <avfvideosink_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <QtCore/qdebug.h> @@ -154,7 +119,7 @@ void AVFVideoRendererControl::setLayer(CALayer *layer) AVFVideoSinkInterface::setLayer(layer); } -void AVFVideoRendererControl::setVideoRotation(QVideoFrame::RotationAngle rotation) +void AVFVideoRendererControl::setVideoRotation(QtVideo::Rotation rotation) { m_rotation = rotation; } @@ -184,34 +149,17 @@ void AVFVideoRendererControl::updateVideoFrame(const CVTimeStamp &ts) CVPixelBufferRef pixelBuffer = copyPixelBufferFromLayer(width, height); if (!pixelBuffer) return; - AVFVideoBuffer *buffer = new AVFVideoBuffer(this, pixelBuffer); -// qDebug() << "Got pixelbuffer with format" << fmt << Qt::hex << CVPixelBufferGetPixelFormatType(pixelBuffer); + auto buffer = std::make_unique<AVFVideoBuffer>(this, pixelBuffer); + // qDebug() << "Got pixelbuffer with format" << fmt << Qt::hex << + // CVPixelBufferGetPixelFormatType(pixelBuffer); CVPixelBufferRelease(pixelBuffer); - frame = QVideoFrame(buffer, buffer->videoFormat()); - frame.setRotationAngle(m_rotation); + frame = QVideoFramePrivate::createFrame(std::move(buffer), buffer->videoFormat()); + frame.setRotation(m_rotation); frame.setMirrored(m_mirrored); m_sink->setVideoFrame(frame); } -static NSDictionary* const AVF_OUTPUT_SETTINGS = @{ - (NSString *)kCVPixelBufferPixelFormatTypeKey: @[ - @(kCVPixelFormatType_32BGRA), - @(kCVPixelFormatType_32RGBA), - @(kCVPixelFormatType_422YpCbCr8), - @(kCVPixelFormatType_422YpCbCr8_yuvs), - @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange), - @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange), - @(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange), - @(kCVPixelFormatType_420YpCbCr10BiPlanarFullRange), - @(kCVPixelFormatType_OneComponent8), - @(q_kCVPixelFormatType_OneComponent16), - @(kCVPixelFormatType_420YpCbCr8Planar), - @(kCVPixelFormatType_420YpCbCr8PlanarFullRange) - ], - (NSString *)kCVPixelBufferMetalCompatibilityKey: @true -}; - CVPixelBufferRef AVFVideoRendererControl::copyPixelBufferFromLayer(size_t& width, size_t& height) { AVPlayerLayer *layer = playerLayer(); @@ -227,7 +175,7 @@ CVPixelBufferRef AVFVideoRendererControl::copyPixelBufferFromLayer(size_t& width if (!m_videoOutput) { if (!m_outputSettings) - m_outputSettings = AVF_OUTPUT_SETTINGS; + setOutputSettings(); m_videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:m_outputSettings]; [m_videoOutput setDelegate:nil queue:nil]; } diff --git a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h index ea04bbde7..177114127 100644 --- a/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h +++ b/src/plugins/multimedia/darwin/mediaplayer/avfvideorenderercontrol_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef AVFVIDEORENDERERCONTROL_H #define AVFVIDEORENDERERCONTROL_H @@ -80,7 +44,7 @@ public: void reconfigure() override; void setLayer(CALayer *layer) override; - void setVideoRotation(QVideoFrame::RotationAngle); + void setVideoRotation(QtVideo::Rotation); void setVideoMirrored(bool mirrored); void setSubtitleText(const QString &subtitle) @@ -99,7 +63,7 @@ private: AVPlayerItemVideoOutput *m_videoOutput = nullptr; AVPlayerItemLegibleOutput *m_subtitleOutput = nullptr; SubtitleDelegate *m_subtitleDelegate = nullptr; - QVideoFrame::RotationAngle m_rotation = QVideoFrame::Rotation0; + QtVideo::Rotation m_rotation = QtVideo::Rotation::None; bool m_mirrored = false; }; |