mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:55:08 +01:00
Fixup AudioTrack locking
This commit is contained in:
parent
727f83e969
commit
2e1a1a965d
@ -35,7 +35,6 @@ namespace skyline::audio {
|
||||
std::lock_guard trackGuard(trackLock);
|
||||
|
||||
audioTracks.erase(std::remove(audioTracks.begin(), audioTracks.end(), track), audioTracks.end());
|
||||
track.reset();
|
||||
}
|
||||
|
||||
oboe::DataCallbackResult Audio::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames) {
|
||||
|
@ -16,11 +16,18 @@ namespace skyline::audio {
|
||||
}
|
||||
|
||||
void AudioTrack::Stop() {
|
||||
while (!identifiers.end()->released);
|
||||
auto allSamplesReleased{[&]() {
|
||||
std::scoped_lock lock{bufferLock};
|
||||
return identifiers.empty() || identifiers.end()->released;
|
||||
}};
|
||||
|
||||
while (!allSamplesReleased());
|
||||
playbackState = AudioOutState::Stopped;
|
||||
}
|
||||
|
||||
bool AudioTrack::ContainsBuffer(u64 tag) {
|
||||
std::scoped_lock lock(bufferLock);
|
||||
|
||||
// Iterate from front of queue as we don't want released samples
|
||||
for (auto identifier{identifiers.crbegin()}; identifier != identifiers.crend(); identifier++) {
|
||||
if (identifier->released)
|
||||
@ -35,7 +42,7 @@ namespace skyline::audio {
|
||||
|
||||
std::vector<u64> AudioTrack::GetReleasedBuffers(u32 max) {
|
||||
std::vector<u64> bufferIds;
|
||||
std::lock_guard trackGuard(bufferLock);
|
||||
std::scoped_lock lock(bufferLock);
|
||||
|
||||
for (u32 index{}; index < max; index++) {
|
||||
if (identifiers.empty() || !identifiers.back().released)
|
||||
@ -48,14 +55,14 @@ namespace skyline::audio {
|
||||
}
|
||||
|
||||
void AudioTrack::AppendBuffer(u64 tag, span<i16> buffer) {
|
||||
std::scoped_lock lock(bufferLock);
|
||||
|
||||
BufferIdentifier identifier{
|
||||
.released = false,
|
||||
.tag = tag,
|
||||
.finalSample = identifiers.empty() ? (buffer.size()) : (buffer.size() + identifiers.front().finalSample)
|
||||
};
|
||||
|
||||
std::lock_guard guard(bufferLock);
|
||||
|
||||
identifiers.push_front(identifier);
|
||||
samples.Append(buffer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user