Fix double stop in ANSVideoPlayer

This commit is contained in:
2026-04-22 10:10:16 +10:00
parent 97d814936d
commit 57cc8e0a56
14 changed files with 492 additions and 70 deletions

View File

@@ -26,11 +26,19 @@ extern "C" {
#include <thread>
#include <mutex>
#include <cstdio>
#include <atomic>
#ifdef _WIN32
#include <windows.h>
#endif
// Leak diagnostic — counts AVFrames handed back to the media layer for
// deferred freeing. Defined in video_player.cpp. Paired with g_nv12Escapes /
// g_cudaHWEscapes in the [MEDIA_Leak] heartbeat: if escapes > pendingReturns
// and the delta grows, external callers (via getNV12Frame/getCudaHWFrame)
// are holding clones instead of returning them.
extern std::atomic<int64_t> g_avframePendingReturns;
// Debug logging macro for GPU frame operations.
// Define ANSCORE_GPU_DEBUG=1 to enable verbose per-frame GPU logging.
#ifndef GPU_FRAME_DBG
@@ -172,6 +180,7 @@ inline void gpu_frame_attach(cv::Mat* mat, AVFrame* nv12, int gpuIdx, int64_t pt
auto& reg = ANSGpuFrameRegistry::instance();
auto lk = reg.acquire_lock();
reg.pushPendingFree_locked(old);
g_avframePendingReturns.fetch_add(1, std::memory_order_relaxed);
}
// NOTE: No drain_pending() here (hot path). Freed by evict_stale.
@@ -378,6 +387,7 @@ inline void gpu_frame_attach_cuda(cv::Mat* mat, AVFrame* cudaFrame, int gpuIdx,
auto& reg = ANSGpuFrameRegistry::instance();
auto lk = reg.acquire_lock();
reg.pushPendingFree_locked(cudaFrame);
g_avframePendingReturns.fetch_add(1, std::memory_order_relaxed);
}
data.avframe = nullptr;
}
@@ -386,6 +396,7 @@ inline void gpu_frame_attach_cuda(cv::Mat* mat, AVFrame* cudaFrame, int gpuIdx,
auto& reg = ANSGpuFrameRegistry::instance();
auto lk = reg.acquire_lock();
reg.pushPendingFree_locked(cpuNV12);
g_avframePendingReturns.fetch_add(1, std::memory_order_relaxed);
}
data.cpuAvframe = nullptr;
@@ -399,6 +410,7 @@ inline void gpu_frame_attach_cuda(cv::Mat* mat, AVFrame* cudaFrame, int gpuIdx,
auto& reg = ANSGpuFrameRegistry::instance();
auto lk = reg.acquire_lock();
reg.pushPendingFree_locked(old);
g_avframePendingReturns.fetch_add(1, std::memory_order_relaxed);
}
// NOTE: No drain_pending() here (hot path). AVFrames accumulate in