forked from rFlex/SCRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCRecordSession.h
executable file
·242 lines (198 loc) · 7.61 KB
/
SCRecordSession.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
//
// SCSession.h
// SCAudioVideoRecorder
//
// Created by Simon CORSIN on 27/03/14.
// Copyright (c) 2014 rFlex. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "SCRecordSessionSegment.h"
#define kRecordSessionDefaultVideoCodec AVVideoCodecH264
#define kRecordSessionDefaultVideoScalingMode AVVideoScalingModeResizeAspectFill
#define kRecordSessionDefaultOutputBitPerPixel 12
#define kRecordSessionDefaultAudioBitrate 128000
#define kRecordSessionDefaultAudioFormat kAudioFormatMPEG4AAC
extern NSString *__nonnull const SCRecordSessionSegmentFilenameKey;
extern NSString *__nonnull const SCRecordSessionSegmentFilenamesKey;
extern NSString *__nonnull const SCRecordSessionSegmentsKey;
extern NSString *__nonnull const SCRecordSessionDurationKey;
extern NSString *__nonnull const SCRecordSessionIdentifierKey;
extern NSString *__nonnull const SCRecordSessionSegmentInfoKey;
extern NSString *__nonnull const SCRecordSessionDateKey;
extern NSString *__nonnull const SCRecordSessionDirectoryKey;
extern NSString *__nonnull const SCRecordSessionTemporaryDirectory;
extern NSString *__nonnull const SCRecordSessionCacheDirectory;
extern NSString *__nonnull const SCRecordSessionDocumentDirectory;
@class SCRecordSession;
@class SCRecorder;
@interface SCRecordSession : NSObject
//////////////////
// GENERAL SETTINGS
////
@property (assign, nonatomic) BOOL recordSegmentStart;
/**
An unique identifier generated when creating this record session.
*/
@property (readonly, nonatomic) NSString *__nonnull identifier;
/**
The date when this record session was created.
*/
@property (readonly, nonatomic) NSDate *__nonnull date;
/**
The directory to which the record segments will be saved.
Can be either SCRecordSessionTemporaryDirectory or an arbritary directory.
Default is SCRecordSessionTemporaryDirectory.
*/
@property (copy, nonatomic) NSString *__nonnull segmentsDirectory;
/**
The output file type used for the AVAssetWriter.
If null, AVFileTypeMPEG4 will be used for a video file, AVFileTypeAppleM4A for an audio file
*/
@property (copy, nonatomic) NSString *__nullable fileType;
/**
The extension of every record segments.
If null, the SCRecordSession will figure out one depending on the fileType.
*/
@property (copy, nonatomic) NSString *__nullable fileExtension;
/**
The output url based on the identifier, the recordSegmentsDirectory and the fileExtension
*/
@property (readonly, nonatomic) NSURL *__nonnull outputUrl;
/**
Contains every record segment as SCRecordSessionSegment.
*/
@property (strong, nonatomic) NSArray<SCRecordSessionSegment *> *__nonnull segments;
/**
The duration of the whole recordSession including the current recording segment
and the previously added record segments.
*/
@property (readonly, nonatomic) CMTime duration;
/**
The duration of the recorded record segments.
*/
@property (readonly, atomic) CMTime segmentsDuration;
/**
The duration of the current recording segment.
*/
@property (readonly, atomic) CMTime currentSegmentDuration;
/**
True if a recordSegment has began
*/
@property (readonly, nonatomic) BOOL recordSegmentBegan;
/**
The recorder that is managing this SCRecordSession
*/
@property (readonly, nonatomic, weak) SCRecorder *__nullable recorder;
//////////////////
// PUBLIC METHODS
////
- (nonnull instancetype)init;
- (nonnull instancetype)initWithDictionaryRepresentation:(nonnull NSDictionary *)dictionaryRepresentation;
/**
Create a SCRecordSession
*/
+ (nonnull instancetype)recordSession;
/**
Create a SCRecordSession based on dictionary representation
*/
+ (nonnull instancetype)recordSession:(nonnull NSDictionary *)dictionaryRepresentation;
/**
Calling any method of SCRecordSession is thread safe. However,
if the record session is inside an SCRecorder instance, its state
might change between 2 calls you are making. Making any modification
within this block will ensure that you are the only one who has
access to any modification on this SCRecordSession.
*/
- (void)dispatchSyncOnSessionQueue:(void(^__nonnull)())block;
//////////////////////
/////// SEGMENTS
////
/**
Remove the record segment. Does not delete the associated file.
*/
- (void)removeSegment:(SCRecordSessionSegment *__nonnull)segment;
/**
Remove the record segment at the given index.
*/
- (void)removeSegmentAtIndex:(NSInteger)segmentIndex deleteFile:(BOOL)deleteFile;
/**
Add a recorded segment.
*/
- (void)addSegment:(SCRecordSessionSegment *__nonnull)segment;
/**
Insert a record segment.
*/
- (void)insertSegment:(SCRecordSessionSegment *__nonnull)segment atIndex:(NSInteger)segmentIndex;
/**
Remove all the record segments and their associated files.
*/
- (void)removeAllSegments;
/**
Remove all the record segments and their associated files if deleteFiles is true.
*/
- (void)removeAllSegments:(BOOL)deleteFiles;
/**
Remove the last segment safely. Does nothing if no segment were recorded.
*/
- (void)removeLastSegment;
/**
Cancel the session.
End the current recordSegment (if any) and call removeAllSegments
If you don't want a segment to be automatically added when calling this method,
you should remove the SCRecordSession from the SCRecorder
*/
- (void)cancelSession:(void(^ __nullable)())completionHandler;
/**
Merge the recorded record segments using the given AVAssetExportSessionPreset.
Returns the AVAssetExportSession used for exporting.
Returns nil and call the completion handler block synchronously if an error happened while preparing the export session.
*/
- (AVAssetExportSession *__nullable)mergeSegmentsUsingPreset:(NSString *__nonnull)exportSessionPreset completionHandler:(void(^__nonnull)(NSURL *__nullable outputUrl, NSError *__nullable error))completionHandler;
/**
Returns an asset representing all the record segments
from this record session. This can be called anytime.
*/
- (AVAsset *__nonnull)assetRepresentingSegments;
/**
Returns a player item representing all the record segments
from this record session and containing an audio mix that smooth
the transition between the segments.
*/
- (AVPlayerItem *__nonnull)playerItemRepresentingSegments;
/**
Append all the record segments to a given AVMutableComposition.
*/
- (void)appendSegmentsToComposition:(AVMutableComposition *__nonnull)composition;
/**
Append all the record segments to a given AVMutableComposition and adds the audio mix instruction
if audioMix is provided
*/
- (void)appendSegmentsToComposition:(AVMutableComposition *__nonnull)composition audioMix:(AVMutableAudioMix *__nullable)audioMix;
/**
Returns a dictionary that represents this SCRecordSession
This will only contains strings and can be therefore safely serialized
in any text format
*/
- (NSDictionary *__nonnull)dictionaryRepresentation;
/**
Stop the current segment and deinitialize the video and the audio.
This can be useful if the input video or audio profile changed.
*/
- (void)deinitialize;
/**
Start a new record segment.
This method is automatically called by the SCRecorder.
*/
- (void)beginSegment:(NSError*__nullable*__nullable)error;
/**
End the current record segment.
This method is automatically called by the SCRecorder
when calling [SCRecorder pause] if necessary.
segmentIndex contains the index of the segment recorded accessible
in the recordSegments array. If error is not null, if will be -1
If you don't remove the SCRecordSession from the SCRecorder while calling this method,
The SCRecorder might create a new recordSegment right after automatically if it is not paused.
*/
- (BOOL)endSegmentWithInfo:(NSDictionary *__nullable)info completionHandler:(void(^__nullable)(SCRecordSessionSegment *__nullable segment, NSError *__nullable error))completionHandler;
@end