UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LiveLinkProviderImpl.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "IMessageContext.h"
7#include "LiveLinkMessages.h"
8#include "LiveLinkProvider.h"
9#include "MessageEndpoint.h"
10
11#define UE_API LIVELINKMESSAGEBUSFRAMEWORK_API
12
14// Subject that the application has told us about
16{
17 // Ref skeleton to go with transform data
19
20 // Bone transform data
22
23 // Curve data
25
26 // MetaData for subject
28
29 // Incrementing time (application time) for interpolation purposes
30 double Time;
31};
33
35{
36private:
37 const FString ProviderName;
38 const FString MachineName;
39
41
42 // Lock to stop multiple threads accessing the CurrentPreset at the same time
43 mutable FCriticalSection CriticalSection;
44
45 // Array of our current connections
46 TArray<struct FTrackedAddress> ConnectedAddresses;
47
48 // Cache of our current subject state
52
53 // Delegate to notify interested parties when the client sources have changed
54 FLiveLinkProviderConnectionStatusChanged OnConnectionStatusChanged;
55
56private:
57 //Message bus message handlers
58 // Handles ping message and sends back a pong
59 void HandlePingMessage(const FLiveLinkPingMessage& Message, const TSharedRef<class IMessageContext, ESPMode::ThreadSafe>& Context);
60
61 void HandleHeartbeat(const FLiveLinkHeartbeatMessage& Message,
63 // End message bus message handlers
64
65 FTrackedSubject& GetTrackedSubject(const FName& SubjectName);
66
67 void SendSubject(FName SubjectName, const struct FTrackedSubject& Subject);
68
69 void SendSubjectFrame(FName SubjectName, const struct FTrackedSubject& Subject);
70
71 // Get the cached data for the named subject
72 FTrackedStaticData* GetLastSubjectStaticData(const FName& SubjectName);
73
74 FTrackedFrameData* GetLastSubjectFrameData(const FName& SubjectName);
75
76 void SetLastSubjectStaticData(FName SubjectName, TSubclassOf<ULiveLinkRole> Role, FLiveLinkStaticDataStruct&& StaticData, TMap<FName, FString>&& Annotations);
77
78 void SetLastSubjectFrameData(FName SubjectName, FLiveLinkFrameDataStruct&& FrameData, TMap<FName, FString>&& SubjectAnnotations);
79
80 // Clear a existing track subject
81 void ClearTrackedSubject(const FName& SubjectName);
82
83 // Get the connected addresses that should receive livelink data.
84 void GetFilteredAddresses(FName SubjectName, TArray<FMessageAddress>& Addresses);
85
86 // Serialize animation frame data into a compressed payload to reduce throughput.
87 struct FLiveLinkSerializedFrameData SerializeAnimationData(struct FLiveLinkAnimationFrameData* AnimData);
88
89protected:
90 // Get the minimum supported version of livelink clients that can connect to this provider.
92
93 // Update connected addresses and send information to the connected source
95
96 // Create the message bus message endoing responsble for dispatching message bus messages to their respective handlers
98
99 // Get the addresses of all connected instances.
101
102 // Validate our current connections, removing those that have timed out.
104
105 // Close a connection using its address.
107
108 // Get the cached data struct for a subject
110
111 // Invoked by MessageBus when a node is registered or unregistered.
113
114 // Send message (only to connected addresses)
115 template<typename MessageType>
117 {
118 if (!Message)
119 {
120 return;
121 }
122
123 TArray<FMessageAddress> Addresses;
124 GetConnectedAddresses(Addresses);
125 if (Addresses.Num() != 0)
126 {
127 MessageEndpoint->Send(Message, Flags, {}, nullptr, Addresses, FTimespan::Zero(), FDateTime::MaxValue());
128 }
129 }
130
131 // Send message to a specific address.
132 template<typename MessageType>
133 void SendMessage(MessageType* Message, const FMessageAddress& Address, EMessageFlags Flags = EMessageFlags::None, const TMap<FName, FString>& Annotations = {})
134 {
135 if (!Message || !Address.IsValid())
136 {
137 return;
138 }
139
140 MessageEndpoint->Send(Message, Flags, Annotations, nullptr, { Address }, FTimespan::Zero(), FDateTime::MaxValue());
141 }
142
143 // Send message to a list of addresses.
144 template<typename MessageType>
145 void SendMessage(MessageType* Message, const TArray<FMessageAddress>& Addresses, EMessageFlags Flags = EMessageFlags::None, const TMap<FName, FString>& Annotations = {})
146 {
147 if (!Message || !Addresses.Num())
148 {
149 return;
150 }
151
152 MessageEndpoint->Send(Message, Flags, Annotations, nullptr, Addresses, FTimespan::Zero(), FDateTime::MaxValue());
153 }
154
155 // Broadcast message on the network.
156 template<typename MessageType>
157 void Publish(MessageType* Message)
158 {
159 if (!Message)
160 {
161 return;
162 }
163
164 MessageEndpoint->Publish(Message);
165 }
166
167 // Subscribe to a message that's been published.
168 template<typename MessageType>
170 {
171 if (MessageEndpoint.IsValid())
172 {
173 MessageEndpoint->Subscribe<MessageType>();
174 }
175 }
176
177 // Get the name of this provider.
178 const FString& GetProviderName() const
179 {
180 return ProviderName;
181 }
182
183 // Get the name of this machine.
184 const FString& GetMachineName() const
185 {
186 return MachineName;
187 }
188
189 // Called after ValidateConnections removes invalid connections
191
192 // Get annotations to include on every message sent by this provider
194 {
195#if WITH_ENGINE
196 // When running a game/editor, mark this provider as an unreal client.
197 FString TopologyModeValue = StaticEnum<ELiveLinkTopologyMode>()->GetNameStringByValue(static_cast<int64>(ELiveLinkTopologyMode::UnrealClient));
199#endif
200 return {};
201 }
202
203 // Get whether a combination of a subject/client should receive livelink data.
204 virtual bool ShouldTransmitToSubject_AnyThread(FName SubjectName, FMessageAddress Address) const
205 {
206 return true;
207 }
208
209 // Send a clear subject message to indicate that the subject should be removed from the connected client.
211
212 // Get the MessageBus address of the provider.
214
215 // Constructor for derived classes that allows specifying that no endpoint should be created.
217
218public:
220
222
223 UE_API virtual ~FLiveLinkProvider() override;
224
225 UE_API virtual void UpdateSubject(const FName& SubjectName, const TArray<FName>& BoneNames, const TArray<int32>& BoneParents);
226
227 UE_API virtual bool UpdateSubjectStaticData(const FName SubjectName, TSubclassOf<ULiveLinkRole> Role, FLiveLinkStaticDataStruct&& StaticData, const TMap<FName, FString>& ExtraAnnotations = {}) override;
228
229 UE_API virtual void ClearSubject(const FName& SubjectName);
230
231 UE_API virtual void RemoveSubject(const FName SubjectName) override;
232
234 virtual void UpdateSubjectFrame(const FName& SubjectName, const TArray<FTransform>& BoneTransforms, const TArray<FLiveLinkCurveElement>& CurveData, double Time);
235
236 UE_API virtual void UpdateSubjectFrame(const FName& SubjectName, const TArray<FTransform>& BoneTransforms, const TArray<FLiveLinkCurveElement>& CurveData,
237 const FLiveLinkMetaData& MetaData, double Time);
239
240 virtual bool UpdateSubjectFrameData(const FName SubjectName, FLiveLinkFrameDataStruct&& FrameData, const TMap<FName, FString>& ExtraAnnotations = {}) override;
241
242 UE_API virtual bool HasConnection() const override;
243
244 UE_API virtual FDelegateHandle RegisterConnStatusChangedHandle(const FLiveLinkProviderConnectionStatusChanged::FDelegate& ConnStatusChanged) override;
245
247};
248
249#undef UE_API
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
EMessageFlags
Definition IMessageContext.h:186
#define UE_API
Definition LiveLinkProviderImpl.h:11
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition IDelegateInstance.h:14
Definition NameTypes.h:617
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
UE_FORCEINLINE_HINT const bool IsValid() const
Definition SharedPointer.h:1085
Definition SharedPointer.h:153
Definition SubclassOf.h:30
static FDateTime MaxValue()
Definition DateTime.h:656
Definition LiveLinkAnimationTypes.h:50
Definition LiveLinkMessages.h:101
Definition LiveLinkMessages.h:110
static UE_API FName TopologyModeAnnotation
Definition LiveLinkMessages.h:17
Definition LiveLinkTypes.h:198
Definition LiveLinkMessages.h:43
Definition LiveLinkProviderImpl.h:35
virtual UE_API void UnregisterConnStatusChangedHandle(FDelegateHandle Handle) override
Definition LiveLinkProvider.cpp:529
void SendMessage(MessageType *Message, EMessageFlags Flags=EMessageFlags::None)
Definition LiveLinkProviderImpl.h:116
UE_API virtual PRAGMA_DISABLE_DEPRECATION_WARNINGS void UpdateSubjectFrame(const FName &SubjectName, const TArray< FTransform > &BoneTransforms, const TArray< FLiveLinkCurveElement > &CurveData, double Time)
Definition LiveLinkProvider.cpp:383
virtual UE_API void RemoveSubject(const FName SubjectName) override
Definition LiveLinkProvider.cpp:375
void Subscribe()
Definition LiveLinkProviderImpl.h:169
virtual UE_API FDelegateHandle RegisterConnStatusChangedHandle(const FLiveLinkProviderConnectionStatusChanged::FDelegate &ConnStatusChanged) override
Definition LiveLinkProvider.cpp:524
void Publish(MessageType *Message)
Definition LiveLinkProviderImpl.h:157
virtual void OnMessageBusNotification(const FMessageBusNotification &Notification)
Definition LiveLinkProviderImpl.h:112
UE_API virtual PRAGMA_ENABLE_DEPRECATION_WARNINGS bool UpdateSubjectFrameData(const FName SubjectName, FLiveLinkFrameDataStruct &&FrameData, const TMap< FName, FString > &ExtraAnnotations={}) override
Definition LiveLinkProvider.cpp:411
UE_API void SendClearSubjectToConnections(FName SubjectName)
Definition LiveLinkProvider.cpp:316
virtual TMap< FName, FString > GetAnnotations() const
Definition LiveLinkProviderImpl.h:193
UE_API void CloseConnection(FMessageAddress Address)
Definition LiveLinkProvider.cpp:136
void SendMessage(MessageType *Message, const FMessageAddress &Address, EMessageFlags Flags=EMessageFlags::None, const TMap< FName, FString > &Annotations={})
Definition LiveLinkProviderImpl.h:133
UE_API TPair< UClass *, FLiveLinkStaticDataStruct * > GetLastSubjectStaticDataStruct(FName SubjectName)
Definition LiveLinkProvider.cpp:195
virtual UE_API ~FLiveLinkProvider() override
Definition LiveLinkProvider.cpp:294
UE_API void CreateMessageEndpoint(struct FMessageEndpointBuilder &EndpointBuilder)
Definition LiveLinkProvider.cpp:620
const FString & GetProviderName() const
Definition LiveLinkProviderImpl.h:178
virtual UE_API void ClearSubject(const FName &SubjectName)
Definition LiveLinkProvider.cpp:368
virtual bool ShouldTransmitToSubject_AnyThread(FName SubjectName, FMessageAddress Address) const
Definition LiveLinkProviderImpl.h:204
void SendMessage(MessageType *Message, const TArray< FMessageAddress > &Addresses, EMessageFlags Flags=EMessageFlags::None, const TMap< FName, FString > &Annotations={})
Definition LiveLinkProviderImpl.h:145
virtual UE_API bool HasConnection() const override
Definition LiveLinkProvider.cpp:508
virtual void OnConnectionsClosed(const TArray< FMessageAddress > &ClosedAddresses)
Definition LiveLinkProviderImpl.h:190
static UE_API int32 GetSupportedLiveLinkVersion()
Definition LiveLinkProvider.cpp:503
UE_API void HandleConnectMessage(const FLiveLinkConnectMessage &Message, const TSharedRef< class IMessageContext, ESPMode::ThreadSafe > &Context)
Definition LiveLinkProvider.cpp:547
const FString & GetMachineName() const
Definition LiveLinkProviderImpl.h:184
UE_API void ValidateConnections()
Definition LiveLinkProvider.cpp:111
virtual UE_API void UpdateSubject(const FName &SubjectName, const TArray< FName > &BoneNames, const TArray< int32 > &BoneParents)
Definition LiveLinkProvider.cpp:304
UE_API FMessageAddress GetEndpointAddress() const
Definition LiveLinkProvider.cpp:324
UE_API void GetConnectedAddresses(TArray< FMessageAddress > &Addresses)
Definition LiveLinkProvider.cpp:633
virtual UE_API bool UpdateSubjectStaticData(const FName SubjectName, TSubclassOf< ULiveLinkRole > Role, FLiveLinkStaticDataStruct &&StaticData, const TMap< FName, FString > &ExtraAnnotations={}) override
Definition LiveLinkProvider.cpp:329
Definition LiveLinkRefSkeleton.h:14
Definition LiveLinkCompression.h:197
Definition IMessageContext.h:26
bool IsValid() const
Definition IMessageContext.h:87
Definition MessageEndpoint.h:36
Definition MessageEndpointBuilder.h:18
static FTimespan Zero()
Definition Timespan.h:747
Definition LiveLinkProvider.cpp:94
Definition LiveLinkProvider.cpp:75
Definition LiveLinkProviderImpl.h:16
TArray< FTransform > Transforms
Definition LiveLinkProviderImpl.h:21
FLiveLinkRefSkeleton RefSkeleton
Definition LiveLinkProviderImpl.h:18
double Time
Definition LiveLinkProviderImpl.h:30
FLiveLinkMetaData MetaData
Definition LiveLinkProviderImpl.h:27
TArray< FLiveLinkCurveElement > Curves
Definition LiveLinkProviderImpl.h:24
Definition LiveLinkProvider.h:26
Definition Tuple.h:652