Skip to content

Commit c51306c

Browse files
committed
modernize
1 parent 25ae678 commit c51306c

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

Sources/NextLevelSessionExporter.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ extension NextLevelSessionExporter {
554554
videoInputSettings = [:]
555555
}
556556
// Use 420YpCbCr10BiPlanarVideoRange for 10-bit HDR processing
557-
videoInputSettings?[kCVPixelBufferPixelFormatTypeKey as String] = NSNumber(integerLiteral: Int(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange))
557+
videoInputSettings?[kCVPixelBufferPixelFormatTypeKey as String] = Int(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange) as NSNumber
558558
}
559559

560560
self._videoOutput = AVAssetReaderVideoCompositionOutput(videoTracks: videoTracks, videoSettings: videoInputSettings)
@@ -603,14 +603,14 @@ extension NextLevelSessionExporter {
603603

604604
// Use 10-bit pixel format for HDR, otherwise 8-bit RGBA for SDR
605605
let pixelFormat = self._detectedHDR ? kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange : kCVPixelFormatType_32RGBA
606-
pixelBufferAttrib[kCVPixelBufferPixelFormatTypeKey as String] = NSNumber(integerLiteral: Int(pixelFormat))
606+
pixelBufferAttrib[kCVPixelBufferPixelFormatTypeKey as String] = Int(pixelFormat) as NSNumber
607607

608608
if let videoComposition = self._videoOutput?.videoComposition {
609-
pixelBufferAttrib[kCVPixelBufferWidthKey as String] = NSNumber(integerLiteral: Int(videoComposition.renderSize.width))
610-
pixelBufferAttrib[kCVPixelBufferHeightKey as String] = NSNumber(integerLiteral: Int(videoComposition.renderSize.height))
609+
pixelBufferAttrib[kCVPixelBufferWidthKey as String] = Int(videoComposition.renderSize.width) as NSNumber
610+
pixelBufferAttrib[kCVPixelBufferHeightKey as String] = Int(videoComposition.renderSize.height) as NSNumber
611611
}
612-
pixelBufferAttrib["IOSurfaceOpenGLESTextureCompatibility"] = NSNumber(booleanLiteral: true)
613-
pixelBufferAttrib["IOSurfaceOpenGLESFBOCompatibility"] = NSNumber(booleanLiteral: true)
612+
pixelBufferAttrib["IOSurfaceOpenGLESTextureCompatibility"] = true as NSNumber
613+
pixelBufferAttrib["IOSurfaceOpenGLESFBOCompatibility"] = true as NSNumber
614614

615615
self._pixelBufferAdaptor = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoInput, sourcePixelBufferAttributes: pixelBufferAttrib)
616616
}
@@ -627,7 +627,12 @@ extension NextLevelSessionExporter {
627627
var audioTracksToUse: [AVAssetTrack] = []
628628
// Remove APAC tracks (See Issue #49)
629629
for audioTrack in audioTracks {
630-
let mediaSubtypes = audioTrack.formatDescriptions.filter { CMFormatDescriptionGetMediaType($0 as! CMFormatDescription) == kCMMediaType_Audio }.map { CMFormatDescriptionGetMediaSubType($0 as! CMFormatDescription) }
630+
// Note: CoreFoundation types require force cast in Swift
631+
let audioFormats = audioTrack.formatDescriptions
632+
.filter { CMFormatDescriptionGetMediaType($0 as! CMFormatDescription) == kCMMediaType_Audio }
633+
634+
let mediaSubtypes = audioFormats.map { CMFormatDescriptionGetMediaSubType($0 as! CMFormatDescription) }
635+
631636
for mediaSubtype in mediaSubtypes where mediaSubtype != kAudioFormatAPAC {
632637
audioTracksToUse.append(audioTrack)
633638
}
@@ -772,8 +777,8 @@ extension NextLevelSessionExporter {
772777
let rect = CGRect(x: 0, y: 0, width: naturalSize.width, height: naturalSize.height)
773778
let transformedRect = rect.applying(transform)
774779
// transformedRect should have origin at 0 if correct; otherwise add offset to correct it
775-
transform.tx -= transformedRect.origin.x;
776-
transform.ty -= transformedRect.origin.y;
780+
transform.tx -= transformedRect.origin.x
781+
transform.ty -= transformedRect.origin.y
777782

778783

779784
let videoAngleInDegrees = atan2(transform.b, transform.a) * 180 / .pi
@@ -848,7 +853,7 @@ extension NextLevelSessionExporter {
848853
self._completionHandler?(.failure(NextLevelSessionExporterError.cancelled))
849854
return
850855
}
851-
if FileManager.default.fileExists(atPath: outputURL.absoluteString) {
856+
if FileManager.default.fileExists(atPath: outputURL.path) {
852857
try? FileManager.default.removeItem(at: outputURL)
853858
}
854859
self._completionHandler?(.failure(NextLevelSessionExporterError.cancelled))
@@ -874,7 +879,7 @@ extension NextLevelSessionExporter {
874879
self._completionHandler?(.failure(reader.error ?? NextLevelSessionExporterError.readingFailure(errorMessage)))
875880
return
876881
}
877-
if FileManager.default.fileExists(atPath: outputURL.absoluteString) {
882+
if FileManager.default.fileExists(atPath: outputURL.path) {
878883
try? FileManager.default.removeItem(at: outputURL)
879884
}
880885
let errorMessage = reader.error?.localizedDescription ?? "Asset reading failed"
@@ -892,7 +897,7 @@ extension NextLevelSessionExporter {
892897
self._completionHandler?(.failure(writer.error ?? NextLevelSessionExporterError.writingFailure(errorMessage)))
893898
return
894899
}
895-
if FileManager.default.fileExists(atPath: outputURL.absoluteString) {
900+
if FileManager.default.fileExists(atPath: outputURL.path) {
896901
try? FileManager.default.removeItem(at: outputURL)
897902
}
898903
let errorMessage = writer.error?.localizedDescription ?? "Asset writing failed"

0 commit comments

Comments
 (0)