From e546231cbecff0b10ae11d7de4668b2e9adf2e14 Mon Sep 17 00:00:00 2001 From: kingslay Date: Fri, 1 Dec 2023 20:10:48 +0800 Subject: [PATCH] xros --- FFmpegKit | 2 +- Package.swift | 8 +++++--- Package@swift-5.9.swift | 9 ++++++--- Sources/KSPlayer/MEPlayer/Resample.swift | 10 ++++------ Sources/KSPlayer/Metal/PixelBufferProtocol.swift | 5 ++--- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/FFmpegKit b/FFmpegKit index 10f2c37fe..e5d259205 160000 --- a/FFmpegKit +++ b/FFmpegKit @@ -1 +1 @@ -Subproject commit 10f2c37fe368dac58b0ee640c4bdccb95c685e2a +Subproject commit e5d259205360f2b82e56b2034be3ac687111c3de diff --git a/Package.swift b/Package.swift index fdd81451b..3d2b9b3df 100644 --- a/Package.swift +++ b/Package.swift @@ -4,9 +4,7 @@ import PackageDescription let package = Package( name: "KSPlayer", defaultLocalization: "en", - platforms: [.macOS(.v10_15), -// .visionOS(.v1), - .iOS(.v13), .tvOS(.v13)], + platforms: [.macOS(.v10_15), .macCatalyst(.v13), .iOS(.v13), .tvOS(.v13)], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( @@ -35,6 +33,10 @@ let package = Package( ] ) var ffmpegKitPath = FileManager.default.currentDirectoryPath + "/FFmpegKit" +if !FileManager.default.fileExists(atPath: ffmpegKitPath) { + ffmpegKitPath = FileManager.default.currentDirectoryPath + "../FFmpegKit" +} + if !FileManager.default.fileExists(atPath: ffmpegKitPath) { ffmpegKitPath = FileManager.default.currentDirectoryPath + "/KSPlayer/FFmpegKit" } diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift index 24d818892..f62abcbd1 100644 --- a/Package@swift-5.9.swift +++ b/Package@swift-5.9.swift @@ -4,9 +4,8 @@ import PackageDescription let package = Package( name: "KSPlayer", defaultLocalization: "en", - platforms: [.macOS(.v10_15), - .visionOS(.v1), - .iOS(.v13), .tvOS(.v13)], + platforms: [.macOS(.v10_15), .macCatalyst(.v13), .iOS(.v13), .tvOS(.v13), + .visionOS(.v1)], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( @@ -36,6 +35,10 @@ let package = Package( ) var ffmpegKitPath = FileManager.default.currentDirectoryPath + "/FFmpegKit" +if !FileManager.default.fileExists(atPath: ffmpegKitPath) { + ffmpegKitPath = FileManager.default.currentDirectoryPath + "../FFmpegKit" +} + if !FileManager.default.fileExists(atPath: ffmpegKitPath) { ffmpegKitPath = FileManager.default.currentDirectoryPath + "/KSPlayer/FFmpegKit" } diff --git a/Sources/KSPlayer/MEPlayer/Resample.swift b/Sources/KSPlayer/MEPlayer/Resample.swift index eb1b22600..a3fdcd6f0 100644 --- a/Sources/KSPlayer/MEPlayer/Resample.swift +++ b/Sources/KSPlayer/MEPlayer/Resample.swift @@ -138,13 +138,11 @@ class VideoSwresample: FrameChange { pbuf.aspectRatio = frame.sample_aspect_ratio.size pbuf.yCbCrMatrix = frame.colorspace.ycbcrMatrix pbuf.colorPrimaries = frame.color_primaries.colorPrimaries + pbuf.transferFunction = frame.color_trc.transferFunction // vt_pixbuf_set_colorspace - if let transferFunction = frame.color_trc.transferFunction { - pbuf.transferFunction = transferFunction - if transferFunction == kCVImageBufferTransferFunction_UseGamma { - let gamma = NSNumber(value: frame.color_trc == AVCOL_TRC_GAMMA22 ? 2.2 : 2.8) - CVBufferSetAttachment(pbuf, kCVImageBufferGammaLevelKey, gamma, .shouldPropagate) - } + if pbuf.transferFunction == kCVImageBufferTransferFunction_UseGamma { + let gamma = NSNumber(value: frame.color_trc == AVCOL_TRC_GAMMA22 ? 2.2 : 2.8) + CVBufferSetAttachment(pbuf, kCVImageBufferGammaLevelKey, gamma, .shouldPropagate) } if let chroma = frame.chroma_location.chroma { CVBufferSetAttachment(pbuf, kCVImageBufferChromaLocationTopFieldKey, chroma, .shouldPropagate) diff --git a/Sources/KSPlayer/Metal/PixelBufferProtocol.swift b/Sources/KSPlayer/Metal/PixelBufferProtocol.swift index c39b34c2f..ea1e214a8 100644 --- a/Sources/KSPlayer/Metal/PixelBufferProtocol.swift +++ b/Sources/KSPlayer/Metal/PixelBufferProtocol.swift @@ -163,20 +163,19 @@ class PixelBuffer: PixelBufferProtocol { let colorPrimaries: CFString? let transferFunction: CFString? let yCbCrMatrix: CFString? + let colorspace: CGColorSpace? private let format: AVPixelFormat private let formats: [MTLPixelFormat] private let widths: [Int] private let heights: [Int] private let buffers: [MTLBuffer?] private let lineSize: [Int] - public var colorspace: CGColorSpace? { - attachmentsDic.flatMap { CVImageBufferCreateColorSpaceFromAttachments($0)?.takeUnretainedValue() } - } init(frame: AVFrame) { yCbCrMatrix = frame.colorspace.ycbcrMatrix colorPrimaries = frame.color_primaries.colorPrimaries transferFunction = frame.color_trc.transferFunction + colorspace = KSOptions.colorSpace(ycbcrMatrix: yCbCrMatrix, transferFunction: transferFunction) var attachments = [CFString: CFString]() attachments[kCVImageBufferColorPrimariesKey] = colorPrimaries attachments[kCVImageBufferTransferFunctionKey] = transferFunction