Loading...
Searching...
No Matches
openshot::CacheBase Class Referenceabstract

All cache managers in libopenshot are based on this CacheBase class. More...

`#include <CacheBase.h>`

Inheritance diagram for openshot::CacheBase:

## Public Member Functions

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

## Protected Member Functions

void | CalculateRanges ()
| Calculate ranges of frames.

## Protected Attributes

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

All cache managers in libopenshot are based on this CacheBase class.

Cache is a very important element of video editing, and is required to achieve a high degree of performance. There are multiple derived cache objects based on this class, some which use memory, and some which use disk to store the cache.

Definition at line 34 of file CacheBase.h.

## Constructor & Destructor Documentation

## CacheBase() [1/2]

CacheBase::CacheBase | ( |  | ) |

Default constructor, no max bytes.

Definition at line 21 of file CacheBase.cpp.

## CacheBase() [2/2]

CacheBase::CacheBase | ( | 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 24 of file CacheBase.cpp.

## ~CacheBase()

virtual openshot::CacheBase::~CacheBase | ( |  | ) |

virtual default

## Member Function Documentation

## Add()

virtual void openshot::CacheBase::Add | ( | std::shared_ptr< openshot::Frame > | frame | ) |

pure virtual

Add a Frame to the cache.

Parameters

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

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Referenced by openshot::Timeline::GetFrame().

## CalculateRanges()

void CacheBase::CalculateRanges | ( |  | ) |

protected

Calculate ranges of frames.

Definition at line 38 of file CacheBase.cpp.

Referenced by openshot::CacheDisk::JsonValue(), and openshot::CacheMemory::JsonValue().

## Clear()

virtual void openshot::CacheBase::Clear | ( |  | ) |

pure virtual

Clear the cache of all frames.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Referenced by openshot::Timeline::ClearAllCache().

## Contains()

virtual bool openshot::CacheBase::Contains | ( | int64_t | frame_number | ) |

pure virtual

Check if frame is already contained in cache.

Parameters

  frame_number | The frame number to be checked

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Referenced by openshot::VideoCacheThread::run(), and openshot::VideoCacheThread::Seek().

## Count()

virtual int64_t openshot::CacheBase::Count | ( |  | ) |

pure virtual

Count the frames in the queue.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Referenced by openshot::DummyReader::GetFrame(), and openshot::VideoCacheThread::run().

## GetBytes()

virtual int64_t openshot::CacheBase::GetBytes | ( |  | ) |

pure virtual

Gets the maximum bytes value.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## GetFrame()

virtual std::shared_ptr< openshot::Frame > openshot::CacheBase::GetFrame | ( | int64_t | frame_number | ) |

pure virtual

Get a frame from the cache.

Parameters

  frame_number | The frame number of the cached frame

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Referenced by openshot::DummyReader::GetFrame(), and openshot::Timeline::GetFrame().

## GetFrames()

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

pure virtual

Get an vector of all Frames.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## GetMaxBytes()

int64_t openshot::CacheBase::GetMaxBytes | ( |  | ) |

inline

Gets the maximum bytes value.

Definition at line 97 of file CacheBase.h.

Referenced by openshot::VideoCacheThread::run().

## GetSmallestFrame()

virtual std::shared_ptr< openshot::Frame > openshot::CacheBase::GetSmallestFrame | ( |  | ) |

pure virtual

Get the smallest frame number.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## Json()

virtual std::string openshot::CacheBase::Json | ( |  | ) |

pure virtual

Generate JSON string of this object.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## JsonValue()

Json::Value CacheBase::JsonValue | ( |  | ) |

pure virtual

Generate Json::Value for this object.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Definition at line 102 of file CacheBase.cpp.

Referenced by openshot::CacheDisk::JsonValue(), and openshot::CacheMemory::JsonValue().

## Remove() [1/2]

virtual void openshot::CacheBase::Remove | ( | int64_t | frame_number | ) |

pure virtual

Remove a specific frame.

Parameters

  frame_number | The frame number of the cached frame

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## Remove() [2/2]

virtual void openshot::CacheBase::Remove | ( | int64_t | start_frame_number,
|  | int64_t | end_frame_number
| ) |  |

pure 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

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## SetJson()

virtual void openshot::CacheBase::SetJson | ( | const std::string | value | ) |

pure virtual

Load JSON string into this object.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

## SetJsonValue()

void CacheBase::SetJsonValue | ( | const Json::Value | root | ) |

pure virtual

Load Json::Value into this object.

Implemented in openshot::CacheDisk, and openshot::CacheMemory.

Definition at line 115 of file CacheBase.cpp.

Referenced by openshot::CacheDisk::SetJsonValue(), and openshot::CacheMemory::SetJsonValue().

## SetMaxBytes()

void openshot::CacheBase::SetMaxBytes | ( | int64_t | number_of_bytes | ) |

inline

Set maximum bytes to a different amount.

Parameters

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

Definition at line 101 of file CacheBase.h.

Referenced by SetMaxBytesFromInfo().

## SetMaxBytesFromInfo()

void CacheBase::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.

Parameters

  number_of_frames | The maximum number of frames to hold in cache
  width | The width of the frame's image
  height | The height of the frame's image
  sample_rate | The sample rate of the frame's audio data
  channels | The number of audio channels in the frame

Definition at line 30 of file CacheBase.cpp.

Referenced by openshot::FrameMapper::ChangeMapping(), openshot::FFmpegReader::FFmpegReader(), openshot::FrameMapper::FrameMapper(), openshot::Clip::init_reader_settings(), openshot::FFmpegReader::Open(), openshot::Timeline::Timeline(), and openshot::Timeline::Timeline().

## Member Data Documentation

## cache_type

std::string openshot::CacheBase::cache_type

protected

This is a friendly type name of the derived cache instance.

Definition at line 37 of file CacheBase.h.

Referenced by openshot::CacheDisk::CacheDisk(), openshot::CacheDisk::CacheDisk(), openshot::CacheMemory::CacheMemory(), openshot::CacheMemory::CacheMemory(), openshot::CacheDisk::JsonValue(), openshot::CacheMemory::JsonValue(), openshot::CacheDisk::SetJsonValue(), and openshot::CacheMemory::SetJsonValue().

## cacheMutex

std::recursive_mutex* openshot::CacheBase::cacheMutex

protected

Mutex for multiple threads.

Definition at line 47 of file CacheBase.h.

Referenced by openshot::CacheDisk::Add(), openshot::CacheMemory::Add(), CacheBase(), CalculateRanges(), openshot::CacheDisk::Clear(), openshot::CacheMemory::Clear(), openshot::CacheDisk::Count(), openshot::CacheMemory::Count(), openshot::CacheDisk::GetBytes(), openshot::CacheMemory::GetBytes(), openshot::CacheDisk::GetFrame(), openshot::CacheMemory::GetFrame(), openshot::CacheDisk::GetFrames(), openshot::CacheMemory::GetFrames(), openshot::CacheDisk::GetSmallestFrame(), openshot::CacheMemory::GetSmallestFrame(), openshot::CacheDisk::MoveToFront(), openshot::CacheMemory::MoveToFront(), openshot::CacheDisk::Remove(), openshot::CacheMemory::Remove(), openshot::CacheDisk::~CacheDisk(), and openshot::CacheMemory::~CacheMemory().

## frame_ranges

std::map<int64_t, int64_t> openshot::CacheBase::frame_ranges

protected

This map holds the ranges of frames, useful for quickly displaying the contents of the cache.

Definition at line 43 of file CacheBase.h.

## json_ranges

std::string openshot::CacheBase::json_ranges

protected

JSON ranges of frame numbers.

Definition at line 41 of file CacheBase.h.

Referenced by CalculateRanges(), openshot::CacheDisk::JsonValue(), and openshot::CacheMemory::JsonValue().

## max_bytes

int64_t openshot::CacheBase::max_bytes

protected

This is the max number of bytes to cache (0 = no limit)

Definition at line 38 of file CacheBase.h.

Referenced by openshot::CacheDisk::CacheDisk(), GetMaxBytes(), JsonValue(), SetJsonValue(), and SetMaxBytes().

## needs_range_processing

bool openshot::CacheBase::needs_range_processing

protected

Something has changed, and the range data needs to be re-calculated.

Definition at line 40 of file CacheBase.h.

Referenced by openshot::CacheDisk::Add(), openshot::CacheMemory::Add(), openshot::CacheDisk::CacheDisk(), openshot::CacheDisk::CacheDisk(), openshot::CacheMemory::CacheMemory(), openshot::CacheMemory::CacheMemory(), CalculateRanges(), openshot::CacheDisk::Clear(), openshot::CacheMemory::Clear(), openshot::CacheDisk::Remove(), and openshot::CacheMemory::Remove().

## ordered_frame_numbers

std::vector<int64_t> openshot::CacheBase::ordered_frame_numbers

protected

Ordered list of frame numbers used by cache.

Definition at line 42 of file CacheBase.h.

Referenced by openshot::CacheDisk::Add(), openshot::CacheMemory::Add(), CalculateRanges(), openshot::CacheDisk::Clear(), openshot::CacheMemory::Clear(), openshot::CacheDisk::GetFrames(), openshot::CacheMemory::GetFrames(), openshot::CacheDisk::Remove(), and openshot::CacheMemory::Remove().

## range_version

int64_t openshot::CacheBase::range_version

protected

The version of the JSON range data (incremented with each change)

Definition at line 44 of file CacheBase.h.

Referenced by openshot::CacheDisk::CacheDisk(), openshot::CacheDisk::CacheDisk(), openshot::CacheMemory::CacheMemory(), openshot::CacheMemory::CacheMemory(), CalculateRanges(), openshot::CacheDisk::JsonValue(), and openshot::CacheMemory::JsonValue().

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

- CacheBase.h
- CacheBase.cpp