mirror of
https://github.com/samsonjs/SJSAssetExportSession.git
synced 2026-04-27 14:57:46 +00:00
Code style and debuggability
This commit is contained in:
parent
658a844257
commit
127dbf296b
1 changed files with 15 additions and 8 deletions
|
|
@ -32,14 +32,19 @@ actor SampleWriter {
|
||||||
}
|
}
|
||||||
private var progressContinuation: AsyncStream<Float>.Continuation?
|
private var progressContinuation: AsyncStream<Float>.Continuation?
|
||||||
|
|
||||||
|
// MARK: Inputs
|
||||||
|
|
||||||
private let audioOutputSettings: [String: any Sendable]
|
private let audioOutputSettings: [String: any Sendable]
|
||||||
private let audioMix: AVAudioMix?
|
private let audioMix: AVAudioMix?
|
||||||
private let videoOutputSettings: [String: any Sendable]
|
private let videoOutputSettings: [String: any Sendable]
|
||||||
private let videoComposition: AVVideoComposition?
|
private let videoComposition: AVVideoComposition?
|
||||||
private let reader: AVAssetReader
|
|
||||||
private let writer: AVAssetWriter
|
|
||||||
private let duration: CMTime
|
private let duration: CMTime
|
||||||
private let timeRange: CMTimeRange
|
private let timeRange: CMTimeRange
|
||||||
|
|
||||||
|
// MARK: Internal state
|
||||||
|
|
||||||
|
private let reader: AVAssetReader
|
||||||
|
private let writer: AVAssetWriter
|
||||||
private var audioOutput: AVAssetReaderAudioMixOutput?
|
private var audioOutput: AVAssetReaderAudioMixOutput?
|
||||||
private var audioInput: AVAssetWriterInput?
|
private var audioInput: AVAssetWriterInput?
|
||||||
private var videoOutput: AVAssetReaderVideoCompositionOutput?
|
private var videoOutput: AVAssetReaderVideoCompositionOutput?
|
||||||
|
|
@ -204,9 +209,11 @@ actor SampleWriter {
|
||||||
|
|
||||||
private func encodeAudioTracks() async {
|
private func encodeAudioTracks() async {
|
||||||
// Don't do anything when we have no audio to encode.
|
// Don't do anything when we have no audio to encode.
|
||||||
guard audioInput != nil, audioOutput != nil else { return }
|
guard audioInput != nil, audioOutput != nil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return await withTaskCancellationHandler {
|
await withTaskCancellationHandler {
|
||||||
await withCheckedContinuation { continuation in
|
await withCheckedContinuation { continuation in
|
||||||
self.audioInput!.requestMediaDataWhenReady(on: queue) {
|
self.audioInput!.requestMediaDataWhenReady(on: queue) {
|
||||||
self.assumeIsolated { _self in
|
self.assumeIsolated { _self in
|
||||||
|
|
@ -238,10 +245,10 @@ actor SampleWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func encodeVideoTracks() async {
|
private func encodeVideoTracks() async {
|
||||||
return await withTaskCancellationHandler {
|
await withTaskCancellationHandler {
|
||||||
await withCheckedContinuation { continuation in
|
await withCheckedContinuation { continuation in
|
||||||
self.videoInput!.requestMediaDataWhenReady(on: queue) {
|
self.videoInput!.requestMediaDataWhenReady(on: queue) {
|
||||||
#warning("FIXME: why is this broken on macOS?!")
|
// NOTE: assumeIsolated crashes on macOS at the moment
|
||||||
self.assumeIsolated { _self in
|
self.assumeIsolated { _self in
|
||||||
guard !_self.isCancelled else {
|
guard !_self.isCancelled else {
|
||||||
log.debug("Cancelled while encoding video")
|
log.debug("Cancelled while encoding video")
|
||||||
|
|
@ -287,8 +294,8 @@ actor SampleWriter {
|
||||||
|
|
||||||
guard input.append(sampleBuffer) else {
|
guard input.append(sampleBuffer) else {
|
||||||
log.error("""
|
log.error("""
|
||||||
Failed to append audio sample buffer \(String(describing: sampleBuffer)) to
|
Failed to append sample buffer \(String(describing: sampleBuffer)) to input
|
||||||
input \(input.debugDescription)
|
\(input.debugDescription)
|
||||||
""")
|
""")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue