fix: availability warnings

This commit is contained in:
Acaki committed 2025-08-15 01:18:03 +08:00
1 parent 73316ab5b8
commit 0d32b8f06f
4 files changed
+44 -8

No files matched your search

+2 -2
View File
@@ -23,8 +23,8 @@
@property (atomic) BOOL isStopping;
- (nonnull instancetype)initWithMetalDevice:(nonnull id<MTLDevice>)device drawablePixelFormat:(MTLPixelFormat)drawablePixelFormat framerate:(float)framerate;
- (void)renderFrame:(nonnull Frame *)frame toLayer:(nonnull CAMetalLayer *)layer;
- (void)waitToRenderTo:(nonnull CAMetalLayer *)layer;
- (void)renderFrame:(nonnull Frame *)frame toLayer:(nonnull CAMetalLayer *)layer API_AVAILABLE(ios(13.0));
- (void)waitToRenderTo:(nonnull CAMetalLayer *)layer API_AVAILABLE(ios(13.0));
- (void)drawableResize:(CGSize)drawableSize;
- (void)shutdown;
+30 -1
View File
@@ -197,21 +197,27 @@ CFStringRef __currentColorSpace;
#if !TARGET_OS_TV
- (void)reportMaxEDRHeadroom {
if (@available(iOS 16.0, *)) {
CGFloat maxHeadroom = [[UIScreen mainScreen] potentialEDRHeadroom];
if (maxHeadroom > 1.0) {
LogOnce(LOG_I, @"Display supports EDR with a max headroom of %.1f", maxHeadroom);
} else {
LogOnce(LOG_I, @"Display does not support EDR");
}
} else {
LogOnce(LOG_I, @"Display does not support EDR (iOS < 16.0)");
}
}
- (void)pollCurrentEDRHeadroom {
if (@available(iOS 16.0, *)) {
CGFloat headroom = [[UIScreen mainScreen] currentEDRHeadroom];
if (headroom != _currentEDRHeadroom) {
Log(LOG_I, @"EDR headroom changed to %.1f", headroom);
_currentEDRHeadroom = (float)headroom;
}
}
}
- (void)setInitialEDRMetadata {
}
@@ -225,13 +231,19 @@ CFStringRef __currentColorSpace;
// These can only be changed on the main thread
dispatch_sync(dispatch_get_main_queue(), ^{
if (@available(iOS 16.0, *)) {
layer.wantsExtendedDynamicRangeContent = YES;
}
layer.pixelFormat = MTLPixelFormatRGBA16Float;
CFStringRef name;
switch (colorspace) {
case COLORSPACE_REC_2020:
if (@available(iOS 12.3, *)) {
name = kCGColorSpaceExtendedLinearITUR_2020;
} else {
name = kCGColorSpaceExtendedLinearSRGB;
}
break;
case COLORSPACE_REC_601:
name = kCGColorSpaceExtendedLinearSRGB;
@@ -246,6 +258,8 @@ CFStringRef __currentColorSpace;
layer.colorspace = colorspace;
CGColorSpaceRelease(colorspace);
// CAEDRMetadata is only available on iOS 16.0+
if (@available(iOS 16.0, tvOS 16.0, *)) {
CFDataRef masteringDisplayColorVolume = CVBufferCopyAttachment(frame.pixelBuffer, kCVImageBufferMasteringDisplayColorVolumeKey, nil);
CFDataRef contentLightLevel = CVBufferCopyAttachment(frame.pixelBuffer, kCVImageBufferContentLightLevelInfoKey, nil);
if (masteringDisplayColorVolume) {
@@ -260,6 +274,9 @@ CFStringRef __currentColorSpace;
opticalOutputScale:100.0f];
}
LogOnce(LOG_I, @"EDRMetadata set to colorspace %@, transfer function %@, %@", layer.colorspace, frame_trc, layer.EDRMetadata);
} else {
LogOnce(LOG_I, @"EDRMetadata not available on iOS < 16.0, colorspace %@, transfer function %@", layer.colorspace, frame_trc);
}
});
}
#endif
@@ -312,7 +329,11 @@ CFStringRef __currentColorSpace;
CFStringRef frame_trc = CFDictionaryGetValue(ext, kCVImageBufferTransferFunctionKey);
if (CFEqual(frame_trc, kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ)) {
isHDR = YES;
if (@available(iOS 14.0, *)) {
newColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2100_PQ);
} else {
newColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020);
}
newPixelFormat = MTLPixelFormatBGR10A2Unorm;
} else {
// SDR 2020, I'm not sure it's possible to stream this though
@@ -362,14 +383,20 @@ CFStringRef __currentColorSpace;
layer.pixelFormat = newPixelFormat;
});
#else
if (useEDR && [CAEDRMetadata isAvailable]) {
BOOL canUseEDR = NO;
if (@available(iOS 16.0, tvOS 16.0, *)) {
canUseEDR = useEDR && [CAEDRMetadata isAvailable];
}
if (canUseEDR) {
[self applyEDRFromFrame:frame withColorspace:colorspace toLayer:layer];
} else {
// These can only be changed on the main thread
dispatch_sync(dispatch_get_main_queue(), ^{
if (@available(iOS 16.0, *)) {
if (isHDR) {
layer.wantsExtendedDynamicRangeContent = YES;
}
}
layer.colorspace = newColorSpace;
layer.pixelFormat = newPixelFormat;
});
@@ -618,6 +645,7 @@ CFStringRef __currentColorSpace;
[renderEncoder endEncoding];
__block MetalVideoRenderer *strongSelf = self;
#if !TARGET_OS_SIMULATOR
[drawable addPresentedHandler:^(id<MTLDrawable> d) {
if (strongSelf.lastPresented > 0.0f) {
CFTimeInterval frametime = d.presentedTime - strongSelf.lastPresented;
@@ -625,6 +653,7 @@ CFStringRef __currentColorSpace;
}
strongSelf.lastPresented = d.presentedTime;
}];
#endif
// signal semaphore, compute GPU time average, and clear textures
__block dispatch_semaphore_t block_semaphore = _inFlightSemaphore;
+4
View File
@@ -91,7 +91,9 @@
- (void)waitToRenderTo:(nonnull CAMetalLayer *)layer {
// Renderer obtains a nextDrawable, waiting if necessary
if (@available(iOS 13.0, *)) {
[_renderer waitToRenderTo:layer];
}
// If we don't have a frame yet, wait on that too
[_frameQueue waitForEnqueue];
@@ -103,10 +105,12 @@
CFTimeInterval timeout = (1.0f / _framerate) - _renderer.averageGPUTime;
Frame *frame = [_frameQueue dequeueWithTimeout:timeout];
if (frame) {
if (@available(iOS 13.0, *)) {
[_renderer renderFrame:frame toLayer:layer];
}
}
}
}
- (void)drawableResize:(CGSize)size {
[_renderer drawableResize:size];
+8 -5
View File
@@ -204,11 +204,14 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
}
#endif
NSDictionary *destinationPixelBufferAttributes = @{
(id)kCVPixelBufferPixelFormatTypeKey : pixelFormat,
(id)kVTDecompressionPropertyKey_GeneratePerFrameHDRDisplayMetadata : @YES,
(id)kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder : @YES
};
NSMutableDictionary *destinationPixelBufferAttributes = [@{
(id)kCVPixelBufferPixelFormatTypeKey : pixelFormat
} mutableCopy];
if (@available(iOS 17.0, tvOS 17.0, *)) {
destinationPixelBufferAttributes[(id)kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder] = @YES;
destinationPixelBufferAttributes[(id)kVTDecompressionPropertyKey_GeneratePerFrameHDRDisplayMetadata] = @YES;
}
return [self setupDecompressionSessionWithAttributes:destinationPixelBufferAttributes];
}