[vlc-commits] [Git][videolan/vlc][master] 3 commits: vout: opengl: reject VLC_CODEC_CVPX_P010 on iOS

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Oct 4 06:06:54 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
5193c8db by Maxime Chapelet at 2023-10-04T05:38:35+00:00
vout: opengl: reject VLC_CODEC_CVPX_P010 on iOS

There’s no possible interoperability between VLC_CODEC_CVPX_P010 and the native
Darwin OpenGLES backend given it can’t allocate more than 8bit-per-pixel textures. Hence we can reject this chroma to prevent the display from opening in this
case.

- - - - -
d80a7ace by Maxime Chapelet at 2023-10-04T05:38:35+00:00
videotoolbox: allow CVPX_P010 on all Darwin systems

Only OpenGLES isn’t compatible with `x420` formats. Other renderer
implementation using Metal or AVSampleBufferDisplayLayer can display
this chroma just fine.

- - - - -
fb5cfd52 by Maxime Chapelet at 2023-10-04T05:38:35+00:00
codec: videotoolbox: Check wherever a metal device can be fetched on iOS

Metal device is mandatory to handle P010 chroma on mobile/tv devices.
The Metal device API can only be used in ObjC context hence a new ObjC source file had to be created to handle the device detection.

- - - - -


6 changed files:

- modules/codec/Makefile.am
- modules/codec/videotoolbox/decoder.c
- modules/codec/vt_utils.h
- + modules/codec/vt_utils_native.m
- modules/video_output/Makefile.am
- modules/video_output/opengl/display.c


Changes:

=====================================
modules/codec/Makefile.am
=====================================
@@ -352,7 +352,7 @@ codec_LTLIBRARIES += $(LTLIBoggspots)
 
 libvideotoolbox_plugin_la_SOURCES = codec/videotoolbox/decoder.c
 libvideotoolbox_plugin_la_LIBADD = libchroma_copy.la libvlc_hxxxhelper.la libvlc_vtutils.la
-libvideotoolbox_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo
+libvideotoolbox_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo -Wl,-framework,Metal
 if HAVE_DARWIN
 codec_LTLIBRARIES += libvideotoolbox_plugin.la
 endif
@@ -360,7 +360,7 @@ endif
 libvideotoolbox_enc_plugin_la_SOURCES = codec/videotoolbox/encoder.c
 libvideotoolbox_enc_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) # Trigger MODULE_NAME declaration
 libvideotoolbox_enc_plugin_la_LIBADD = libvlc_hxxxhelper.la libvlc_vtutils.la
-libvideotoolbox_enc_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo
+libvideotoolbox_enc_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo -Wl,-framework,Metal
 if HAVE_DARWIN
 if ENABLE_SOUT
 codec_LTLIBRARIES += libvideotoolbox_enc_plugin.la
@@ -652,6 +652,6 @@ libhxxxhelper_testdec_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
 libhxxxhelper_testdec_plugin_la_LIBADD = libvlc_hxxxhelper.la
 noinst_LTLIBRARIES += libhxxxhelper_testdec_plugin.la
 
-libvlc_vtutils_la_SOURCES = codec/vt_utils.c codec/vt_utils.h
+libvlc_vtutils_la_SOURCES = codec/vt_utils.c codec/vt_utils.h codec/vt_utils_native.m
 libvlc_vtutils_la_LDFLAGS = -static -no-undefined
 EXTRA_LTLIBRARIES += libvlc_vtutils.la


=====================================
modules/codec/videotoolbox/decoder.c
=====================================
@@ -73,6 +73,7 @@ static void Drain(decoder_t *p_dec, bool flush);
 static void DecoderCallback(void *, void *, OSStatus, VTDecodeInfoFlags,
                             CVPixelBufferRef, CMTime, CMTime);
 static Boolean deviceSupportsHEVC();
+static bool deviceSupports42010bitRendering();
 static Boolean deviceSupportsAdvancedProfiles();
 static Boolean deviceSupportsAdvancedLevels();
 
