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