Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
recording callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Moldover committed Feb 7, 2018
1 parent f807a95 commit a74674e
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions Source/PBJVision.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ @interface PBJVision () <

CMTime _lastAudioTimestamp;

CMTime _audioToVideoRecordStartOffset;
BOOL makeRecordingStartCallback;

CMTime _lastVideoDisplayTimestamp;
CMTime _minDisplayDuration;
Expand Down Expand Up @@ -261,7 +261,6 @@ @implementation PBJVision
@synthesize maximumCaptureDuration = _maximumCaptureDuration;
@synthesize detectLowLight = _detectLowLight;
@synthesize luminanceValues = _luminanceValues;
@synthesize audioToVideoRecordStartOffset = _audioToVideoRecordStartOffset;

+ (NSString*)hardwareString
{
Expand Down Expand Up @@ -694,9 +693,11 @@ - (NSTimeInterval)startDiffFromAudioStartTimestamp:(CMTime)audioStartTimestamp
- (void)setAudioStartTimestamp:(CMTime)audioStartTimestamp
{
[self _enqueueBlockOnCaptureVideoQueue:^{
_audioToVideoRecordStartOffset = CMTimeSubtract(_startTimestamp, audioStartTimestamp);
DLog(@"_audioToVideoRecordStartOffset: %f", CMTimeGetSeconds(_audioToVideoRecordStartOffset));

CMTime audioOffset = CMTimeSubtract(_startTimestamp, audioStartTimestamp);
DLog(@"AudioVideoRecordOffset: %f", CMTimeGetSeconds(audioOffset));

makeRecordingStartCallback = NO;

if (CMTIME_IS_INVALID(_lastTimestamp)) {
_lastTimestamp = audioStartTimestamp;
_startTimestamp = audioStartTimestamp;
Expand Down Expand Up @@ -1905,12 +1906,10 @@ - (void)setupVideoCapture
return;
}

DLog(@"setting up video capture");

if (_flags.recording || _flags.paused)
return;
NSString *guid = [[NSUUID new] UUIDString];
NSString *outputPath = [NSString stringWithFormat:@"%@video_%@.mp4", [MagicFileManager uploadsDirectory], guid];
NSString *outputPath = [[MagicFileManager uploadsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", guid]];
NSURL *outputURL = [NSURL fileURLWithPath:outputPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:outputPath]) {
NSError *error = nil;
Expand Down Expand Up @@ -1953,9 +1952,8 @@ - (void)startVideoCapture
[self _enqueueBlockOnCaptureVideoQueue:^{
_startTimestamp = CMClockGetTime(CMClockGetHostTimeClock());
_lastTimestamp = kCMTimeInvalid;
//_lastTimestamp = _startTimestamp;
_lastAudioTimestamp = kCMTimeInvalid;
_audioToVideoRecordStartOffset = kCMTimeInvalid;
makeRecordingStartCallback = YES;
_totalPauseTime = kCMTimeZero;
_lastPauseTimestamp = kCMTimeInvalid;

Expand Down Expand Up @@ -2010,7 +2008,6 @@ - (void)resumeVideoCapture

DLog(@"resuming video capture");

//_audioToVideoRecordStartOffset = kCMTimeInvalid;
_flags.paused = NO;
_flags.interrupted = NO;

Expand Down Expand Up @@ -2224,10 +2221,8 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
}
}

CMTime currentTimestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);

if (_flags.recording && CMTIME_IS_INVALID(_audioToVideoRecordStartOffset)) {
// this will grab the info need to compute _audioToVideoRecordStartOffset
// this will kick off the performance in SingingViewController
if (_flags.recording && makeRecordingStartCallback) {
if ([_delegate respondsToSelector:@selector(visionWillStartWritingVideo:fileURL:)]) {
[_delegate visionWillStartWritingVideo:self fileURL:_mediaWriter.outputURL];
}
Expand Down Expand Up @@ -2283,7 +2278,8 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
_lastAudioTimestamp = time;
}
}


CMTime currentTimestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
if (!_flags.interrupted && CMTIME_IS_VALID(currentTimestamp) && CMTIME_IS_VALID(_startTimestamp) && CMTIME_IS_VALID(_maximumCaptureDuration)) {

if (CMTIME_IS_VALID(_lastTimestamp)) {
Expand Down Expand Up @@ -2668,7 +2664,6 @@ - (void)mediaWriterDidFinishRecording:(PBJMediaWriter *)mediaWriter
}
}
#endif

_mediaWriter = nil;

[self _enqueueBlockOnMainQueue:^{
Expand Down

0 comments on commit a74674e

Please sign in to comment.