Hi all,
I have a issue which is driving me nuts, so I decided I need an extra opinion on the issue :).
For a project I am working on I am using Wongfei UE4Gstreamer Plugin (GitHub - wongfei/ue4-gstreamer: Render video content to texture via appsink node).
When I use the plugin, I notice my memory usage is increasing by about 100mb/s.
Strange thing is that this only occurs when the editor is in focus.
When I minimize it, the Memory Usage is stable.
This is causing me to doubt if the issue lies within the plugin or if it is an editor issue.
Only lead I have is that the plugin is retrieving the TextureTarget from the gamethread and then adds it to a buffer.
I checked and the buffer is deleting older data so that is not the issue.
So maybe the TextureTargets get stuck somewhere in memory and does not get deleted.
This is the piece of code which I suspect is the culprit:
void UGstAppSrcComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (AppSrc)
{
AActor* Actor = GetOwner();
for (FComponentReference& ComponentReference : AppSrcCaptures)
{
USceneCaptureComponent2D* CaptureComponent = Cast<USceneCaptureComponent2D>(ComponentReference.GetComponent(Actor));
if (CaptureComponent)
{
UTextureRenderTarget2D* TextureTarget = CaptureComponent->TextureTarget;
if (TextureTarget)
{
FTextureRenderTargetResource* TextureResource = TextureTarget->GameThread_GetRenderTargetResource();
PushBufferAsync(TextureResource);
}
}
}
if (BufferQueue.Num() > 0)
{
auto* Buffer = BufferQueue[0];
if (Buffer->Fence.IsFenceComplete())
{
BufferQueue.RemoveAt(0);
AppSrc->PushBuffer(Buffer);
}
}
}
FrameId++;
}
void UGstAppSrcComponent::PushBufferAsync(FTextureRenderTargetResource* TextureResource)
{
if (BufferQueue.Num() > MaxQueueLength)
{
GST_LOG_ERR(TEXT("PushBufferAsync overflow"));
return;
}
FIntPoint Size = TextureResource->GetSizeXY();
FIntRect InRect = FIntRect(0, 0, Size.X, Size.Y);
FReadSurfaceDataFlags InFlags = FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX);
FGstAppSrcBuffer* Buffer = GetBuffer();
Buffer->ColorBuffer.SetNum(Size.X * Size.Y);
Buffer->FrameId = FrameId;
BufferQueue.Add(Buffer);
struct FReadSurfaceContext
{
UGstAppSrcComponent* AppSrc;
FGstAppSrcBuffer* Buffer;
FRenderTarget* SrcRenderTarget;
FIntRect Rect;
FReadSurfaceDataFlags Flags;
};
FReadSurfaceContext Context =
{
this,
Buffer,
TextureResource,
InRect,
InFlags
};
ENQUEUE_RENDER_COMMAND(ReadSurfaceCommand)(
[Context](FRHICommandListImmediate& RHICmdList)
{
RHICmdList.ReadSurfaceData(
Context.SrcRenderTarget->GetRenderTargetTexture(),
Context.Rect,
Context.Buffer->ColorBuffer,
Context.Flags
);
});
Buffer->Fence.BeginFence();
}
Thanks in advance!