You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
std:: prefixes for CacheBase/Disk/Memory
This commit is contained in:
@@ -48,7 +48,7 @@ namespace openshot {
|
||||
class CacheBase
|
||||
{
|
||||
protected:
|
||||
string cache_type; ///< This is a friendly type name of the derived cache instance
|
||||
std::string cache_type; ///< This is a friendly type name of the derived cache instance
|
||||
int64_t max_bytes; ///< This is the max number of bytes to cache (0 = no limit)
|
||||
|
||||
/// Section lock for multiple threads
|
||||
@@ -108,8 +108,8 @@ namespace openshot {
|
||||
void SetMaxBytesFromInfo(int64_t number_of_frames, int width, int height, int sample_rate, int channels);
|
||||
|
||||
/// Get and Set JSON methods
|
||||
virtual string Json() = 0; ///< Generate JSON string of this object
|
||||
virtual void SetJson(string value) = 0; ///< Load JSON string into this object
|
||||
virtual std::string Json() = 0; ///< Generate JSON string of this object
|
||||
virtual void SetJson(std::string value) = 0; ///< Load JSON string into this object
|
||||
virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
|
||||
virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue into this object
|
||||
virtual ~CacheBase() = default;
|
||||
|
||||
@@ -53,24 +53,24 @@ namespace openshot {
|
||||
class CacheDisk : public CacheBase {
|
||||
private:
|
||||
QDir path; ///< This is the folder path of the cache directory
|
||||
map<int64_t, int64_t> frames; ///< This map holds the frame number and Frame objects
|
||||
deque<int64_t> frame_numbers; ///< This queue holds a sequential list of cached Frame numbers
|
||||
string image_format;
|
||||
std::map<int64_t, int64_t> frames; ///< This map holds the frame number and Frame objects
|
||||
std::deque<int64_t> frame_numbers; ///< This queue holds a sequential list of cached Frame numbers
|
||||
std::string image_format;
|
||||
float image_quality;
|
||||
float image_scale;
|
||||
|
||||
int64_t frame_size_bytes; ///< The size of the cached frame in bytes
|
||||
bool needs_range_processing; ///< Something has changed, and the range data needs to be re-calculated
|
||||
string json_ranges; ///< JSON ranges of frame numbers
|
||||
vector<int64_t> ordered_frame_numbers; ///< Ordered list of frame numbers used by cache
|
||||
map<int64_t, int64_t> frame_ranges; ///< This map holds the ranges of frames, useful for quickly displaying the contents of the cache
|
||||
std::string json_ranges; ///< JSON ranges of frame numbers
|
||||
std::vector<int64_t> ordered_frame_numbers; ///< Ordered list of frame numbers used by cache
|
||||
std::map<int64_t, int64_t> frame_ranges; ///< This map holds the ranges of frames, useful for quickly displaying the contents of the cache
|
||||
int64_t range_version; ///< The version of the JSON range data (incremented with each change)
|
||||
|
||||
/// Clean up cached frames that exceed the max number of bytes
|
||||
void CleanUp();
|
||||
|
||||
/// Init path directory
|
||||
void InitPath(string cache_path);
|
||||
void InitPath(std::string cache_path);
|
||||
|
||||
/// Calculate ranges of frames
|
||||
void CalculateRanges();
|
||||
@@ -81,7 +81,7 @@ namespace openshot {
|
||||
/// @param format The image format for disk caching (ppm, jpg, png)
|
||||
/// @param quality The quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed)
|
||||
/// @param scale The scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...)
|
||||
CacheDisk(string cache_path, string format, float quality, float scale);
|
||||
CacheDisk(std::string cache_path, std::string format, float quality, float scale);
|
||||
|
||||
/// @brief Constructor that sets the max bytes to cache
|
||||
/// @param cache_path The folder path of the cache directory (empty string = /tmp/preview-cache/)
|
||||
@@ -89,7 +89,7 @@ namespace openshot {
|
||||
/// @param quality The quality of the image (1.0=highest quality/slowest speed, 0.0=worst quality/fastest speed)
|
||||
/// @param scale The scale factor for the preview images (1.0 = original size, 0.5=half size, 0.25=quarter size, etc...)
|
||||
/// @param max_bytes The maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames.
|
||||
CacheDisk(string cache_path, string format, float quality, float scale, int64_t max_bytes);
|
||||
CacheDisk(std::string cache_path, std::string format, float quality, float scale, int64_t max_bytes);
|
||||
|
||||
// Default destructor
|
||||
~CacheDisk();
|
||||
@@ -128,8 +128,8 @@ namespace openshot {
|
||||
void Remove(int64_t start_frame_number, int64_t end_frame_number);
|
||||
|
||||
/// Get and Set JSON methods
|
||||
string Json(); ///< Generate JSON string of this object
|
||||
void SetJson(string value); ///< Load JSON string into this object
|
||||
std::string Json(); ///< Generate JSON string of this object
|
||||
void SetJson(std::string value); ///< Load JSON string into this object
|
||||
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
||||
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
||||
};
|
||||
|
||||
@@ -50,13 +50,13 @@ namespace openshot {
|
||||
*/
|
||||
class CacheMemory : public CacheBase {
|
||||
private:
|
||||
map<int64_t, std::shared_ptr<Frame> > frames; ///< This map holds the frame number and Frame objects
|
||||
deque<int64_t> frame_numbers; ///< This queue holds a sequential list of cached Frame numbers
|
||||
std::map<int64_t, std::shared_ptr<Frame> > frames; ///< This map holds the frame number and Frame objects
|
||||
std::deque<int64_t> frame_numbers; ///< This queue holds a sequential list of cached Frame numbers
|
||||
|
||||
bool needs_range_processing; ///< Something has changed, and the range data needs to be re-calculated
|
||||
string json_ranges; ///< JSON ranges of frame numbers
|
||||
vector<int64_t> ordered_frame_numbers; ///< Ordered list of frame numbers used by cache
|
||||
map<int64_t, int64_t> frame_ranges; ///< This map holds the ranges of frames, useful for quickly displaying the contents of the cache
|
||||
std::string json_ranges; ///< JSON ranges of frame numbers
|
||||
std::vector<int64_t> ordered_frame_numbers; ///< Ordered list of frame numbers used by cache
|
||||
std::map<int64_t, int64_t> frame_ranges; ///< This map holds the ranges of frames, useful for quickly displaying the contents of the cache
|
||||
int64_t range_version; ///< The version of the JSON range data (incremented with each change)
|
||||
|
||||
/// Clean up cached frames that exceed the max number of bytes
|
||||
@@ -110,8 +110,8 @@ namespace openshot {
|
||||
void Remove(int64_t start_frame_number, int64_t end_frame_number);
|
||||
|
||||
/// Get and Set JSON methods
|
||||
string Json(); ///< Generate JSON string of this object
|
||||
void SetJson(string value); ///< Load JSON string into this object
|
||||
std::string Json(); ///< Generate JSON string of this object
|
||||
void SetJson(std::string value); ///< Load JSON string into this object
|
||||
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
||||
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ Json::Value CacheBase::JsonValue() {
|
||||
|
||||
// Create root json object
|
||||
Json::Value root;
|
||||
stringstream max_bytes_stream;
|
||||
std::stringstream max_bytes_stream;
|
||||
max_bytes_stream << max_bytes;
|
||||
root["max_bytes"] = max_bytes_stream.str();
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ using namespace std;
|
||||
using namespace openshot;
|
||||
|
||||
// Default constructor, no max bytes
|
||||
CacheDisk::CacheDisk(string cache_path, string format, float quality, float scale) : CacheBase(0) {
|
||||
CacheDisk::CacheDisk(std::string cache_path, std::string format, float quality, float scale) : CacheBase(0) {
|
||||
// Set cache type name
|
||||
cache_type = "CacheDisk";
|
||||
range_version = 0;
|
||||
@@ -50,7 +50,7 @@ CacheDisk::CacheDisk(string cache_path, string format, float quality, float scal
|
||||
};
|
||||
|
||||
// Constructor that sets the max bytes to cache
|
||||
CacheDisk::CacheDisk(string cache_path, string format, float quality, float scale, int64_t max_bytes) : CacheBase(max_bytes) {
|
||||
CacheDisk::CacheDisk(std::string cache_path, std::string format, float quality, float scale, int64_t max_bytes) : CacheBase(max_bytes) {
|
||||
// Set cache type name
|
||||
cache_type = "CacheDisk";
|
||||
range_version = 0;
|
||||
@@ -65,7 +65,7 @@ CacheDisk::CacheDisk(string cache_path, string format, float quality, float scal
|
||||
};
|
||||
|
||||
// Initialize cache directory
|
||||
void CacheDisk::InitPath(string cache_path) {
|
||||
void CacheDisk::InitPath(std::string cache_path) {
|
||||
QString qpath;
|
||||
|
||||
if (!cache_path.empty()) {
|
||||
@@ -103,7 +103,7 @@ void CacheDisk::CalculateRanges() {
|
||||
// Increment range version
|
||||
range_version++;
|
||||
|
||||
vector<int64_t>::iterator itr_ordered;
|
||||
std::vector<int64_t>::iterator itr_ordered;
|
||||
int64_t starting_frame = *ordered_frame_numbers.begin();
|
||||
int64_t ending_frame = *ordered_frame_numbers.begin();
|
||||
|
||||
@@ -116,9 +116,9 @@ void CacheDisk::CalculateRanges() {
|
||||
|
||||
// Add JSON object with start/end attributes
|
||||
// Use strings, since int64_ts are supported in JSON
|
||||
stringstream start_str;
|
||||
std::stringstream start_str;
|
||||
start_str << starting_frame;
|
||||
stringstream end_str;
|
||||
std::stringstream end_str;
|
||||
end_str << ending_frame;
|
||||
range["start"] = start_str.str();
|
||||
range["end"] = end_str.str();
|
||||
@@ -137,9 +137,9 @@ void CacheDisk::CalculateRanges() {
|
||||
|
||||
// Add JSON object with start/end attributes
|
||||
// Use strings, since int64_ts are supported in JSON
|
||||
stringstream start_str;
|
||||
std::stringstream start_str;
|
||||
start_str << starting_frame;
|
||||
stringstream end_str;
|
||||
std::stringstream end_str;
|
||||
end_str << ending_frame;
|
||||
range["start"] = start_str.str();
|
||||
range["end"] = end_str.str();
|
||||
@@ -302,7 +302,7 @@ std::shared_ptr<Frame> CacheDisk::GetSmallestFrame()
|
||||
std::shared_ptr<openshot::Frame> f;
|
||||
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
int64_t smallest_frame = -1;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
|
||||
{
|
||||
@@ -325,7 +325,7 @@ int64_t CacheDisk::GetBytes()
|
||||
int64_t total_bytes = 0;
|
||||
|
||||
// Loop through frames, and calculate total bytes
|
||||
deque<int64_t>::reverse_iterator itr;
|
||||
std::deque<int64_t>::reverse_iterator itr;
|
||||
for(itr = frame_numbers.rbegin(); itr != frame_numbers.rend(); ++itr)
|
||||
total_bytes += frame_size_bytes;
|
||||
|
||||
@@ -345,7 +345,7 @@ void CacheDisk::Remove(int64_t start_frame_number, int64_t end_frame_number)
|
||||
const GenericScopedLock<CriticalSection> lock(*cacheCriticalSection);
|
||||
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end();)
|
||||
{
|
||||
//deque<int64_t>::iterator current = itr++;
|
||||
@@ -358,7 +358,7 @@ void CacheDisk::Remove(int64_t start_frame_number, int64_t end_frame_number)
|
||||
}
|
||||
|
||||
// Loop through ordered frame numbers
|
||||
vector<int64_t>::iterator itr_ordered;
|
||||
std::vector<int64_t>::iterator itr_ordered;
|
||||
for(itr_ordered = ordered_frame_numbers.begin(); itr_ordered != ordered_frame_numbers.end();)
|
||||
{
|
||||
if (*itr_ordered >= start_frame_number && *itr_ordered <= end_frame_number)
|
||||
@@ -397,7 +397,7 @@ void CacheDisk::MoveToFront(int64_t frame_number)
|
||||
const GenericScopedLock<CriticalSection> lock(*cacheCriticalSection);
|
||||
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
|
||||
{
|
||||
if (*itr == frame_number)
|
||||
@@ -465,7 +465,7 @@ void CacheDisk::CleanUp()
|
||||
}
|
||||
|
||||
// Generate JSON string of this object
|
||||
string CacheDisk::Json() {
|
||||
std::string CacheDisk::Json() {
|
||||
|
||||
// Return formatted string
|
||||
return JsonValue().toStyledString();
|
||||
@@ -483,7 +483,7 @@ Json::Value CacheDisk::JsonValue() {
|
||||
root["path"] = path.path().toStdString();
|
||||
|
||||
Json::Value version;
|
||||
stringstream range_version_str;
|
||||
std::stringstream range_version_str;
|
||||
range_version_str << range_version;
|
||||
root["version"] = range_version_str.str();
|
||||
|
||||
@@ -492,7 +492,7 @@ Json::Value CacheDisk::JsonValue() {
|
||||
Json::CharReaderBuilder rbuilder;
|
||||
Json::CharReader* reader(rbuilder.newCharReader());
|
||||
|
||||
string errors;
|
||||
std::string errors;
|
||||
bool success = reader->parse( json_ranges.c_str(),
|
||||
json_ranges.c_str() + json_ranges.size(), &ranges, &errors );
|
||||
delete reader;
|
||||
@@ -505,14 +505,14 @@ Json::Value CacheDisk::JsonValue() {
|
||||
}
|
||||
|
||||
// Load JSON string into this object
|
||||
void CacheDisk::SetJson(string value) {
|
||||
void CacheDisk::SetJson(std::string value) {
|
||||
|
||||
// Parse JSON string into JSON objects
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder rbuilder;
|
||||
Json::CharReader* reader(rbuilder.newCharReader());
|
||||
|
||||
string errors;
|
||||
std::string errors;
|
||||
bool success = reader->parse( value.c_str(),
|
||||
value.c_str() + value.size(), &root, &errors );
|
||||
delete reader;
|
||||
|
||||
@@ -79,7 +79,7 @@ void CacheMemory::CalculateRanges() {
|
||||
// Increment range version
|
||||
range_version++;
|
||||
|
||||
vector<int64_t>::iterator itr_ordered;
|
||||
std::vector<int64_t>::iterator itr_ordered;
|
||||
int64_t starting_frame = *ordered_frame_numbers.begin();
|
||||
int64_t ending_frame = *ordered_frame_numbers.begin();
|
||||
|
||||
@@ -92,9 +92,9 @@ void CacheMemory::CalculateRanges() {
|
||||
|
||||
// Add JSON object with start/end attributes
|
||||
// Use strings, since int64_ts are supported in JSON
|
||||
stringstream start_str;
|
||||
std::stringstream start_str;
|
||||
start_str << starting_frame;
|
||||
stringstream end_str;
|
||||
std::stringstream end_str;
|
||||
end_str << ending_frame;
|
||||
range["start"] = start_str.str();
|
||||
range["end"] = end_str.str();
|
||||
@@ -113,9 +113,9 @@ void CacheMemory::CalculateRanges() {
|
||||
|
||||
// Add JSON object with start/end attributes
|
||||
// Use strings, since int64_ts are not supported in JSON
|
||||
stringstream start_str;
|
||||
std::stringstream start_str;
|
||||
start_str << starting_frame;
|
||||
stringstream end_str;
|
||||
std::stringstream end_str;
|
||||
end_str << ending_frame;
|
||||
range["start"] = start_str.str();
|
||||
range["end"] = end_str.str();
|
||||
@@ -178,7 +178,7 @@ std::shared_ptr<Frame> CacheMemory::GetSmallestFrame()
|
||||
std::shared_ptr<openshot::Frame> f;
|
||||
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
int64_t smallest_frame = -1;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
|
||||
{
|
||||
@@ -201,7 +201,7 @@ int64_t CacheMemory::GetBytes()
|
||||
int64_t total_bytes = 0;
|
||||
|
||||
// Loop through frames, and calculate total bytes
|
||||
deque<int64_t>::reverse_iterator itr;
|
||||
std::deque<int64_t>::reverse_iterator itr;
|
||||
for(itr = frame_numbers.rbegin(); itr != frame_numbers.rend(); ++itr)
|
||||
{
|
||||
total_bytes += frames[*itr]->GetBytes();
|
||||
@@ -223,7 +223,7 @@ void CacheMemory::Remove(int64_t start_frame_number, int64_t end_frame_number)
|
||||
const GenericScopedLock<CriticalSection> lock(*cacheCriticalSection);
|
||||
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end();)
|
||||
{
|
||||
if (*itr >= start_frame_number && *itr <= end_frame_number)
|
||||
@@ -235,7 +235,7 @@ void CacheMemory::Remove(int64_t start_frame_number, int64_t end_frame_number)
|
||||
}
|
||||
|
||||
// Loop through ordered frame numbers
|
||||
vector<int64_t>::iterator itr_ordered;
|
||||
std::vector<int64_t>::iterator itr_ordered;
|
||||
for(itr_ordered = ordered_frame_numbers.begin(); itr_ordered != ordered_frame_numbers.end();)
|
||||
{
|
||||
if (*itr_ordered >= start_frame_number && *itr_ordered <= end_frame_number)
|
||||
@@ -261,7 +261,7 @@ void CacheMemory::MoveToFront(int64_t frame_number)
|
||||
if (frames.count(frame_number))
|
||||
{
|
||||
// Loop through frame numbers
|
||||
deque<int64_t>::iterator itr;
|
||||
std::deque<int64_t>::iterator itr;
|
||||
for(itr = frame_numbers.begin(); itr != frame_numbers.end(); ++itr)
|
||||
{
|
||||
if (*itr == frame_number)
|
||||
@@ -321,7 +321,7 @@ void CacheMemory::CleanUp()
|
||||
|
||||
|
||||
// Generate JSON string of this object
|
||||
string CacheMemory::Json() {
|
||||
std::string CacheMemory::Json() {
|
||||
|
||||
// Return formatted string
|
||||
return JsonValue().toStyledString();
|
||||
@@ -337,7 +337,7 @@ Json::Value CacheMemory::JsonValue() {
|
||||
Json::Value root = CacheBase::JsonValue(); // get parent properties
|
||||
root["type"] = cache_type;
|
||||
|
||||
stringstream range_version_str;
|
||||
std::stringstream range_version_str;
|
||||
range_version_str << range_version;
|
||||
root["version"] = range_version_str.str();
|
||||
|
||||
@@ -346,7 +346,7 @@ Json::Value CacheMemory::JsonValue() {
|
||||
Json::CharReaderBuilder rbuilder;
|
||||
Json::CharReader* reader(rbuilder.newCharReader());
|
||||
|
||||
string errors;
|
||||
std::string errors;
|
||||
bool success = reader->parse( json_ranges.c_str(),
|
||||
json_ranges.c_str() + json_ranges.size(), &ranges, &errors );
|
||||
delete reader;
|
||||
@@ -359,14 +359,14 @@ Json::Value CacheMemory::JsonValue() {
|
||||
}
|
||||
|
||||
// Load JSON string into this object
|
||||
void CacheMemory::SetJson(string value) {
|
||||
void CacheMemory::SetJson(std::string value) {
|
||||
|
||||
// Parse JSON string into JSON objects
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder rbuilder;
|
||||
Json::CharReader* reader(rbuilder.newCharReader());
|
||||
|
||||
string errors;
|
||||
std::string errors;
|
||||
bool success = reader->parse( value.c_str(),
|
||||
value.c_str() + value.size(), &root, &errors );
|
||||
delete reader;
|
||||
|
||||
Reference in New Issue
Block a user