r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / cache.h
blobe05e3a1e481eda30b998ac5ba49731694d9f3c4f
1 #ifndef CACHE_H
2 #define CACHE_H
4 // CICache for quickly reading data that is hard to decompress yet used
5 // over and over.
7 // Actual caching is done in the File object
8 // the CICache keeps files open while rendering.
10 // Since the CICache outlives EDLs it must copy every parameter given to it.
12 // Files given as arguments must outlive the cache.
14 #include "arraylist.h"
15 #include "assets.inc"
16 #include "cache.inc"
17 #include "edl.inc"
18 #include "file.inc"
19 #include "linklist.h"
20 #include "mutex.h"
21 #include "pluginserver.inc"
22 #include "preferences.inc"
24 #include <stdint.h>
26 class CICacheItem : public ListItem<CICacheItem>
28 public:
29 CICacheItem(CICache *cache, File *file);
30 CICacheItem(CICache *cache, Asset *asset);
31 CICacheItem() {};
32 ~CICacheItem();
34 File *file;
35 int64_t counter; // number of age calls ago this asset was last needed
36 // assets used in the last render have counter == 1
37 Asset *asset; // Copy of asset. CICache should outlive EDLs.
38 Mutex item_lock;
39 int checked_out;
40 private:
41 CICache *cache;
44 class CICache : public List<CICacheItem>
46 public:
47 CICache(EDL *edl,
48 Preferences *preferences,
49 ArrayList<PluginServer*> *plugindb);
50 ~CICache();
52 friend class CICacheItem;
54 // Enter a new file into the cache which is already open.
55 // If the file doesn't exist return the arguments.
56 // If the file exists delete the arguments and return the file which exists.
57 void update(File* &file);
58 void set_edl(EDL *edl);
60 // open it, lock it and add it to the cache if it isn't here already
61 File* check_out(Asset *asset);
63 // unlock a file from the cache
64 int check_in(Asset *asset);
66 // delete an entry from the cache
67 // before deleting an asset, starting a new project or something
68 int delete_entry(Asset *asset);
69 int delete_entry(char *path);
71 // increment counters after rendering a buffer length
72 // since you can't know how big the cache is until after rendering the buffer
73 // deletes oldest assets until under the memory limit
74 int age();
76 int dump();
78 ArrayList<PluginServer*> *plugindb;
80 private:
81 int delete_oldest(); // returns 0 if successful
82 // 1 if nothing was old
83 int64_t get_memory_usage();
85 // for deleting items
86 int lock_all();
87 int unlock_all();
89 // to prevent one from checking the same asset out before it's checked in
90 // yet without blocking the asset trying to get checked in
91 // use a seperate mutex for checkouts and checkins
92 Mutex check_in_lock, check_out_lock, total_lock;
93 // Copy of EDL
94 EDL *edl;
95 Preferences *preferences;
105 #endif