// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "ElectraProtronPlayer.h" #include "Containers/Queue.h" #include "Misc/TVariant.h" #include "Misc/Optional.h" #include "Math/Range.h" #include "Math/RangeSet.h" #include "MediaSamples.h" class FProtronVideoCache { public: FProtronVideoCache(); void SetMaxFramesToCache(int32 InNumVideoFramesToCacheAhead, int32 InNumVideoFramesToCacheBehind); void SetPlaybackRange(TRange InRange); void SeekIssuedTo(FTimespan InNewPosition); void SetPlaybackRate(float InNewRate); bool Contains(FTimespan InPTS); int32 Find(FTimespan InPTS); bool CanAccept(FTimespan InPTS); void Empty(); void QueryCacheState(TRangeSet& OutTimeRanges); enum class EGetResult { Hit, Miss, PurgedEmpty }; EGetResult GetFrame(TSharedPtr& OutFrame, const TRange& InTimeRange, bool bIsLooping, bool bInReverse, bool bInUseFirstMatch); void PerformMaintenance(int32 InAtIndex, bool bIsLooping, bool bInReverse); void AddFrame(TSharedRef InFrame, FTimespan InRawPTS, FTimespan InRawDuration); private: FCriticalSection Lock; struct FEntry { TRange RawRange; TSharedPtr Frame; }; int32 GetConsecutiveFutureSamples(TArray& OutIndices, int32& OutWrapIndex, int32 InStartFrameIndex, bool bInLooping); int32 GetConsecutivePreviousSamples(TArray& OutIndices, int32& OutWrapIndex, int32 InStartFrameIndex, bool bInLooping); TArray Entries; TRange PlaybackRange; FTimespan PlaybackRangeEndInclusive; // The position around which to check for consecutive future and past samples when adding. TOptional CurrentReadTime; float PlaybackRate = 0.0f; int32 MaxFramesToCache = 0; int32 NumVideoFramesToCacheAhead = 0; int32 NumVideoFramesToCacheBehind = 0; };