Fixup AudioTrack locking

This commit is contained in:
Billy Laws 2022-01-22 19:27:16 +00:00 committed by PixelyIon
parent 727f83e969
commit 2e1a1a965d
2 changed files with 11 additions and 5 deletions

View File

@ -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) {

View File

@ -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);
}