Skip to content

Commit 5a64457

Browse files
committed
add: Implement frame disk cache and enhance cache key
- Add FrameDiskCache class with get, set, remove, and clear methods - Extend FrameCacheKey with path and UUID fields for disk persistence - Implement qHash function for FrameCacheKey to support QHash storage - Add GPL license headers to frame cache files - Fix FrameCacheEntry frame assignment and update last_use on access - Update CMakeLists to include new framediskcache source files
1 parent b10218f commit 5a64457

7 files changed

Lines changed: 164 additions & 45 deletions

File tree

app/render/cache/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ set(OLIVE_SOURCES
66
render/cache/framehashcache.h
77
render/cache/framememcache.h
88
render/cache/framememcache.cpp
9+
render/cache/framediskcache.h
10+
render/cache/framediskcache.cpp
911
PARENT_SCOPE
1012
)

app/render/cache/framecache.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/***
2+
3+
Oak Video Editor - Non-Linear Video Editor
4+
Copyright (C) 2026 Oak Team
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
***/
120
#include "framecache.h"
221
using namespace olive::cache;
322
size_t FrameCacheEntry::size(){
@@ -7,4 +26,22 @@ size_t FrameCacheEntry::size(){
726
int channel_count = texture_->channel_count();
827
int overhead_factor = 1.3; // std::shared_ptr, metadata
928
return byte_per_channel * width * height * channel_count * overhead_factor;
29+
}
30+
size_t qHash(const FrameCacheKey &key, size_t seed)
31+
{
32+
const olive::VideoParams params = key.params();
33+
return qHashMulti(
34+
seed, key.version(), key.time().toDouble(), params.width(),
35+
params.height(), params.depth(), params.time_base().numerator(),
36+
params.time_base().denominator(), static_cast<int>(params.format()),
37+
params.channel_count(), params.pixel_aspect_ratio().numerator(),
38+
params.pixel_aspect_ratio().denominator(),
39+
static_cast<int>(params.interlacing()), params.divider(),
40+
params.effective_width(), params.effective_height(),
41+
params.effective_depth(), params.square_pixel_width(), params.enabled(),
42+
params.stream_index(), static_cast<int>(params.video_type()),
43+
params.frame_rate().numerator(), params.frame_rate().denominator(),
44+
params.start_time(), params.duration(), params.premultiplied_alpha(),
45+
params.colorspace(), params.x(), params.y(),
46+
static_cast<int>(params.color_range()), key.path(), key.uuid());
1047
}

app/render/cache/framecache.h

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11

2+
/***
3+
4+
Oak Video Editor - Non-Linear Video Editor
5+
Copyright (C) 2026 Oak Team
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
***/
221
#ifndef FRAME_CACHE_H
322
#define FRAME_CACHE_H
423
#include "codec/frame.h"
@@ -16,71 +35,65 @@
1635
#include <QThread>
1736
#include <qobject.h>
1837
#include <qtmetamacros.h>
38+
#include <quuid.h>
1939
#include <thread>
2040
#include <utility>
2141
#include <hash>
2242
#include <qhashfunctions.h>
2343
namespace olive::cache{
2444
class FrameCacheKey;
25-
static size_t qHashForFrameCacheKey(const FrameCacheKey &key, size_t seed = 0);
45+
size_t qHash(const FrameCacheKey &key, size_t seed = 0);
2646
class FrameCacheKey {
2747
private:
2848
uint64_t version_ = 0;
2949
rational time_ = 0;
3050
VideoParams params_;
51+
QString path_;
52+
QUuid uuid_;
3153
public:
32-
FrameCacheKey() = default;
54+
FrameCacheKey() = default;
3355
FrameCacheKey(uint64_t version, rational time, VideoParams &params)
34-
: version_(version), time_(time), params_(params){}
35-
uint64_t version() const{
56+
: version_(version), time_(time), params_(params){
57+
uuid_=QUuid::createUuid();
58+
}
59+
FrameCacheKey(uint64_t version, rational time, VideoParams &params,
60+
QString &path, QUuid uuid)
61+
: version_(version)
62+
, time_(time)
63+
, params_(params)
64+
, path_(path)
65+
, uuid_(uuid)
66+
{
67+
}
68+
[[nodiscard]] uint64_t version() const{
3669
return version_;
3770
}
38-
rational time() const{
71+
[[nodiscard]] rational time() const{
3972
return time_;
4073
}
41-
VideoParams params() const {
74+
[[nodiscard]] VideoParams params() const {
4275
return params_;
4376
}
44-
bool operator==(FrameCacheKey &other) const{
77+
void set_path(QString &path){
78+
this->path_=path;
79+
}
80+
void set_uuid(QUuid &uuid)
81+
{
82+
this->uuid_ = uuid;
83+
}
84+
[[nodiscard]] QString path() const{
85+
return path_;
86+
}
87+
[[nodiscard]] QUuid uuid() const
88+
{
89+
return uuid_;
90+
}
91+
bool operator==(FrameCacheKey &other) const{
4592
return version_==other.version_ && time_ == other.time_
46-
&& params_ == other.params_;
93+
&& params_ == other.params_ && path_ == other.path_;
4794
}
4895
size_t qHash(const FrameCacheKey& key, size_t seed);
4996
};
50-
static size_t qHashForFrameCacheKey(const FrameCacheKey &key, size_t seed)
51-
{
52-
const VideoParams params = key.params();
53-
return qHashMulti(seed,
54-
key.version(),
55-
key.time().toDouble(),
56-
params.width(),
57-
params.height(),
58-
params.depth(),
59-
params.time_base().numerator(),
60-
params.time_base().denominator(),
61-
static_cast<int>(params.format()),
62-
params.channel_count(),
63-
params.pixel_aspect_ratio().numerator(),
64-
params.pixel_aspect_ratio().denominator(),
65-
static_cast<int>(params.interlacing()),
66-
params.divider(),
67-
params.effective_width(),
68-
params.effective_height(),
69-
params.effective_depth(),
70-
params.square_pixel_width(),
71-
params.enabled(),
72-
params.stream_index(),
73-
static_cast<int>(params.video_type()),
74-
params.frame_rate().numerator(),
75-
params.frame_rate().denominator(),
76-
params.start_time(),
77-
params.duration(),
78-
params.premultiplied_alpha(),
79-
params.colorspace(),
80-
params.x(),
81-
params.y(),
82-
static_cast<int>(params.color_range()));
83-
}
8497
class FrameCacheEntry{
8598
private:
8699
TexturePtr texture_;
@@ -96,7 +109,7 @@ class FrameCacheEntry{
96109
}
97110
explicit FrameCacheEntry(FramePtr &frame)
98111
{
99-
frame = frame;
112+
frame_ = frame;
100113
last_use = std::time(nullptr);
101114
}
102115
TexturePtr texture(){
@@ -105,7 +118,8 @@ class FrameCacheEntry{
105118
}
106119

107120
FramePtr frame(){
108-
return frame_;
121+
last_use = std::time(nullptr);
122+
return frame_;
109123
}
110124

111125
bool is_cpu(){
@@ -122,7 +136,6 @@ class FrameCacheEntry{
122136
using FrameCacheEntryPtr = std::shared_ptr<FrameCacheEntry>;
123137
class FrameCacheStore {
124138
public:
125-
126139
virtual FrameCacheEntryPtr get(FrameCacheKey &key) = 0;
127140
virtual void set(FrameCacheKey &key, FrameCacheEntryPtr entry) = 0;
128141
virtual void remove(FrameCacheKey &key) = 0;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "framediskcache.h"
2+
#include "render/cache/framecache.h"
3+
#include "render/cache/framehashcache.h"
4+
#include <memory>
5+
using namespace olive::cache;
6+
7+
FrameCacheEntryPtr FrameDiskCacheStore::get(FrameCacheKey& key){
8+
FramePtr frame=FrameHashCache::LoadCacheFrame(key.path(), key.uuid(), key.time().toDouble());
9+
return std::make_shared<FrameCacheEntry>(frame);
10+
}
11+
12+
void FrameDiskCacheStore::set(FrameCacheKey& key, FrameCacheEntryPtr entry){
13+
14+
}

app/render/cache/framediskcache.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef APP_RENDER_CACHE_FRAMEDISKCACHE_H_
2+
#define APP_RENDER_CACHE_FRAMEDISKCACHE_H_
3+
4+
#include "render/cache/framecache.h"
5+
namespace olive::cache {
6+
7+
class FrameDiskCacheStore: public FrameCacheStore{
8+
public:
9+
FrameCacheEntryPtr get(FrameCacheKey &key) override;
10+
void set(FrameCacheKey &key, FrameCacheEntryPtr entry) override;
11+
void remove(FrameCacheKey &key) override;
12+
};
13+
}
14+
15+
#endif // APP_RENDER_CACHE_FRAMEDISKCACHE_H_

app/render/cache/framememcache.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/***
2+
3+
Oak Video Editor - Non-Linear Video Editor
4+
Copyright (C) 2026 Oak Team
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
***/
120
#include "framecache.h"
221
#include "framememcache.h"
322
#include <mutex>

app/render/cache/framememcache.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/***
2+
3+
Oak Video Editor - Non-Linear Video Editor
4+
Copyright (C) 2026 Oak Team
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
***/
120
#ifndef APP_RENDER_CACHE_FRAMEMEMCACHE_H_
221
#define APP_RENDER_CACHE_FRAMEMEMCACHE_H_
322
#include "render/cache/framecache.h"

0 commit comments

Comments
 (0)