Add files via upload

This commit is contained in:
Khaled Alshehri 2018-08-08 02:34:41 +03:00 committed by GitHub
parent 402429fa18
commit c69a609542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 2125 additions and 0 deletions

View File

@ -0,0 +1,22 @@
//
// SCCaptureImageState.h
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureImageState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,65 @@
//
// SCCaptureImageState.m
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureImageState.h"
#import "SCCaptureImageStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureImageState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureImageState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCAssert(payload.toState == [self stateId], @"");
if (![payload isKindOfClass:[SCCaptureImageStateTransitionPayload class]]) {
SCAssertFail(@"wrong payload pass in");
[_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
return;
}
SCCaptureImageStateTransitionPayload *captureImagePayload = (SCCaptureImageStateTransitionPayload *)payload;
[SCCaptureWorker
captureStillImageWithCaptureResource:resource
aspectRatio:captureImagePayload.aspectRatio
captureSessionID:captureImagePayload.captureSessionID
shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
completionHandler:captureImagePayload.block
context:context];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureImageStateId;
}
@end

View File

@ -0,0 +1,29 @@
//
// SCCaptureImageStateTransitionPayload.h
// Snapchat
//
// Created by Lin Jia on 1/9/18.
//
#import "SCCaptureCommon.h"
#import "SCStateTransitionPayload.h"
#import <Foundation/Foundation.h>
@interface SCCaptureImageStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_capture_still_image_completion_handler_t block;
@property (nonatomic, readonly, assign) CGFloat aspectRatio;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block;
@end

View File

@ -0,0 +1,27 @@
//
// SCCaptureImageStateTransitionPayload.m
// Snapchat
//
// Created by Lin Jia on 1/9/18.
//
#import "SCCaptureImageStateTransitionPayload.h"
@implementation SCCaptureImageStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_captureSessionID = captureSessionID;
_aspectRatio = aspectRatio;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureImageWhileRecordingState.h
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureImageWhileRecordingState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,85 @@
//
// SCCaptureImageWhileRecordingState.m
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureImageWhileRecordingState.h"
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureImageWhileRecordingState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureImageWhileRecordingState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureImageWhileRecordingStateId;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCAssert(payload.fromState == SCCaptureRecordingStateId, @"");
SCAssert(payload.toState == [self stateId], @"");
SCAssert([payload isKindOfClass:[SCCaptureImageWhileRecordingStateTransitionPayload class]], @"");
;
SCCaptureImageWhileRecordingStateTransitionPayload *captureImagePayload =
(SCCaptureImageWhileRecordingStateTransitionPayload *)payload;
@weakify(self);
sc_managed_capturer_capture_still_image_completion_handler_t block =
^(UIImage *fullScreenImage, NSDictionary *metadata, NSError *error, SCManagedCapturerState *state) {
captureImagePayload.block(fullScreenImage, metadata, error, state);
[_performer perform:^{
@strongify(self);
[self _cancelRecordingWithContext:context resource:resource];
}];
};
[SCCaptureWorker
captureStillImageWithCaptureResource:resource
aspectRatio:captureImagePayload.aspectRatio
captureSessionID:captureImagePayload.captureSessionID
shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
completionHandler:block
context:context];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
}
- (void)_cancelRecordingWithContext:(NSString *)context resource:(SCCaptureResource *)resource
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker cancelRecordingWithCaptureResource:resource];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,29 @@
//
// SCCaptureImageWhileRecordingStateTransitionPayload.h
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureCommon.h"
#import "SCStateTransitionPayload.h"
#import <Foundation/Foundation.h>
@interface SCCaptureImageWhileRecordingStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_capture_still_image_completion_handler_t block;
@property (nonatomic, readonly, assign) CGFloat aspectRatio;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block;
@end

View File

