Ejemplo n.º 1
0
const AegiVideoFrame VideoProviderCache::GetFrame(int n) {
	size_t total_size = 0;

	// See if frame is cached
	for (auto cur = cache.begin(); cur != cache.end(); ++cur) {
		if (cur->frame_number == n) {
			cache.push_front(*cur);
			cache.erase(cur);
			return cache.front();
		}

		total_size += cur->memSize;
	}

	// Not cached, retrieve it
	const AegiVideoFrame frame = master->GetFrame(n);

	// Cache full, use oldest frame
	if (total_size >= max_cache_size) {
		cache.push_front(cache.back());
		cache.pop_back();
	}
	// Cache not full, insert new one
	else
		cache.push_front(CachedFrame());

	// Cache
	cache.front().frame_number = n;
	cache.front().CopyFrom(frame);
	return cache.front();
}
Ejemplo n.º 2
0
/// @brief Add to cache 
/// @param n     
/// @param frame 
void VideoProviderCache::Cache(int n,const AegiVideoFrame frame) {
	// Cache full, use frame at front
	if (GetCurCacheSize() >= cacheMax) {
		cache.push_back(cache.front());
		cache.pop_front();
	}

	// Cache not full, insert new one
	else {
		cache.push_back(CachedFrame());
	}

	// Cache
	cache.back().n = n;
	cache.back().frame.CopyFrom(frame);
}