OpenShot Library | libopenshot  0.1.3
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 (tr1::shared_ptr< Frame > frame)
 Add a Frame to the cache. More...
 
 CacheMemory ()
 Default constructor, no max bytes. More...
 
 CacheMemory (long long int max_bytes)
 Constructor that sets the max bytes to cache. More...
 
void Clear ()
 Clear the cache of all frames. More...
 
long int Count ()
 Count the frames in the queue. More...
 
long long int GetBytes ()
 Gets the maximum bytes value. More...
 
tr1::shared_ptr< FrameGetFrame (long int frame_number)
 Get a frame from the cache. More...
 
tr1::shared_ptr< FrameGetSmallestFrame ()
 Get the smallest frame number. More...
 
string Json ()
 Get and Set JSON methods. More...
 
Json::Value JsonValue ()
 Generate Json::JsonValue for this object. More...
 
void MoveToFront (long int frame_number)
 Move frame to front of queue (so it lasts longer) More...
 
void Remove (long int frame_number)
 Remove a specific frame. More...
 
void Remove (long int start_frame_number, long int end_frame_number)
 Remove a range of frames. More...
 
void SetJson (string value) throw (InvalidJSON)
 Load JSON string into this object. More...
 
void SetJsonValue (Json::Value root) throw (InvalidFile, ReaderClosed)
 Load Json::JsonValue into this object. More...
 
 ~CacheMemory ()
 
- Public Member Functions inherited from openshot::CacheBase
 CacheBase ()
 Default constructor, no max bytes. More...
 
 CacheBase (long long int max_bytes)
 Constructor that sets the max bytes to cache. More...
 
long long int GetMaxBytes ()
 Gets the maximum bytes value. More...
 
void SetMaxBytes (long long int number_of_bytes)
 Set maximum bytes to a different amount. More...
 
void SetMaxBytesFromInfo (long int 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...
 

Additional Inherited Members

- Protected Attributes inherited from openshot::CacheBase
string cache_type
 This is a friendly type name of the derived cache instance. More...
 
CriticalSection * cacheCriticalSection
 Section lock for multiple threads. More...
 
long long int 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 48 of file CacheMemory.h.

Constructor & Destructor Documentation

◆ CacheMemory() [1/2]

CacheMemory::CacheMemory ( )

Default constructor, no max bytes.

Definition at line 34 of file CacheMemory.cpp.

◆ CacheMemory() [2/2]

CacheMemory::CacheMemory ( long long int  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 42 of file CacheMemory.cpp.

◆ ~CacheMemory()

CacheMemory::~CacheMemory ( )

Definition at line 50 of file CacheMemory.cpp.

Member Function Documentation

◆ Add()

void CacheMemory::Add ( tr1::shared_ptr< Frame frame)
virtual

Add a Frame to the cache.

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

Implements openshot::CacheBase.

Definition at line 130 of file CacheMemory.cpp.

◆ Clear()

void CacheMemory::Clear ( )
virtual

Clear the cache of all frames.

Implements openshot::CacheBase.

Definition at line 278 of file CacheMemory.cpp.

◆ Count()

long int CacheMemory::Count ( )
virtual

Count the frames in the queue.

Implements openshot::CacheBase.

Definition at line 289 of file CacheMemory.cpp.

◆ GetBytes()

long long int CacheMemory::GetBytes ( )
virtual

Gets the maximum bytes value.

Implements openshot::CacheBase.

Definition at line 193 of file CacheMemory.cpp.

◆ GetFrame()

tr1::shared_ptr< Frame > CacheMemory::GetFrame ( long int  frame_number)
virtual

Get a frame from the cache.

Parameters
frame_numberThe frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 155 of file CacheMemory.cpp.

◆ GetSmallestFrame()

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

Get the smallest frame number.

Implements openshot::CacheBase.

Definition at line 171 of file CacheMemory.cpp.

◆ Json()

string CacheMemory::Json ( )
virtual

Get and Set JSON methods.

Generate JSON string of this object

Implements openshot::CacheBase.

Definition at line 320 of file CacheMemory.cpp.

◆ JsonValue()

Json::Value CacheMemory::JsonValue ( )
virtual

Generate Json::JsonValue for this object.

Implements openshot::CacheBase.

Definition at line 327 of file CacheMemory.cpp.

◆ MoveToFront()

void CacheMemory::MoveToFront ( long int  frame_number)

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

Parameters
frame_numberThe frame number of the cached frame

Definition at line 252 of file CacheMemory.cpp.

◆ Remove() [1/2]

void CacheMemory::Remove ( long int  frame_number)
virtual

Remove a specific frame.

Parameters
frame_numberThe frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 211 of file CacheMemory.cpp.

◆ Remove() [2/2]

void CacheMemory::Remove ( long int  start_frame_number,
long int  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 217 of file CacheMemory.cpp.

◆ SetJson()

void CacheMemory::SetJson ( string  value)
throw (InvalidJSON
)
virtual

Load JSON string into this object.

Implements openshot::CacheBase.

Definition at line 352 of file CacheMemory.cpp.

◆ SetJsonValue()

void CacheMemory::SetJsonValue ( Json::Value  root)
throw (InvalidFile,
ReaderClosed
)
virtual

Load Json::JsonValue into this object.

Implements openshot::CacheBase.

Definition at line 375 of file CacheMemory.cpp.


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