OpenShot Library | libopenshot  0.1.9
Public Member Functions | List of all members
openshot::CacheDisk Class Reference

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

#include <CacheDisk.h>

Inheritance diagram for openshot::CacheDisk:
openshot::CacheBase

Public Member Functions

void Add (std::shared_ptr< Frame > frame)
 Add a Frame to the cache. More...
 
 CacheDisk (string cache_path, string format, float quality, float scale)
 Default constructor, no max bytes. More...
 
 CacheDisk (string cache_path, string format, float quality, float scale, 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< FrameGetFrame (int64_t frame_number)
 Get a frame from the cache. More...
 
std::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 (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 (string value)
 Load JSON string into this object. More...
 
void SetJsonValue (Json::Value root)
 Load Json::JsonValue into this object. More...
 
 ~CacheDisk ()
 
- Public Member Functions inherited from openshot::CacheBase
 CacheBase ()
 Default constructor, no max bytes. More...
 
 CacheBase (int64_t max_bytes)
 Constructor that sets the max bytes to cache. More...
 
int64_t GetMaxBytes ()
 Gets the maximum bytes value. 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...
 

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...
 
int64_t max_bytes
 This is the max number of bytes to cache (0 = no limit) More...
 

Detailed Description

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

It is used by the Timeline class, if enabled, to cache video and audio frames to disk, to cut down on CPU and memory utilization. This will thrash a user's disk, but save their memory and CPU. It's a trade off that sometimes makes perfect sense. You can also set the max number of bytes to cache.

Definition at line 50 of file CacheDisk.h.

Constructor & Destructor Documentation

◆ CacheDisk() [1/2]

CacheDisk::CacheDisk ( string  cache_path,
string  format,
float  quality,
float  scale 
)

Default constructor, no max bytes.

Parameters
cache_pathThe folder path of the cache directory (empty string = /tmp/preview-cache/)
formatThe image format for disk caching (ppm, jpg, png)
qualityThe quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed)
scaleThe scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...)

Definition at line 34 of file CacheDisk.cpp.

◆ CacheDisk() [2/2]

CacheDisk::CacheDisk ( string  cache_path,
string  format,
float  quality,
float  scale,
int64_t  max_bytes 
)

Constructor that sets the max bytes to cache.

Parameters
cache_pathThe folder path of the cache directory (empty string = /tmp/preview-cache/)
formatThe image format for disk caching (ppm, jpg, png)
qualityThe quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed)
scaleThe scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...)
max_bytesThe maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames.

Definition at line 50 of file CacheDisk.cpp.

◆ ~CacheDisk()

CacheDisk::~CacheDisk ( )

Definition at line 154 of file CacheDisk.cpp.

Member Function Documentation

◆ Add()

void CacheDisk::Add ( std::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 166 of file CacheDisk.cpp.

◆ Clear()

void CacheDisk::Clear ( )
virtual

Clear the cache of all frames.

Implements openshot::CacheBase.

Definition at line 414 of file CacheDisk.cpp.

◆ Count()

int64_t CacheDisk::Count ( )
virtual

Count the frames in the queue.

Implements openshot::CacheBase.

Definition at line 435 of file CacheDisk.cpp.

◆ GetBytes()

int64_t CacheDisk::GetBytes ( )
virtual

Gets the maximum bytes value.

Implements openshot::CacheBase.

Definition at line 317 of file CacheDisk.cpp.

◆ GetFrame()

std::shared_ptr< Frame > CacheDisk::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 225 of file CacheDisk.cpp.

◆ GetSmallestFrame()

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

Get the smallest frame number.

Implements openshot::CacheBase.

Definition at line 295 of file CacheDisk.cpp.

◆ Json()

string CacheDisk::Json ( )
virtual

Get and Set JSON methods.

Generate JSON string of this object

Implements openshot::CacheBase.

Definition at line 465 of file CacheDisk.cpp.

◆ JsonValue()

Json::Value CacheDisk::JsonValue ( )
virtual

Generate Json::JsonValue for this object.

Implements openshot::CacheBase.

Definition at line 472 of file CacheDisk.cpp.

◆ MoveToFront()

void CacheDisk::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 388 of file CacheDisk.cpp.

◆ Remove() [1/2]

void CacheDisk::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 333 of file CacheDisk.cpp.

◆ Remove() [2/2]

void CacheDisk::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 339 of file CacheDisk.cpp.

◆ SetJson()

void CacheDisk::SetJson ( string  value)
virtual

Load JSON string into this object.

Implements openshot::CacheBase.

Definition at line 499 of file CacheDisk.cpp.

◆ SetJsonValue()

void CacheDisk::SetJsonValue ( Json::Value  root)
virtual

Load Json::JsonValue into this object.

Implements openshot::CacheBase.

Definition at line 522 of file CacheDisk.cpp.


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