Skip to content

Commit 5341161

Browse files
committed
Remove FirstActiveDecoderStateWithDecodingNotComplete
1 parent cabd738 commit 5341161

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

Sources/CSFBAudioEngine/Player/AudioPlayer.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ class AudioPlayer final {
360360
/// Cancels all active decoders in sequence
361361
void CancelActiveDecoders() noexcept;
362362

363-
/// Returns the decoder state in `activeDecoders_` with the smallest sequence number that has not been canceled and has not completed decoding
364-
DecoderState * const _Nullable FirstActiveDecoderStateWithDecodingNotComplete() const noexcept;
365-
366-
/// Returns the decoder state in `activeDecoders_` with the smallest sequence number that has not been canceled
363+
/// Returns the first decoder state in `activeDecoders_` that has not been canceled
367364
DecoderState * const _Nullable FirstActiveDecoderState() const noexcept;
368365

369366
public:

Sources/CSFBAudioEngine/Player/AudioPlayer.mm

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ bool PerformSeek() noexcept
954954

955955
// Process cancellations
956956
auto signal = false;
957-
for(auto& decoderState : activeDecoders_) {
957+
for(const auto& decoderState : activeDecoders_) {
958958
if(const auto flags = decoderState->flags_.load(std::memory_order_acquire); !(flags & static_cast<unsigned int>(DecoderState::Flags::cancelRequested)))
959959
continue;
960960

@@ -999,7 +999,7 @@ bool PerformSeek() noexcept
999999
std::lock_guard lock{activeDecodersLock_};
10001000

10011001
// Rewind ensuing decoder states if possible to avoid discarding frames
1002-
for(auto& nextDecoderState : activeDecoders_) {
1002+
for(const auto& nextDecoderState : activeDecoders_) {
10031003
if(nextDecoderState->sequenceNumber_ <= decoderState->sequenceNumber_)
10041004
continue;
10051005

@@ -1033,7 +1033,17 @@ bool PerformSeek() noexcept
10331033
// Get the earliest decoder state that has not completed decoding
10341034
{
10351035
std::lock_guard lock{activeDecodersLock_};
1036-
decoderState = FirstActiveDecoderStateWithDecodingNotComplete();
1036+
1037+
const auto iter = std::ranges::find_if(activeDecoders_, [](const auto& decoderState) {
1038+
const auto flags = decoderState->flags_.load(std::memory_order_acquire);
1039+
constexpr auto mask = static_cast<unsigned int>(DecoderState::Flags::isCanceled) | static_cast<unsigned int>(DecoderState::Flags::decodingComplete);
1040+
return !(flags & mask);
1041+
});
1042+
1043+
if(iter != activeDecoders_.cend())
1044+
decoderState = (*iter).get();
1045+
else
1046+
decoderState = nullptr;
10371047
}
10381048

10391049
// Dequeue the next decoder if there are no decoders that haven't completed decoding
@@ -1755,7 +1765,7 @@ bool PerformSeek() noexcept
17551765

17561766
// Cancel all active decoders
17571767
auto signal = false;
1758-
for(auto& decoderState : activeDecoders_) {
1768+
for(const auto& decoderState : activeDecoders_) {
17591769
const auto flags = decoderState->flags_.load(std::memory_order_acquire);
17601770
if(!(flags & static_cast<unsigned int>(DecoderState::Flags::isCanceled))) {
17611771
decoderState->flags_.fetch_or(static_cast<unsigned int>(DecoderState::Flags::cancelRequested), std::memory_order_acq_rel);
@@ -1768,22 +1778,6 @@ bool PerformSeek() noexcept
17681778
dispatch_semaphore_signal(decodingSemaphore_);
17691779
}
17701780

1771-
SFB::AudioPlayer::DecoderState * const SFB::AudioPlayer::FirstActiveDecoderStateWithDecodingNotComplete() const noexcept
1772-
{
1773-
#if DEBUG
1774-
activeDecodersLock_.assert_owner();
1775-
#endif /* DEBUG */
1776-
1777-
const auto iter = std::ranges::find_if(activeDecoders_, [](const auto& decoderState) {
1778-
const auto flags = decoderState->flags_.load(std::memory_order_acquire);
1779-
constexpr auto mask = static_cast<unsigned int>(DecoderState::Flags::isCanceled) | static_cast<unsigned int>(DecoderState::Flags::decodingComplete);
1780-
return !(flags & mask);
1781-
});
1782-
if(iter == activeDecoders_.cend())
1783-
return nullptr;
1784-
return iter->get();
1785-
}
1786-
17871781
SFB::AudioPlayer::DecoderState * const SFB::AudioPlayer::FirstActiveDecoderState() const noexcept
17881782
{
17891783
#if DEBUG

0 commit comments

Comments
 (0)