Forráskód Böngészése

[*] 修复VAP播放问题

yanxuyao 3 hete
szülő
commit
6f1b48aa5f

+ 2 - 10
QGVAPlayer/QGVAPlayer.xcodeproj/project.pbxproj

@@ -155,7 +155,6 @@
 				BCFCF18C219ED666D3D894D2 /* LNVAPPlayerView.swift */,
 				1826895ABCB13AB1313356B1 /* LNVAPWrapView.swift */,
 			);
-			name = View;
 			path = View;
 			sourceTree = "<group>";
 		};
@@ -164,7 +163,6 @@
 			children = (
 				0423F5B5825E119BA494D53B /* LNRenderers.swift */,
 			);
-			name = Render;
 			path = Render;
 			sourceTree = "<group>";
 		};
@@ -394,7 +392,6 @@
 			children = (
 				290BBFEF3F6577C4848CB922 /* LNUtilities.swift */,
 			);
-			name = Utils;
 			path = Utils;
 			sourceTree = "<group>";
 		};
@@ -403,7 +400,6 @@
 			children = (
 				0DFC2669FA8BE22005CBC78B /* LNMP4Parser.swift */,
 			);
-			name = Parser;
 			path = Parser;
 			sourceTree = "<group>";
 		};
@@ -418,7 +414,6 @@
 				9584B67AA626C136945E2165 /* Utils */,
 				D8332413532597C3E92EED74 /* Bridges */,
 			);
-			name = LNSwift;
 			path = LNSwift;
 			sourceTree = "<group>";
 		};
@@ -427,7 +422,6 @@
 			children = (
 				ADF46D8C8C93AA38D15B3345 /* LNLegacyMappings.swift */,
 			);
-			name = Bridges;
 			path = Bridges;
 			sourceTree = "<group>";
 		};
@@ -438,7 +432,6 @@
 				E18C9AF6293B68DAD4F8640E /* LNVAPFacade.swift */,
 				CC2DF61A816CBDC209E81671 /* LNControllers.swift */,
 			);
-			name = Core;
 			path = Core;
 			sourceTree = "<group>";
 		};
@@ -447,7 +440,6 @@
 			children = (
 				85972E2BAAEE4BC57BC70D7D /* LNModels.swift */,
 			);
-			name = Model;
 			path = Model;
 			sourceTree = "<group>";
 		};
@@ -724,7 +716,7 @@
 					"@executable_path/Frameworks",
 					"@loader_path/Frameworks",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.debug;
 				PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
 				SKIP_INSTALL = YES;
 				SWIFT_VERSION = 5.0;
@@ -749,7 +741,7 @@
 					"@executable_path/Frameworks",
 					"@loader_path/Frameworks",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.debug;
 				PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
 				SKIP_INSTALL = YES;
 				SWIFT_VERSION = 5.0;

+ 49 - 28
QGVAPlayer/QGVAPlayer/LNSwift/Core/LNControllers.swift

