Loading...
Searching...
No Matches
CacheMemory.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_MEMORY_H
#define OPENSHOT_CACHE_MEMORY_H
#include "CacheBase.h"
namespace openshot {
class Frame;
class CacheMemory : public CacheBase {
private:
std::map<int64_t, std::shared_ptr<openshot::Frame> > frames;
std::deque<int64_t> frame_numbers;
void CleanUp();
public:
CacheMemory();
CacheMemory(int64_t max_bytes);
// Default destructor
virtual ~CacheMemory();
void Add(std::shared_ptr<openshot::Frame> frame);
void Clear();
bool Contains(int64_t frame_number);
int64_t Count();
std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
int64_t GetBytes();
std::shared_ptr<openshot::Frame> GetSmallestFrame();
void MoveToFront(int64_t frame_number);
void Remove(int64_t frame_number);
void Remove(int64_t start_frame_number, int64_t end_frame_number);
// Get and Set JSON methods
std::string Json();
void SetJson(const std::string value);
Json::Value JsonValue();
void SetJsonValue(const Json::Value root);
};
}
#endif
CacheBase.h
Header file for CacheBase class.
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition CacheBase.h:35
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::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition CacheMemory.h:29
openshot::CacheMemory::CacheMemory
CacheMemory()
Default constructor, no max bytes.
Definition CacheMemory.cpp:21
openshot::CacheMemory::Count
int64_t Count()
Count the frames in the queue.
Definition CacheMemory.cpp:235
openshot::CacheMemory::Add
void Add(std::shared_ptr< openshot::Frame > frame)
Add a Frame to the cache.
Definition CacheMemory.cpp:46
openshot::CacheMemory::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition CacheMemory.cpp:295
openshot::CacheMemory::GetBytes
int64_t GetBytes()
Gets the maximum bytes value.
Definition CacheMemory.cpp:136
openshot::CacheMemory::~CacheMemory
virtual ~CacheMemory()
Definition CacheMemory.cpp:37
openshot::CacheMemory::Json
std::string Json()
Generate JSON string of this object.
Definition CacheMemory.cpp:266
openshot::CacheMemory::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)
Get a frame from the cache.
Definition CacheMemory.cpp:80
openshot::CacheMemory::GetFrames
std::vector< std::shared_ptr< openshot::Frame > > GetFrames()
Get an array of all Frames.
Definition CacheMemory.cpp:96
openshot::CacheMemory::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition CacheMemory.cpp:312
openshot::CacheMemory::MoveToFront
void MoveToFront(int64_t frame_number)
Move frame to front of queue (so it lasts longer)
Definition CacheMemory.cpp:195
openshot::CacheMemory::Remove
void Remove(int64_t frame_number)
Remove a specific frame.
Definition CacheMemory.cpp:154
openshot::CacheMemory::Clear
void Clear()
Clear the cache of all frames.
Definition CacheMemory.cpp:221
openshot::CacheMemory::JsonValue
Json::Value JsonValue()
Generate Json::Value for this object.
Definition CacheMemory.cpp:273
openshot::CacheMemory::Contains
bool Contains(int64_t frame_number)
Check if frame is already contained in cache.
Definition CacheMemory.cpp:71
openshot::CacheMemory::GetSmallestFrame
std::shared_ptr< openshot::Frame > GetSmallestFrame()
Get the smallest frame number.
Definition CacheMemory.cpp:113
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29