4 #include "framecache.h"
15 FrameCacheItem::FrameCacheItem()
20 frame_rate = (double)30000.0 / 1001;
23 FrameCacheItem::~FrameCacheItem()
28 int FrameCacheItem::get_size()
30 if(data) return data->get_data_size() + (path ? strlen(path) : 0);
48 FrameCache::FrameCache()
53 FrameCache::~FrameCache()
58 // Returns 1 if frame exists in cache and copies it to the frame argument.
59 int FrameCache::get_frame(VFrame *frame,
65 lock->lock("FrameCache::get_frame");
66 FrameCacheItem *result = 0;
68 if(frame_exists(frame,
77 frame->copy_from(result->data);
78 frame->copy_stacks(result->data);
80 result->age = get_age();
89 VFrame* FrameCache::get_frame_ptr(int64_t position,
97 lock->lock("FrameCache::get_frame_ptr");
98 FrameCacheItem *result = 0;
99 if(frame_exists(position,
108 result->age = get_age();
117 // Puts frame in cache if enough space exists and the frame doesn't already
119 void FrameCache::put_frame(VFrame *frame,
126 lock->lock("FrameCache::put_frame");
127 FrameCacheItem *item = 0;
128 if(frame_exists(frame,
133 asset ? asset->id : -1))
135 item->age = get_age();
141 item = new FrameCacheItem;
145 item->data = new VFrame(*frame);
153 item->position = position;
155 item->frame_rate = frame_rate;
158 item->asset_id = asset->id;
159 item->path = strdup(asset->path);
165 item->age = get_age();
174 int FrameCache::frame_exists(VFrame *format,
178 FrameCacheItem **item_return,
181 FrameCacheItem *item = (FrameCacheItem*)get_item(position);
182 while(item && item->position == position)
184 if(EQUIV(item->frame_rate, frame_rate) &&
185 layer == item->layer &&
186 format->equivalent(item->data, 1) &&
187 (asset_id == -1 || item->asset_id == -1 || asset_id == item->asset_id))
193 item = (FrameCacheItem*)item->next;
198 int FrameCache::frame_exists(int64_t position,
204 FrameCacheItem **item_return,
207 FrameCacheItem *item = (FrameCacheItem*)get_item(position);
208 while(item && item->position == position)
210 if(EQUIV(item->frame_rate, frame_rate) &&
211 layer == item->layer &&
212 color_model == item->data->get_color_model() &&
213 w == item->data->get_w() &&
214 h == item->data->get_h() &&
215 (asset_id == -1 || item->asset_id == -1 || asset_id == item->asset_id))
221 item = (FrameCacheItem*)item->next;
227 void FrameCache::dump()
229 // lock->lock("FrameCache::dump");
230 // printf("FrameCache::dump 1 %d\n", items.total);
231 // for(int i = 0; i < items.total; i++)
233 // FrameCacheItem *item = (FrameCacheItem*)items.values[i];
234 // printf(" position=%lld frame_rate=%f age=%d size=%d\n",
238 // item->data->get_data_size());