no longer need ffmpeg patch0 which was for Termux
[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 pointer to cache entry if frame exists or 0.
61 // If a frame is found, the frame cache is left in the locked state until
62 // unlock is called.  If nothing is found, the frame cache is unlocked before
63 // returning.  This keeps the item from being deleted.
64 // asset - supplied by user if the cache is not part of a file.
65         VFrame* get_frame_ptr(int64_t position, int layer, double frame_rate,
66                         int color_model, int w, int h, int source_id);
67 // lock and call get_vframe
68         VFrame *get_vframe(int64_t position, int w, int h,
69                         int color_model, int layer, double frame_rate,
70                         int source_id);
71 // caller holds lock
72         VFrame *get_frame(int64_t position, int w, int h,
73                         int color_model, int layer, double frame_rate,
74                         int source_id);
75 // Returns 1 if frame exists in cache and copies it to the frame argument.
76         int get_frame(VFrame *frame, int64_t position,
77                         int layer, double frame_rate, int source_id);
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 // caller holds lock
83         void put_vframe(VFrame *frame, int64_t position,
84                         int layer, double frame_rate, int source_id);
85 // lock, call get_vframe, if exists: ret = 0; else add frame, ret = 1; unlock
86         void put_frame(VFrame *frame, int64_t position,
87                         int layer, double frame_rate, int use_copy, Indexable *idxbl);
88         int get_cache_frame(VFrame *frame, int64_t position,
89                         int layer, double frame_rate);
90         void put_cache_frame(VFrame *frame, int64_t position,
91                         int layer, double frame_rate, int use_copy);
92         void dump();
93
94 private:
95 // Return 1 if matching frame exists.
96 // Return 0 if not.
97         int frame_exists(VFrame *format,
98                         int64_t position, int layer, double frame_rate,
99                         FrameCacheItem **item_return, int source_id);
100         int frame_exists(int64_t position, int layer, double frame_rate,
101                         int w, int h, int color_model,
102                         FrameCacheItem **item_return, int source_id);
103 };
104
105 #endif