ASAPCabinetFE
 
Loading...
Searching...
No Matches
video_player_cache.h
1#ifndef VIDEO_PLAYER_CACHE_H
2#define VIDEO_PLAYER_CACHE_H
3
4#include <unordered_map>
5#include <list>
6#include <string>
7#include <memory>
8#include <deque>
9#include "render/ivideo_player.h"
10
12public:
15
16 std::unique_ptr<IVideoPlayer> getVideoPlayer(const std::string& key, SDL_Renderer* renderer, int width, int height);
17 void cacheVideoPlayer(const std::string& key, std::unique_ptr<IVideoPlayer> player, SDL_Renderer* renderer, int width, int height);
18 void addOldVideoPlayer(std::unique_ptr<IVideoPlayer> player);
19 void clearOldVideoPlayers();
20 void clearCache();
21
22private:
23 struct CacheEntry {
24 SDL_Renderer* renderer;
25 int width;
26 int height;
27 std::unique_ptr<IVideoPlayer> player;
28 CacheEntry(SDL_Renderer* r, int w, int h, std::unique_ptr<IVideoPlayer> p)
29 : renderer(r), width(w), height(h), player(std::move(p)) {}
30 };
31
32 std::unordered_map<std::string, CacheEntry> cache_;
33 std::list<std::string> lruKeys_;
34 std::deque<std::unique_ptr<IVideoPlayer>> oldVideoPlayers_;
35 static const size_t MAX_CACHE_SIZE = 48;
36
37 void evictOldest();
38};
39
40#endif // VIDEO_PLAYER_CACHE_H
Definition video_player_cache.h:11