29fe98cc44
* feat: Create `TypedArray` class for Frame Processor Plugins * Type * feat: Pass `VisionCameraProxy` along (BREAKING) * feat: Finish implementation * Log a bit * feat: Successfully convert JSI <> JNI buffers * Wrap buffer * fix: Fix using wrong Runtime * feat: Add docs * add zero copy example * Format C++ * Create iOS base * feat: Finish iOS implementation * chore: Format * fix: Use `NSData` instead of `NSMutableData` * Format * fix: Fix build when Frame Processors are disabled * chore: Rename `TypedArray` to `SharedArray` * fix: Fix Swift typings for Array * Remove a few default inits * fix: Fix Android build * fix: Use `NSInteger` * Update SharedArray.mm * fix: Expose bytes directly on iOS (NSData was immutable)
59 lines
1.4 KiB
Plaintext
59 lines
1.4 KiB
Plaintext
//
|
|
// SharedArray.mm
|
|
// VisionCamera
|
|
//
|
|
// Created by Marc Rousavy on 12.01.24.
|
|
// Copyright © 2024 mrousavy. All rights reserved.
|
|
//
|
|
|
|
#import "SharedArray.h"
|
|
#import "JSITypedArray.h"
|
|
#import <Foundation/Foundation.h>
|
|
#import <jsi/jsi.h>
|
|
|
|
using namespace facebook;
|
|
|
|
@implementation SharedArray {
|
|
uint8_t* _data;
|
|
NSInteger _count;
|
|
std::shared_ptr<vision::TypedArrayBase> _array;
|
|
}
|
|
|
|
vision::TypedArrayKind getTypedArrayKind(int unsafeEnumValue) {
|
|
return static_cast<vision::TypedArrayKind>(unsafeEnumValue);
|
|
}
|
|
|
|
- (instancetype)initWithProxy:(VisionCameraProxyHolder*)proxy type:(SharedArrayType)type size:(NSInteger)size {
|
|
if (self = [super init]) {
|
|
jsi::Runtime& runtime = proxy.proxy->getWorkletRuntime();
|
|
vision::TypedArrayKind kind = getTypedArrayKind((int)type);
|
|
_array = std::make_shared<vision::TypedArrayBase>(vision::TypedArrayBase(runtime, size, kind));
|
|
_data = _array->getBuffer(runtime).data(runtime);
|
|
_count = size;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithRuntime:(jsi::Runtime&)runtime typedArray:(std::shared_ptr<vision::TypedArrayBase>)typedArray {
|
|
if (self = [super init]) {
|
|
_array = typedArray;
|
|
_data = _array->getBuffer(runtime).data(runtime);
|
|
_count = _array->getBuffer(runtime).size(runtime);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (std::shared_ptr<vision::TypedArrayBase>)typedArray {
|
|
return _array;
|
|
}
|
|
|
|
- (uint8_t*)data {
|
|
return _data;
|
|
}
|
|
|
|
- (NSInteger)count {
|
|
return _count;
|
|
}
|
|
|
|
@end
|