Harden playback/cache path for malformed media and concurrent timeline updates

- Invalidate timeline cache on ApplyJsonDiff() clip insert (remove affected frame range).
  - Add lock in Timeline::ClearAllCache() for safe concurrent access.
  - Make VideoCacheThread cross-thread state safe (atomics + seek-state mutex).
  - Lock CacheMemory::Contains() to avoid races.
  - Handle malformed audio streams in FFmpegReader by disabling invalid audio and continuing video-only.
  - Add FPS/timebase safety fallbacks in FFmpeg frame/PTS math.
  - Guard Frame::GetSamplesPerFrame() against invalid inputs.
  - Add/adjust regression tests for cache invalidation and invalid rate handling.
This commit is contained in:
Jonathan Thomas
2026-02-11 20:11:47 -06:00
parent 57c1fb2ec3
commit d70e80eac4
9 changed files with 238 additions and 83 deletions

View File

@@ -1461,6 +1461,11 @@ void Timeline::apply_json_to_clips(Json::Value change) {
// Add clip to timeline
AddClip(clip);
// Calculate start and end frames that this impacts, and remove those frames from the cache
int64_t new_starting_frame = (clip->Position() * info.fps.ToDouble()) + 1;
int64_t new_ending_frame = ((clip->Position() + clip->Duration()) * info.fps.ToDouble()) + 1;
final_cache->Remove(new_starting_frame - 8, new_ending_frame + 8);
} else if (change_type == "update") {
// Update existing clip
@@ -1747,6 +1752,8 @@ void Timeline::apply_json_to_timeline(Json::Value change) {
// Clear all caches
void Timeline::ClearAllCache(bool deep) {
// Get lock (prevent getting frames while this happens)
const std::lock_guard<std::recursive_mutex> guard(getFrameMutex);
// Clear primary cache
if (final_cache) {