diff --git a/AudioStreaming/Streaming/AudioPlayer/Processors/AudioFileStreamProcessor.swift b/AudioStreaming/Streaming/AudioPlayer/Processors/AudioFileStreamProcessor.swift index 77d560e..49060b7 100644 --- a/AudioStreaming/Streaming/AudioPlayer/Processors/AudioFileStreamProcessor.swift +++ b/AudioStreaming/Streaming/AudioPlayer/Processors/AudioFileStreamProcessor.swift @@ -587,7 +587,7 @@ final class AudioFileStreamProcessor { fillUsedFrames(framesCount: framesAdded) return } else if status != 0 { - fileStreamCallback?(.raiseError(.codecError)) + raiseCodecError(resetting: converter) return } @@ -620,7 +620,7 @@ final class AudioFileStreamProcessor { fillUsedFrames(framesCount: framesAdded) continue packetProcess } else if status != 0 { - fileStreamCallback?(.raiseError(.codecError)) + raiseCodecError(resetting: converter) return } } else { @@ -651,13 +651,24 @@ final class AudioFileStreamProcessor { fillUsedFrames(framesCount: framesAdded) continue packetProcess } else if status != 0 { - fileStreamCallback?(.raiseError(.codecError)) + raiseCodecError(resetting: converter) return } } } } + /// Resets the converter and raises `.codecError`. + /// + /// A failed fill can leave the converter holding a span of `inInputData`, which is freed once the + /// packets proc returns; resetting drops it, as `processSeek()` does. + /// + /// - parameter converter: The `AudioConverterRef` that failed. + private func raiseCodecError(resetting converter: AudioConverterRef) { + AudioConverterReset(converter) + fileStreamCallback?(.raiseError(.codecError)) + } + /// Fills the `AudioBuffer` with data as required /// /// - parameter list: An `UnsafeMutableAudioBufferListPointer` object representing the buffer list be filled with data