Build on Linux: compile locally, link/sign on the iPhone; FFmpeg audio decoders; SDK stub patching

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-27 20:22:19 -05:00
commit 66f4e7e3ea

View file

@ -1,17 +1,36 @@
import AVFoundation
/// Decoder for formats Apple doesn't handle (Ogg Vorbis/Opus, WMA, APE, WavPack, Musepack, DSD, trackers…).
/// Backed by FFmpeg when the build links it (MULBERRY_FFMPEG); otherwise nothing opens.
/// Backed by FFmpeg (Native/ffdecode.c) when the build links it (MULBERRY_FFMPEG); otherwise nothing opens.
final class FFSource: AudioSource {
static func open(_ url: URL) -> FFSource? {
#if MULBERRY_FFMPEG
return FFSource(url: url)
#else
return nil
#endif
#if MULBERRY_FFMPEG
private let d: OpaquePointer
let frames: AVAudioFramePosition
private init(_ d: OpaquePointer) {
self.d = d
frames = AVAudioFramePosition(ff_frames(d))
}
deinit { ff_close(d) }
static func open(_ url: URL) -> FFSource? {
guard let d = ff_open(url.path) else { return nil }
return FFSource(d)
}
func read(into buffer: AVAudioPCMBuffer) -> Bool {
guard let ch = buffer.floatChannelData else { return false }
let n = ff_read(d, ch[0], ch[1], Int32(buffer.frameCapacity))
buffer.frameLength = AVAudioFrameCount(max(0, n))
return n > 0
}
func seek(to frame: AVAudioFramePosition) { ff_seek(d, Int64(frame)) }
#else
static func open(_ url: URL) -> FFSource? { nil }
var frames: AVAudioFramePosition { 0 }
func read(into buffer: AVAudioPCMBuffer) -> Bool { false }
func seek(to frame: AVAudioFramePosition) {}
#endif
}