diff --git a/modules/juce_video/native/juce_mac_CameraDevice.h b/modules/juce_video/native/juce_mac_CameraDevice.h index 6280e56fb7..35cfd67bd2 100644 --- a/modules/juce_video/native/juce_mac_CameraDevice.h +++ b/modules/juce_video/native/juce_mac_CameraDevice.h @@ -288,44 +288,44 @@ private: PhotoOutputDelegateClass::setOwner (delegate.get(), &p); [imageOutput capturePhotoWithSettings: [AVCapturePhotoSettings photoSettings] - delegate: id (delegate.get())]; + delegate: delegate.get()]; } private: - class PhotoOutputDelegateClass : public ObjCClass + class PhotoOutputDelegateClass : public ObjCClass> { public: - PhotoOutputDelegateClass() : ObjCClass ("PhotoOutputDelegateClass_") + PhotoOutputDelegateClass() + : ObjCClass ("PhotoOutputDelegateClass_") { - addMethod (@selector (captureOutput:didFinishProcessingPhoto:error:), didFinishProcessingPhoto); + addMethod (@selector (captureOutput:didFinishProcessingPhoto:error:), [] (id self, SEL, AVCapturePhotoOutput*, AVCapturePhoto* photo, NSError* error) + { + if (error != nil) + { + [[maybe_unused]] String errorString = error != nil ? nsStringToJuce (error.localizedDescription) : String(); + + JUCE_CAMERA_LOG ("Still picture capture failed, error: " + errorString); + jassertfalse; + + return; + } + + auto* imageData = [photo fileDataRepresentation]; + auto image = ImageFileFormat::loadFrom (imageData.bytes, (size_t) imageData.length); + + getOwner (self).imageCaptureFinished (image); + }); + addIvar ("owner"); registerClass(); } - static void didFinishProcessingPhoto (id self, SEL, AVCapturePhotoOutput*, AVCapturePhoto* photo, NSError* error) - { - if (error != nil) - { - [[maybe_unused]] String errorString = error != nil ? nsStringToJuce (error.localizedDescription) : String(); - - JUCE_CAMERA_LOG ("Still picture capture failed, error: " + errorString); - jassertfalse; - - return; - } - - auto* imageData = [photo fileDataRepresentation]; - auto image = ImageFileFormat::loadFrom (imageData.bytes, (size_t) imageData.length); - - getOwner (self).imageCaptureFinished (image); - } - static Pimpl& getOwner (id self) { return *getIvar (self, "owner"); } static void setOwner (id self, Pimpl* t) { object_setInstanceVariable (self, "owner", t); } }; AVCapturePhotoOutput* imageOutput = nil; - std::unique_ptr delegate; + NSUniquePtr> delegate; }; #endif