| 38 | } |
| 39 | |
| 40 | std::optional<DecodedFrame> EntryThumbnailCache::lookup(Timestamp ts_ns) const { |
| 41 | std::lock_guard<std::mutex> lock(mutex_); |
| 42 | if (tiles_.empty()) { |
| 43 | return std::nullopt; |
| 44 | } |
| 45 | // Nearest at-or-before: first tile with ts > ts_ns, then step back one. |
| 46 | auto it = |
| 47 | std::upper_bound(tiles_.begin(), tiles_.end(), ts_ns, [](Timestamp t, const Tile& tile) { return t < tile.ts; }); |
| 48 | if (it == tiles_.begin()) { |
| 49 | return std::nullopt; |
| 50 | } |
| 51 | --it; |
| 52 | return decodeThumbnailJpeg(it->jpeg.data(), it->jpeg.size(), it->width, it->height); |
| 53 | } |
| 54 | |
| 55 | void EntryThumbnailCache::prune(Timestamp before_ns) { |
| 56 | std::lock_guard<std::mutex> lock(mutex_); |
no test coverage detected