From d9ce7421598f5055bb4acbdf09796643bc326da1 Mon Sep 17 00:00:00 2001 From: shogo4405 Date: Wed, 1 Nov 2023 11:38:39 +0900 Subject: [PATCH] Performance improvements related to CIContext --- Sources/Media/IOVideoMixer.swift | 8 +++++++- Sources/Media/IOVideoUnit.swift | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/Media/IOVideoMixer.swift b/Sources/Media/IOVideoMixer.swift index dc9c91e61..c3791be98 100644 --- a/Sources/Media/IOVideoMixer.swift +++ b/Sources/Media/IOVideoMixer.swift @@ -15,7 +15,13 @@ final class IOVideoMixer { var muted = false var multiCamCaptureSettings: MultiCamCaptureSettings = .default weak var delegate: T? - var context: CIContext = .init() + var context: CIContext = .init() { + didSet { + for effect in effects { + effect.ciContext = context + } + } + } private var extent = CGRect.zero { didSet { guard extent != oldValue else { diff --git a/Sources/Media/IOVideoUnit.swift b/Sources/Media/IOVideoUnit.swift index c39badf6a..30e6f359c 100644 --- a/Sources/Media/IOVideoUnit.swift +++ b/Sources/Media/IOVideoUnit.swift @@ -74,7 +74,17 @@ final class IOVideoUnit: NSObject, IOUnit { } #endif - var context: CIContext = .init() + var context: CIContext { + get { + return lockQueue.sync { self.videoMixer.context } + } + set { + lockQueue.async { + self.videoMixer.context = newValue + } + } + } + var isRunning: Atomic { return codec.isRunning }