Loading...
Searching...
No Matches
openshot::CacheMemory Class Reference

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

`#include <CacheMemory.h>`

Inheritance diagram for openshot::CacheMemory:

## Public Member Functions

void | Add (std::shared_ptr< openshot::Frame > frame)
| Add a Frame to the cache.
| CacheMemory ()
| Default constructor, no max bytes.
| CacheMemory (int64_t max_bytes)
| Constructor that sets the max bytes to cache.
void | Clear ()
| Clear the cache of all frames.
bool | Contains (int64_t frame_number)
| Check if frame is already contained in cache.
int64_t | Count ()
| Count the frames in the queue.
int64_t | GetBytes ()
| Gets the maximum bytes value.
std::shared_ptr< openshot::Frame > | GetFrame (int64_t frame_number)
| Get a frame from the cache.
std::vector< std::shared_ptr< openshot::Frame > > | GetFrames ()
| Get an array of all Frames.
std::shared_ptr< openshot::Frame > | GetSmallestFrame ()
| Get the smallest frame number.
std::string | Json ()
| Generate JSON string of this object.
Json::Value | JsonValue ()
| Generate Json::Value for this object.
void | Remove (int64_t frame_number)
| Remove a specific frame.
void | Remove (int64_t start_frame_number, int64_t end_frame_number)
| Remove a range of frames.
void | SetJson (const std::string value)
| Load JSON string into this object.
void | SetJsonValue (const Json::Value root)
| Load Json::Value into this object.
void | Touch (int64_t frame_number)
| Move frame to front of queue (so it lasts longer).
virtual | ~CacheMemory ()
Public Member Functions inherited from openshot::CacheBase
| CacheBase ()
| Default constructor, no max bytes.
| CacheBase (int64_t max_bytes)
| Constructor that sets the max bytes to cache.
int64_t | GetMaxBytes ()
| Gets the maximum bytes value.
void | SetMaxBytes (int64_t number_of_bytes)
| Set maximum bytes to a different amount.
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.
virtual | ~CacheBase ()=default

## Additional Inherited Members

Protected Member Functions inherited from openshot::CacheBase
void | CalculateRanges ()
| Calculate ranges of frames.
Protected Attributes inherited from openshot::CacheBase
std::string | cache_type
| This is a friendly type name of the derived cache instance.
std::recursive_mutex * | cacheMutex
| Mutex for multiple threads.
std::map< int64_t, int64_t > | frame_ranges
| This map holds the ranges of frames, useful for quickly displaying the contents of the cache.
std::string | json_ranges
| JSON ranges of frame numbers.
int64_t | max_bytes
| This is the max number of bytes to cache (0 = no limit).
bool | needs_range_processing
| Something has changed, and the range data needs to be re-calculated.
std::vector< int64_t > | ordered_frame_numbers
| Ordered list of frame numbers used by cache.
int64_t | range_version
| The version of the JSON range data (incremented with each change).

## 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 29 of file CacheMemory.h.

## Constructor & Destructor Documentation

## CacheMemory() [1/2]

CacheMemory::CacheMemory | ( |  | ) |

Default constructor, no max bytes.

Definition at line 22 of file CacheMemory.cpp.

## CacheMemory() [2/2]

CacheMemory::CacheMemory | ( | int64_t | max_bytes | ) |

Constructor that sets the max bytes to cache.

Parameters

  max_bytes | The maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames.

Definition at line 30 of file CacheMemory.cpp.

## ~CacheMemory()

CacheMemory::~CacheMemory | ( |  | ) |

virtual

Definition at line 38 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

  frame | The openshot::Frame object needing to be cached.

Implements openshot::CacheBase.

Definition at line 47 of file CacheMemory.cpp.

## Clear()

void CacheMemory::Clear | ( |  | ) |

virtual

Clear the cache of all frames.

Implements openshot::CacheBase.

Definition at line 238 of file CacheMemory.cpp.

Referenced by SetJsonValue(), and ~CacheMemory().

## Contains()

bool CacheMemory::Contains | ( | int64_t | frame_number | ) |

virtual

Check if frame is already contained in cache.

Parameters

  frame_number | The frame number to be checked

Implements openshot::CacheBase.

Definition at line 72 of file CacheMemory.cpp.

## Count()

int64_t CacheMemory::Count | ( |  | ) |

virtual

Count the frames in the queue.

Implements openshot::CacheBase.

Definition at line 256 of file CacheMemory.cpp.

## GetBytes()

int64_t CacheMemory::GetBytes | ( |  | ) |

virtual

Gets the maximum bytes value.

Implements openshot::CacheBase.

Definition at line 137 of file CacheMemory.cpp.

## GetFrame()

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

virtual

Get a frame from the cache.

Parameters

  frame_number | The frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 81 of file CacheMemory.cpp.

Referenced by GetFrames().

## GetFrames()

std::vector< std::shared_ptr< openshot::Frame > > CacheMemory::GetFrames | ( |  | ) |

virtual

Get an array of all Frames.

Implements openshot::CacheBase.

Definition at line 97 of file CacheMemory.cpp.

## GetSmallestFrame()

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

virtual

Get the smallest frame number.

Implements openshot::CacheBase.

Definition at line 114 of file CacheMemory.cpp.

## Json()

std::string CacheMemory::Json | ( |  | ) |

virtual

Generate JSON string of this object.

Implements openshot::CacheBase.

Definition at line 287 of file CacheMemory.cpp.

## JsonValue()

Json::Value CacheMemory::JsonValue | ( |  | ) |

virtual

Generate Json::Value for this object.

Implements openshot::CacheBase.

Definition at line 294 of file CacheMemory.cpp.

Referenced by Json().

## Remove() [1/2]

void CacheMemory::Remove | ( | int64_t | frame_number | ) |

virtual

Remove a specific frame.

Parameters

  frame_number | The frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 155 of file CacheMemory.cpp.

Referenced by 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_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 161 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 316 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 333 of file CacheMemory.cpp.

Referenced by SetJson().

## Touch()

void CacheMemory::Touch | ( | int64_t | frame_number | ) |

virtual

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

Parameters

  frame_number | The frame number of the cached frame

Implements openshot::CacheBase.

Definition at line 212 of file CacheMemory.cpp.

Referenced by Add().

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

- CacheMemory.h
- CacheMemory.cpp