429c5bbada836ee64b9269e7ad503832485f9668
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / framecache.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 FRAMECACHE_H
23 #define FRAMECACHE_H
24
25
26 #include "cachebase.h"
27 #include "indexable.inc"
28 #include "mutex.inc"
29 #include "vframe.inc"
30
31
32 #include <stdint.h>
33
34 // Simply a table of images described by frame position and dimensions.
35 // The frame position is relative to the frame rate of the source file.
36 // This object is used by File for playback.
37 // and MWindow for timeline drawing.
38 // CICache scans all the files for
39 // frame caches and deletes what's needed to maintain the cache size.
40
41 class FrameCacheItem : public CacheItemBase
42 {
43 public:
44         FrameCacheItem();
45         ~FrameCacheItem();
46
47         int get_size();
48
49         VFrame *data;
50         double frame_rate;
51         int layer;
52 };
53
54 class FrameCache : public CacheBase
55 {
56 public:
57         FrameCache();
58         ~FrameCache();
59
60 // Returns 1 if frame exists in cache and copies it to the frame argument.
61         int get_frame(VFrame *frame,
62                 int64_t position,
63                 int layer,
64                 double frame_rate,
65                 int source_id = -1);
66 // Returns pointer to cache entry if frame exists or 0.
67 // If a frame is found, the frame cache is left in the locked state until
68 // unlock is called.  If nothing is found, the frame cache is unlocked before
69 // returning.  This keeps the item from being deleted.
70 // asset - supplied by user if the cache is not part of a file.
71         VFrame* get_frame_ptr(int64_t position,
72                 int layer,
73                 double frame_rate,
74                 int color_model,
75                 int w,
76                 int h,
77                 int source_id = -1);
78 // Puts the frame in cache.
79 // use_copy - if 1 a copy of the frame is made.  if 0 the argument is stored.
80 // The copy of the frame is deleted by FrameCache in a future delete_oldest.
81 // asset - supplied by user if the cache is not part of a file.
82         void put_frame(VFrame *frame,
83                 int64_t position,
84                 int layer,
85                 double frame_rate,
86                 int use_copy,
87                 Indexable *indexable);
88 // create new cache vframe at position, return 0 if it already exists
89 // if first_frame set, clear cache before new vframe created
90 // if new vframe created, leave cache locked for frame load
91         VFrame *new_cache_frame(int64_t position, int w, int h,
92                         int color_model, int layer, double frame_rate,
93                         int first_frame);
94         void put_cache_frame();
95
96         void dump();
97
98
99
100
101
102 private:
103 // Return 1 if matching frame exists.
104 // Return 0 if not.
105         int frame_exists(VFrame *format,
106                 int64_t position,
107                 int layer,
108                 double frame_rate,
109                 FrameCacheItem **item_return,
110                 int source_id);
111         int frame_exists(int64_t position,
112                 int layer,
113                 double frame_rate,
114                 int color_model,
115                 int w,
116                 int h,
117                 FrameCacheItem **item_return,
118                 int source_id);
119 };
120
121
122
123 #endif