@ -0,0 +1,27 @@
//
// SCCaptureImageWhileRecordingStateTransitionPayload.m
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
@implementation SCCaptureImageWhileRecordingStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_captureSessionID = captureSessionID;
_aspectRatio = aspectRatio;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureInitializedState.h
// Snapchat
//
// Created by Jingtian Yang on 20/12/2017.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureInitializedState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,68 @@
//
// SCCaptureInitializedState.m
// Snapchat
//
// Created by Jingtian Yang on 20/12/2017.
//
#import "SCCaptureInitializedState.h"
#import "SCCapturerToken.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureInitializedState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureInitializedState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureInitializedStateId;
}
- (void)startRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"startRunningAsynchronouslyWithCompletionHandler called. token: %@", token);
[SCCaptureWorker startRunningWithCaptureResource:resource token:token completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureRecordingState.h
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureRecordingState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,114 @@
//
// SCCaptureRecordingState.m
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureRecordingState.h"
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
#import "SCCaptureRecordingStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureRecordingState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureRecordingState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(resource.queuePerformer);
SCAssert(payload.toState == [self stateId], @"");
if (![payload isKindOfClass:[SCCaptureRecordingStateTransitionPayload class]]) {
SCAssertFail(@"wrong payload pass in");
[_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
return;
}
SCCaptureRecordingStateTransitionPayload *recordingPayload = (SCCaptureRecordingStateTransitionPayload *)payload;
[SCCaptureWorker startRecordingWithCaptureResource:resource
outputSettings:recordingPayload.outputSettings
audioConfiguration:recordingPayload.configuration
maxDuration:recordingPayload.maxDuration
fileURL:recordingPayload.fileURL
captureSessionID:recordingPayload.captureSessionID
completionHandler:recordingPayload.block];
}
- (void)stopRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker stopRecordingWithCaptureResource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker cancelRecordingWithCaptureResource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureRecordingStateId;
}
- (void)captureStillImageWithResource:(SCCaptureResource *)resource
aspectRatio:(CGFloat)aspectRatio
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCCaptureImageWhileRecordingStateTransitionPayload *payload = [
[SCCaptureImageWhileRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRecordingStateId
toState:SCCaptureImageWhileRecordingStateId
captureSessionId:captureSessionID
aspectRatio:aspectRatio
completionHandler:completionHandler];
[_delegate currentState:self
requestToTransferToNewState:SCCaptureImageWhileRecordingStateId
payload:payload
context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,41 @@
//
// SCCaptureRecordingStateTransitionPayload.h
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureCommon.h"
#import "SCManagedVideoCapturerOutputSettings.h"
#import "SCStateTransitionPayload.h"
#import <SCAudio/SCAudioConfiguration.h>
#import <Foundation/Foundation.h>
@interface SCCaptureRecordingStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) SCManagedVideoCapturerOutputSettings *outputSettings;
@property (nonatomic, readonly, strong) SCAudioConfiguration *configuration;
@property (nonatomic, readonly, assign) NSTimeInterval maxDuration;
@property (nonatomic, readonly, strong) NSURL *fileURL;
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_start_recording_completion_handler_t block;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
audioConfiguration:(SCAudioConfiguration *)configuration
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)block;
@end

View File

