49 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
50 int64_t frame_number = frame->number;
53 if (frames.count(frame_number))
60 frames[frame_number] = frame;
61 frame_numbers.push_front(frame_number);
72 if (frames.count(frame_number) > 0) {
83 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
86 if (frames.count(frame_number))
88 return frames[frame_number];
92 return std::shared_ptr<Frame>();
99 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
101 std::vector<std::shared_ptr<openshot::Frame>> all_frames;
102 std::vector<int64_t>::iterator itr_ordered;
105 int64_t frame_number = *itr_ordered;
106 all_frames.push_back(
GetFrame(frame_number));
116 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
119 std::deque<int64_t>::iterator itr;
120 int64_t smallest_frame = -1;
121 for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
123 if (*itr < smallest_frame || smallest_frame == -1)
124 smallest_frame = *itr;
128 if (smallest_frame != -1) {
129 return frames[smallest_frame];
139 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
141 int64_t total_bytes = 0;
144 std::deque<int64_t>::reverse_iterator itr;
145 for(itr = frame_numbers.rbegin(); itr != frame_numbers.rend(); ++itr)
147 total_bytes += frames[*itr]->GetBytes();
156 Remove(frame_number, frame_number);
163 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
166 std::deque<int64_t>::iterator itr;
167 for(itr = frame_numbers.begin(); itr != frame_numbers.end();)
169 if (*itr >= start_frame_number && *itr <= end_frame_number)
172 itr = frame_numbers.erase(itr);
178 std::vector<int64_t>::iterator itr_ordered;
181 if (*itr_ordered >= start_frame_number && *itr_ordered <= end_frame_number)
184 frames.erase(*itr_ordered);
198 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
201 if (frames.count(frame_number))
204 std::deque<int64_t>::iterator itr;
205 for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
207 if (*itr == frame_number)
210 frame_numbers.erase(itr);
213 frame_numbers.push_front(frame_number);
224 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
227 frame_numbers.clear();
228 frame_numbers.shrink_to_fit();
238 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
241 return frames.size();
245 void CacheMemory::CleanUp()
251 const std::lock_guard<std::recursive_mutex> lock(*
cacheMutex);
256 int64_t frame_to_remove = frame_numbers.back();
287 root[
"ranges"] = ranges;
304 catch (
const std::exception& e)
307 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
320 if (!root[
"type"].isNull())