Loading...
Searching...
No Matches
CacheBase.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_CACHE_BASE_H
#define OPENSHOT_CACHE_BASE_H
#include <map>
#include <vector>
#include <memory>
#include <mutex>
#include <algorithm>
#include "Json.h"
namespace openshot {
class Frame;
class CacheBase
{
protected:
std::string cache_type;
int64_t max_bytes;
bool needs_range_processing;
std::string json_ranges;
std::vector<int64_t> ordered_frame_numbers;
std::map<int64_t, int64_t> frame_ranges;
int64_t range_version;
std::recursive_mutex *cacheMutex;
void CalculateRanges();
public:
CacheBase();
CacheBase(int64_t max_bytes);
virtual void Add(std::shared_ptr<openshot::Frame> frame) = 0;
virtual void Clear() = 0;
virtual bool Contains(int64_t frame_number) = 0;
virtual int64_t Count() = 0;
virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) = 0;
virtual std::vector<std::shared_ptr<openshot::Frame>> GetFrames() = 0;
virtual int64_t GetBytes() = 0;
virtual std::shared_ptr<openshot::Frame> GetSmallestFrame() = 0;
virtual void Remove(int64_t frame_number) = 0;
virtual void Remove(int64_t start_frame_number, int64_t end_frame_number) = 0;
virtual void Touch(int64_t frame_number) = 0;
int64_t GetMaxBytes() { return max_bytes; };
void SetMaxBytes(int64_t number_of_bytes) { max_bytes = number_of_bytes; };
void SetMaxBytesFromInfo(int64_t number_of_frames, int width, int height, int sample_rate, int channels);
// Get and Set JSON methods
virtual std::string Json() = 0;
virtual void SetJson(const std::string value) = 0;
virtual Json::Value JsonValue() = 0;
virtual void SetJsonValue(const Json::Value root) = 0;
virtual ~CacheBase() = default;
};
}
#endif
Json.h
Header file for JSON class.
openshot::CacheBase::range_version
int64_t range_version
The version of the JSON range data (incremented with each change).
Definition CacheBase.h:44
openshot::CacheBase::CacheBase
CacheBase()
Default constructor, no max bytes.
Definition CacheBase.cpp:19
openshot::CacheBase::SetJson
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
openshot::CacheBase::GetBytes
virtual int64_t GetBytes()=0
Gets the maximum bytes value.
openshot::CacheBase::GetSmallestFrame
virtual std::shared_ptr< openshot::Frame > GetSmallestFrame()=0
Get the smallest frame number.
openshot::CacheBase::Clear
virtual void Clear()=0
Clear the cache of all frames.
openshot::CacheBase::Contains
virtual bool Contains(int64_t frame_number)=0
Check if frame is already contained in cache.
openshot::CacheBase::GetFrames
virtual std::vector< std::shared_ptr< openshot::Frame > > GetFrames()=0
Get an vector of all Frames.
openshot::CacheBase::JsonValue
virtual Json::Value JsonValue()=0
Generate Json::Value for this object.
Definition CacheBase.cpp:100
openshot::CacheBase::frame_ranges
std::map< int64_t, int64_t > frame_ranges
This map holds the ranges of frames, useful for quickly displaying the contents of the cache.
Definition CacheBase.h:43
openshot::CacheBase::cache_type
std::string cache_type
This is a friendly type name of the derived cache instance.
Definition CacheBase.h:37
openshot::CacheBase::Remove
virtual void Remove(int64_t start_frame_number, int64_t end_frame_number)=0
Remove a range of frames.
openshot::CacheBase::CalculateRanges
void CalculateRanges()
Calculate ranges of frames.
Definition CacheBase.cpp:36
openshot::CacheBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition CacheBase.cpp:111
openshot::CacheBase::Remove
virtual void Remove(int64_t frame_number)=0
Remove a specific frame.
openshot::CacheBase::GetFrame
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)=0
Get a frame from the cache.
openshot::CacheBase::needs_range_processing
bool needs_range_processing
Something has changed, and the range data needs to be re-calculated.
Definition CacheBase.h:40
openshot::CacheBase::~CacheBase
virtual ~CacheBase()=default
openshot::CacheBase::Count
virtual int64_t Count()=0
Count the frames in the queue.
openshot::CacheBase::Add
virtual void Add(std::shared_ptr< openshot::Frame > frame)=0
Add a Frame to the cache.
openshot::CacheBase::Touch
virtual void Touch(int64_t frame_number)=0
Move frame to front of queue (so it lasts longer).
openshot::CacheBase::Json
virtual std::string Json()=0
Generate JSON string of this object.
openshot::CacheBase::max_bytes
int64_t max_bytes
This is the max number of bytes to cache (0 = no limit).
Definition CacheBase.h:38
openshot::CacheBase::GetMaxBytes
int64_t GetMaxBytes()
Gets the maximum bytes value.
Definition CacheBase.h:101
openshot::CacheBase::SetMaxBytesFromInfo
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.
Definition CacheBase.cpp:28
openshot::CacheBase::cacheMutex
std::recursive_mutex * cacheMutex
Mutex for multiple threads.
Definition CacheBase.h:47
openshot::CacheBase::json_ranges
std::string json_ranges
JSON ranges of frame numbers.
Definition CacheBase.h:41
openshot::CacheBase::ordered_frame_numbers
std::vector< int64_t > ordered_frame_numbers
Ordered list of frame numbers used by cache.
Definition CacheBase.h:42
openshot::CacheBase::SetMaxBytes
void SetMaxBytes(int64_t number_of_bytes)
Set maximum bytes to a different amount.
Definition CacheBase.h:105
openshot::Frame
This class represents a single frame of video (i.e. image & audio data).
Definition Frame.h:89
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29