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

@@ -7,8 +7,11 @@
#define NOMINMAX
#include <windows.h>
#include "GpuNV12SlotPool.h"
#include "ANSLicense.h" // ANS_DBG macro for [Pool_Leak] heartbeat
#include <cuda_runtime.h>
#include <atomic>
#include <chrono>
// ANSCV.dll owns the process-wide singleton.
GpuNV12SlotPool* GpuNV12SlotPool::resolveProcessWide() {
@@ -40,6 +43,41 @@ void GpuNV12SlotPool::drainCooledSlots_locked() {
GpuNV12Slot* GpuNV12SlotPool::acquire(int gpuIdx, int w, int h) {
std::lock_guard<std::mutex> lock(m_mutex);
// Leak diagnostic — [Pool_Leak] heartbeat fires at most once per 60 s.
// Reports current slot count and rough VRAM footprint. Slot count is
// bounded by GPU_NV12_POOL_MAX_SLOTS; if it persists near the cap we
// also see ACTIVE/COOLING state distribution which can hint at slots
// not being released.
{
using clk = std::chrono::steady_clock;
static std::atomic<long long> s_nextLog{0};
const long long tick = clk::now().time_since_epoch().count();
long long expected = s_nextLog.load(std::memory_order_relaxed);
if (tick >= expected) {
const long long deadline = tick +
std::chrono::duration_cast<clk::duration>(
std::chrono::seconds(60)).count();
if (s_nextLog.compare_exchange_strong(expected, deadline,
std::memory_order_relaxed)) {
size_t totalBytes = 0;
size_t active = 0, cooling = 0, free_ = 0;
for (const auto& sp : m_slots) {
totalBytes += sp->pitchY * sp->height
+ sp->pitchUV * (sp->height / 2);
const int st = sp->state.load(std::memory_order_relaxed);
if (st == GpuNV12Slot::STATE_ACTIVE) ++active;
else if (st == GpuNV12Slot::STATE_COOLING) ++cooling;
else ++free_;
}
ANS_DBG("Pool_Leak",
"NV12Pool slots=%zu (active=%zu cooling=%zu free=%zu) bytesMB=%.1f (max=%d)",
m_slots.size(), active, cooling, free_,
(double)totalBytes / (1024.0 * 1024.0),
GPU_NV12_POOL_MAX_SLOTS);
}
}
}
// 1. Drain cooled-down slots to make them available
drainCooledSlots_locked();