OpenShot Library | libopenshot  0.3.3
CacheMemory.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CACHE_MEMORY_H
14 #define OPENSHOT_CACHE_MEMORY_H
15 
16 #include "CacheBase.h"
17 
18 namespace openshot {
19  class Frame;
20 
29  class CacheMemory : public CacheBase {
30  private:
31  std::map<int64_t, std::shared_ptr<openshot::Frame> > frames;
32  std::deque<int64_t> frame_numbers;
33 
35  void CleanUp();
36 
37  public:
39  CacheMemory();
40 
43  CacheMemory(int64_t max_bytes);
44 
45  // Default destructor
46  virtual ~CacheMemory();
47 
50  void Add(std::shared_ptr<openshot::Frame> frame);
51 
53  void Clear();
54 
57  bool Contains(int64_t frame_number);
58 
60  int64_t Count();
61 
64  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
65 
67  std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
68 
70  int64_t GetBytes();
71 
73  std::shared_ptr<openshot::Frame> GetSmallestFrame();
74 
77  void MoveToFront(int64_t frame_number);
78 
81  void Remove(int64_t frame_number);
82 
86  void Remove(int64_t start_frame_number, int64_t end_frame_number);
87 
88  // Get and Set JSON methods
89  std::string Json();
90  void SetJson(const std::string value);
91  Json::Value JsonValue();
92  void SetJsonValue(const Json::Value root);
93  };
94 
95 }
96 
97 #endif
openshot::CacheMemory::Clear
void Clear()
Clear the cache of all frames.
Definition: CacheMemory.cpp:221
openshot::CacheMemory::Count
int64_t Count()
Count the frames in the queue.
Definition: CacheMemory.cpp:235
openshot::CacheMemory::GetBytes
int64_t GetBytes()
Gets the maximum bytes value.
Definition: CacheMemory.cpp:136
openshot::CacheMemory::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)
Get a frame from the cache.
Definition: CacheMemory.cpp:80
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::Add
void Add(std::shared_ptr< openshot::Frame > frame)
Add a Frame to the cache.
Definition: CacheMemory.cpp:46
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::CacheMemory::Contains
bool Contains(int64_t frame_number)
Check if frame is already contained in cache.
Definition: CacheMemory.cpp:71
openshot::CacheMemory::Remove
void Remove(int64_t frame_number)
Remove a specific frame.
Definition: CacheMemory.cpp:154
openshot::CacheMemory::JsonValue
Json::Value JsonValue()
Generate Json::Value for this object.
Definition: CacheMemory.cpp:273
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:34
CacheBase.h
Header file for CacheBase class.
openshot::CacheMemory::~CacheMemory
virtual ~CacheMemory()
Definition: CacheMemory.cpp:37
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:29
openshot::CacheMemory::Json
std::string Json()
Generate JSON string of this object.
Definition: CacheMemory.cpp:266
openshot::CacheMemory::GetSmallestFrame
std::shared_ptr< openshot::Frame > GetSmallestFrame()
Get the smallest frame number.
Definition: CacheMemory.cpp:113
openshot::CacheMemory::CacheMemory
CacheMemory()
Default constructor, no max bytes.
Definition: CacheMemory.cpp:21
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::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: CacheMemory.cpp:295
openshot::CacheMemory::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: CacheMemory.cpp:312
openshot::CacheMemory::GetFrames
std::vector< std::shared_ptr< openshot::Frame > > GetFrames()
Get an array of all Frames.
Definition: CacheMemory.cpp:96