Skip to content

Commit

Permalink
Merge pull request #122 from seriyvolk83/audio_crash_fix
Browse files Browse the repository at this point in the history
Fixing potential crash #101
  • Loading branch information
AFathi authored Dec 9, 2020
2 parents 63c9ebb + 0c9a76a commit b7e1fac
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ARVideoKit/Rendering/Writer/WritAR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
audioInput.expectsMediaDataInRealTime = true

audioBufferQueue.async {
self.session.startRunning()
self.session?.startRunning()
}

if assetWriter.canAdd(audioInput) {
Expand Down Expand Up @@ -208,7 +208,10 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
if let input = audioInput {
audioBufferQueue.async { [weak self] in
if input.isReadyForMoreMediaData && (self?.isRecording)! {
if let isRecording = self?.isRecording,
let session = self?.session,
input.isReadyForMoreMediaData && isRecording
&& session.isRunning {
input.append(sampleBuffer)
}
}
Expand All @@ -227,6 +230,7 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
}

if assetWriter.status == .writing {
isRecording = false
assetWriter.finishWriting(completionHandler: finished)
}
}
Expand All @@ -237,6 +241,7 @@ class WritAR: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
session.stopRunning()
}
}
isRecording = false
assetWriter.cancelWriting()
}
}
Expand Down

0 comments on commit b7e1fac

Please sign in to comment.