Browse Source

[*] 暂时提交

yanxuyao 2 weeks ago
parent
commit
9bd5b03965

+ 30 - 4
QGVAPlayer/QGVAPlayer/Classes/Controllers/Decoders/QGMP4FrameHWDecoder.m

@@ -24,15 +24,20 @@
 #import "NSNotificationCenter+VAPThreadSafe.h"
 #import "NSNotificationCenter+VAPThreadSafe.h"
 #include <sys/sysctl.h>
 #include <sys/sysctl.h>
 #import <AVFoundation/AVFoundation.h>
 #import <AVFoundation/AVFoundation.h>
+#import <TargetConditionals.h>
 
 
 @implementation UIDevice (HWD)
 @implementation UIDevice (HWD)
 
 
 - (BOOL)hwd_isSimulator {
 - (BOOL)hwd_isSimulator {
+    #if TARGET_OS_SIMULATOR
+    return YES;
+    #endif
+    
     static dispatch_once_t token;
     static dispatch_once_t token;
     static BOOL isSimulator = NO;
     static BOOL isSimulator = NO;
     dispatch_once(&token, ^{
     dispatch_once(&token, ^{
         NSString *model = [self machineName];
         NSString *model = [self machineName];
-        if ([model isEqualToString:@"x86_64"] || [model isEqualToString:@"i386"]) {
+        if ([model isEqualToString:@"x86_64"] || [model isEqualToString:@"i386"] || [model isEqualToString:@"arm64"]) {
             isSimulator = YES;
             isSimulator = YES;
         }
         }
     });
     });
@@ -207,11 +212,23 @@ NSString *const QGMP4HWDErrorDomain = @"QGMP4HWDErrorDomain";
     CMBlockBufferRef blockBuffer = NULL;
     CMBlockBufferRef blockBuffer = NULL;
     
     
     _status = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault,
     _status = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault,
-                                                 (void *)packetData.bytes,
+                                                 NULL,
                                                  packetData.length,
                                                  packetData.length,
-                                                 kCFAllocatorNull, NULL, 0,
+                                                 kCFAllocatorDefault, NULL, 0,
                                                  packetData.length, 0,
                                                  packetData.length, 0,
-                                                 &blockBuffer);    
+                                                 &blockBuffer);
+    if (_status != kCMBlockBufferNoErr || blockBuffer == NULL) {
+        VAP_Error(kQGVAPModuleCommon, @"create block buffer fail! frame:%@ status:%@", @(frameIndex), @(_status));
+        return;
+    }
+    
+    _status = CMBlockBufferReplaceDataBytes(packetData.bytes, blockBuffer, 0, packetData.length);
+    if (_status != kCMBlockBufferNoErr) {
+        VAP_Error(kQGVAPModuleCommon, @"copy packet data to block buffer fail! frame:%@ status:%@", @(frameIndex), @(_status));
+        CFRelease(blockBuffer);
+        return;
+    }
+    
     // 6. create a CMSampleBuffer.
     // 6. create a CMSampleBuffer.
     CMSampleBufferRef sampleBuffer = NULL;
     CMSampleBufferRef sampleBuffer = NULL;
     const size_t sampleSizeArray[] = {packetData.length};
     const size_t sampleSizeArray[] = {packetData.length};
@@ -225,6 +242,11 @@ NSString *const QGMP4HWDErrorDomain = @"QGMP4HWDErrorDomain";
         CFRelease(blockBuffer);
         CFRelease(blockBuffer);
     }
     }
     
     
+    if (_status != noErr || sampleBuffer == NULL) {
+        VAP_Error(kQGVAPModuleCommon, @"create sample buffer fail! frame:%@ status:%@", @(frameIndex), @(_status));
+        return;
+    }
+    
     // 7. use VTDecompressionSessionDecodeFrame
     // 7. use VTDecompressionSessionDecodeFrame
     if (@available(iOS 9.0, *)) {
     if (@available(iOS 9.0, *)) {
         __typeof(self) __weak weakSelf = self;
         __typeof(self) __weak weakSelf = self;
@@ -258,6 +280,10 @@ NSString *const QGMP4HWDErrorDomain = @"QGMP4HWDErrorDomain";
             [self findKeyFrameAndDecodeToCurrent:frameIndex];
             [self findKeyFrameAndDecodeToCurrent:frameIndex];
         } else {
         } else {
             _invalidRetryCount = 0;
             _invalidRetryCount = 0;
+            if (status != noErr) {
+                VAP_Error(kQGVAPModuleCommon, @"decode frame fail! frame:%@ error:%@", @(frameIndex), @(status));
+                CFRelease(sampleBuffer);
+            }
         }
         }
         
         
     } else {
     } else {