diff mbox

[FFmpeg-devel,09/14] videotoolbox: allow software implementation

Message ID 20171215070423.34629-1-wbsecg1@gmail.com
State New
Headers show

Commit Message

Wang Bin Dec. 15, 2017, 7:04 a.m. UTC
From: wang-bin <wbsecg1@gmail.com>

hevc is supported on macOS 10.12+ and iOS11+. sw implementaion is
provided for old devices. vt sw decoder is more energy effecient than
ffmpeg sw decoder. the sum of program and vt service cpu usage is about
50% lower than ffmpeg. decoding speed is faster sometimes(if opengl
compatiblility attribute is disabled)
---
 libavcodec/videotoolbox.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index e66cd23451..9d2f0afa20 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -40,6 +40,9 @@ 
 #ifndef kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder
 #  define kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder CFSTR("RequireHardwareAcceleratedVideoDecoder")
 #endif
+#ifndef kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder
+#  define kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder CFSTR("EnableHardwareAcceleratedVideoDecoder")
+#endif
 
 #if !HAVE_KCMVIDEOCODECTYPE_HEVC
 enum { kCMVideoCodecType_HEVC = 'hvc1' };
@@ -684,7 +687,9 @@  static CFDictionaryRef videotoolbox_decoder_config_create(CMVideoCodecType codec
                                                                    &kCFTypeDictionaryValueCallBacks);
 
     CFDictionarySetValue(config_info,
-                         kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
+                         (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_SOFTWARE)
+                         ? kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder
+                         : kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
                          kCFBooleanTrue);
 
     CFMutableDictionaryRef avc_info;