OpenShot Library | libopenshot 0.2.7
Public Member Functions | List of all members
openshot::CacheMemory Class Reference

This class is a memory-based cache manager for Frame objects. More...

#include <CacheMemory.h>

Inheritance diagram for openshot::CacheMemory:
openshot::CacheBase

Public Member Functions

void Add (std::shared_ptr< openshot::Frame > frame)
 Add a Frame to the cache. More...
 
 CacheMemory ()
 Default constructor, no max bytes. More...
 
 CacheMemory (int64_t max_bytes)
 Constructor that sets the max bytes to cache. More...
 
void Clear ()
 Clear the cache of all frames. More...
 
int64_t Count ()
 Count the frames in the queue. More...
 
int64_t GetBytes ()
 Gets the maximum bytes value. More...
 
std::shared_ptr< openshot::FrameGetFrame (int64_t frame_number)
 Get a frame from the cache. More...
 
std::shared_ptr< openshot::FrameGetSmallestFrame ()
 Get the smallest frame number. More...
 
std::string Json ()
 Generate JSON string of this object. More...
 
Json::Value JsonValue ()
 Generate Json::Value for this object. More...
 
void MoveToFront (int64_t frame_number)
 Move frame to front of queue (so it lasts longer) More...
 
void Remove (int64_t frame_number)
 Remove a specific frame. More...
 
void Remove (int64_t start_frame_number, int64_t end_frame_number)
 Remove a range of frames. More...
 
void SetJson (const std::string value)
 Load JSON string into this object. More...
 
void SetJsonValue (const Json::Value root)
 Load Json::Value into this object. More...
 
virtual ~CacheMemory ()
 
- Public Member Functions inherited from openshot::CacheBase
virtual void Add (std::shared_ptr< openshot::Frame > frame)=0
 Add a Frame to the cache. More...
 
 CacheBase ()
 Default constructor, no max bytes. More...
 
 CacheBase (int64_t max_bytes)
 Constructor that sets the max bytes to cache. More...
 
virtual void Clear ()=0
 Clear the cache of all frames. More...
 
virtual int64_t Count ()=0
 Count the frames in the queue. More...
 
virtual int64_t GetBytes ()=0
 Gets the maximum bytes value. More...
 
virtual std::shared_ptr< openshot::FrameGetFrame (int64_t frame_number)=0
 Get a frame from the cache. More...
 
int64_t GetMaxBytes ()
 Gets the maximum bytes value. More...
 
virtual std::shared_ptr< openshot::FrameGetSmallestFrame ()=0
 Get the smallest frame number. More...
 
virtual std::string Json ()=0
 Generate JSON string of this object. More...
 
virtual Json::Value JsonValue ()=0
 Generate Json::Value for this object. More...
 
virtual void Remove (int64_t frame_number)=0
 Remove a specific frame. More...
 
virtual void Remove (int64_t start_frame_number, int64_t end_frame_number)=0
 Remove a range of frames. More...
 
virtual void SetJson (const std::string value)=0
 Load JSON string into this object. More...
 
virtual void SetJsonValue (const Json::Value root)=0
 Load Json::Value into this object. More...
 
void SetMaxBytes (int64_t number_of_bytes)
 Set maximum bytes to a different amount. More...
 
void SetMaxBytesFromInfo (int64_t number_of_frames, int width, int height, int sample_rate, int channels)
 Set maximum bytes to a different amount based on a ReaderInfo struct. More...
 
virtual ~CacheBase ()=default
 

Additional Inherited Members

- Protected Attributes inherited from openshot::CacheBase
std::string cache_type
 This is a friendly type name of the derived cache instance. More...
 
juce::CriticalSection * cacheCriticalSection
 Section lock for multiple threads. More...
 
int64_t max_bytes
 This is the max number of bytes to cache (0 = no limit) More...
 

Detailed Description

This class is a memory-based cache manager for Frame objects.

It is used by FileReaders (such as FFmpegReader) to cache recently accessed frames. Due to the high cost of decoding streams, once a frame is decoded, converted to RGB, and a Frame object is created, it critical to keep these Frames cached for performance reasons. However, the larger the cache, the more memory is required. You can set the max number of bytes to cache.

