Adding new GetFrames method to CacheBase, to return an ordered vector of Frame objects. Useful when needing to iterate through the current cached frames.

This commit is contained in:
Jonathan Thomas
2022-06-25 17:32:36 -05:00
parent 5776efd71c
commit d243db8aaa
5 changed files with 43 additions and 0 deletions

View File

@@ -152,6 +152,23 @@ std::shared_ptr<Frame> CacheMemory::GetFrame(int64_t frame_number)
return std::shared_ptr<Frame>();
}
// @brief Get an array of all Frames
std::vector<std::shared_ptr<openshot::Frame>> CacheMemory::GetFrames()
{
// Create a scoped lock, to protect the cache from multiple threads
const std::lock_guard<std::recursive_mutex> lock(*cacheMutex);
std::vector<std::shared_ptr<openshot::Frame>> all_frames;
std::vector<int64_t>::iterator itr_ordered;
for(itr_ordered = ordered_frame_numbers.begin(); itr_ordered != ordered_frame_numbers.end(); ++itr_ordered)
{
int64_t frame_number = *itr_ordered;
all_frames.push_back(GetFrame(frame_number));
}
return all_frames;
}
// Get the smallest frame number (or NULL shared_ptr if no frame is found)
std::shared_ptr<Frame> CacheMemory::GetSmallestFrame()
{