-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMCaptureImageControllerBase.m
More file actions
135 lines (112 loc) · 3.22 KB
/
CMCaptureImageControllerBase.m
File metadata and controls
135 lines (112 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#import "CMCaptureImageControllerBase.h"
@interface CMCaptureImageControllerBase()
@end
@implementation CMCaptureImageControllerBase
ARC_SYNTHESIZEOUTLET(delegate);
ARC_SYNTHESIZEOUTLET(outletCaptureStillModel);
ARC_SYNTHESIZEOUTLET(outletCaptureVideoModel);
ARC_SYNTHESIZEOUTLET(outletCapturePreviewView);
ARC_SYNTHESIZE(captureVideoQueue,__captureVideoQueue);
- (instancetype) init
{
if ((self=[super init])!=nil)
{
__captureVideoQueue = dispatch_queue_create("CMCaptureImageControllerBase.captureVideoQueue", DISPATCH_QUEUE_SERIAL);
REQUIRED_DEBUG(__captureVideoQueue);
}
return self;
}
- (void)dealloc
{
/* ideally, we want the subclasses to teardown */
if (REQUIRED_DEBUG(!self.captureTeardownNeeded))
[self captureTeardown];
if (self.captureVideoQueue!=0)
{
/* make sure queue is empty */
dispatch_sync(self.captureVideoQueue,^{});
ARC_DISPATCH_RELEASE(__captureVideoQueue);
__captureVideoQueue = 0;
}
ARC_SUPERDEALLOC(self);
}
- (void)captureDisplayErrorOnMainQueue:(NSError *)error messageTitle:(NSString *)messageTitle
{
}
- (BOOL)captureRequirementNilError:(NSError*)error message:(NSString*)message
{
BOOL result = REQUIRED_NSERROR_NIL(error);
if (result==NO)
{
[self captureDisplayErrorOnMainQueue:error messageTitle:message];
}
return result;
}
-(dispatch_queue_t) captureSavingQueue
{
return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0L);
}
- (BOOL)captureSetupNeeded
{
return YES;
}
- (void)captureSetup
{
NSLOG_METHOD(self);
}
#pragma mark -
- (BOOL)captureTeardownNeeded
{
return YES;
}
- (void)captureTeardown
{
NSLOG_METHOD(self);
}
- (NSString*)captureStillPictureFileName {
NSURL* defaultFolderURL = [[[NSFileManager defaultManager] URLsForDirectory:NSPicturesDirectory inDomains:NSUserDomainMask] objectAtIndex:0];
NSString* defaultFolderPath = [[defaultFolderURL filePathURL] path];
NSString* classFileName = NSStringFromClass([self class]);
return [[defaultFolderPath stringByAppendingPathComponent:classFileName] stringByAppendingPathExtension:@"JPG"];
}
-(void) captureWriteImageData:(NSData*)imageData imageMetadata:(id)imageMetadata
{
if (REQUIRED_DEBUG(imageData!=nil))
{
ARC_RETAIN(imageData);
dispatch_async(self.captureSavingQueue,^{
[imageData writeToFile:self.captureStillPictureFileName atomically:YES];
ARC_RELEASE(imageData);
});
}
}
-(void) captureSnapStillPictureFromSampleBuffer:(CMSampleBufferRef)imageDataSampleBuffer
{
NSLOG_METHOD(self);
}
- (IBAction) actionCaptureSnapshot:(id)sender
{
NSLOG_METHOD(sender);
}
#pragma mark -
- (void)captureOutputImageUsingDelegate:(CMCaptureImageModel*)model imageBuffer:(CVImageBufferRef)imageBuffer
{
if (delegate!=nil)
{
if (REQUIRED_DEBUG([(id)delegate respondsToSelector:@selector(captureController:outputCaptureImage:imageBuffer:)]))
{
[delegate captureController:self outputCaptureImage:model imageBuffer:imageBuffer];
}
}
}
- (void)captureOutputImageUsingDelegate:(CMCaptureImageModel*)model sampleBuffer:(CMSampleBufferRef)sampleBuffer
{
if (delegate!=nil)
{
if (REQUIRED_DEBUG([(id)delegate respondsToSelector:@selector(captureController:outputCaptureImage:sampleBuffer:)]))
{
[delegate captureController:self outputCaptureImage:model sampleBuffer:sampleBuffer];
}
}
}
@end