Definition at line 50 of file CacheMemory.h.

Constructor & Destructor Documentation

◆ CacheMemory() [1/2]

CacheMemory::CacheMemory ( )

Default constructor, no max bytes.

Definition at line 38 of file CacheMemory.cpp.

◆ CacheMemory() [2/2]

CacheMemory::CacheMemory ( int64_t  max_bytes)

Constructor that sets the max bytes to cache.

Parameters
max_bytesThe maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames.

Definition at line 46 of file CacheMemory.cpp.

◆ ~CacheMemory()

CacheMemory::~CacheMemory ( )
virtual

Definition at line 54 of file CacheMemory.cpp.

Member Function Documentation

◆ Add()

void CacheMemory::Add ( std::shared_ptr< openshot::Frame frame)
virtual

Add a Frame to the cache.

Parameters
frameThe openshot::Frame object needing to be cached.

Implements openshot::CacheBase.

Definition at line 126 of file CacheMemory.cpp.

Referenced by openshot::FrameMapper::GetFrame(), and DeckLinkInputDelegate::VideoInputFrameArrived().

◆ Clear()

void CacheMemory::Clear ( )
virtual

◆ Count()

int64_t CacheMemory::Count ( )
virtual

Count the frames in the queue.

Implements openshot::CacheBase.

Definition at line 286 of file CacheMemory.cpp.

◆ GetBytes()

int64_t CacheMemory::GetBytes ( )
virtual

Gets the maximum bytes value.

Implements openshot::CacheBase.

Definition at line 189 of file CacheMemory.cpp.

◆ GetFrame()

std::shared_ptr< Frame > CacheMemory::GetFrame ( int64_t  frame_number)
virtual

Get a frame from the cache.

Parameters
frame_numberThe frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 151 of file CacheMemory.cpp.

Referenced by DeckLinkInputDelegate::GetFrame(), openshot::FFmpegReader::GetFrame(), openshot::FrameMapper::GetFrame(), and GetSmallestFrame().

◆ GetSmallestFrame()

std::shared_ptr< Frame > CacheMemory::GetSmallestFrame ( )
virtual

Get the smallest frame number.

Implements openshot::CacheBase.

Definition at line 167 of file CacheMemory.cpp.

◆ Json()

std::string CacheMemory::Json ( )
virtual

Generate JSON string of this object.

Implements openshot::CacheBase.

Definition at line 317 of file CacheMemory.cpp.

◆ JsonValue()

Json::Value CacheMemory::JsonValue ( )
virtual

Generate Json::Value for this object.

Implements openshot::CacheBase.

Definition at line 324 of file CacheMemory.cpp.

Referenced by Json().

◆ MoveToFront()

void CacheMemory::MoveToFront ( int64_t  frame_number)

Move frame to front of queue (so it lasts longer)

Parameters
frame_numberThe frame number of the cached frame

Definition at line 248 of file CacheMemory.cpp.

Referenced by Add().

◆ Remove() [1/2]

void CacheMemory::Remove ( int64_t  frame_number)
virtual

Remove a specific frame.

Parameters
frame_numberThe frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 207 of file CacheMemory.cpp.

Referenced by DeckLinkInputDelegate::GetFrame(), and Remove().

◆ Remove() [2/2]

void CacheMemory::Remove ( int64_t  start_frame_number,
int64_t  end_frame_number 
)
virtual

Remove a range of frames.

Parameters
start_frame_numberThe starting frame number of the cached frame
end_frame_numberThe ending frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 213 of file CacheMemory.cpp.

◆ SetJson()

void CacheMemory::SetJson ( const std::string  value)
virtual

Load JSON string into this object.

Implements openshot::CacheBase.

Definition at line 346 of file CacheMemory.cpp.

◆ SetJsonValue()

void CacheMemory::SetJsonValue ( const Json::Value  root)
virtual

Load Json::Value into this object.

Implements openshot::CacheBase.

Definition at line 363 of file CacheMemory.cpp.

Referenced by SetJson().


The documentation for this class was generated from the following files: