diff options
| author | 2022-07-16 23:48:45 +0100 | |
|---|---|---|
| committer | 2022-07-22 01:11:32 +0100 | |
| commit | 458da8a94877677f086f06cdeecf959ec4283a33 (patch) | |
| tree | 583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/audio_event.h | |
| parent | Merge pull request #8598 from Link4565/recv-dontwait (diff) | |
| download | yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip | |
Project Andio
Diffstat (limited to 'src/audio_core/audio_event.h')
| -rw-r--r-- | src/audio_core/audio_event.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/audio_core/audio_event.h b/src/audio_core/audio_event.h new file mode 100644 index 000000000..82dd32dca --- /dev/null +++ b/src/audio_core/audio_event.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <atomic> | ||
| 8 | #include <chrono> | ||
| 9 | #include <condition_variable> | ||
| 10 | #include <mutex> | ||
| 11 | |||
| 12 | namespace AudioCore { | ||
| 13 | /** | ||
| 14 | * Responsible for the input/output events, set by the stream backend when buffers are consumed, and | ||
| 15 | * waited on by the audio manager. These callbacks signal the game's events to keep the audio buffer | ||
| 16 | * recycling going. | ||
| 17 | * In a real Switch this is not a seprate class, and exists entirely within the audio manager. | ||
| 18 | * On the Switch it's implemented more simply through a MultiWaitEventHolder, where it can | ||
| 19 | * wait on multiple events at once, and the events are not needed by the backend. | ||
| 20 | */ | ||
| 21 | class Event { | ||
| 22 | public: | ||
| 23 | enum class Type { | ||
| 24 | AudioInManager, | ||
| 25 | AudioOutManager, | ||
| 26 | FinalOutputRecorderManager, | ||
| 27 | Max, | ||
| 28 | }; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * Convert a manager type to an index. | ||
| 32 | * | ||
| 33 | * @param type - The manager type to convert | ||
| 34 | * @return The index of the type. | ||
| 35 | */ | ||
| 36 | size_t GetManagerIndex(Type type) const; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Set an audio event to true or false. | ||
| 40 | * | ||
| 41 | * @param type - The manager type to signal. | ||
| 42 | * @param signalled - Its signal state. | ||
| 43 | */ | ||
| 44 | void SetAudioEvent(Type type, bool signalled); | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Check if the given manager type is signalled. | ||
| 48 | * | ||
| 49 | * @param type - The manager type to check. | ||
| 50 | * @return True if the event is signalled, otherwise false. | ||
| 51 | */ | ||
| 52 | bool CheckAudioEventSet(Type type) const; | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Get the lock for audio events. | ||
| 56 | * | ||
| 57 | * @return Reference to the lock. | ||
| 58 | */ | ||
| 59 | std::mutex& GetAudioEventLock(); | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Get the manager event, this signals the audio manager to release buffers and signal the game | ||
| 63 | * for more. | ||
| 64 | * | ||
| 65 | * @return Reference to the condition variable. | ||
| 66 | */ | ||
| 67 | std::condition_variable_any& GetAudioEvent(); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Wait on the manager_event. | ||
| 71 | * | ||
| 72 | * @param l - Lock held by the wait. | ||
| 73 | * @param timeout - Timeout for the wait. This is 2 seconds by default. | ||
| 74 | * @return True if the wait timed out, otherwise false if signalled. | ||
| 75 | */ | ||
| 76 | bool Wait(std::unique_lock<std::mutex>& l, std::chrono::seconds timeout); | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Reset all manager events. | ||
| 80 | */ | ||
| 81 | void ClearEvents(); | ||
| 82 | |||
| 83 | private: | ||
| 84 | /// Lock, used bythe audio manager | ||
| 85 | std::mutex event_lock; | ||
| 86 | /// Array of events, one per system type (see Type), last event is used to terminate | ||
| 87 | std::array<std::atomic<bool>, 4> events_signalled; | ||
| 88 | /// Event to signal the audio manager | ||
| 89 | std::condition_variable_any manager_event; | ||
| 90 | }; | ||
| 91 | |||
| 92 | } // namespace AudioCore | ||