Skip to content

Commit 01ff7e9

Browse files
committed
fix: fix macOS run failed. close #40
1 parent 3279468 commit 01ff7e9

File tree

4 files changed

+69
-52
lines changed

4 files changed

+69
-52
lines changed

Demo/Demo-macOS/Demo-macOS/Player/Metal/MPVMetalViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ final class MPVMetalViewController: NSViewController {
1313
lazy var queue = DispatchQueue(label: "mpv", qos: .userInitiated)
1414

1515
var playUrl: URL?
16-
var hdrAvailable : Bool {
17-
let maxEDRRange = NSScreen.main?.maximumPotentialExtendedDynamicRangeColorComponentValue ?? 1.0
18-
let sigPeak = getDouble(MPVProperty.videoParamsSigPeak)
19-
// display screen support HDR and current playing HDR video
20-
return maxEDRRange > 1.0 && sigPeak > 1.0
21-
}
16+
var hdrAvailable : Bool = false
2217
var hdrEnabled = false {
2318
didSet {
2419
// FIXME: target-colorspace-hint does not support being changed at runtime.
@@ -104,6 +99,7 @@ final class MPVMetalViewController: NSViewController {
10499
checkError(mpv_set_option_string(mpv, "subs-fallback", "yes"))
105100
checkError(mpv_set_option_string(mpv, "vo", "gpu-next"))
106101
checkError(mpv_set_option_string(mpv, "gpu-api", "vulkan"))
102+
checkError(mpv_set_option_string(mpv, "gpu-context", "moltenvk"))
107103
checkError(mpv_set_option_string(mpv, "hwdec", "videotoolbox"))
108104
checkError(mpv_set_option_string(mpv, "ytdl", "no"))
109105
// checkError(mpv_set_option_string(mpv, "target-colorspace-hint", "yes")) // HDR passthrough
@@ -228,6 +224,10 @@ final class MPVMetalViewController: NSViewController {
228224
switch propertyName {
229225
case MPVProperty.videoParamsSigPeak:
230226
if let sigPeak = UnsafePointer<Double>(OpaquePointer(property.data))?.pointee {
227+
let maxEDRRange = NSScreen.main?.maximumPotentialExtendedDynamicRangeColorComponentValue ?? 1.0
228+
// display screen support HDR and current playing HDR video
229+
self.hdrAvailable = maxEDRRange > 1.0 && sigPeak > 1.0
230+
231231
DispatchQueue.main.async {
232232
self.playDelegate?.propertyChange(mpv: self.mpv, propertyName: propertyName, data: sigPeak)
233233
}

Sources/BuildScripts/XCFrameworkBuild/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ private class BuildMPV: BaseBuild {
418418
array.append("-Davfoundation=enabled")
419419
array.append("-Dgl-cocoa=enabled")
420420
array.append("-Dvideotoolbox-gl=enabled")
421+
array.append("-Dvideotoolbox-pl=enabled")
421422
array.append("-Dlua=luajit") // macos show video stats need enable
422423
} else {
423424
array.append("-Dvideotoolbox-gl=disabled")
425+
array.append("-Dvideotoolbox-pl=enabled")
424426
array.append("-Dswift-build=disabled")
425427
array.append("-Daudiounit=enabled")
426428
array.append("-Davfoundation=disabled")

Sources/BuildScripts/patch/libmpv/0001-player-add-moltenvk-context.patch

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,42 @@ index 7572769e0e6f280391668c6797d67e37e2dea30f..e6109987a3d38025a5eede04441c03ee
2020
features += {'vk-khr-display': vulkan.type_name() == 'internal' or
2121
cc.has_function('vkCreateDisplayPlaneSurfaceKHR', prefix: '#include <vulkan/vulkan_core.h>',
2222
dependencies: [vulkan])}
23-
diff --git forkSrcPrefix/meson.options forkDstPrefix/meson.options
24-
index dae0a333ef71b75a6bb36a236de7feebd99bda40..6ed28af20a09501b4997ca81e86bb198e75327fd 100644
25-
--- forkSrcPrefix/meson.options
26-
+++ forkDstPrefix/meson.options
27-
@@ -101,6 +101,7 @@ option('gl-dxinterop-d3d9', type: 'feature', value: 'auto', description: 'OpenGL
28-
option('ios-gl', type: 'feature', value: 'auto', description: 'iOS OpenGL ES interop support')
29-
option('videotoolbox-gl', type: 'feature', value: 'auto', description: 'Videotoolbox with OpenGL')
30-
option('videotoolbox-pl', type: 'feature', value: 'auto', description: 'Videotoolbox with libplacebo')
31-
+option('moltenvk', type: 'feature', value: 'auto', description: 'Moltenvk context')
23+
diff --git forkSrcPrefix/video/out/gpu/context.c forkDstPrefix/video/out/gpu/context.c
24+
index 75dd804005ba3a1e36375b47dcc9d9bb756ab867..299841cb256372a04c3d1603f856695ce246ec01 100644
25+
--- forkSrcPrefix/video/out/gpu/context.c
26+
+++ forkDstPrefix/video/out/gpu/context.c
27+
@@ -50,6 +50,7 @@ extern const struct ra_ctx_fns ra_ctx_vulkan_xlib;
28+
extern const struct ra_ctx_fns ra_ctx_vulkan_android;
29+
extern const struct ra_ctx_fns ra_ctx_vulkan_display;
30+
extern const struct ra_ctx_fns ra_ctx_vulkan_mac;
31+
+extern const struct ra_ctx_fns ra_ctx_vulkan_moltenvk;
3232

33-
# macOS features
34-
option('macos-10-15-4-features', type: 'feature', value: 'auto', description: 'macOS 10.15.4 SDK Features')
33+
/* Direct3D 11 */
34+
extern const struct ra_ctx_fns ra_ctx_d3d11;
35+
@@ -93,6 +94,9 @@ static const struct ra_ctx_fns *contexts[] = {
36+
#if HAVE_X11
37+
&ra_ctx_vulkan_xlib,
38+
#endif
39+
+#if HAVE_SWIFT && HAVE_MOLTENVK
40+
+ &ra_ctx_vulkan_moltenvk,
41+
+#endif
42+
#if HAVE_COCOA && HAVE_SWIFT
43+
&ra_ctx_vulkan_mac,
44+
#endif
45+
diff --git forkSrcPrefix/video/out/vulkan/common.h forkDstPrefix/video/out/vulkan/common.h
46+
index e75cb228f8d99462ccecf7780098ea97ae7cfe02..afc17284773204563f4c90b4860758e61068d460 100644
47+
--- forkSrcPrefix/video/out/vulkan/common.h
48+
+++ forkDstPrefix/video/out/vulkan/common.h
49+
@@ -22,6 +22,9 @@
50+
#if HAVE_WIN32_DESKTOP
51+
#define VK_USE_PLATFORM_WIN32_KHR
52+
#endif
53+
+#if HAVE_MOLTENVK
54+
+#include <MoltenVK/mvk_vulkan.h>
55+
+#endif
56+
#if HAVE_COCOA
57+
#define VK_USE_PLATFORM_METAL_EXT
58+
#endif
3559
diff --git forkSrcPrefix/video/out/vulkan/context_moltenvk.m forkDstPrefix/video/out/vulkan/context_moltenvk.m
3660
new file mode 100644
3761
index 0000000000000000000000000000000000000000..445b907f795b24b8df80389394d4ae7b3f94c6e5
@@ -134,39 +158,15 @@ index 0000000000000000000000000000000000000000..445b907f795b24b8df80389394d4ae7b
134158
+ .init = moltenvk_init,
135159
+ .uninit = moltenvk_uninit,
136160
+};
137-
diff --git forkSrcPrefix/video/out/vulkan/common.h forkDstPrefix/video/out/vulkan/common.h
138-
index e75cb228f8d99462ccecf7780098ea97ae7cfe02..afc17284773204563f4c90b4860758e61068d460 100644
139-
--- forkSrcPrefix/video/out/vulkan/common.h
140-
+++ forkDstPrefix/video/out/vulkan/common.h
141-
@@ -22,6 +22,9 @@
142-
#if HAVE_WIN32_DESKTOP
143-
#define VK_USE_PLATFORM_WIN32_KHR
144-
#endif
145-
+#if HAVE_MOLTENVK
146-
+#include <MoltenVK/mvk_vulkan.h>
147-
+#endif
148-
#if HAVE_COCOA
149-
#define VK_USE_PLATFORM_METAL_EXT
150-
#endif
151-
diff --git forkSrcPrefix/video/out/gpu/context.c forkDstPrefix/video/out/gpu/context.c
152-
index 75dd804005ba3a1e36375b47dcc9d9bb756ab867..4ab72a00b3dd3539a06129702e41796fd00a8af3 100644
153-
--- forkSrcPrefix/video/out/gpu/context.c
154-
+++ forkDstPrefix/video/out/gpu/context.c
155-
@@ -50,6 +50,7 @@ extern const struct ra_ctx_fns ra_ctx_vulkan_xlib;
156-
extern const struct ra_ctx_fns ra_ctx_vulkan_android;
157-
extern const struct ra_ctx_fns ra_ctx_vulkan_display;
158-
extern const struct ra_ctx_fns ra_ctx_vulkan_mac;
159-
+extern const struct ra_ctx_fns ra_ctx_vulkan_moltenvk;
160-
161-
/* Direct3D 11 */
162-
extern const struct ra_ctx_fns ra_ctx_d3d11;
163-
@@ -126,6 +127,9 @@ static const struct ra_ctx_fns *contexts[] = {
161+
diff --git forkSrcPrefix/meson.options forkDstPrefix/meson.options
162+
index dae0a333ef71b75a6bb36a236de7feebd99bda40..6ed28af20a09501b4997ca81e86bb198e75327fd 100644
163+
--- forkSrcPrefix/meson.options
164+
+++ forkDstPrefix/meson.options
165+
@@ -101,6 +101,7 @@ option('gl-dxinterop-d3d9', type: 'feature', value: 'auto', description: 'OpenGL
166+
option('ios-gl', type: 'feature', value: 'auto', description: 'iOS OpenGL ES interop support')
167+
option('videotoolbox-gl', type: 'feature', value: 'auto', description: 'Videotoolbox with OpenGL')
168+
option('videotoolbox-pl', type: 'feature', value: 'auto', description: 'Videotoolbox with libplacebo')
169+
+option('moltenvk', type: 'feature', value: 'auto', description: 'Moltenvk context')
164170

165-
// Vulkan contexts (fallbacks):
166-
#if HAVE_VULKAN
167-
+#if HAVE_MOLTENVK
168-
+ &ra_ctx_vulkan_moltenvk,
169-
+#endif
170-
#if HAVE_ANDROID
171-
&ra_ctx_vulkan_android,
172-
#endif
171+
# macOS features
172+
option('macos-10-15-4-features', type: 'feature', value: 'auto', description: 'macOS 10.15.4 SDK Features')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git forkSrcPrefix/osdep/mac/meson.build forkDstPrefix/osdep/mac/meson.build
2+
index d886e5406a03ad2d46171aba5fb4c56840aac4a8..aebee946a795b39834ffdd558810ef0761392b16 100644
3+
--- forkSrcPrefix/osdep/mac/meson.build
4+
+++ forkDstPrefix/osdep/mac/meson.build
5+
@@ -2,8 +2,8 @@
6+
bridge = join_paths(source_root, 'osdep/mac/app_bridge_objc.h')
7+
module = join_paths(build_root, 'osdep/mac/swift.swiftmodule')
8+
9+
-swift_flags = ['-c', '-emit-library', '-static', '-sdk', macos_sdk_path,
10+
- '-emit-objc-header', '-parse-as-library']
11+
+swift_flags = ['-frontend', '-c', '-sdk', macos_sdk_path,
12+
+ '-enable-objc-interop', '-emit-objc-header', '-parse-as-library']
13+
14+
if swift_ver.version_compare('>=6.0')
15+
swift_flags += ['-swift-version', '5']

0 commit comments

Comments
 (0)