a1eb465142
Replace Data/AudioPacket allocations with raw pointer callbacks through the entire audio pipeline. Ring buffer hands out direct pointers (or linearizes into a pre-allocated scratch buffer on wrap-around), converter accepts/emits pointers via its cached buffers, and output handler writes to stdout via write(2) with EINTR handling. Remove AudioPacket (dead code), --flush flag (no-op with raw write(2)). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
999 B
Swift
35 lines
999 B
Swift
import AudioTeeCore
|
|
import Foundation
|
|
|
|
/// CLI-specific output handler that writes raw PCM audio to stdout
|
|
/// and lifecycle messages to stderr via the logger.
|
|
class BinaryAudioOutputHandler: AudioOutputHandler {
|
|
private let fd = STDOUT_FILENO
|
|
|
|
func handleAudioData(_ pointer: UnsafeRawPointer, count: Int) {
|
|
var written = 0
|
|
while written < count {
|
|
let result = write(fd, pointer.advanced(by: written), count - written)
|
|
if result >= 0 {
|
|
written += result
|
|
} else if errno == EINTR {
|
|
continue
|
|
} else {
|
|
break // EPIPE, EIO, etc — consumer gone or real error
|
|
}
|
|
}
|
|
}
|
|
|
|
func handleMetadata(_ metadata: AudioStreamMetadata) {
|
|
AudioTeeLogging.logger.writeMessage(.metadata, data: metadata)
|
|
}
|
|
|
|
func handleStreamStart() {
|
|
AudioTeeLogging.logger.writeMessage(.streamStart, data: Optional<String>.none)
|
|
}
|
|
|
|
func handleStreamStop() {
|
|
AudioTeeLogging.logger.writeMessage(.streamStop, data: Optional<String>.none)
|
|
}
|
|
}
|