diff --git a/FFmpegKit b/FFmpegKit index 86afd7287..7340b3242 160000 --- a/FFmpegKit +++ b/FFmpegKit @@ -1 +1 @@ -Subproject commit 86afd7287945a1789072439c2ab12be487d1a133 +Subproject commit 7340b3242320d69b13f89e5cf7e771d7369138a6 diff --git a/Sources/KSPlayer/AVPlayer/KSPictureInPictureController.swift b/Sources/KSPlayer/AVPlayer/KSPictureInPictureController.swift index 2ad783f5b..b54e45854 100644 --- a/Sources/KSPlayer/AVPlayer/KSPictureInPictureController.swift +++ b/Sources/KSPlayer/AVPlayer/KSPictureInPictureController.swift @@ -57,6 +57,10 @@ public class KSPictureInPictureController: AVPictureInPictureController { startPictureInPicture() delegate = view guard KSOptions.isPipPopViewController else { + #if canImport(UIKit) + // 直接退到后台 + UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil) + #endif return } self.view = view diff --git a/Sources/KSPlayer/MEPlayer/FFmpegDecode.swift b/Sources/KSPlayer/MEPlayer/FFmpegDecode.swift index 03b7f674a..9096940b2 100644 --- a/Sources/KSPlayer/MEPlayer/FFmpegDecode.swift +++ b/Sources/KSPlayer/MEPlayer/FFmpegDecode.swift @@ -61,7 +61,6 @@ class FFmpegDecode: DecodeProtocol { let subtitle = closedCaptionsTrack.subtitle { let closedCaptionsPacket = Packet() - closedCaptionsPacket.assetTrack = closedCaptionsTrack if let corePacket = packet.corePacket { closedCaptionsPacket.corePacket?.pointee.pts = corePacket.pointee.pts closedCaptionsPacket.corePacket?.pointee.dts = corePacket.pointee.dts @@ -74,7 +73,7 @@ class FFmpegDecode: DecodeProtocol { let buffer = av_buffer_ref(sideData.pointee.buf) closedCaptionsPacket.corePacket?.pointee.data = buffer?.pointee.data closedCaptionsPacket.corePacket?.pointee.buf = buffer - closedCaptionsPacket.fill() + closedCaptionsPacket.assetTrack = closedCaptionsTrack subtitle.putPacket(packet: closedCaptionsPacket) } if let sideData = av_frame_get_side_data(avframe, AV_FRAME_DATA_SEI_UNREGISTERED) { diff --git a/Sources/KSPlayer/MEPlayer/MEPlayerItem.swift b/Sources/KSPlayer/MEPlayer/MEPlayerItem.swift index 8c442e39b..1005eb086 100644 --- a/Sources/KSPlayer/MEPlayer/MEPlayerItem.swift +++ b/Sources/KSPlayer/MEPlayer/MEPlayerItem.swift @@ -544,7 +544,6 @@ extension MEPlayerItem { if corePacket.pointee.size <= 0 { return 0 } - packet.fill() let first = assetTracks.first { $0.trackID == corePacket.pointee.stream_index } if let first, first.isEnabled { packet.assetTrack = first diff --git a/Sources/KSPlayer/MEPlayer/Model.swift b/Sources/KSPlayer/MEPlayer/Model.swift index c966c1c8e..2dd24a6ff 100644 --- a/Sources/KSPlayer/MEPlayer/Model.swift +++ b/Sources/KSPlayer/MEPlayer/Model.swift @@ -50,6 +50,7 @@ protocol MEPlayerDelegate: AnyObject { // MARK: protocol public protocol ObjectQueueItem { + var timebase: Timebase { get } var timestamp: Int64 { get set } var duration: Int64 { get set } // byte position @@ -57,6 +58,11 @@ public protocol ObjectQueueItem { var size: Int32 { get set } } +extension ObjectQueueItem { + var seconds: TimeInterval { cmtime.seconds } + var cmtime: CMTime { timebase.cmtime(for: timestamp) } +} + public protocol FrameOutput: AnyObject { var renderSource: OutputRenderSourceDelegate? { get set } func pause() @@ -67,11 +73,6 @@ protocol MEFrame: ObjectQueueItem { var timebase: Timebase { get set } } -extension MEFrame { - var seconds: TimeInterval { cmtime.seconds } - var cmtime: CMTime { timebase.cmtime(for: timestamp) } -} - // MARK: model // for MEPlayer @@ -196,8 +197,11 @@ final class Packet: ObjectQueueItem { var timestamp: Int64 = 0 var position: Int64 = 0 var size: Int32 = 0 - var assetTrack: FFmpegAssetTrack! private(set) var corePacket = av_packet_alloc() + var timebase: Timebase { + assetTrack.timebase + } + var isKeyFrame: Bool { if let corePacket { return corePacket.pointee.flags & AV_PKT_FLAG_KEY == AV_PKT_FLAG_KEY @@ -206,18 +210,16 @@ final class Packet: ObjectQueueItem { } } - var seconds: Double { - assetTrack.timebase.cmtime(for: position).seconds - } - - func fill() { - guard let corePacket else { - return + var assetTrack: FFmpegAssetTrack! { + didSet { + guard let packet = corePacket?.pointee else { + return + } + timestamp = packet.pts == Int64.min ? packet.dts : packet.pts + position = packet.pos + duration = packet.duration + size = packet.size } - timestamp = corePacket.pointee.pts == Int64.min ? corePacket.pointee.dts : corePacket.pointee.pts - position = corePacket.pointee.pos - duration = corePacket.pointee.duration - size = corePacket.pointee.size } deinit { diff --git a/Sources/KSPlayer/Metal/PixelBufferProtocol.swift b/Sources/KSPlayer/Metal/PixelBufferProtocol.swift index ac5f38844..766daf6cf 100644 --- a/Sources/KSPlayer/Metal/PixelBufferProtocol.swift +++ b/Sources/KSPlayer/Metal/PixelBufferProtocol.swift @@ -230,7 +230,7 @@ class PixelBuffer: PixelBufferProtocol { let contents = buffer?.contents() let source = bytes[i]! var j = 0 - // while 的性能比for in快。 + // 性能 while > stride(from:to:by:) > for in while j < height { contents?.advanced(by: j * size).copyMemory(from: source.advanced(by: j * byteCount), byteCount: byteCount) j += 1