forked from computer-graphics-tools/core-video-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVReturn+Result.swift
39 lines (34 loc) · 1.65 KB
/
CVReturn+Result.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import CoreVideo
public extension CVReturn {
enum Result {
case success
case error(CVError)
func throwOnError() throws {
switch self {
case .success: return
case let .error(cvError): throw cvError
}
}
}
var result: Result {
switch self {
case kCVReturnSuccess: return .success
case kCVReturnAllocationFailed: return .error(.allocationFailed)
case kCVReturnUnsupported: return .error(.unsupported)
case kCVReturnInvalidDisplay: return .error(.invalidDisplay)
case kCVReturnDisplayLinkAlreadyRunning: return .error(.displayLinkAlreadyRunning)
case kCVReturnDisplayLinkNotRunning: return .error(.displayLinkNotRunning)
case kCVReturnDisplayLinkCallbacksNotSet: return .error(.displayLinkCallbacksNotSet)
case kCVReturnInvalidPixelFormat: return .error(.invalidPixelFormat)
case kCVReturnInvalidSize: return .error(.invalidSize)
case kCVReturnInvalidPixelBufferAttributes: return .error(.invalidPixelBufferAttributes)
case kCVReturnPixelBufferNotOpenGLCompatible: return .error(.pixelBufferNotOpenGLCompatible)
case kCVReturnPixelBufferNotMetalCompatible: return .error(.pixelBufferNotMetalCompatible)
case kCVReturnWouldExceedAllocationThreshold: return .error(.wouldExceedAllocationThreshold)
case kCVReturnPoolAllocationFailed: return .error(.poolAllocationFailed)
case kCVReturnInvalidPoolAttributes: return .error(.invalidPoolAttributes)
case kCVReturnRetry: return .error(.retry)
default: return .error(.error)
}
}
}