react-native-vision-camera/package/ios/Extensions/AVAudioSession+updateCategory.swift
Marc Rousavy cf8f3d05e3
fix: Fix Video Recording delay and improve startRecording() performance (#2192)
* fix: Add more logs

* perf: Init audio AVAssetWriter in parallel

* chore: Log Audio Session activation

* perf: Init Audio Session asynchronously

* chore: Log when category changed

* fix: Revert lazy audio initialization

* Update Podfile.lock

* Pass `sourceFormatHint` to video and audio AVAssetWriter

* fix: Remove `sourceFormatHint` from Video Asset Writer

* Use default options for Audio Asset Writer

* Update Podfile.lock

* Revert "Use default options for Audio Asset Writer"

This reverts commit e575a14c5342ddc7f9db557d5e3915328ed9e798.

* Add time logs

* fix: Don't synchronize audio buffers, they are already in sync

* shouldOptimizeForNetworkUse = false

* fix: Only update `latestTimestamp` once video buffer has been written

* perf: Use `AVAssetWriterInput` instead of `AVAssetWriterInputPixelBufferAdaptor`

* fix: Fix Audio not being synchronized with Video

* Remove logs add comments

* Format

* feat: Set `.videoRecording` AVAudioSession mode

* Refactor `startRecording()` a bit

* Format

* chore: Throw error directly instead of double-checking
2023-11-22 17:53:10 +01:00

27 lines
954 B
Swift

//
// AVAudioSession+updateCategory.swift
// VisionCamera
//
// Created by Marc Rousavy on 01.06.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
import AVFoundation
import Foundation
extension AVAudioSession {
/**
Calls [setCategory] if the given category or options are not equal to the currently set category and options.
*/
func updateCategory(_ category: AVAudioSession.Category,
mode: AVAudioSession.Mode,
options: AVAudioSession.CategoryOptions = []) throws {
if self.category != category || categoryOptions.rawValue != options.rawValue || self.mode != mode {
ReactLogger.log(level: .info,
message: "Changing AVAudioSession category from \(self.category.rawValue) -> \(category.rawValue)")
try setCategory(category, mode: mode, options: options)
ReactLogger.log(level: .info, message: "AVAudioSession category changed!")
}
}
}