- shared_ptr<Frame> frame;
- if (id.interpolated) {
- // Interpolated frames are never decoded by us,
- // put directly into the cache from VideoStream.
- unique_lock<mutex> lock(cache_mu);
- cache_updated.wait(lock, [id] {
- return cache.count(id) != 0 || should_quit.load();
- });
- if (should_quit.load()) break;
- found_in_cache = true; // Don't count it as a decode.
-
- auto it = cache.find(id);
- assert(it != cache.end());
-
- it->second.last_used = event_counter++;
- frame = it->second.frame;
- if (frame == nullptr) {
- // We inserted a nullptr as signal that the frame was never
- // interpolated and that we should stop waiting.
- // But don't let it linger in the cache anymore.
- cache.erase(it);
- }
- } else {
- frame = decode_jpeg_with_cache(id, cache_miss_behavior, &found_in_cache);
- }