#pragma once #include #include #include #include #include #include "packets/AudioPacket.hpp" // TODO(Faraphel): should be moved somewhere else struct AudioPacketsComparator { bool operator() (const AudioPacket &a, const AudioPacket &b) const { return a.timePlay > b.timePlay; } }; /** * the audio Client. * Receive audio packets and play them at a specific time. */ class Client { public: /** * :param channels: the number of channel in the audio * :param rate: the rate of the audio */ explicit Client(int channels, double rate); ~Client(); /** * Indefinitely receive and play audio data. */ void loop(); private: /** * Indefinitely receive audio data. */ void loopReceiver(); /** * Indefinitely play audio data. */ void loopPlayer(); PaStream* stream; int channels; std::priority_queue, AudioPacketsComparator> audioQueue; std::mutex audioMutex; std::unique_lock audioLock; std::condition_variable audioCondition; std::thread receiverThread; std::thread playerThread; };