Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

framecache.h

Go to the documentation of this file.
00001 #ifndef FRAMECACHE_H
00002 #define FRAMECACHE_H
00003 
00004 
00005 #include "arraylist.h"
00006 #include "mutex.inc"
00007 #include "vframe.inc"
00008 
00009 
00010 #include <stdint.h>
00011 
00012 // Simply a table of images described by frame position and dimensions.
00013 // The frame position is relative to the frame rate of the source file.
00014 // This object is held by File.  CICache scans all the files for
00015 // frame caches and deletes what's needed to maintain the cache size.
00016 
00017 class FrameCacheItem
00018 {
00019 public:
00020         FrameCacheItem();
00021         ~FrameCacheItem();
00022 
00023         VFrame *data;
00024         int64_t position;
00025         double frame_rate;
00026 // Number of last get or put operation involving this object.
00027         int age;
00028 };
00029 
00030 class FrameCache
00031 {
00032 public:
00033         FrameCache();
00034         ~FrameCache();
00035 
00036 // Returns 1 if frame exists in cache and copies it to the frame argument.
00037         int get_frame(VFrame *frame, 
00038                 int64_t position,
00039                 double frame_rate);
00040 // Returns pointer to cache entry if frame exists or 0.
00041 // If a frame is found, the frame cache is left in the locked state until 
00042 // unlock is called.  If nothing is found, the frame cache is unlocked before
00043 // returning.  This keeps the item from being deleted.
00044         VFrame* get_frame_ptr(int64_t position,
00045                 double frame_rate,
00046                 int color_model,
00047                 int w,
00048                 int h);
00049         void unlock();
00050 // Puts the frame in cache.
00051 // use_copy - if 1 a copy of the frame is made.  if 0 the argument is stored.
00052 // The copy of the frame is deleted by FrameCache in a future delete_oldest.
00053         void put_frame(VFrame *frame, 
00054                 int64_t position,
00055                 double frame_rate,
00056                 int use_copy);
00057 
00058 // Delete oldest item.  Return 0 if successful.  Return 1 if nothing to delete.
00059         int delete_oldest();
00060 
00061 // Calculate current size of cache in bytes
00062         int64_t get_memory_usage();
00063         void dump();
00064 
00065 
00066 
00067 
00068 private:
00069 // Return 1 if matching frame exists.
00070 // Return 0 if not.
00071         int frame_exists(VFrame *format,
00072                 int64_t position,
00073                 double frame_rate,
00074                 int *item_return);
00075         int FrameCache::frame_exists(int64_t position, 
00076                 double frame_rate,
00077                 int color_model,
00078                 int w,
00079                 int h,
00080                 int *item_return);
00081 
00082         Mutex *lock;
00083 // Current get or put operation since creation of FrameCache object
00084         int current_age;
00085         ArrayList<FrameCacheItem*> items;
00086 // Maximum size of cache in bytes.
00087         int64_t max_bytes;
00088 };
00089 
00090 
00091 
00092 #endif

Generated on Sun Jan 8 13:38:55 2006 for Cinelerra-svn by  doxygen 1.4.4