OpenShot Library | libopenshot  0.3.3
CacheDisk.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_DISK_H
14 #define OPENSHOT_CACHE_DISK_H
15 
16 #include "CacheBase.h"
17 
18 #include <QDir>
19 
20 namespace openshot {
21  class Frame;
22 
30  class CacheDisk : public CacheBase {
31  private:
32  QDir path;
33  std::map<int64_t, int64_t> frames;
34  std::deque<int64_t> frame_numbers;
35  std::string image_format;
36  float image_quality;
37  float image_scale;
38  int64_t frame_size_bytes;
39 
41  void CleanUp();
42 
44  void InitPath(std::string cache_path);
45 
46  public:
52  CacheDisk(std::string cache_path, std::string format, float quality, float scale);
53 
60  CacheDisk(std::string cache_path, std::string format, float quality, float scale, int64_t max_bytes);
61 
62  // Default destructor
63  ~CacheDisk();
64 
67  void Add(std::shared_ptr<openshot::Frame> frame);
68 
70  void Clear();
71 
74  bool Contains(int64_t frame_number);
75 
77  int64_t Count();
78 
81  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
82 
84  std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
85 
87  int64_t GetBytes();
88 
90  std::shared_ptr<openshot::Frame> GetSmallestFrame();
91 
94  void MoveToFront(int64_t frame_number);
95 
98  void Remove(int64_t frame_number);
99 
103  void Remove(int64_t start_frame_number, int64_t end_frame_number);
104 
105  // Get and Set JSON methods
106  std::string Json();
107  void SetJson(const std::string value);
108  Json::Value JsonValue();
109  void SetJsonValue(const Json::Value root);
110  };
111 
112 }
113 
114 #endif
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::CacheDisk
This class is a disk-based cache manager for Frame objects.
Definition: CacheDisk.h:30
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::CacheDisk::Contains
bool Contains(int64_t frame_number)
Check if frame is already contained in cache.
Definition: CacheDisk.cpp:147
openshot::CacheDisk::Remove
void Remove(int64_t frame_number)
Remove a specific frame.
Definition: CacheDisk.cpp:282
openshot::CacheDisk::Clear
void Clear()
Clear the cache of all frames.
Definition: CacheDisk.cpp:363
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::CacheDisk::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: CacheDisk.cpp:467
openshot::CacheDisk::Count
int64_t Count()
Count the frames in the queue.
Definition: CacheDisk.cpp:386
openshot::CacheDisk::Json
std::string Json()
Generate JSON string of this object.
Definition: CacheDisk.cpp:416
openshot::CacheDisk::CacheDisk
CacheDisk(std::string cache_path, std::string format, float quality, float scale)
Default constructor, no max bytes.
Definition: CacheDisk.cpp:26
openshot::CacheDisk::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)
Get a frame from the cache.
Definition: CacheDisk.cpp:156
openshot::CacheDisk::GetBytes
int64_t GetBytes()
Gets the maximum bytes value.
Definition: CacheDisk.cpp:266
openshot::CacheDisk::GetFrames
std::vector< std::shared_ptr< openshot::Frame > > GetFrames()
Get an array of all Frames.
Definition: CacheDisk.cpp:226
openshot::CacheDisk::JsonValue
Json::Value JsonValue()
Generate Json::Value for this object.
Definition: CacheDisk.cpp:423
openshot::CacheDisk::GetSmallestFrame
std::shared_ptr< openshot::Frame > GetSmallestFrame()
Get the smallest frame number.
Definition: CacheDisk.cpp:243
openshot::CacheDisk::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: CacheDisk.cpp:450
openshot::CacheDisk::Add
void Add(std::shared_ptr< openshot::Frame > frame)
Add a Frame to the cache.
Definition: CacheDisk.cpp:88
openshot::CacheDisk::MoveToFront
void MoveToFront(int64_t frame_number)
Move frame to front of queue (so it lasts longer)
Definition: CacheDisk.cpp:337
openshot::CacheDisk::~CacheDisk
~CacheDisk()
Definition: CacheDisk.cpp:79