diff options
Diffstat (limited to 'src/plugins/multimedia/darwin/avfvideosink.mm')
-rw-r--r-- | src/plugins/multimedia/darwin/avfvideosink.mm | 107 |
1 files changed, 52 insertions, 55 deletions
diff --git a/src/plugins/multimedia/darwin/avfvideosink.mm b/src/plugins/multimedia/darwin/avfvideosink.mm index f44a65683..f4c8bdb2e 100644 --- a/src/plugins/multimedia/darwin/avfvideosink.mm +++ b/src/plugins/multimedia/darwin/avfvideosink.mm @@ -1,57 +1,19 @@ -/**************************************************************************** -** -** 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 "avfvideosink_p.h" -#include <private/qrhi_p.h> -#include <private/qrhimetal_p.h> -#include <private/qrhigles2_p.h> +#include <rhi/qrhi.h> #include <QtGui/qopenglcontext.h> #include <AVFoundation/AVFoundation.h> #import <QuartzCore/CATransaction.h> -#if QT_HAS_INCLUDE(<AppKit/AppKit.h>) +#if __has_include(<AppKit/AppKit.h>) #include <AppKit/AppKit.h> #endif -#if QT_HAS_INCLUDE(<UIKit/UIKit.h>) +#if __has_include(<UIKit/UIKit.h>) #include <UIKit/UIKit.h> #endif @@ -91,18 +53,12 @@ void AVFVideoSink::setVideoSinkInterface(AVFVideoSinkInterface *interface) m_interface->setRhi(m_rhi); } -// The OpengGL texture cache can apparently only handle single plane formats, so lets simply restrict to BGRA -static NSDictionary* const AVF_OUTPUT_SETTINGS_OPENGL = @{ - (NSString *)kCVPixelBufferPixelFormatTypeKey: @[ - @(kCVPixelFormatType_32BGRA), - ], - (NSString *)kCVPixelBufferOpenGLCompatibilityKey: @true -}; - AVFVideoSinkInterface::~AVFVideoSinkInterface() { if (m_layer) [m_layer release]; + if (m_outputSettings) + [m_outputSettings release]; freeTextureCaches(); } @@ -127,7 +83,11 @@ void AVFVideoSinkInterface::setVideoSink(AVFVideoSink *sink) if (sink == m_sink) return; + if (m_sink) + m_sink->setVideoSinkInterface(nullptr); + m_sink = sink; + if (m_sink) { m_sink->setVideoSinkInterface(this); reconfigure(); @@ -136,6 +96,7 @@ void AVFVideoSinkInterface::setVideoSink(AVFVideoSink *sink) void AVFVideoSinkInterface::setRhi(QRhi *rhi) { + QMutexLocker locker(&m_textureCacheMutex); if (m_rhi == rhi) return; freeTextureCaches(); @@ -159,8 +120,6 @@ void AVFVideoSinkInterface::setRhi(QRhi *rhi) } } else if (rhi->backend() == QRhi::OpenGLES2) { #if QT_CONFIG(opengl) - setOutputSettings(AVF_OUTPUT_SETTINGS_OPENGL); - #ifdef Q_OS_MACOS const auto *gl = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles()); @@ -195,6 +154,7 @@ void AVFVideoSinkInterface::setRhi(QRhi *rhi) m_rhi = nullptr; #endif // QT_CONFIG(opengl) } + setOutputSettings(); } void AVFVideoSinkInterface::setLayer(CALayer *layer) @@ -212,9 +172,46 @@ void AVFVideoSinkInterface::setLayer(CALayer *layer) reconfigure(); } -void AVFVideoSinkInterface::setOutputSettings(NSDictionary *settings) +void AVFVideoSinkInterface::setOutputSettings() { - m_outputSettings = settings; + if (m_outputSettings) + [m_outputSettings release]; + m_outputSettings = nil; + + // Set pixel format + NSDictionary *dictionary = nil; + if (m_rhi && m_rhi->backend() == QRhi::OpenGLES2) { +#if QT_CONFIG(opengl) + dictionary = @{(NSString *)kCVPixelBufferPixelFormatTypeKey: + @(kCVPixelFormatType_32BGRA) +#ifndef Q_OS_IOS // On iOS this key generates a warning about unsupported key. + , (NSString *)kCVPixelBufferOpenGLCompatibilityKey: @true +#endif // Q_OS_IOS + }; +#endif + } else { + dictionary = @{(NSString *)kCVPixelBufferPixelFormatTypeKey: + @[ + @(kCVPixelFormatType_32BGRA), + @(kCVPixelFormatType_32RGBA), + @(kCVPixelFormatType_422YpCbCr8), + @(kCVPixelFormatType_422YpCbCr8_yuvs), + @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange), + @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange), + @(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange), + @(kCVPixelFormatType_420YpCbCr10BiPlanarFullRange), + @(kCVPixelFormatType_OneComponent8), + @(kCVPixelFormatType_OneComponent16), + @(kCVPixelFormatType_420YpCbCr8Planar), + @(kCVPixelFormatType_420YpCbCr8PlanarFullRange) + ] +#ifndef Q_OS_IOS // This key is not supported and generates a warning. + , (NSString *)kCVPixelBufferMetalCompatibilityKey: @true +#endif // Q_OS_IOS + }; + } + + m_outputSettings = [[NSDictionary alloc] initWithDictionary:dictionary]; } void AVFVideoSinkInterface::updateLayerBounds() |