UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioRenderScheduler.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "AudioBusSubsystem.h"
6#include "Containers/Map.h"
7#include "Tasks/Task.h"
8
10
11namespace Audio
12{
13 // Forward declarations
14 struct FAudioBusKey;
15 class FMixerDevice;
16 struct IAudioMixerRenderStep;
17
18 // An identifier that uniquely identifies a given render step to the scheduler.
20 {
21 public:
26
27 static FAudioRenderStepId FromTransmitterID(const uint64 TransmitterID);
29
31 {
32 return Value;
33 }
34
36 {
37 return GetTypeHash(Id.Value);
38 }
39
41 {
42 return InLHS.Value == InRHS.Value;
43 }
44
46 {
47 return InLHS.Value != InRHS.Value;
48 }
49
50 bool IsValid() const
51 {
52 return Value != INDEX_NONE;
53 }
54
55 protected:
60
62 };
63
64 // FAudioRenderScheduler allows individual audio render work items ("steps") to be added to be run as part of each rendering block.
65 // Dependencies can be declared to enforce ordering and synchronization between steps when needed. There can be cyclical
66 // dependencies, in which case the scheduler will do its best to consistently break the cycles in the same way every block;
67 // but cycles should be avoided when possible.
68 //
69 // Render steps are executed on worker threads using the UE Tasks system, unless single-threaded rendering is requested. Currently
70 // only source rendering uses the scheduler.
71 //
72 // All methods of this class are to be called from the audio render thread only.
73
75 {
76 public:
78
80
81 // Add/remove a render step.
84
85 // Declare that one step is dependent on another. It's possible to add a dependency without
86 // having previously called AddStep; in this case the dependency will still be respected with
87 // an empty placeholder step.
89
90 // All dependencies declared with AddDependency() must be removed by a corresponding call to RemoveDependency().
92
93 // Execute all steps and block until they're done.
94 void RenderBlock(const bool bSingleThreaded);
95
96 private:
97 // Internally the step id's are mapped to smaller internal indices to reduce
98 // memory footprint.
99 using FInternalIndex = int16;
100
101 void ScheduleAll(const bool bSingleThreaded);
102
103 FInternalIndex GetInternalIndex(const FAudioRenderStepId Id);
104 void RemoveReference(FAudioRenderScheduler::FInternalIndex Index);
105
106 void BreakCycle(const int FirstPendingStepIndex);
107 void CheckBrokenLinks();
108 void BreakLink(FInternalIndex FirstStep, FInternalIndex SecondStep);
109
110 // Helpers to verify that a link is still part of a cycle
111 bool FindIndirectLink(const FInternalIndex FirstStep, const FInternalIndex SecondStep);
112 bool FindIndirectLinkSkipping(const FInternalIndex FirstStep, const FInternalIndex SecondStep, TArray<FInternalIndex>& StepsToSkip);
113
114 struct FStepEntry
115 {
116 FAudioRenderStepId StepId;
117 IAudioMixerRenderStep* StepInterface = nullptr;
119 int32 ReferenceCount = 0;
120 bool bLaunched = false;
121 bool bCheckBrokenLinks = false;
122 UE::Tasks::FTask TaskHandle;
123
124 // Unused step entries are added to a free list.
125 FInternalIndex NextFreeIndex = INDEX_NONE;
126 };
127
128 // Only used to check the current thread; may be null.
129 FMixerDevice* MixerDevice;
130
132 TArray<FStepEntry> Steps;
133 FInternalIndex FirstFreeIndex = INDEX_NONE;
134
135 // Array of all used step indices. Ends up sorted at the end of RenderBlock().
136 TArray<FInternalIndex> ActiveSteps;
137
138 // Have any changes happened since the previous call to RenderBlock()?
139 bool bDirty = true;
140
141 // Links that have been broken to eliminate cycles. These are retained between
142 // blocks to improve stability of step ordering.
144 };
145}
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
DIRECTLINK_API Display
Definition DirectLinkLog.h:8
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioRenderScheduler.h:75
UE_NONCOPYABLE(FAudioRenderScheduler)
void AddDependency(const FAudioRenderStepId FirstStep, const FAudioRenderStepId SecondStep)
Definition AudioRenderScheduler.cpp:114
void RemoveDependency(const FAudioRenderStepId FirstStep, const FAudioRenderStepId SecondStep)
Definition AudioRenderScheduler.cpp:135
void RenderBlock(const bool bSingleThreaded)
Definition AudioRenderScheduler.cpp:157
void AddStep(const FAudioRenderStepId Id, IAudioMixerRenderStep *Step)
Definition AudioRenderScheduler.cpp:82
void RemoveStep(const FAudioRenderStepId Id)
Definition AudioRenderScheduler.cpp:98
Definition AudioRenderScheduler.h:20
bool IsValid() const
Definition AudioRenderScheduler.h:50
FAudioRenderStepId()
Definition AudioRenderScheduler.h:22
uint64 Value
Definition AudioRenderScheduler.h:61
static FAudioRenderStepId FromAudioBusKey(const FAudioBusKey BusKey)
Definition AudioRenderScheduler.cpp:23
friend uint32 GetTypeHash(FAudioRenderStepId Id)
Definition AudioRenderScheduler.h:35
uint64 GetRawValue() const
Definition AudioRenderScheduler.h:30
friend bool operator!=(const FAudioRenderStepId InLHS, const FAudioRenderStepId InRHS)
Definition AudioRenderScheduler.h:45
friend bool operator==(const FAudioRenderStepId InLHS, const FAudioRenderStepId InRHS)
Definition AudioRenderScheduler.h:40
FAudioRenderStepId(uint64 InValue)
Definition AudioRenderScheduler.h:56
static FAudioRenderStepId FromTransmitterID(const uint64 TransmitterID)
Definition AudioRenderScheduler.cpp:18
Definition AudioMixerDevice.h:117
Definition Array.h:670
Definition UnrealString.h.inl:34
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
U16 Index
Definition radfft.cpp:71
Definition AudioBusSubsystem.h:22
Definition IAudioMixerRenderStep.h:13