forked from rFlex/SCRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCRecorder.h
429 lines (354 loc) · 12.1 KB
/
SCRecorder.h
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
//
// SCRecorder.h
// SCRecorder
//
// Created by Simon CORSIN on 27/03/14.
// Copyright (c) 2014 rFlex. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "SCRecordSession.h"
#import "SCAssetExportSession.h"
#import "SCImageView.h"
#import "SCVideoConfiguration.h"
#import "SCAudioConfiguration.h"
#import "SCPhotoConfiguration.h"
#import "SCRecorderTools.h"
#import "SCRecorderDelegate.h"
// Convenience
#import "SCRecorderHeader.h"
@interface SCRecorder : NSObject<AVCaptureAudioDataOutputSampleBufferDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureFileOutputRecordingDelegate>
/**
Access the configuration for the video.
*/
@property (readonly, nonatomic) SCVideoConfiguration * __nonnull videoConfiguration;
/**
Access the configuration for the audio.
*/
@property (readonly, nonatomic) SCAudioConfiguration *__nonnull audioConfiguration;
/**
Access the configuration for the photo.
*/
@property (readonly, nonatomic) SCPhotoConfiguration *__nonnull photoConfiguration;
/**
Return whether the video is enabled and ready to use.
*/
@property (readonly, nonatomic) BOOL videoEnabledAndReady;
/**
Return whether the audio is enabled and ready to use.
*/
@property (readonly, nonatomic) BOOL audioEnabledAndReady;
/**
Will be true if the SCRecorder is currently recording
*/
@property (readonly, nonatomic) BOOL isRecording;
/**
Change the flash mode on the camera
*/
@property (assign, nonatomic) SCFlashMode flashMode;
/**
Determine whether the device has flash
*/
@property (nonatomic, readonly) BOOL deviceHasFlash;
/**
Change the current used device
*/
@property (assign, nonatomic) AVCaptureDevicePosition device;
/**
The zoom factor applied to the video.
*/
@property (assign, nonatomic) CGFloat videoZoomFactor;
/**
The max zoom factor for the current device
*/
@property (assign, nonatomic) CGFloat maxVideoZoomFactor;
/**
Returns the max zoom factor for the given device
*/
- (CGFloat)maxVideoZoomFactorForDevice:(AVCaptureDevicePosition)devicePosition;
/**
Whether the zoom should be reset whenever the device changes.
*/
@property (assign, nonatomic) BOOL resetZoomOnChangeDevice;
/**
Get the current focus mode used by the camera device
*/
@property (readonly, nonatomic) AVCaptureFocusMode focusMode;
/**
Will be true if the camera is adjusting the focus.
This property is KVO observable.
*/
@property (readonly, nonatomic) BOOL isAdjustingFocus;
/**
Will be true if the camera is adjusting exposure.
This property is KVO observable.
*/
@property (readonly, nonatomic) BOOL isAdjustingExposure;
/**
The session preset used for the AVCaptureSession
*/
@property (copy, nonatomic) NSString *__nonnull captureSessionPreset;
/**
The value of this property defaults to YES, causing the capture session to automatically configure the app’s shared AVAudioSession instance for optimal recording.
If you set this property’s value to NO, your app is responsible for selecting appropriate audio session settings. Recording may fail if the audio session’s settings are incompatible with the capture session.
*/
@property (assign, nonatomic) BOOL automaticallyConfiguresApplicationAudioSession;
/**
The captureSession. This will be null until prepare or startRunning has
been called. Calling unprepare will set this property to null again.
*/
@property (readonly, nonatomic) AVCaptureSession *__nullable captureSession;
/**
Whether the recorder has been prepared.
*/
@property (readonly, nonatomic) BOOL isPrepared;
/**
The preview layer used for the video preview
*/
@property (readonly, nonatomic) AVCaptureVideoPreviewLayer *__nonnull previewLayer;
/**
Convenient way to set a view inside the preview layer
*/
@property (strong, nonatomic) UIView *__nullable previewView;
/**
If set, this render will receive every received frames as CIImage.
Can be useful for displaying a real time filter for example.
*/
@property (strong, nonatomic) SCImageView *__nullable SCImageView;
/**
Set the delegate used to receive messages for the SCRecorder
*/
@property (weak, nonatomic) id<SCRecorderDelegate> __nullable delegate;
/**
The record session to which the recorder will flow the camera/microphone buffers
*/
@property (strong, nonatomic) SCRecordSession *__nullable session;
/**
The video orientation. This is automatically set if autoSetVideoOrientation is enabled
*/
@property (assign, nonatomic) AVCaptureVideoOrientation videoOrientation;
/**
The video stabilization mode to use.
Default is AVCaptureVideoStabilizationModeStandard
*/
@property (assign, nonatomic) AVCaptureVideoStabilizationMode videoStabilizationMode;
/**
If true, the videoOrientation property will be set automatically
depending on the current device orientation
Default is NO
*/
@property (assign, nonatomic) BOOL autoSetVideoOrientation;
/**
The frameRate for the video
*/
@property (assign, nonatomic) CMTimeScale frameRate;
/**
The maximum record duration. When the record session record duration
reaches this bound, the recorder will automatically pause the recording,
end the current record segment and send recorder:didCompletesession: on the
delegate.
*/
@property (assign, nonatomic) CMTime maxRecordDuration;
/**
Whether the fast recording method should be enabled.
Enabling this will disallow pretty much every features provided
by SCVideoConfiguration and SCAudioConfiguration. It will internally
uses a AVCaptureMovieFileOutput that provides no settings. If you have
some performance issue, you can try enabling this.
Default is NO.
*/
@property (assign, nonatomic) BOOL fastRecordMethodEnabled;
/**
If maxRecordDuration is not kCMTimeInvalid,
this will contains a float between 0 and 1 representing the
recorded ratio on the current record session, 1 being fully recorded.
*/
@property (readonly, nonatomic) CGFloat ratioRecorded;
/**
If enabled, the recorder will initialize the session and create the record segments
when asking to record. Otherwise it will do it as soon as possible.
Default is YES
*/
@property (assign, nonatomic) BOOL initializeSessionLazily;
/**
If enabled, flips the video about its vertical axis and produce a mirror-image effect,
when recording with the front camera.
*/
@property (assign, nonatomic) BOOL mirrorOnFrontCamera;
/**
If enabled, mirrored video buffers like when using a front camera
will be written also as mirrored.
*/
@property (assign, nonatomic) BOOL keepMirroringOnWrite;
/**
Whether adjusting exposure is supported on the current camera device
*/
@property (readonly, nonatomic) BOOL exposureSupported;
/**
The current exposure point of interest
*/
@property (readonly, nonatomic) CGPoint exposurePointOfInterest;
/**
Whether the focus is supported on the current camera device
*/
@property (readonly, nonatomic) BOOL focusSupported;
/**
The current focus point of interest
*/
@property (readonly, nonatomic) CGPoint focusPointOfInterest;
/**
Will be true if the recorder is currently performing a focus because
the subject area changed.
*/
@property (readonly, nonatomic) BOOL subjectAreaChanged;
/**
Will contains an error if an error occured while reconfiguring
the underlying AVCaptureSession.
*/
@property (readonly, nonatomic) NSError *__nullable error;
/**
The underlying AVCaptureVideoDataOutput
*/
@property (readonly, nonatomic) AVCaptureVideoDataOutput *__nullable videoOutput;
/**
The underlying AVCaptureAudioDataOutput
*/
@property (readonly, nonatomic) AVCaptureAudioDataOutput *__nullable audioOutput;
/**
The underlying AVCaptureStillImageOutput
*/
@property (readonly, nonatomic) AVCaptureStillImageOutput *__nullable photoOutput;
/**
The dispatch queue that the SCRecorder uses for sending messages to the attached
SCRecordSession.
*/
@property (readonly, nonatomic) dispatch_queue_t __nonnull sessionQueue;
/**
Create a recorder
@return the newly created recorder
*/
+ (SCRecorder *__nonnull)recorder;
/**
Create the AVCaptureSession
Calling this method will set the captureSesion and configure it properly.
If an error occured during the creation of the captureSession, this methods will return NO.
*/
- (BOOL)prepare:(NSError *__nullable *__nullable)error;
/**
Close and destroy the AVCaptureSession.
*/
- (void)unprepare;
/**
Start the flow of inputs in the AVCaptureSession.
prepare will be called if it wasn't prepared before.
Calling this method will block until it's done.
If it returns NO, an error will be set in the "error" property.
*/
- (BOOL)startRunning;
/**
End the flow of inputs in the AVCaptureSession
This wont destroy the AVCaptureSession.
*/
- (void)stopRunning;
/**
Offer a way to configure multiple things at once.
You can call beginSessionConfiguration multiple times.
Only the latest most outer commitSessionConfiguration will effectively commit
the configuration
*/
- (void)beginConfiguration;
/**
Commit the session configuration after beginSessionConfiguration has been called
*/
- (void)commitConfiguration;
/**
Switch between the camera devices
*/
- (void)switchCaptureDevices;
/**
Convert a point from the previewView coordinates into a point of interest
@return a point of interest usable in the focus methods
*/
- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates;
/**
Convert the point of interest into a point from the previewView coordinates
*/
- (CGPoint)convertPointOfInterestToViewCoordinates:(CGPoint)pointOfInterest;
/**
Focus automatically at the given point of interest.
Once the focus is completed, the camera device will goes to locked mode
and won't try to do any further focus
@param point A point of interest between 0,0 and 1,1
*/
- (void)autoFocusAtPoint:(CGPoint)point;
/**
Continously focus at a point. The camera device detects when it needs to focus
and focus automatically when needed.
@param point A point of interest between 0,0 and 1,1,
*/
- (void)continuousFocusAtPoint:(CGPoint)point;
/**
Focus at the center then switch back to a continuous focus at the center.
*/
- (void)focusCenter;
/**
Refocus at the current position
*/
- (void)refocus;
/**
Lock the current focus and prevent any new further focus
*/
- (void)lockFocus;
/**
Set an active device format that supports the requested framerate and the current video size
This changes the frameRate.
@return whether the method has succeeded or not
*/
- (BOOL)setActiveFormatWithFrameRate:(CMTimeScale)frameRate error:(NSError *__nullable*__nullable)error;
/**
Set an active device format that supports the request framerate and size
This changes the frameRate.
@return whether the method has succeeded or not
*/
- (BOOL)setActiveFormatWithFrameRate:(CMTimeScale)frameRate width:(int)width andHeight:(int)height error:(NSError*__nullable*__nullable)error;
/**
Allow the recorder to append the sample buffers inside the current setted session
*/
- (void)record;
/**
Disallow the recorder to append the sample buffers inside the current setted session.
If a record segment has started, this will be either canceled or completed depending on
if it is empty or not.
*/
- (void)pause;
/**
Disallow the recorder to append the sample buffers inside the current setted session.
If a record segment has started, this will be either canceled or completed depending on
if it is empty or not.
@param completionHandler called on the main queue when the recorder is ready to record again.
*/
- (void)pause:( void(^ __nullable)()) completionHandler;
/**
Capture a photo from the camera
@param completionHandler called on the main queue with the image taken or an error in case of a problem
*/
- (void)capturePhoto:(void(^ __nonnull)(NSError *__nullable error, UIImage *__nullable image))completionHandler;
/**
Signal to the recorder that the previewView frame has changed.
This will make the previewLayer to matches the size of the previewView.
*/
- (void)previewViewFrameChanged;
/**
Get an image representing the last output video buffer.
*/
- (UIImage *__nullable)snapshotOfLastVideoBuffer;
/**
Returns a shared recorder if you want to use the same instance throughout your app.
*/
+ (SCRecorder *__nonnull)sharedRecorder;
/**
Returns whether the current queue is the record session queue.
*/
+ (BOOL)isSessionQueue;
@end