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"
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>
2343namespace olive ::cache{
2444class FrameCacheKey ;
25- static size_t qHashForFrameCacheKey (const FrameCacheKey &key, size_t seed = 0 );
45+ size_t qHash (const FrameCacheKey &key, size_t seed = 0 );
2646class FrameCacheKey {
2747private:
2848 uint64_t version_ = 0 ;
2949 rational time_ = 0 ;
3050 VideoParams params_;
51+ QString path_;
52+ QUuid uuid_;
3153public:
32- FrameCacheKey () = default ;
54+ FrameCacheKey () = default ;
3355 FrameCacheKey (uint64_t version, rational time, VideoParams ¶ms)
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 ¶ms,
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- }
8497class FrameCacheEntry {
8598private:
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{
122136using FrameCacheEntryPtr = std::shared_ptr<FrameCacheEntry>;
123137class FrameCacheStore {
124138public:
125-
126139 virtual FrameCacheEntryPtr get (FrameCacheKey &key) = 0;
127140 virtual void set (FrameCacheKey &key, FrameCacheEntryPtr entry) = 0;
128141 virtual void remove (FrameCacheKey &key) = 0;
0 commit comments