Add back 2 patches for histogram and overlayframe that are working correctly and...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cache.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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 2 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, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef CACHE_H
23 #define CACHE_H
24
25 // CICache for quickly reading data that is hard to decompress yet used
26 // over and over.
27
28 // Actual caching is done in the File object
29 // the CICache keeps files open while rendering.
30
31 // Since the CICache outlives EDLs it must copy every parameter given to it.
32
33 // Files given as arguments must outlive the cache.
34
35 #include "asset.inc"
36 #include "cache.inc"
37 #include "condition.inc"
38 #include "edl.inc"
39 #include "file.inc"
40 #include "garbage.h"
41 #include "linklist.h"
42 #include "mutex.inc"
43 #include "preferences.inc"
44
45 #include <stdint.h>
46
47 class CICacheItem : public Garbage, public ListItem<CICacheItem>
48 {
49 public:
50         CICacheItem(CICache *cache, EDL *edl, Asset *asset);
51         CICacheItem();
52         ~CICacheItem();
53
54         File *file;
55 // Number of last get or put operation involving this object.
56         int age;
57         Asset *asset;     // Copy of asset.  CICache should outlive EDLs.
58         Condition *item_lock;
59         long checked_out; // thread id of owner
60 private:
61         CICache *cache;
62 };
63
64 class CICache : public Garbage, public List<CICacheItem>
65 {
66 public:
67         CICache(Preferences *preferences);
68         ~CICache();
69
70         friend class CICacheItem;
71
72 // Enter a new file into the cache which is already open.
73 // If the file doesn't exist return the arguments.
74 // If the file exists delete the arguments and return the file which exists.
75 //      void update(File* &file);
76 //      void set_edl(EDL *edl);
77
78 // open it, lock it and add it to the cache if it isn't here already
79 // If it's already checked out, the value of block causes it to wait
80 // until it's checked in.
81         File* check_out(Asset *asset, EDL *edl, int block = 1);
82
83 // unlock a file from the cache
84         int check_in(Asset *asset);
85
86 // delete an entry from the cache
87 // before deleting an asset, starting a new project or something
88         int delete_entry(Asset *asset);
89         int delete_entry(char *path);
90 // Remove all entries from the cache.
91         void remove_all();
92
93 // Get ID of oldest member.
94 // Called by MWindow::age_caches.
95         int get_oldest();
96         int64_t get_memory_usage(int use_lock);
97
98 // Called by age() and MWindow::age_caches
99 // returns 1 if nothing was available to delete
100 // 0 if successful
101         int delete_oldest();
102
103 // Called by check_in() and modules.
104 // deletes oldest assets until under the memory limit
105         int age();
106
107         void dump(FILE *fp);
108 private:
109
110 // for deleting items
111         int lock_all();
112         int unlock_all();
113
114         int check_outs;
115
116 // to prevent one from checking the same asset out before it's checked in
117 // yet without blocking the asset trying to get checked in
118 // use a seperate mutex for checkouts and checkins
119         Mutex *total_lock;
120         Condition *check_out_lock;
121 // Copy of EDL
122         EDL *edl;
123         Preferences *preferences;
124 };
125
126
127
128
129
130
131
132
133 #endif