/* * Copyright (c) 2021, kleines Filmröllchen * Copyright (c) 2021, JJ Roberts-White * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include "Music.h" #include #include #include #include #include #include #include #include class TrackManager; // Wrapper class accepting custom events to advance the track playing and forward audio data to the system. // This does not run on a separate thread, preventing IPC multithreading madness. class AudioPlayerLoop final : public Core::Object { C_OBJECT(AudioPlayerLoop) public: virtual ~AudioPlayerLoop() override; void toggle_paused(); bool is_playing() const { return m_should_play_audio; } private: AudioPlayerLoop(TrackManager& track_manager, Atomic& need_to_write_wav, Atomic& wav_percent_written, Threading::MutexProtected& wav_writer); intptr_t pipeline_thread_main(); ErrorOr send_audio_to_server(); void write_wav_if_needed(); TrackManager& m_track_manager; FixedArray m_buffer; Optional> m_resampler; RefPtr m_audio_client; NonnullRefPtr m_pipeline_thread; Vector m_remaining_samples {}; Atomic m_should_play_audio { true }; Atomic m_exit_requested { false }; Atomic& m_need_to_write_wav; Atomic& m_wav_percent_written; Threading::MutexProtected& m_wav_writer; };