UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioDeviceHandle.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5
6// Set this to one if you'd like to check who owns
7// handles to an audio device.
8#ifndef INSTRUMENT_AUDIODEVICE_HANDLES
9#define INSTRUMENT_AUDIODEVICE_HANDLES 0
10#endif
11
12namespace Audio
13{
14 class FMixerDevice;
15
19 using FDeviceId = uint32;
20}
21
22class FAudioDevice;
23class UWorld;
24
25
26// Strong handle to an audio device. Guarantees that the audio device it references will stay alive while it is in scope.
28{
29public:
33
36
37
39
40 // gets a pointer to the audio device.
42
43 // Returns the device ID for the audio device referenced by this handle.
45
46 // Returns world set when handle was created
48
49 // Checks whether this points to a valid AudioDevice.
50 ENGINE_API bool IsValid() const;
51
52 // Resets handle to invalid state
53 ENGINE_API void Reset();
54
55private:
56 // This constructor should only be called by FAudioDeviceManager.
58
59 // The world that this FAudioDeviceHandle was requested with.
60 // Null if this device handle wasn't generated by RequestAudioDevice.
62
63 FAudioDevice* Device;
64 Audio::FDeviceId DeviceId;
65
66#if INSTRUMENT_AUDIODEVICE_HANDLES
69#endif
70
71 friend class FAudioDeviceManager;
72
73public:
74 // These are convenience operators to use an FAudioDeviceHandle like an FAudioDevice* or an Audio::FDeviceId.
75 // For safety, we still require explicit casting to an FAudioDevice* to ensure ownership isn't lost due to programmer error.
76 const FAudioDevice& operator*() const
77 {
78 check(IsValid());
79 return *Device;
80 }
81
83 {
84 check(IsValid());
85 return *Device;
86 }
87
88 const FAudioDevice* operator->() const
89 {
90 check(IsValid());
91 return Device;
92 }
93
95 {
96 check(IsValid());
97 return Device;
98 }
99
100 inline explicit operator bool() const
101 {
102 return IsValid();
103 }
104
105 inline bool operator==(const FAudioDeviceHandle& Other) const
106 {
107 return DeviceId == Other.DeviceId;
108 }
109
110 inline bool operator==(const FAudioDevice*& Other) const
111 {
112 return Device == Other;
113 }
114
115 inline bool operator==(FAudioDevice*& Other) const
116 {
117 return Device == Other;
118 }
119
120 inline bool operator==(const Audio::FDeviceId& Other) const
121 {
122 return DeviceId == Other;
123 }
124
125 explicit operator FAudioDevice*() const
126 {
127 check(IsValid());
128 return Device;
129 }
130
131 explicit operator Audio::FDeviceId() const
132 {
133 return DeviceId;
134 }
135};
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioDeviceHandle.h:28
ENGINE_API TWeakObjectPtr< UWorld > GetWorld() const
Definition AudioDeviceManager.cpp:1452
ENGINE_API ~FAudioDeviceHandle()
Definition AudioDeviceManager.cpp:1430
FAudioDevice * operator->()
Definition AudioDeviceHandle.h:94
ENGINE_API bool IsValid() const
Definition AudioDeviceManager.cpp:1462
ENGINE_API FAudioDeviceHandle()
Definition AudioDeviceManager.cpp:1374
ENGINE_API FAudioDeviceHandle & operator=(const FAudioDeviceHandle &Other)
Definition AudioDeviceManager.cpp:1472
ENGINE_API void Reset()
Definition AudioDeviceManager.cpp:1467
bool operator==(const Audio::FDeviceId &Other) const
Definition AudioDeviceHandle.h:120
bool operator==(const FAudioDevice *&Other) const
Definition AudioDeviceHandle.h:110
FAudioDevice & operator*()
Definition AudioDeviceHandle.h:82
ENGINE_API Audio::FDeviceId GetDeviceID() const
Definition AudioDeviceManager.cpp:1457
ENGINE_API FAudioDevice * GetAudioDevice() const
Definition AudioDeviceManager.cpp:1447
bool operator==(FAudioDevice *&Other) const
Definition AudioDeviceHandle.h:115
const FAudioDevice * operator->() const
Definition AudioDeviceHandle.h:88
const FAudioDevice & operator*() const
Definition AudioDeviceHandle.h:76
bool operator==(const FAudioDeviceHandle &Other) const
Definition AudioDeviceHandle.h:105
Definition AudioDeviceManager.h:87
Definition AudioDevice.h:417
Definition World.h:918
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
uint32 FDeviceId
Definition AudioDefines.h:66
Definition WeakObjectPtrTemplates.h:25