From d6e340047f3f809efe7be1a0e7589aed0f3dc3dd Mon Sep 17 00:00:00 2001
From: Pierre Lespagnol <pierre.lespagnol@savoirfairelinux.com>
Date: Tue, 25 Feb 2020 15:46:54 -0500
Subject: [PATCH] accel: enable hardware encoding with videotoolbox on macOS

Change-Id: Icc6a87f62aaf80f867d7dd3ef6927f9940e724a0
---
 src/media/media_encoder.cpp | 3 +++
 src/media/video/accel.cpp   | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp
index 4849facc7a..62598a6cab 100644
--- a/src/media/media_encoder.cpp
+++ b/src/media/media_encoder.cpp
@@ -564,8 +564,11 @@ MediaEncoder::prepareEncoderContext(AVCodec* outputCodec, bool is_video)
         encoderCtx->max_b_frames = 0;
         encoderCtx->pix_fmt = AV_PIX_FMT_YUV420P;
 #ifdef RING_ACCEL
+// Keep YUV format for macOS
+#if !(defined(__APPLE__) && !TARGET_OS_IOS)
         if (accel_)
             encoderCtx->pix_fmt = accel_->getFormat();
+#endif
 #endif
 
         // Fri Jul 22 11:37:59 EDT 2011:tmatth:XXX: DON'T set this, we want our
diff --git a/src/media/video/accel.cpp b/src/media/video/accel.cpp
index 46a05bc705..b76163629b 100644
--- a/src/media/video/accel.cpp
+++ b/src/media/video/accel.cpp
@@ -335,7 +335,7 @@ HardwareAccel::initAPI(bool linkable, AVBufferRef* framesCtx)
         if (linkable && framesCtx)
             link = linkHardware(framesCtx);
         // we don't need frame context for videotoolbox
-        if (format_ == AV_PIX_FMT_VIDEOTOOLBOX || link || initFrame()) {
+        if (hwType_ == AV_HWDEVICE_TYPE_VIDEOTOOLBOX || link || initFrame()) {
             return 0;
         }
     }
-- 
GitLab