OpenShot Library | libopenshot
0.3.3
|
This class is a disk-based cache manager for Frame objects. More...
#include <CacheDisk.h>
Public Member Functions | |
void | Add (std::shared_ptr< openshot::Frame > frame) |
Add a Frame to the cache. More... | |
CacheDisk (std::string cache_path, std::string format, float quality, float scale) | |
Default constructor, no max bytes. More... | |
CacheDisk (std::string cache_path, std::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... | |
bool | Contains (int64_t frame_number) |
Check if frame is already contained in cache. More... | |
int64_t | Count () |
Count the frames in the queue. More... | |
int64_t | GetBytes () |
Gets the maximum bytes value. More... | |
std::shared_ptr< openshot::Frame > | GetFrame (int64_t frame_number) |
Get a frame from the cache. More... | |
std::vector< std::shared_ptr< openshot::Frame > > | GetFrames () |
Get an array of all Frames. More... | |
std::shared_ptr< openshot::Frame > | GetSmallestFrame () |
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... | |
~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... | |
virtual | ~CacheBase ()=default |
Additional Inherited Members | |
Protected Member Functions inherited from openshot::CacheBase | |
void | CalculateRanges () |
Calculate ranges of frames. More... | |
Protected Attributes inherited from openshot::CacheBase | |
std::string | cache_type |
This is a friendly type name of the derived cache instance. More... | |
std::recursive_mutex * | cacheMutex |
Mutex for multiple threads. More... | |
std::map< int64_t, int64_t > | frame_ranges |
This map holds the ranges of frames, useful for quickly displaying the contents of the cache. More... | |
std::string | json_ranges |
JSON ranges of frame numbers. More... | |
int64_t | max_bytes |
This is the max number of bytes to cache (0 = no limit) More... | |
bool | needs_range_processing |
Something has changed, and the range data needs to be re-calculated. More... | |
std::vector< int64_t > | ordered_frame_numbers |
Ordered list of frame numbers used by cache. More... | |
int64_t | range_version |
The version of the JSON range data (incremented with each change) More... | |
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 30 of file CacheDisk.h.
CacheDisk::CacheDisk | ( | std::string | cache_path, |
std::string | format, | ||
float | quality, | ||
float | scale | ||
) |
Default constructor, no max bytes.
cache_path | The folder path of the cache directory (empty string = /tmp/preview-cache/) |
format | The image format for disk caching (ppm, jpg, png) |
quality | The quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed) |
scale | The scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...) |
Definition at line 26 of file CacheDisk.cpp.
CacheDisk::CacheDisk | ( | std::string | cache_path, |
std::string | format, | ||
float | quality, | ||
float | scale, | ||
int64_t | max_bytes | ||
) |
Constructor that sets the max bytes to cache.
cache_path | The folder path of the cache directory (empty string = /tmp/preview-cache/) |
format | The image format for disk caching (ppm, jpg, png) |
quality | The quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed) |
scale | The scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...) |
max_bytes | The maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames. |
Definition at line 42 of file CacheDisk.cpp.
CacheDisk::~CacheDisk | ( | ) |
Definition at line 79 of file CacheDisk.cpp.
|
virtual |
Add a Frame to the cache.
frame | The openshot::Frame object needing to be cached. |
Implements openshot::CacheBase.
Definition at line 88 of file CacheDisk.cpp.
|
virtual |
Clear the cache of all frames.
Implements openshot::CacheBase.
Definition at line 363 of file CacheDisk.cpp.
Referenced by SetJsonValue(), and ~CacheDisk().
|
virtual |
Check if frame is already contained in cache.
frame_number | The frame number to be checked |
Implements openshot::CacheBase.
Definition at line 147 of file CacheDisk.cpp.
|
virtual |
Count the frames in the queue.
Implements openshot::CacheBase.
Definition at line 386 of file CacheDisk.cpp.
|
virtual |
Gets the maximum bytes value.
Implements openshot::CacheBase.
Definition at line 266 of file CacheDisk.cpp.
|
virtual |
Get a frame from the cache.
frame_number | The frame number of the cached frame |
Implements openshot::CacheBase.
Definition at line 156 of file CacheDisk.cpp.
Referenced by GetFrames(), and GetSmallestFrame().
|
virtual |
Get an array of all Frames.
Implements openshot::CacheBase.
Definition at line 226 of file CacheDisk.cpp.
|
virtual |
Get the smallest frame number.
Implements openshot::CacheBase.
Definition at line 243 of file CacheDisk.cpp.
|
virtual |
Generate JSON string of this object.
Implements openshot::CacheBase.
Definition at line 416 of file CacheDisk.cpp.
|
virtual |
Generate Json::Value for this object.
Implements openshot::CacheBase.
Definition at line 423 of file CacheDisk.cpp.
Referenced by Json().
void CacheDisk::MoveToFront | ( | int64_t | frame_number | ) |
Move frame to front of queue (so it lasts longer)
frame_number | The frame number of the cached frame |
Definition at line 337 of file CacheDisk.cpp.
Referenced by Add().
|
virtual |
Remove a specific frame.
frame_number | The frame number of the cached frame |
Implements openshot::CacheBase.
Definition at line 282 of file CacheDisk.cpp.
|
virtual |
Remove a range of frames.
start_frame_number | The starting frame number of the cached frame |
end_frame_number | The ending frame number of the cached frame |
Implements openshot::CacheBase.
Definition at line 288 of file CacheDisk.cpp.
|
virtual |
Load JSON string into this object.
Implements openshot::CacheBase.
Definition at line 450 of file CacheDisk.cpp.
|
virtual |
Load Json::Value into this object.
Implements openshot::CacheBase.
Definition at line 467 of file CacheDisk.cpp.
Referenced by SetJson().