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

@@ -64,6 +64,9 @@ namespace openshot {
/// @param frame_number The frame number of the cached frame
virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) = 0;
/// @brief Get an vector of all Frames
virtual std::vector<std::shared_ptr<openshot::Frame>> GetFrames() = 0;
/// Gets the maximum bytes value
virtual int64_t GetBytes() = 0;

View File

@@ -279,6 +279,23 @@ std::shared_ptr<Frame> CacheDisk::GetFrame(int64_t frame_number)
return std::shared_ptr<Frame>();
}
// @brief Get an array of all Frames
std::vector<std::shared_ptr<openshot::Frame>> CacheDisk::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> CacheDisk::GetSmallestFrame()
{

View File

@@ -93,6 +93,9 @@ namespace openshot {
/// @param frame_number The frame number of the cached frame
std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
/// @brief Get an array of all Frames
std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
/// Gets the maximum bytes value
int64_t GetBytes();

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()
{

View File

@@ -76,6 +76,9 @@ namespace openshot {
/// @param frame_number The frame number of the cached frame
std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number);
/// @brief Get an array of all Frames
std::vector<std::shared_ptr<openshot::Frame>> GetFrames();
/// Gets the maximum bytes value
int64_t GetBytes();