-
-
Save rcombs/7362df8a689c41b9174ac50fdeda3e43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h | |
index bd0319f63c..7350d42a35 100644 | |
--- a/libavfilter/metal/utils.h | |
+++ b/libavfilter/metal/utils.h | |
@@ -20,16 +20,40 @@ | |
#define AVFILTER_METAL_UTILS_H | |
#include <Metal/Metal.h> | |
+ | |
+#include <AvailabilityMacros.h> | |
+ | |
+// CoreVideo accidentally(?) preprocessor-gates Metal functionality | |
+// on MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 (FB9816002). | |
+// There doesn't seem to be any particular reason for this, | |
+// so here we temporarily redefine it to at least that value | |
+// so CV will give us CVMetalTextureRef and the related functions. | |
+ | |
+#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101100) | |
+#define ORIG_MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_MIN_REQUIRED | |
+#undef MAC_OS_X_VERSION_MIN_REQUIRED | |
+#define MAC_OS_X_VERSION_MIN_REQUIRED 101100 | |
+#endif | |
+ | |
#include <CoreVideo/CoreVideo.h> | |
+#ifdef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED | |
+#undef MAC_OS_X_VERSION_MIN_REQUIRED | |
+#define MAC_OS_X_VERSION_MIN_REQUIRED ORIG_MAC_OS_X_VERSION_MIN_REQUIRED | |
+#undef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED | |
+#endif | |
+ | |
void ff_metal_compute_encoder_dispatch(id<MTLDevice> device, | |
id<MTLComputePipelineState> pipeline, | |
id<MTLComputeCommandEncoder> encoder, | |
- NSUInteger width, NSUInteger height); | |
+ NSUInteger width, NSUInteger height) | |
+ API_AVAILABLE(macos(10.11), ios(8.0)); | |
CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass, | |
CVMetalTextureCacheRef textureCache, | |
CVPixelBufferRef pixbuf, | |
int plane, | |
- MTLPixelFormat format); | |
+ MTLPixelFormat format) | |
+ API_AVAILABLE(macos(10.11), ios(8.0)); | |
+ | |
#endif /* AVFILTER_METAL_UTILS_H */ | |
diff --git a/libavfilter/metal/utils.m b/libavfilter/metal/utils.m | |
index 759ebedfba..f831502065 100644 | |
--- a/libavfilter/metal/utils.m | |
+++ b/libavfilter/metal/utils.m | |
@@ -17,7 +17,7 @@ | |
*/ | |
#include "libavutil/log.h" | |
-#include <libavfilter/metal/utils.h> | |
+#include "utils.h" | |
void ff_metal_compute_encoder_dispatch(id<MTLDevice> device, | |
id<MTLComputePipelineState> pipeline, | |
diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m | |
index af83a73e89..543227b4d4 100644 | |
--- a/libavfilter/vf_yadif_videotoolbox.m | |
+++ b/libavfilter/vf_yadif_videotoolbox.m | |
@@ -20,16 +20,18 @@ | |
*/ | |
#include "internal.h" | |
+#include "metal/utils.h" | |
#include "yadif.h" | |
-#include <libavutil/avassert.h> | |
-#include <libavutil/hwcontext.h> | |
-#include <libavutil/objc.h> | |
-#include <libavfilter/metal/utils.h> | |
+#include "libavutil/avassert.h" | |
+#include "libavutil/hwcontext.h" | |
+#include "libavutil/objc.h" | |
+ | |
+#include <assert.h> | |
extern char ff_vf_yadif_videotoolbox_metallib_data[]; | |
extern unsigned int ff_vf_yadif_videotoolbox_metallib_len; | |
-typedef struct YADIFVTContext { | |
+typedef struct API_AVAILABLE(macos(10.11), ios(8.0)) YADIFVTContext { | |
YADIFContext yadif; | |
AVBufferRef *device_ref; | |
@@ -44,7 +46,9 @@ typedef struct YADIFVTContext { | |
id<MTLBuffer> mtlParamsBuffer; | |
CVMetalTextureCacheRef textureCache; | |
-} YADIFVTContext; | |
+} YADIFVTContext API_AVAILABLE(macos(10.11), ios(8.0)); | |
+ | |
+#define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10) | |
struct mtlYadifParams { | |
uint channels; | |
@@ -62,7 +66,7 @@ static void call_kernel(AVFilterContext *ctx, | |
id<MTLTexture> next, | |
int channels, | |
int parity, | |
- int tff) | |
+ int tff) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
YADIFVTContext *s = ctx->priv; | |
id<MTLCommandBuffer> buffer = s->mtlQueue.commandBuffer; | |
@@ -93,7 +97,7 @@ static void call_kernel(AVFilterContext *ctx, | |
} | |
static void filter(AVFilterContext *ctx, AVFrame *dst, | |
- int parity, int tff) | |
+ int parity, int tff) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
YADIFVTContext *s = ctx->priv; | |
YADIFContext *y = &s->yadif; | |
@@ -162,7 +166,7 @@ exit: | |
return; | |
} | |
-static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx) | |
+static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
YADIFVTContext *s = ctx->priv; | |
YADIFContext *y = &s->yadif; | |
@@ -188,7 +192,15 @@ static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx) | |
} | |
} | |
-static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx) | |
+ | |
+static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx) | |
+{ | |
+ if (@available(macOS 10.11, iOS 8.0, *)) { | |
+ do_uninit(ctx); | |
+ } | |
+} | |
+ | |
+static av_cold int do_init(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
YADIFVTContext *s = ctx->priv; | |
NSError *err = nil; | |
@@ -261,7 +273,18 @@ fail: | |
return AVERROR_EXTERNAL; | |
} | |
-static int config_input(AVFilterLink *inlink) | |
+static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx) | |
+{ | |
+ if (@available(macOS 10.11, iOS 8.0, *)) { | |
+ static_assert(YADIF_VT_CTX_SIZE == sizeof(YADIFVTContext), "Incorrect YADIF_VT_CTX_SIZE value!"); | |
+ return do_init(ctx); | |
+ } else { | |
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n"); | |
+ return AVERROR(ENOSYS); | |
+ } | |
+} | |
+ | |
+static int do_config_input(AVFilterLink *inlink) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
AVFilterContext *ctx = inlink->dst; | |
YADIFVTContext *s = ctx->priv; | |
@@ -283,7 +306,18 @@ static int config_input(AVFilterLink *inlink) | |
return 0; | |
} | |
-static int config_output(AVFilterLink *link) | |
+static int config_input(AVFilterLink *inlink) | |
+{ | |
+ AVFilterContext *ctx = inlink->dst; | |
+ if (@available(macOS 10.11, iOS 8.0, *)) { | |
+ return do_config_input(inlink); | |
+ } else { | |
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n"); | |
+ return AVERROR(ENOSYS); | |
+ } | |
+} | |
+ | |
+static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0)) | |
{ | |
AVHWFramesContext *output_frames; | |
AVFilterContext *ctx = link->src; | |
@@ -347,6 +381,17 @@ exit: | |
return ret; | |
} | |
+static int config_output(AVFilterLink *link) | |
+{ | |
+ AVFilterContext *ctx = link->src; | |
+ if (@available(macOS 10.11, iOS 8.0, *)) { | |
+ return do_config_output(link); | |
+ } else { | |
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n"); | |
+ return AVERROR(ENOSYS); | |
+ } | |
+} | |
+ | |
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM | |
#define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit } | |
@@ -394,7 +439,7 @@ static const AVFilterPad yadif_videotoolbox_outputs[] = { | |
AVFilter ff_vf_yadif_videotoolbox = { | |
.name = "yadif_videotoolbox", | |
.description = NULL_IF_CONFIG_SMALL("YADIF for VideoToolbox frames using Metal compute"), | |
- .priv_size = sizeof(YADIFVTContext), | |
+ .priv_size = YADIF_VT_CTX_SIZE, | |
.priv_class = &yadif_videotoolbox_class, | |
.init = yadif_videotoolbox_init, | |
.uninit = yadif_videotoolbox_uninit, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment