Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/CSFBAudioEngine/Player/AudioPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ class AudioPlayer final {
isMuted = 1u << 2,
/// The ring buffer needs to be drained during the next render cycle
drainRequired = 1u << 3,
/// A ring buffer format change is pending
pendingFormatChange = 1u << 4,
/// The event message queue had insufficient space to record a render event
renderEventDropped = 1u << 4,
renderEventDropped = 1u << 5,
};

// Enable bitmask operations for `Flags`
Expand Down
15 changes: 10 additions & 5 deletions Sources/CSFBAudioEngine/Player/AudioPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,16 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re
}();

if (okToReconfigure) {
clearFlags(Flags::drainRequired);
formatMismatch = false;

os_log_debug(log_, "Non-gapless join for %{public}@", decoderState->decoder_);

auto renderFormat = decoderState->converter_.outputFormat;
if (NSError *error = nil; !configureProcessingGraphAndRingBufferForFormat(renderFormat, &error)) {
NSError *error = nil;
const auto reconfigured = configureProcessingGraphAndRingBufferForFormat(renderFormat, &error);

clearFlags(Flags::drainRequired | Flags::pendingFormatChange);
formatMismatch = false;
Comment thread
sbooth marked this conversation as resolved.

if (!reconfigured) {
decoderState->error_ = error;
decoderState->setFlags(DecoderState::Flags::cancelRequested);
continue;
Expand All @@ -1452,6 +1455,7 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re
}
}
} else {
setFlags(Flags::pendingFormatChange);
decoderState = nullptr;
}
}
Expand Down Expand Up @@ -1606,7 +1610,8 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re
isSilence = YES;
}

if (framesRead != frameCount) {
// A short frame count without a pending format change is unexpected
if (framesRead != frameCount && bits::is_clear(flags, Flags::pendingFormatChange)) {
if (!events_.enqueue(EventCommand::renderBufferUnderrun, timestamp.mHostTime, static_cast<uint32_t>(framesRead),
static_cast<uint32_t>(frameCount))) {
setFlags(Flags::renderEventDropped);
Comment thread
sbooth marked this conversation as resolved.
Outdated
Expand Down
Loading