@@ -259,19 +259,28 @@ public final class LNMP4FrameHWDecoder: LNBaseDecoder {
 
         if parser.videoCodecID == .h264 {
             guard spsData.count > 0, ppsData.count > 0 else { return false }
-            let spsPtr = spsData.withUnsafeBytes { $0.baseAddress!.assumingMemoryBound(to: UInt8.self) }
-            let ppsPtr = ppsData.withUnsafeBytes { $0.baseAddress!.assumingMemoryBound(to: UInt8.self) }
-            var parameterSetPointers: [UnsafePointer<UInt8>] = [spsPtr, ppsPtr]
-            var parameterSetSizes: [Int] = [spsData.count, ppsData.count]
-
-            let status = CMVideoFormatDescriptionCreateFromH264ParameterSets(
-                allocator: kCFAllocatorDefault,
-                parameterSetCount: 2,
-                parameterSetPointers: &parameterSetPointers,
-                parameterSetSizes: &parameterSetSizes,
-                nalUnitHeaderLength: 4,
-                formatDescriptionOut: &formatDescription
-            )
+            let status = spsData.withUnsafeBytes { spsRawPtr in
+                ppsData.withUnsafeBytes { ppsRawPtr in
+                    guard let spsBase = spsRawPtr.baseAddress,
+                          let ppsBase = ppsRawPtr.baseAddress else {
+                        return OSStatus(-50)
+                    }
+                    var parameterSetPointers: [UnsafePointer<UInt8>] = [
+                        spsBase.assumingMemoryBound(to: UInt8.self),
+                        ppsBase.assumingMemoryBound(to: UInt8.self)
+                    ]
+                    var parameterSetSizes: [Int] = [spsData.count, ppsData.count]
+
+                    return CMVideoFormatDescriptionCreateFromH264ParameterSets(
+                        allocator: kCFAllocatorDefault,
+                        parameterSetCount: 2,
+                        parameterSetPointers: &parameterSetPointers,
+                        parameterSetSizes: &parameterSetSizes,
+                        nalUnitHeaderLength: 4,
+                        formatDescriptionOut: &formatDescription
+                    )
+                }
+            }
             if status != noErr {
                 initializationError = NSError(domain: Self.errorDomain, code: LNMP4HWDErrorCode.errorCreateVTBDesc.rawValue, userInfo: ["location": fileInfo.filePath])
                 return false
@@ -282,21 +291,33 @@ public final class LNMP4FrameHWDecoder: LNBaseDecoder {
                 return false
             }
             guard vpsData.count > 0, spsData.count > 0, ppsData.count > 0 else { return false }
-            let vpsPtr = vpsData.withUnsafeBytes { $0.baseAddress!.assumingMemoryBound(to: UInt8.self) }
-            let spsPtr = spsData.withUnsafeBytes { $0.baseAddress!.assumingMemoryBound(to: UInt8.self) }
-            let ppsPtr = ppsData.withUnsafeBytes { $0.baseAddress!.assumingMemoryBound(to: UInt8.self) }
-            var parameterSetPointers: [UnsafePointer<UInt8>] = [vpsPtr, spsPtr, ppsPtr]
-            var parameterSetSizes: [Int] = [vpsData.count, spsData.count, ppsData.count]
-
-            let status = CMVideoFormatDescriptionCreateFromHEVCParameterSets(
-                allocator: kCFAllocatorDefault,
-                parameterSetCount: 3,
-                parameterSetPointers: &parameterSetPointers,
-                parameterSetSizes: &parameterSetSizes,
-                nalUnitHeaderLength: 4,
-                extensions: nil,
-                formatDescriptionOut: &formatDescription
-            )
+            let status = vpsData.withUnsafeBytes { vpsRawPtr in
+                spsData.withUnsafeBytes { spsRawPtr in
+                    ppsData.withUnsafeBytes { ppsRawPtr in
+                        guard let vpsBase = vpsRawPtr.baseAddress,
+                              let spsBase = spsRawPtr.baseAddress,
+                              let ppsBase = ppsRawPtr.baseAddress else {
+                            return OSStatus(-50)
+                        }
+                        var parameterSetPointers: [UnsafePointer<UInt8>] = [
+                            vpsBase.assumingMemoryBound(to: UInt8.self),
+                            spsBase.assumingMemoryBound(to: UInt8.self),
+                            ppsBase.assumingMemoryBound(to: UInt8.self)
+                        ]
+                        var parameterSetSizes: [Int] = [vpsData.count, spsData.count, ppsData.count]
+
+                        return CMVideoFormatDescriptionCreateFromHEVCParameterSets(
+                            allocator: kCFAllocatorDefault,
+                            parameterSetCount: 3,
+                            parameterSetPointers: &parameterSetPointers,
+                            parameterSetSizes: &parameterSetSizes,
+                            nalUnitHeaderLength: 4,
+                            extensions: nil,
+                            formatDescriptionOut: &formatDescription
+                        )
+                    }
+                }
+            }
             if status != noErr {
                 initializationError = NSError(domain: Self.errorDomain, code: LNMP4HWDErrorCode.errorCreateVTBDesc.rawValue, userInfo: ["location": fileInfo.filePath])
                 return false

+ 10 - 3
QGVAPlayer/QGVAPlayer/LNSwift/Render/LNRenderers.swift

@@ -25,7 +25,14 @@ import simd
 private final class LNPixelBufferLayerRenderer {
     private let ciContext = CIContext(options: nil)
 
+    static func clearContentsIfNeeded(_ layer: CALayer) {
+        if let metalLayerClass = NSClassFromString("CAMetalLayer"), layer.isKind(of: metalLayerClass) { return }
+        layer.contents = nil
+    }
+
     func render(pixelBuffer: CVPixelBuffer, into layer: CALayer) {
+        // CAMetalLayer content is driven by drawables; assigning `contents` can trigger runtime warnings.
+        if let metalLayerClass = NSClassFromString("CAMetalLayer"), layer.isKind(of: metalLayerClass) { return }
         let image = CIImage(cvPixelBuffer: pixelBuffer)
         guard let cgImage = ciContext.createCGImage(image, from: image.extent) else { return }
         DispatchQueue.main.async {
@@ -687,7 +694,7 @@ public final class LNHWDMetalView: UIView {
     @objc(dispose)
     public func dispose() {
         fallbackRenderer.dispose()
-        renderLayer.contents = nil
+        LNPixelBufferLayerRenderer.clearContentsIfNeeded(renderLayer)
     }
 }
 
@@ -832,7 +839,7 @@ public final class LNVAPMetalView: UIView {
     @objc(dispose)
     public func dispose() {
         fallbackRenderer.dispose()
-        renderLayer.contents = nil
+        LNPixelBufferLayerRenderer.clearContentsIfNeeded(renderLayer)
     }
 }
 
@@ -900,7 +907,7 @@ public final class LNHWDMP4OpenGLView: UIView {
     @objc(dispose)
     public func dispose() {
         fallbackRenderer.dispose()
-        renderLayer.contents = nil
+        LNPixelBufferLayerRenderer.clearContentsIfNeeded(renderLayer)
     }
 
     @objc(updateBackingSize)

+ 2 - 2
QGVAPlayerDemo/QGVAPlayerDemo.xcodeproj/project.pbxproj

@@ -568,7 +568,7 @@
 					"@executable_path/Frameworks",
 				);
 				LIBRARY_SEARCH_PATHS = "$(inherited)";
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.dev;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};
@@ -590,7 +590,7 @@
 					"@executable_path/Frameworks",
 				);
 				LIBRARY_SEARCH_PATHS = "$(inherited)";
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.dev;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};

+ 1 - 1
QGVAPlayerDemo/QGVAPlayerDemo/ViewController.m

@@ -59,7 +59,7 @@
     [self.playerView lnAddTapGestureWithTarget:self action:@selector(onPlayerTap:)];
     [self.view addSubview:self.playerView];
 
-    NSString *resPath = [NSString stringWithFormat:@"%@/Resource/demo.mp4", NSBundle.mainBundle.resourcePath];
+    NSString *resPath = [NSString stringWithFormat:@"%@/Resource/vap.mp4", NSBundle.mainBundle.resourcePath];
     [LNVAPFacade lnPlayPlayer:self.playerView filePath:resPath repeatCount:-1 delegate:self];
 }
 

+ 2 - 2
QGVAPlayerDemoSwift/QGVAPlayerDemoSwift.xcodeproj/project.pbxproj

@@ -394,7 +394,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.dev;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
 				SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/QGVAPlayerDemoSwift/QGVAPlayer-Bridging-Header.h";
@@ -417,7 +417,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				PRODUCT_BUNDLE_IDENTIFIER = com.gami.vap;
+				PRODUCT_BUNDLE_IDENTIFIER = com.jiehe.gami.dev;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PROVISIONING_PROFILE_SPECIFIER = "";
 				SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/QGVAPlayerDemoSwift/QGVAPlayer-Bridging-Header.h";