OpenShot Library | libopenshot 0.5.0
Loading...
Searching...
No Matches
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
18namespace openshot {
19 class Frame;
20
29 class CacheMemory : public CacheBase {
30 private:
31 static constexpr int64_t TRIM_THRESHOLD_BYTES = 1024LL * 1024 * 1024;
32 std::map<int64_t, std::shared_ptr<openshot::Frame> > frames;
33 std::deque<int64_t> frame_numbers;
34 int64_t bytes_freed_since_trim;
35
37 void CleanUp();
38
39 public:
42
45 CacheMemory(int64_t max_bytes);
46
47 // Default destructor
48 virtual ~CacheMemory();
49
52 void Add(std::shared_ptr<openshot::Frame> frame);
53
55 void Clear();
56
59 bool Contains(int64_t frame_number);
60
62 int64_t Count();
63
66 std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
67
69 std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
70
72 int64_t GetBytes();
73
75 std::shared_ptr<openshot::Frame> GetSmallestFrame();
76
79 void Touch(int64_t frame_number);
80
83 void Remove(int64_t frame_number);
84
88 void Remove(int64_t start_frame_number, int64_t end_frame_number);
89
90 // Get and Set JSON methods
91 std::string Json();
92 void SetJson(const std::string value);
93 Json::Value JsonValue();
94 void SetJsonValue(const Json::Value root);
95 };
96
97}
98
99#endif
Header file for CacheBase class.
All cache managers in libopenshot are based on this CacheBase class.
Definition CacheBase.h:35
int64_t max_bytes
This is the max number of bytes to cache (0 = no limit)
Definition CacheBase.h:38
This class is a memory-based cache manager for Frame objects.
Definition CacheMemory.h:29
CacheMemory()
Default constructor, no max bytes.
int64_t Count()
Count the frames in the queue.
void Add(std::shared_ptr< openshot::Frame > frame)
Add a Frame to the cache.
void SetJson(const std::string value)
Load JSON string into this object.
int64_t GetBytes()
Gets the maximum bytes value.
std::string Json()
Generate JSON string of this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)
Get a frame from the cache.
std::vector< std::shared_ptr< openshot::Frame > > GetFrames()
Get an array of all Frames.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void Remove(int64_t frame_number)
Remove a specific frame.
void Clear()
Clear the cache of all frames.
Json::Value JsonValue()
Generate Json::Value for this object.
void Touch(int64_t frame_number)
Move frame to front of queue (so it lasts longer)
bool Contains(int64_t frame_number)
Check if frame is already contained in cache.
std::shared_ptr< openshot::Frame > GetSmallestFrame()
Get the smallest frame number.
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29