feat: Complete iOS Codebase rewrite (#1647)

* Make Frame Processors an extra subspec

* Update VisionCamera.podspec

* Make optional

* Make VisionCamera compile without Skia

* Fix

* Add skia again

* Update VisionCamera.podspec

* Make VisionCamera build without Frame Processors

* Rename error to `system/frame-processors-unavailable`

* Fix Frame Processor returning early

* Remove `preset`, FP partial rewrite

* Only warn on frame drop

* Fix wrong queue

* fix: Run on CameraQueue again

* Update CameraView.swift

* fix: Activate audio session asynchronously on audio queue

* Update CameraView+RecordVideo.swift

* Update PreviewView.h

* Cleanups

* Cleanup

* fix cast

* feat: Add LiDAR Depth Camera support

* Upgrade Ruby

* Add vector icons type

* Update Gemfile.lock

* fix: Stop queues on deinit

* Also load `builtInTrueDepthCamera`

* Update CameraViewManager.swift

* Update SkImageHelpers.mm

* Extract FrameProcessorCallback to FrameProcessor

Holds more context now :)

* Rename to .m

* fix: Add `RCTLog` import

* Create SkiaFrameProcessor

* Update CameraBridge.h

* Call Frame Processor

* Fix defines

* fix: Allow deleting callback funcs

* fix Skia build

* batch

* Just call `setSkiaFrameProcessor`

* Rewrite in Swift

* Pass `SkiaRenderer`

* Fix Import

* Move `PreviewView` to Swift

* Fix Layer

* Set Skia Canvas to Frame Host Object

* Make `DrawableFrameHostObject` subclass

* Fix TS types

* Use same MTLDevice and apply scale

* Make getter

* Extract `setTorch` and `Preview`

* fix: Fix nil metal device

* Don't wait for session stop in deinit

* Use main pixel ratio

* Use unique_ptr for Render Contexts

* fix: Fix SkiaPreviewDisplayLink broken after deinit

* inline `getTextureCache`

* Update CameraPage.tsx

* chore: Format iOS

* perf: Allow MTLLayer to be optimized for only frame buffers

* Add RN Video types

* fix: Fix Frame Processors if guard

* Find nodeModules recursively

* Create `Frame.isDrawable`

* Add `cocoapods-check` dependency
This commit is contained in:
Marc Rousavy
2023-07-20 15:30:04 +02:00
committed by GitHub
parent 5fb594ce6b
commit 375e894038
78 changed files with 1278 additions and 1245 deletions

View File

@@ -1,20 +0,0 @@
//
// JSConsoleHelper.h
// VisionCamera
//
// Created by Marc Rousavy on 02.06.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
#pragma once
#import <React/RCTBridge.h>
#import <React/RCTLog.h>
@interface JSConsoleHelper : NSObject
typedef void (^ConsoleLogFunction) (RCTLogLevel level, NSString* message);
+ (ConsoleLogFunction) getLogFunctionForBridge:(RCTBridge*)bridge;
@end

View File

@@ -1,60 +0,0 @@
//
// JSConsoleHelper.mm
// VisionCamera
//
// Created by Marc Rousavy on 02.06.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "JSConsoleHelper.h"
#import <React/RCTBridge.h>
#import <ReactCommon/RCTTurboModule.h>
#import <React/RCTBridge+Private.h>
#import <jsi/jsi.h>
#import "RCTBridge+runOnJS.h"
@implementation JSConsoleHelper
+ (const char *) getLogFunctionNameForLogLevel:(RCTLogLevel)level {
switch (level) {
case RCTLogLevelTrace:
return "trace";
case RCTLogLevelInfo:
return "log";
case RCTLogLevelWarning:
return "warn";
case RCTLogLevelError:
case RCTLogLevelFatal:
return "error";
}
}
+ (ConsoleLogFunction) getLogFunctionForBridge:(RCTBridge*)bridge {
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
if (!cxxBridge.runtime) {
return nil;
}
facebook::jsi::Runtime* jsiRuntime = (facebook::jsi::Runtime*)cxxBridge.runtime;
return ^(RCTLogLevel level, NSString* message) {
[bridge runOnJS:^{
if (jsiRuntime != nullptr) {
facebook::jsi::Runtime& runtime = *jsiRuntime;
auto logFunctionName = [JSConsoleHelper getLogFunctionNameForLogLevel:level];
try {
auto console = runtime.global().getPropertyAsObject(runtime, "console");
auto log = console.getPropertyAsFunction(runtime, logFunctionName);
log.call(runtime, facebook::jsi::String::createFromAscii(runtime, [message UTF8String]));
} catch (facebook::jsi::JSError& jsError) {
NSLog(@"%@", message);
NSLog(@"Failed to call `console.%s`: %s", logFunctionName, jsError.getMessage().c_str());
}
}
}];
};
}
@end

View File

@@ -20,6 +20,7 @@
#import <ReactCommon/CallInvoker.h>
#import <React/RCTBridge.h>
#import <ReactCommon/TurboModuleUtils.h>
#import <ReactCommon/RCTBlockGuard.h>
#import "../Frame Processor/Frame.h"
#import "../Frame Processor/FrameHostObject.h"
@@ -173,6 +174,13 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const jsi::Function &value, std::shared_ptr<CallInvoker> jsInvoker)
{
auto weakWrapper = CallbackWrapper::createWeak(value.getFunction(runtime), runtime, jsInvoker);
RCTBlockGuard *blockGuard = [[RCTBlockGuard alloc] initWithCleanup:^() {
auto strongWrapper = weakWrapper.lock();
if (strongWrapper) {
strongWrapper->destroy();
}
}];
BOOL __block wrapperWasCalled = NO;
RCTResponseSenderBlock callback = ^(NSArray *responses) {
if (wrapperWasCalled) {
@@ -184,7 +192,7 @@ RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const
return;
}
strongWrapper->jsInvoker().invokeAsync([weakWrapper, responses]() {
strongWrapper->jsInvoker().invokeAsync([weakWrapper, responses, blockGuard]() {
auto strongWrapper2 = weakWrapper.lock();
if (!strongWrapper2) {
return;
@@ -194,6 +202,9 @@ RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const
strongWrapper2->callback().call(strongWrapper2->runtime(), args, static_cast<size_t>(responses.count));
strongWrapper2->destroy();
delete[] args;
// Delete the CallbackWrapper when the block gets dealloced without being invoked.
(void)blockGuard;
});
wrapperWasCalled = YES;

View File

@@ -1,18 +0,0 @@
//
// RCTBridge+runOnJS.h
// VisionCamera
//
// Created by Marc Rousavy on 23.03.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
#pragma once
#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>
@interface RCTBridge (RunOnJS)
- (void) runOnJS:(void (^)(void))block NS_SWIFT_NAME( runOnJS(_:) );
@end

View File

@@ -1,23 +0,0 @@
//
// RCTBridge+runOnJS.mm
// VisionCamera
//
// Created by Marc Rousavy on 23.03.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
#import "RCTBridge+runOnJS.h"
#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>
#import <ReactCommon/RCTTurboModule.h>
@implementation RCTBridge (RunOnJS)
- (void) runOnJS:(void (^)())block {
auto callInvoker = [self jsCallInvoker];
callInvoker->invokeAsync([block]() {
block();
});
}
@end