@@ -252,10 +253,9 @@ static OSType GetBestChroma(uint8_t i_chroma_format, uint8_t i_depth_luma,
             return kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
         if (i_depth_luma == 10 && i_depth_chroma == 10)
         {
-#if !TARGET_OS_IPHONE
-            if (deviceSupportsHEVC()) /* 42010bit went with HEVC on macOS */
+            if (deviceSupportsHEVC() && deviceSupports42010bitRendering())
                 return kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange;
-#endif
+
            /* Force BGRA output (and let VT handle the tone mapping) since the
             * Apple openGL* implementation can't handle 16 bit textures. This
             * is the case for iOS and some macOS devices (ones that are not
@@ -1634,6 +1634,17 @@ static Boolean deviceSupportsHEVC()
         return false;
 }
 
+static bool deviceSupports42010bitRendering()
+{
+#if TARGET_OS_IPHONE
+    /* iPhone/iPad/aTV needs metal device to render 420 10bit */
+    return cvpx_system_has_metal_device();
+#else
+    /* macOS can render 420 10bit with OpenGL and Metal */
+    return true;
+#endif
+}
+
 static Boolean deviceSupportsAdvancedProfiles()
 {
 #if TARGET_OS_IPHONE


=====================================
modules/codec/vt_utils.h
=====================================
@@ -129,6 +129,13 @@ bool cvpx_has_attachment(CVPixelBufferRef pixelBuffer, CFStringRef key);
  */
 void cvpx_attach_mapped_color_properties(CVPixelBufferRef cvpx, 
                                          const video_format_t *fmt);
+/**
+ * @brief Check if current system has at least one metal GPU device
+ * 
+ * @return true if there's at least one metal device available
+ * @return false if there's no metal device
+ */
+bool cvpx_system_has_metal_device();
 
 enum cvpx_video_context_type
 {


=====================================
modules/codec/vt_utils_native.m
=====================================
@@ -0,0 +1,14 @@
+#import "vt_utils.h"
+#import <Foundation/Foundation.h>
+#import <Metal/Metal.h>
+
+bool cvpx_system_has_metal_device()
+{
+#if TARGET_OS_IPHONE
+    id<MTLDevice> device = MTLCreateSystemDefaultDevice();
+    return device != nil;
+#else
+    NSArray <id<MTLDevice>> *devices = MTLCopyAllDevices();
+    return devices.count > 0;
+#endif
+}
\ No newline at end of file


=====================================
modules/video_output/Makefile.am
=====================================
@@ -37,7 +37,7 @@ libglinterop_cvpx_plugin_la_SOURCES = video_output/opengl/interop_cvpx.m \
 	video_output/opengl/interop.h
 libglinterop_cvpx_plugin_la_LIBADD = libvlc_vtutils.la
 libglinterop_cvpx_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)' \
-	-Wl,-framework,Foundation,-framework,CoreVideo,-framework,IOSurface
+	-Wl,-framework,Foundation,-framework,CoreVideo,-framework,IOSurface,-framework,Metal
 libglinterop_cvpx_plugin_la_CPPFLAGS = $(AM_CPPFLAGS)
 if HAVE_DARWIN
 if HAVE_OSX
@@ -105,7 +105,7 @@ libcvpx_gl_plugin_la_SOURCES = video_output/apple/VLCCVOpenGLProvider.m
 libcvpx_gl_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
 libcvpx_gl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DGL_SILENCE_DEPRECATION
 libcvpx_gl_plugin_la_LDFLAGS = $(AM_LDFLAGS) \
-    -Wl,-framework,Foundation,-framework,CoreFoundation,-framework,CoreVideo
+    -Wl,-framework,Foundation,-framework,CoreFoundation,-framework,CoreVideo,-framework,Metal
 libcvpx_gl_plugin_la_LIBADD = libvlc_vtutils.la
 
 if HAVE_DARWIN


=====================================
modules/video_output/opengl/display.c
=====================================
@@ -190,6 +190,10 @@ static void PlacePicture(vout_display_t *vd, vout_display_place_t *place,
 static int Open(vout_display_t *vd,
                 video_format_t *fmt, vlc_video_context *context)
 {
+#if TARGET_OS_IPHONE
+    if (fmt->i_chroma == VLC_CODEC_CVPX_P010)
+        return VLC_EGENERIC;
+#endif
     vout_display_sys_t *sys = malloc (sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/93907682b4c68fda13b15b7961f38863baaf944d...fb5cfd5204bdada4a1f2fbe08cec816b424fc513

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/93907682b4c68fda13b15b7961f38863baaf944d...fb5cfd5204bdada4a1f2fbe08cec816b424fc513
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list