diff --git a/Meta/gn/secondary/Userland/Libraries/LibMedia/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibMedia/BUILD.gn index 51eb30f7531..f8a47ff2f90 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibMedia/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibMedia/BUILD.gn @@ -12,7 +12,6 @@ shared_library("LibMedia") { "Audio/QOALoader.cpp", "Audio/QOATypes.cpp", "Audio/SampleFormats.cpp", - "Audio/UserSampleQueue.cpp", "Audio/VorbisComment.cpp", "Audio/WavLoader.cpp", ] diff --git a/Userland/Libraries/LibMedia/Audio/FlacTypes.h b/Userland/Libraries/LibMedia/Audio/FlacTypes.h index 64026a57561..86a986c1444 100644 --- a/Userland/Libraries/LibMedia/Audio/FlacTypes.h +++ b/Userland/Libraries/LibMedia/Audio/FlacTypes.h @@ -6,11 +6,11 @@ #pragma once -#include "Queue.h" #include "SampleFormats.h" #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibMedia/Audio/Queue.h b/Userland/Libraries/LibMedia/Audio/Queue.h deleted file mode 100644 index 6b8f2793d63..00000000000 --- a/Userland/Libraries/LibMedia/Audio/Queue.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2018-2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include "Sample.h" -#include - -namespace Audio { - -static constexpr size_t AUDIO_BUFFERS_COUNT = 128; -// The audio buffer size is specifically chosen to be about 1/1000th of a second (1ms). -// This has the biggest impact on latency and performance. -// The currently chosen value was not put here with much thought and a better choice is surely possible. -static constexpr size_t AUDIO_BUFFER_SIZE = 50; -using AudioQueue = Core::SharedSingleProducerCircularQueue, AUDIO_BUFFERS_COUNT>; - -} diff --git a/Userland/Libraries/LibMedia/Audio/UserSampleQueue.cpp b/Userland/Libraries/LibMedia/Audio/UserSampleQueue.cpp deleted file mode 100644 index 020cafb8b11..00000000000 --- a/Userland/Libraries/LibMedia/Audio/UserSampleQueue.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022, kleines Filmröllchen - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "UserSampleQueue.h" - -namespace Audio { - -void UserSampleQueue::append(FixedArray&& samples) -{ - Threading::MutexLocker lock(m_sample_mutex); - if (m_samples_to_discard != 0) - m_backing_samples = m_backing_samples.release_slice(m_samples_to_discard); - m_backing_samples.append(move(samples)); - fix_spans(); -} - -void UserSampleQueue::clear() -{ - discard_samples(size()); -} - -void UserSampleQueue::fix_spans() -{ - Threading::MutexLocker lock(m_sample_mutex); - m_enqueued_samples = m_backing_samples.spans(); - m_samples_to_discard = 0; -} - -Sample UserSampleQueue::operator[](size_t index) -{ - Threading::MutexLocker lock(m_sample_mutex); - return m_enqueued_samples[index]; -} - -void UserSampleQueue::discard_samples(size_t count) -{ - Threading::MutexLocker lock(m_sample_mutex); - m_samples_to_discard += count; - m_enqueued_samples = m_enqueued_samples.slice(count); -} - -size_t UserSampleQueue::size() -{ - Threading::MutexLocker lock(m_sample_mutex); - return m_enqueued_samples.size(); -} - -size_t UserSampleQueue::remaining_samples() -{ - Threading::MutexLocker lock(m_sample_mutex); - VERIFY(m_backing_samples.size() >= m_samples_to_discard); - return m_backing_samples.size() - m_samples_to_discard; -} - -bool UserSampleQueue::is_empty() -{ - Threading::MutexLocker lock(m_sample_mutex); - return m_enqueued_samples.is_empty(); -} - -} diff --git a/Userland/Libraries/LibMedia/Audio/UserSampleQueue.h b/Userland/Libraries/LibMedia/Audio/UserSampleQueue.h deleted file mode 100644 index 9d14222473a..00000000000 --- a/Userland/Libraries/LibMedia/Audio/UserSampleQueue.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, kleines Filmröllchen - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include "Sample.h" -#include -#include -#include -#include -#include - -namespace Audio { - -// A sample queue providing synchronized access to efficiently-stored segmented user-provided audio data. -class UserSampleQueue { - AK_MAKE_NONCOPYABLE(UserSampleQueue); - AK_MAKE_NONMOVABLE(UserSampleQueue); - -public: - UserSampleQueue() = default; - - void append(FixedArray&& samples); - void clear(); - // Slice off some amount of samples from the beginning. - void discard_samples(size_t count); - Sample operator[](size_t index); - - // The number of samples in the span. - size_t size(); - bool is_empty(); - size_t remaining_samples(); - -private: - // Re-initialize the spans after a vector resize. - void fix_spans(); - - Threading::Mutex m_sample_mutex; - // Sample data view to keep track of what to play next. - DisjointSpans m_enqueued_samples; - // The number of samples that were played from the backing store since last discarding its start. - size_t m_samples_to_discard { 0 }; - // The backing store for the enqueued sample view. - DisjointChunks> m_backing_samples {}; -}; - -} diff --git a/Userland/Libraries/LibMedia/CMakeLists.txt b/Userland/Libraries/LibMedia/CMakeLists.txt index 9a9c81eeef9..b548b6909a1 100644 --- a/Userland/Libraries/LibMedia/CMakeLists.txt +++ b/Userland/Libraries/LibMedia/CMakeLists.txt @@ -9,7 +9,6 @@ set(SOURCES Audio/PlaybackStream.cpp Audio/QOALoader.cpp Audio/QOATypes.cpp - Audio/UserSampleQueue.cpp Audio/VorbisComment.cpp Color/ColorConverter.cpp Color/ColorPrimaries.cpp