OpenShot Library | libopenshot 0.3.3
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 std::map<int64_t, std::shared_ptr<openshot::Frame> > frames;
32 std::deque<int64_t> frame_numbers;
33
35 void CleanUp();
36
37 public:
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
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 MoveToFront(int64_t frame_number)
Move frame to front of queue (so it lasts longer)
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.
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