[vlc-devel] [PATCH 4/4] ci_filters: don't use a vlc_variable provided context

Alexandre Janniaux ajanni at videolabs.io
Fri Nov 6 13:26:41 CET 2020


We actually don't need to provide a context matching the display or a
context in the same share group as the display because it exports
CVPixelBuffer.s and not OpenGL textures.

Instead, create a new context locally for the filter, using CGL for
MacOSX and EAGL for iOS.
---
 modules/video_filter/Makefile.am  |  3 ++-
 modules/video_filter/ci_filters.m | 44 +++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/modules/video_filter/Makefile.am b/modules/video_filter/Makefile.am
index 7a51d960eb..e4aff521a6 100644
--- a/modules/video_filter/Makefile.am
+++ b/modules/video_filter/Makefile.am
@@ -113,7 +113,8 @@ video_filter_LTLIBRARIES = \
 libci_filters_plugin_la_SOURCES = video_filter/ci_filters.m codec/vt_utils.c codec/vt_utils.h
 if HAVE_OSX
 libci_filters_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(video_filterdir)' \
-	-Wl,-framework,Foundation -Wl,-framework,CoreGraphics -Wl,-framework,CoreImage -Wl,-framework,CoreVideo
+	-Wl,-framework,Foundation -Wl,-framework,CoreGraphics -Wl,-framework,CoreImage \
+	-Wl,-framework,CoreVideo -Wl,-framework,OpenGL
 video_filter_LTLIBRARIES += libci_filters_plugin.la
 endif
 
diff --git a/modules/video_filter/ci_filters.m b/modules/video_filter/ci_filters.m
index 21f0e18cd4..6466bd25dd 100644
--- a/modules/video_filter/ci_filters.m
+++ b/modules/video_filter/ci_filters.m
@@ -85,6 +85,11 @@ struct  ci_filters_ctx
     struct filter_chain *       fchain;
     filter_t *                  src_converter;
     filter_t *                  dst_converter;
+#if !TARGET_OS_IPHONE
+    CGLContextObj               cgl_context;
+#else
+    CVEAGLContext               eagl_context;
+#endif
 };
 
 typedef struct filter_sys_t
@@ -670,13 +675,21 @@ Open(filter_t *filter, char const *psz_filter)
         }
 
 #if !TARGET_OS_IPHONE
-        CGLContextObj glctx = var_InheritAddress(filter, "macosx-glcontext");
-        if (!glctx)
-        {
-            msg_Err(filter, "can't find 'macosx-glcontext' var");
-            goto error;
-        }
-        ctx->ci_ctx = [CIContext contextWithCGLContext: glctx
+        CGLPixelFormatAttribute pixel_attr[] = {
+            kCGLPFAAccelerated,
+            kCGLPFAAllowOfflineRenderers,
+            0,
+        };
+
+        CGLPixelFormatObj pixelFormat;
+        GLint numPixelFormats = 0;
+
+        CGLChoosePixelFormat (pixel_attr, &pixelFormat, &numPixelFormats);
+
+        CGLCreateContext( pixelFormat, NULL, &ctx->cgl_context) ;
+        CGLDestroyPixelFormat( pixelFormat ) ;
+
+        ctx->ci_ctx = [CIContext contextWithCGLContext: ctx->cgl_context
                                            pixelFormat: nil
                                             colorSpace: nil
                                                options: @{
@@ -684,13 +697,8 @@ Open(filter_t *filter, char const *psz_filter)
                                                 kCIContextOutputColorSpace : [NSNull null],
                                                }];
 #else
-        CVEAGLContext eaglctx = var_InheritAddress(filter, "ios-eaglcontext");
-        if (!eaglctx)
-        {
-            msg_Err(filter, "can't find 'ios-eaglcontext' var");
-            goto error;
-        }
-        ctx->ci_ctx = [CIContext contextWithEAGLContext: eaglctx];
+        ctx->eagl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+        ctx->ci_ctx = [CIContext contextWithEAGLContext: ctx->eagl_context];
 #endif
         if (!ctx->ci_ctx)
             goto error;
@@ -710,6 +718,14 @@ Open(filter_t *filter, char const *psz_filter)
     return VLC_SUCCESS;
 
 error:
+#if !TARGET_OS_IPHONE
+    if (ctx->cgl_context)
+        CGLDestroyContext(ctx->cgl_context);
+#else
+    if (ctx->eagl_context)
+        [ctx->eagl_context release];
+#endif
+
     if (filter->vctx_out)
         vlc_video_context_Release(filter->vctx_out);
     free(p_sys);
-- 
2.29.2



More information about the vlc-devel mailing list