r793: Small API addon, so plugins can 'see' camera and projector automation
[cinelerra_cv/mob.git] / cinelerra / framecache.h
blobb7cbc961b0a1962d2e5838a58e2f54c6a94ad5e2
1 #ifndef FRAMECACHE_H
2 #define FRAMECACHE_H
5 #include "arraylist.h"
6 #include "mutex.inc"
7 #include "vframe.inc"
10 #include <stdint.h>
12 // Simply a table of images described by frame position and dimensions.
13 // The frame position is relative to the frame rate of the source file.
14 // This object is held by File. CICache scans all the files for
15 // frame caches and deletes what's needed to maintain the cache size.
17 class FrameCacheItem
19 public:
20 FrameCacheItem();
21 ~FrameCacheItem();
23 VFrame *data;
24 int64_t position;
25 double frame_rate;
26 // Number of last get or put operation involving this object.
27 int age;
30 class FrameCache
32 public:
33 FrameCache();
34 ~FrameCache();
36 // Returns 1 if frame exists in cache and copies it to the frame argument.
37 int get_frame(VFrame *frame,
38 int64_t position,
39 double frame_rate);
40 // Returns pointer to cache entry if frame exists or 0.
41 // If a frame is found, the frame cache is left in the locked state until
42 // unlock is called. If nothing is found, the frame cache is unlocked before
43 // returning. This keeps the item from being deleted.
44 VFrame* get_frame_ptr(int64_t position,
45 double frame_rate,
46 int color_model,
47 int w,
48 int h);
49 void unlock();
50 // Puts the frame in cache.
51 // use_copy - if 1 a copy of the frame is made. if 0 the argument is stored.
52 // The copy of the frame is deleted by FrameCache in a future delete_oldest.
53 void put_frame(VFrame *frame,
54 int64_t position,
55 double frame_rate,
56 int use_copy);
58 // Delete oldest item. Return 0 if successful. Return 1 if nothing to delete.
59 int delete_oldest();
61 // Calculate current size of cache in bytes
62 int64_t get_memory_usage();
63 void dump();
68 private:
69 // Return 1 if matching frame exists.
70 // Return 0 if not.
71 int frame_exists(VFrame *format,
72 int64_t position,
73 double frame_rate,
74 int *item_return);
75 int frame_exists(int64_t position,
76 double frame_rate,
77 int color_model,
78 int w,
79 int h,
80 int *item_return);
82 Mutex *lock;
83 // Current get or put operation since creation of FrameCache object
84 int current_age;
85 ArrayList<FrameCacheItem*> items;
86 // Maximum size of cache in bytes.
87 int64_t max_bytes;
92 #endif