MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / CalculateRanges

Method CalculateRanges

src/CacheBase.cpp:36–97  ·  view source on GitHub ↗

Calculate ranges of frames

Source from the content-addressed store, hash-verified

34
35// Calculate ranges of frames
36void CacheBase::CalculateRanges() {
37 // Only calculate when something has changed
38 if (needs_range_processing) {
39
40 // Create a scoped lock, to protect the cache from multiple threads
41 const std::lock_guard<std::recursive_mutex> lock(*cacheMutex);
42
43 // Sort ordered frame #s, and calculate JSON ranges
44 std::sort(ordered_frame_numbers.begin(), ordered_frame_numbers.end());
45
46 // Clear existing JSON variable
47 Json::Value ranges = Json::Value(Json::arrayValue);
48
49 // Increment range version
50 range_version++;
51
52 std::vector<int64_t>::iterator itr_ordered;
53
54 int64_t starting_frame = 0;
55 int64_t ending_frame = 0;
56 if (ordered_frame_numbers.size() > 0) {
57 starting_frame = *ordered_frame_numbers.begin();
58 ending_frame = *ordered_frame_numbers.begin();
59
60 // Loop through all known frames (in sequential order)
61 for (itr_ordered = ordered_frame_numbers.begin(); itr_ordered != ordered_frame_numbers.end(); ++itr_ordered) {
62 int64_t frame_number = *itr_ordered;
63 if (frame_number - ending_frame > 1) {
64 // End of range detected
65 Json::Value range;
66
67 // Add JSON object with start/end attributes
68 // Use strings, since int64_ts are supported in JSON
69 range["start"] = std::to_string(starting_frame);
70 range["end"] = std::to_string(ending_frame);
71 ranges.append(range);
72
73 // Set new starting range
74 starting_frame = frame_number;
75 }
76
77 // Set current frame as end of range, and keep looping
78 ending_frame = frame_number;
79 }
80 }
81
82 // APPEND FINAL VALUE
83 Json::Value range;
84
85 // Add JSON object with start/end attributes
86 // Use strings, since int64_ts are not supported in JSON
87 range["start"] = std::to_string(starting_frame);
88 range["end"] = std::to_string(ending_frame);
89 ranges.append(range);
90
91 // Cache range JSON as string
92 json_ranges = ranges.toStyledString();
93

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected