Skip to content

Commit

Permalink
Removing caching from Clip object. Causes too many issues and does no…
Browse files Browse the repository at this point in the history
…t add any performance (in my tests)
  • Loading branch information
jonoomph committed Feb 18, 2021
1 parent 563c8fd commit 0e30ecc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 52 deletions.
35 changes: 4 additions & 31 deletions src/Clip.cpp
Expand Up @@ -99,7 +99,7 @@ void Clip::init_settings()
has_audio = Keyframe(-1.0);
has_video = Keyframe(-1.0);

// Init reader info struct and cache size
// Init reader info struct
init_reader_settings();
}

Expand All @@ -111,9 +111,6 @@ void Clip::init_reader_settings() {

// Initialize info struct
info = reader->info;

// Initialize Clip cache
cache.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * 2, info.width, info.height, info.sample_rate, info.channels);
}
}

Expand Down Expand Up @@ -162,7 +159,7 @@ Clip::Clip(ReaderBase* new_reader) : resampler(NULL), reader(new_reader), alloca
if (reader) {
End(reader->info.duration);
reader->ParentClip(this);
// Init reader info struct and cache size
// Init reader info struct
init_reader_settings();
}
}
Expand Down Expand Up @@ -222,7 +219,7 @@ Clip::Clip(std::string path) : resampler(NULL), reader(NULL), allocated_reader(N
End(reader->info.duration);
reader->ParentClip(this);
allocated_reader = reader;
// Init reader info struct and cache size
// Init reader info struct
init_reader_settings();
}
}
Expand Down Expand Up @@ -252,7 +249,7 @@ void Clip::Reader(ReaderBase* new_reader)
// set parent
reader->ParentClip(this);

// Init reader info struct and cache size
// Init reader info struct
init_reader_settings();
}

Expand Down Expand Up @@ -357,16 +354,6 @@ std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> backgroun
// Adjust out of bounds frame number
frame_number = adjust_frame_number_minimum(frame_number);

// Check the cache for this frame
std::shared_ptr<Frame> cached_frame = cache.GetFrame(frame_number);
if (cached_frame) {
// Debug output
ZmqLogger::Instance()->AppendDebugMethod("Clip::GetFrame", "returned cached frame", frame_number);

// Return the cached frame
return cached_frame;
}

// Adjust has_video and has_audio overrides
int enabled_audio = has_audio.GetInt(frame_number);
if (enabled_audio == -1 && reader && reader->info.has_audio)
Expand Down Expand Up @@ -411,11 +398,6 @@ std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> backgroun
// Apply keyframe / transforms
apply_keyframes(original_frame, background_frame->GetImage());

// Cache frame
// TODO: disable clip cache temporarily for testing
// with this enabled, black frames appear when seeking to previous frames
//cache.Add(original_frame);

// Return processed 'frame'
return original_frame;
}
Expand Down Expand Up @@ -896,9 +878,6 @@ void Clip::SetJsonValue(const Json::Value root) {
// Set parent data
ClipBase::SetJsonValue(root);

// Clear cache
cache.Clear();

// Set data from Json (if key is found)
if (!root["gravity"].isNull())
gravity = (GravityType) root["gravity"].asInt();
Expand Down Expand Up @@ -1082,18 +1061,12 @@ void Clip::AddEffect(EffectBase* effect)

// Sort effects
sort_effects();

// Clear cache
cache.Clear();
}

// Remove an effect from the clip
void Clip::RemoveEffect(EffectBase* effect)
{
effects.remove(effect);

// Clear cache
cache.Clear();
}

// Apply effects to the source frame (if any)
Expand Down
4 changes: 2 additions & 2 deletions src/Clip.h
Expand Up @@ -192,8 +192,8 @@ namespace openshot {
/// Destructor
virtual ~Clip();

/// Get the cache object used by this clip
CacheMemory* GetCache() override { return &cache; };
/// Get the cache object (always return NULL for this reader)
openshot::CacheMemory* GetCache() override { return NULL; };

/// Determine if reader is open or closed
bool IsOpen() override { return is_open; };
Expand Down
19 changes: 0 additions & 19 deletions src/Timeline.cpp
Expand Up @@ -1176,12 +1176,6 @@ void Timeline::apply_json_to_effects(Json::Value change, EffectBase* existing_ef

// Add Effect to Timeline
AddEffect(e);

// Clear cache on parent clip (if any)
Clip* parent_clip = (Clip*) e->ParentClip();
if (parent_clip && parent_clip->GetCache()) {
parent_clip->GetCache()->Clear();
}
}

} else if (change_type == "update") {
Expand All @@ -1194,12 +1188,6 @@ void Timeline::apply_json_to_effects(Json::Value change, EffectBase* existing_ef
int64_t old_ending_frame = ((existing_effect->Position() + existing_effect->Duration()) * info.fps.ToDouble()) + 1;
final_cache->Remove(old_starting_frame - 8, old_ending_frame + 8);

// Clear cache on parent clip (if any)
Clip* parent_clip = (Clip*) existing_effect->ParentClip();
if (parent_clip && parent_clip->GetCache()) {
parent_clip->GetCache()->Clear();
}

// Update effect properties from JSON
existing_effect->SetJsonValue(change["value"]);
}
Expand All @@ -1214,12 +1202,6 @@ void Timeline::apply_json_to_effects(Json::Value change, EffectBase* existing_ef
int64_t old_ending_frame = ((existing_effect->Position() + existing_effect->Duration()) * info.fps.ToDouble()) + 1;
final_cache->Remove(old_starting_frame - 8, old_ending_frame + 8);

// Clear cache on parent clip (if any)
Clip* parent_clip = (Clip*) existing_effect->ParentClip();
if (parent_clip && parent_clip->GetCache()) {
parent_clip->GetCache()->Clear();
}

// Remove effect from timeline
RemoveEffect(existing_effect);
}
Expand Down Expand Up @@ -1363,7 +1345,6 @@ void Timeline::ClearAllCache() {
for (auto clip : clips)
{
// Clear cache on clip
clip->GetCache()->Clear();
clip->Reader()->GetCache()->Clear();

// Clear nested Reader (if any)
Expand Down

0 comments on commit 0e30ecc

Please sign in to comment.