@ -0,0 +1,33 @@
//
// SCCaptureRecordingStateTransitionPayload.m
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureRecordingStateTransitionPayload.h"
@implementation SCCaptureRecordingStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
audioConfiguration:configuration
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_outputSettings = outputSettings;
_configuration = configuration;
_maxDuration = maxDuration;
_fileURL = fileURL;
_captureSessionID = captureSessionID;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureRunningState.h
// Snapchat
//
// Created by Jingtian Yang on 08/01/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureRunningState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,176 @@
//
// SCCaptureRunningState.m
// Snapchat
//
// Created by Jingtian Yang on 08/01/2018.
//
#import "SCCaptureRunningState.h"
#import "SCCaptureImageStateTransitionPayload.h"
#import "SCCaptureRecordingStateTransitionPayload.h"
#import "SCCaptureWorker.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCScanConfiguration.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureRunningState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureRunningState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (void)captureStillImageWithResource:(SCCaptureResource *)resource
aspectRatio:(CGFloat)aspectRatio
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCCaptureImageStateTransitionPayload *payload =
[[SCCaptureImageStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
toState:SCCaptureImageStateId
captureSessionId:captureSessionID
aspectRatio:aspectRatio
completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureImageStateId payload:payload context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureRunningStateId;
}
- (void)startRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"startRunningAsynchronouslyWithCompletionHandler called. token: %@", token);
[SCCaptureWorker startRunningWithCaptureResource:resource token:token completionHandler:completionHandler];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)stopRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
SCLogCapturerInfo(@"Stop running asynchronously. token:%@", token);
if ([[SCManagedCapturerV1 sharedInstance] stopRunningWithCaptureToken:token
completionHandler:completionHandler
context:context]) {
[_delegate currentState:self
requestToTransferToNewState:SCCaptureInitializedStateId
payload:nil
context:context];
}
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)startScanWithScanConfiguration:(SCScanConfiguration *)configuration
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"Start scan on preview asynchronously. configuration:%@", configuration);
SCAssertPerformer(_performer);
[SCCaptureWorker startScanWithScanConfiguration:configuration resource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureScanningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)prepareForRecordingWithResource:(SCCaptureResource *)resource
audioConfiguration:(SCAudioConfiguration *)configuration
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
[SCCaptureWorker prepareForRecordingWithAudioConfiguration:configuration resource:resource];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)startRecordingWithResource:(SCCaptureResource *)resource
audioConfiguration:(SCAudioConfiguration *)configuration
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)completionHandler
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
SCCaptureRecordingStateTransitionPayload *payload =
[[SCCaptureRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
toState:SCCaptureRecordingStateId
outputSettings:outputSettings
audioConfiguration:configuration
maxDuration:maxDuration
fileURL:fileURL
captureSessionID:captureSessionID
completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRecordingStateId payload:payload context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
// Intentionally No Op, this will be removed once CCAM-13851 gets resolved.
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,18 @@
//
// SCCaptureScanningState.h
// Snapchat
//
// Created by Xiaokang Liu on 09/01/2018.
//
#import "SCCaptureBaseState.h"
@class SCQueuePerformer;
@interface SCCaptureScanningState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,75 @@
//
// SCCaptureScanningState.m
// Snapchat
//
// Created by Xiaokang Liu on 09/01/2018.
//
#import "SCCaptureScanningState.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureScanningState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureScanningState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
SCAssert(delegate, @"");
SCAssert(performer, @"");
SCAssert(bookKeeper, @"");
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureScanningStateId;
}
- (void)stopScanWithCompletionHandler:(dispatch_block_t)completionHandler
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"stop scan asynchronously.");
[SCCaptureWorker stopScanWithCompletionHandler:completionHandler resource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
// Intentionally No Op, this will be removed once CCAM-13851 gets resolved.
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,26 @@
//
// SCCaptureUninitializedState.h
// Snapchat
//
// Created by Lin Jia on 10/19/17.
//
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
/*
State which handles capture initialialization, which should be used only once for every app life span.
*/
@class SCQueuePerformer;
@interface SCCaptureUninitializedState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,70 @@
//
// SCCaptureUninitializedState.m
// Snapchat
//
// Created by Lin Jia on 10/19/17.
//
//
#import "SCCaptureUninitializedState.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureUninitializedState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureUninitializedState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureUninitializedStateId;
}
- (void)initializeCaptureWithDevicePosition:(SCManagedCaptureDevicePosition)devicePosition
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"Setting up with devicePosition:%lu", (unsigned long)devicePosition);
// TODO: we need to push completionHandler to a payload and let intializedState handle.
[[SCManagedCapturerV1 sharedInstance] setupWithDevicePosition:devicePosition completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureInitializedStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,22 @@
//
// SCStateTransitionPayload.h
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureStateUtil.h"
#import <Foundation/Foundation.h>
@interface SCStateTransitionPayload : NSObject
@property (nonatomic, readonly, assign) SCCaptureStateMachineStateId fromState;
@property (nonatomic, readonly, assign) SCCaptureStateMachineStateId toState;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState toState:(SCCaptureStateMachineStateId)toState;
@end

View File

@ -0,0 +1,27 @@
//
// SCStateTransitionPayload.m
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
@implementation SCStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState toState:(SCCaptureStateMachineStateId)toState
{
self = [super init];
if (self) {
SCAssert(fromState != toState, @"");
SCAssert(fromState > SCCaptureBaseStateId && fromState < SCCaptureStateMachineStateIdCount, @"");
SCAssert(toState > SCCaptureBaseStateId && toState < SCCaptureStateMachineStateIdCount, @"");
_fromState = fromState;
_toState = toState;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureImageState.h
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureImageState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,65 @@
//
// SCCaptureImageState.m
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureImageState.h"
#import "SCCaptureImageStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureImageState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureImageState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCAssert(payload.toState == [self stateId], @"");
if (![payload isKindOfClass:[SCCaptureImageStateTransitionPayload class]]) {
SCAssertFail(@"wrong payload pass in");
[_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
return;
}
SCCaptureImageStateTransitionPayload *captureImagePayload = (SCCaptureImageStateTransitionPayload *)payload;
[SCCaptureWorker
captureStillImageWithCaptureResource:resource
aspectRatio:captureImagePayload.aspectRatio
captureSessionID:captureImagePayload.captureSessionID
shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
completionHandler:captureImagePayload.block
context:context];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureImageStateId;
}
@end

View File

@ -0,0 +1,29 @@
//
// SCCaptureImageStateTransitionPayload.h
// Snapchat
//
// Created by Lin Jia on 1/9/18.
//
#import "SCCaptureCommon.h"
#import "SCStateTransitionPayload.h"
#import <Foundation/Foundation.h>
@interface SCCaptureImageStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_capture_still_image_completion_handler_t block;
@property (nonatomic, readonly, assign) CGFloat aspectRatio;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block;
@end

View File

@ -0,0 +1,27 @@
//
// SCCaptureImageStateTransitionPayload.m
// Snapchat
//
// Created by Lin Jia on 1/9/18.
//
#import "SCCaptureImageStateTransitionPayload.h"
@implementation SCCaptureImageStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_captureSessionID = captureSessionID;
_aspectRatio = aspectRatio;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureImageWhileRecordingState.h
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureImageWhileRecordingState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,85 @@
//
// SCCaptureImageWhileRecordingState.m
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureImageWhileRecordingState.h"
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureImageWhileRecordingState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureImageWhileRecordingState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureImageWhileRecordingStateId;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCAssert(payload.fromState == SCCaptureRecordingStateId, @"");
SCAssert(payload.toState == [self stateId], @"");
SCAssert([payload isKindOfClass:[SCCaptureImageWhileRecordingStateTransitionPayload class]], @"");
;
SCCaptureImageWhileRecordingStateTransitionPayload *captureImagePayload =
(SCCaptureImageWhileRecordingStateTransitionPayload *)payload;
@weakify(self);
sc_managed_capturer_capture_still_image_completion_handler_t block =
^(UIImage *fullScreenImage, NSDictionary *metadata, NSError *error, SCManagedCapturerState *state) {
captureImagePayload.block(fullScreenImage, metadata, error, state);
[_performer perform:^{
@strongify(self);
[self _cancelRecordingWithContext:context resource:resource];
}];
};
[SCCaptureWorker
captureStillImageWithCaptureResource:resource
aspectRatio:captureImagePayload.aspectRatio
captureSessionID:captureImagePayload.captureSessionID
shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
completionHandler:block
context:context];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
}
- (void)_cancelRecordingWithContext:(NSString *)context resource:(SCCaptureResource *)resource
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker cancelRecordingWithCaptureResource:resource];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,29 @@
//
// SCCaptureImageWhileRecordingStateTransitionPayload.h
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureCommon.h"
#import "SCStateTransitionPayload.h"
#import <Foundation/Foundation.h>
@interface SCCaptureImageWhileRecordingStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_capture_still_image_completion_handler_t block;
@property (nonatomic, readonly, assign) CGFloat aspectRatio;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block;
@end

View File

@ -0,0 +1,27 @@
//
// SCCaptureImageWhileRecordingStateTransitionPayload.m
// Snapchat
//
// Created by Sun Lei on 22/02/2018.
//
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
@implementation SCCaptureImageWhileRecordingStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
captureSessionId:(NSString *)captureSessionID
aspectRatio:(CGFloat)aspectRatio
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_captureSessionID = captureSessionID;
_aspectRatio = aspectRatio;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureInitializedState.h
// Snapchat
//
// Created by Jingtian Yang on 20/12/2017.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureInitializedState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,68 @@
//
// SCCaptureInitializedState.m
// Snapchat
//
// Created by Jingtian Yang on 20/12/2017.
//
#import "SCCaptureInitializedState.h"
#import "SCCapturerToken.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureInitializedState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureInitializedState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureInitializedStateId;
}
- (void)startRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"startRunningAsynchronouslyWithCompletionHandler called. token: %@", token);
[SCCaptureWorker startRunningWithCaptureResource:resource token:token completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureRecordingState.h
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureRecordingState : SCCaptureBaseState
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,114 @@
//
// SCCaptureRecordingState.m
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureRecordingState.h"
#import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
#import "SCCaptureRecordingStateTransitionPayload.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
@interface SCCaptureRecordingState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureRecordingState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(resource.queuePerformer);
SCAssert(payload.toState == [self stateId], @"");
if (![payload isKindOfClass:[SCCaptureRecordingStateTransitionPayload class]]) {
SCAssertFail(@"wrong payload pass in");
[_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
return;
}
SCCaptureRecordingStateTransitionPayload *recordingPayload = (SCCaptureRecordingStateTransitionPayload *)payload;
[SCCaptureWorker startRecordingWithCaptureResource:resource
outputSettings:recordingPayload.outputSettings
audioConfiguration:recordingPayload.configuration
maxDuration:recordingPayload.maxDuration
fileURL:recordingPayload.fileURL
captureSessionID:recordingPayload.captureSessionID
completionHandler:recordingPayload.block];
}
- (void)stopRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker stopRecordingWithCaptureResource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
[SCCaptureWorker cancelRecordingWithCaptureResource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureRecordingStateId;
}
- (void)captureStillImageWithResource:(SCCaptureResource *)resource
aspectRatio:(CGFloat)aspectRatio
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCCaptureImageWhileRecordingStateTransitionPayload *payload = [
[SCCaptureImageWhileRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRecordingStateId
toState:SCCaptureImageWhileRecordingStateId
captureSessionId:captureSessionID
aspectRatio:aspectRatio
completionHandler:completionHandler];
[_delegate currentState:self
requestToTransferToNewState:SCCaptureImageWhileRecordingStateId
payload:payload
context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,41 @@
//
// SCCaptureRecordingStateTransitionPayload.h
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureCommon.h"
#import "SCManagedVideoCapturerOutputSettings.h"
#import "SCStateTransitionPayload.h"
#import <SCAudio/SCAudioConfiguration.h>
#import <Foundation/Foundation.h>
@interface SCCaptureRecordingStateTransitionPayload : SCStateTransitionPayload
@property (nonatomic, readonly, strong) SCManagedVideoCapturerOutputSettings *outputSettings;
@property (nonatomic, readonly, strong) SCAudioConfiguration *configuration;
@property (nonatomic, readonly, assign) NSTimeInterval maxDuration;
@property (nonatomic, readonly, strong) NSURL *fileURL;
@property (nonatomic, readonly, strong) NSString *captureSessionID;
@property (nonatomic, readonly, copy) sc_managed_capturer_start_recording_completion_handler_t block;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
audioConfiguration:(SCAudioConfiguration *)configuration
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)block;
@end

View File

@ -0,0 +1,33 @@
//
// SCCaptureRecordingStateTransitionPayload.m
// Snapchat
//
// Created by Jingtian Yang on 12/01/2018.
//
#import "SCCaptureRecordingStateTransitionPayload.h"
@implementation SCCaptureRecordingStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState
toState:(SCCaptureStateMachineStateId)toState
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
audioConfiguration:configuration
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)block
{
self = [super initWithFromState:fromState toState:toState];
if (self) {
_outputSettings = outputSettings;
_configuration = configuration;
_maxDuration = maxDuration;
_fileURL = fileURL;
_captureSessionID = captureSessionID;
_block = block;
}
return self;
}
@end

View File

@ -0,0 +1,22 @@
//
// SCCaptureRunningState.h
// Snapchat
//
// Created by Jingtian Yang on 08/01/2018.
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
@class SCQueuePerformer;
@interface SCCaptureRunningState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,176 @@
//
// SCCaptureRunningState.m
// Snapchat
//
// Created by Jingtian Yang on 08/01/2018.
//
#import "SCCaptureRunningState.h"
#import "SCCaptureImageStateTransitionPayload.h"
#import "SCCaptureRecordingStateTransitionPayload.h"
#import "SCCaptureWorker.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import "SCScanConfiguration.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureRunningState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureRunningState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (void)captureStillImageWithResource:(SCCaptureResource *)resource
aspectRatio:(CGFloat)aspectRatio
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCCaptureImageStateTransitionPayload *payload =
[[SCCaptureImageStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
toState:SCCaptureImageStateId
captureSessionId:captureSessionID
aspectRatio:aspectRatio
completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureImageStateId payload:payload context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureRunningStateId;
}
- (void)startRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"startRunningAsynchronouslyWithCompletionHandler called. token: %@", token);
[SCCaptureWorker startRunningWithCaptureResource:resource token:token completionHandler:completionHandler];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)stopRunningWithCapturerToken:(SCCapturerToken *)token
resource:(SCCaptureResource *)resource
completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
SCLogCapturerInfo(@"Stop running asynchronously. token:%@", token);
if ([[SCManagedCapturerV1 sharedInstance] stopRunningWithCaptureToken:token
completionHandler:completionHandler
context:context]) {
[_delegate currentState:self
requestToTransferToNewState:SCCaptureInitializedStateId
payload:nil
context:context];
}
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)startScanWithScanConfiguration:(SCScanConfiguration *)configuration
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"Start scan on preview asynchronously. configuration:%@", configuration);
SCAssertPerformer(_performer);
[SCCaptureWorker startScanWithScanConfiguration:configuration resource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureScanningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)prepareForRecordingWithResource:(SCCaptureResource *)resource
audioConfiguration:(SCAudioConfiguration *)configuration
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
[SCCaptureWorker prepareForRecordingWithAudioConfiguration:configuration resource:resource];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)startRecordingWithResource:(SCCaptureResource *)resource
audioConfiguration:(SCAudioConfiguration *)configuration
outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
maxDuration:(NSTimeInterval)maxDuration
fileURL:(NSURL *)fileURL
captureSessionID:(NSString *)captureSessionID
completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)completionHandler
context:(NSString *)context
{
SCTraceODPCompatibleStart(2);
SCAssertPerformer(_performer);
SCCaptureRecordingStateTransitionPayload *payload =
[[SCCaptureRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
toState:SCCaptureRecordingStateId
outputSettings:outputSettings
audioConfiguration:configuration
maxDuration:maxDuration
fileURL:fileURL
captureSessionID:captureSessionID
completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRecordingStateId payload:payload context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
// Intentionally No Op, this will be removed once CCAM-13851 gets resolved.
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,18 @@
//
// SCCaptureScanningState.h
// Snapchat
//
// Created by Xiaokang Liu on 09/01/2018.
//
#import "SCCaptureBaseState.h"
@class SCQueuePerformer;
@interface SCCaptureScanningState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,75 @@
//
// SCCaptureScanningState.m
// Snapchat
//
// Created by Xiaokang Liu on 09/01/2018.
//
#import "SCCaptureScanningState.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureScanningState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureScanningState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
SCAssert(delegate, @"");
SCAssert(performer, @"");
SCAssert(bookKeeper, @"");
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureScanningStateId;
}
- (void)stopScanWithCompletionHandler:(dispatch_block_t)completionHandler
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"stop scan asynchronously.");
[SCCaptureWorker stopScanWithCompletionHandler:completionHandler resource:resource];
[_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
- (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
{
// Intentionally No Op, this will be removed once CCAM-13851 gets resolved.
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,26 @@
//
// SCCaptureUninitializedState.h
// Snapchat
//
// Created by Lin Jia on 10/19/17.
//
//
#import "SCCaptureBaseState.h"
#import <Foundation/Foundation.h>
/*
State which handles capture initialialization, which should be used only once for every app life span.
*/
@class SCQueuePerformer;
@interface SCCaptureUninitializedState : SCCaptureBaseState
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate;
@end

View File

@ -0,0 +1,70 @@
//
// SCCaptureUninitializedState.m
// Snapchat
//
// Created by Lin Jia on 10/19/17.
//
//
#import "SCCaptureUninitializedState.h"
#import "SCManagedCapturerLogging.h"
#import "SCManagedCapturerV1_Private.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCQueuePerformer.h>
#import <SCFoundation/SCTraceODPCompatible.h>
@interface SCCaptureUninitializedState () {
__weak id<SCCaptureStateDelegate> _delegate;
SCQueuePerformer *_performer;
}
@end
@implementation SCCaptureUninitializedState
- (instancetype)initWithPerformer:(SCQueuePerformer *)performer
bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
delegate:(id<SCCaptureStateDelegate>)delegate
{
self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
if (self) {
_delegate = delegate;
_performer = performer;
}
return self;
}
- (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
resource:(SCCaptureResource *)resource
context:(NSString *)context
{
// No op.
}
- (SCCaptureStateMachineStateId)stateId
{
return SCCaptureUninitializedStateId;
}
- (void)initializeCaptureWithDevicePosition:(SCManagedCaptureDevicePosition)devicePosition
resource:(SCCaptureResource *)resource
completionHandler:(dispatch_block_t)completionHandler
context:(NSString *)context
{
SCAssertPerformer(_performer);
SCTraceODPCompatibleStart(2);
SCLogCapturerInfo(@"Setting up with devicePosition:%lu", (unsigned long)devicePosition);
// TODO: we need to push completionHandler to a payload and let intializedState handle.
[[SCManagedCapturerV1 sharedInstance] setupWithDevicePosition:devicePosition completionHandler:completionHandler];
[_delegate currentState:self requestToTransferToNewState:SCCaptureInitializedStateId payload:nil context:context];
NSString *apiName =
[NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
[self.bookKeeper logAPICalled:apiName context:context];
}
@end

View File

@ -0,0 +1,22 @@
//
// SCStateTransitionPayload.h
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCCaptureStateUtil.h"
#import <Foundation/Foundation.h>
@interface SCStateTransitionPayload : NSObject
@property (nonatomic, readonly, assign) SCCaptureStateMachineStateId fromState;
@property (nonatomic, readonly, assign) SCCaptureStateMachineStateId toState;
SC_INIT_AND_NEW_UNAVAILABLE
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState toState:(SCCaptureStateMachineStateId)toState;
@end

View File

@ -0,0 +1,27 @@
//
// SCStateTransitionPayload.m
// Snapchat
//
// Created by Lin Jia on 1/8/18.
//
#import "SCStateTransitionPayload.h"
#import <SCFoundation/SCAssertWrapper.h>
@implementation SCStateTransitionPayload
- (instancetype)initWithFromState:(SCCaptureStateMachineStateId)fromState toState:(SCCaptureStateMachineStateId)toState
{
self = [super init];
if (self) {
SCAssert(fromState != toState, @"");
SCAssert(fromState > SCCaptureBaseStateId && fromState < SCCaptureStateMachineStateIdCount, @"");
SCAssert(toState > SCCaptureBaseStateId && toState < SCCaptureStateMachineStateIdCount, @"");
_fromState = fromState;
_toState = toState;
}
return self;
}
@end

View File

@ -0,0 +1,13 @@
//
// UIScreen+Debug.h
// Snapchat
//
// Created by Derek Peirce on 6/1/17.
// Copyright © 2017 Snapchat, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIScreen (Debug)
@end

View File

@ -0,0 +1,28 @@
#import "UIScreen+Debug.h"
#import <SCFoundation/SCAppEnvironment.h>
#import <SCFoundation/SCLog.h>
#import <objc/runtime.h>
@implementation UIScreen (Debug)
+ (void)load
{
if (SCIsPerformanceLoggingEnabled()) {
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
SEL setBrightnessSelector = @selector(setBrightness:);
SEL setBrightnessLoggerSelector = @selector(logged_setBrightness:);
Method originalMethod = class_getInstanceMethod(self, setBrightnessSelector);
Method extendedMethod = class_getInstanceMethod(self, setBrightnessLoggerSelector);
method_exchangeImplementations(originalMethod, extendedMethod);
});
}
}
- (void)logged_setBrightness:(CGFloat)brightness
{
SCLogGeneralInfo(@"Setting brightness from %f to %f", self.brightness, brightness);
[self logged_setBrightness:brightness];
}
@end