Skip to content

Commit

Permalink
Use different EXFaceDetectorManagers for different EXCamera instances (
Browse files Browse the repository at this point in the history
…expo#2998)

fbshipit-source-id: 54d3228
  • Loading branch information
sjchmiela authored and expbot committed Aug 16, 2018
1 parent c7ef50d commit a75b455
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 25 deletions.
37 changes: 21 additions & 16 deletions modules/expo-camera/ios/EXCamera/EXCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <EXCamera/EXCameraManager.h>
#import <EXPermissionsInterface/EXPermissionsInterface.h>
#import <EXFileSystemInterface/EXFileSystemInterface.h>
#import <EXFaceDetectorInterface/EXFaceDetectorManager.h>
#import <EXFaceDetectorInterface/EXFaceDetectorManagerProvider.h>
#import <EXCore/EXAppLifecycleService.h>
#import <EXCore/EXUtilities.h>

Expand Down Expand Up @@ -831,23 +831,28 @@ - (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToO

- (id)createFaceDetectorManager
{
id <EXFaceDetectorManager> faceDetector = [_moduleRegistry getModuleImplementingProtocol:@protocol(EXFaceDetectorManager)];
if (faceDetector) {
__weak EXCamera *weakSelf = self;
[faceDetector setOnFacesDetected:^(NSArray<NSDictionary *> *faces) {
__strong EXCamera *strongSelf = weakSelf;
if (strongSelf) {
if (strongSelf.onFacesDetected) {
strongSelf.onFacesDetected(@{
@"type": @"face",
@"faces": faces
});
id <EXFaceDetectorManagerProvider> faceDetectorProvider = [_moduleRegistry getModuleImplementingProtocol:@protocol(EXFaceDetectorManagerProvider)];

if (faceDetectorProvider) {
id <EXFaceDetectorManager> faceDetector = [faceDetectorProvider createFaceDetectorManager];
if (faceDetector) {
__weak EXCamera *weakSelf = self;
[faceDetector setOnFacesDetected:^(NSArray<NSDictionary *> *faces) {
__strong EXCamera *strongSelf = weakSelf;
if (strongSelf) {
if (strongSelf.onFacesDetected) {
strongSelf.onFacesDetected(@{
@"type": @"face",
@"faces": faces
});
}
}
}
}];
[faceDetector setSessionQueue:_sessionQueue];
}];
[faceDetector setSessionQueue:_sessionQueue];
}
return faceDetector;
}
return faceDetector;
return nil;
}

@end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright © 2018 650 Industries. All rights reserved.

#import <EXFaceDetectorInterface/EXFaceDetectorManager.h>

@protocol EXFaceDetectorManagerProvider

- (id<EXFaceDetectorManager>)createFaceDetectorManager;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#import <AVFoundation/AVFoundation.h>
#import <GoogleMobileVision/GoogleMobileVision.h>
#import <GoogleMVDataOutput/GoogleMVDataOutput.h>
#import <EXCore/EXInternalModule.h>
#import <EXFaceDetectorInterface/EXFaceDetectorManager.h>

@interface EXFaceDetectorManager : NSObject <EXInternalModule>
@interface EXFaceDetectorManager : NSObject <EXFaceDetectorManager>

- (void)setOnFacesDetected:(void (^)(NSArray<NSDictionary *> *))onFacesDetected;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// Created by Stanisław Chmiela on 22.11.2017.
// Copyright © 2017 650 Industries. All rights reserved.
//

#import <EXFaceDetector/EXFaceEncoder.h>
#import <EXFaceDetector/EXFaceDetectorUtils.h>
Expand Down Expand Up @@ -32,12 +31,6 @@ @interface EXFaceDetectorManager() <GMVDataOutputDelegate>

@implementation EXFaceDetectorManager

EX_REGISTER_MODULE();

+ (const NSArray<Protocol *> *)exportedInterfaces {
return @[@protocol(EXFaceDetectorManager)];
}

static NSDictionary *defaultFaceDetectorOptions = nil;

- (instancetype)init
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2018-present 650 Industries. All rights reserved.

#import <Foundation/Foundation.h>
#import <EXCore/EXInternalModule.h>
#import <EXFaceDetectorInterface/EXFaceDetectorManagerProvider.h>

@interface EXFaceDetectorManagerProvider : NSObject <EXInternalModule, EXFaceDetectorManagerProvider>

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2018-present 650 Industries. All rights reserved.

#import <EXFaceDetector/EXFaceDetectorManagerProvider.h>
#import <EXFaceDetector/EXFaceDetectorManager.h>

@implementation EXFaceDetectorManagerProvider

EX_REGISTER_MODULE();

+ (const NSArray<Protocol *> *)exportedInterfaces {
return @[@protocol(EXFaceDetectorManagerProvider)];
}

- (id<EXFaceDetectorManager>)createFaceDetectorManager {
return [[EXFaceDetectorManager alloc] init];
}

@end

0 comments on commit a75b455

Please sign in to comment.