Disable NV12 path for ANSCV by default. Currenly use cv::Mat** directly

This commit is contained in:
2026-04-04 10:09:47 +11:00
parent 445abefebe
commit 3a21026790
19 changed files with 575 additions and 232 deletions

View File

@@ -652,6 +652,14 @@ namespace ANSCENTER {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_playerClient->setImageQuality(mode); // 0=fast (AI), 1=quality (display)
}
void ANSSRTClient::SetTargetFPS(double intervalMs) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_playerClient->setTargetFPS(intervalMs); // 0=no limit, 100=~10FPS, 200=~5FPS
}
void ANSSRTClient::SetNV12FastPath(bool enable) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_useNV12FastPath = enable;
}
AVFrame* ANSSRTClient::GetNV12Frame() {
std::lock_guard<std::recursive_mutex> lock(_mutex);
return _playerClient->getNV12Frame(); // Returns clone, caller must av_frame_free
@@ -809,20 +817,18 @@ extern "C" __declspec(dllexport) int GetSRTCVImage(ANSCENTER::ANSSRTClient** Han
// Thread-safe Mat pointer swap (anscv_mat_replace has its own internal lock)
anscv_mat_replace(image, std::move(img));
// Attach NV12 frame for GPU fast-path inference (side-table registry)
// attach() takes ownership — do NOT av_frame_free here
int gpuIdx = (*Handle)->GetHWDecodingGpuIndex();
AVFrame* cudaHW = (*Handle)->GetCudaHWFrame();
if (cudaHW) {
// CUDA zero-copy: frame data[0]/data[1] are CUDA device pointers.
// Also attach CPU NV12 as fallback for cross-GPU inference
// (when decode GPU != inference GPU, CUDA ptrs aren't accessible).
AVFrame* cpuNV12 = (*Handle)->GetNV12Frame();
gpu_frame_attach_cuda(*image, cudaHW, gpuIdx, timeStamp, cpuNV12);
} else {
AVFrame* nv12 = (*Handle)->GetNV12Frame();
if (nv12) {
gpu_frame_attach(*image, nv12, gpuIdx, timeStamp);
// NV12 GPU fast path (optional — disabled by default for stability)
if ((*Handle)->IsNV12FastPath()) {
int gpuIdx = (*Handle)->GetHWDecodingGpuIndex();
AVFrame* cudaHW = (*Handle)->GetCudaHWFrame();
if (cudaHW) {
AVFrame* cpuNV12 = (*Handle)->GetNV12Frame();
gpu_frame_attach_cuda(*image, cudaHW, gpuIdx, timeStamp, cpuNV12);
} else {
AVFrame* nv12 = (*Handle)->GetNV12Frame();
if (nv12) {
gpu_frame_attach(*image, nv12, gpuIdx, timeStamp);
}
}
}
@@ -994,6 +1000,18 @@ extern "C" __declspec(dllexport) void SetSRTDisplayResolution(ANSCENTER::ANSSRTC
(*Handle)->SetDisplayResolution(width, height);
} catch (...) { }
}
extern "C" __declspec(dllexport) void SetSRTTargetFPS(ANSCENTER::ANSSRTClient** Handle, double intervalMs) {
if (Handle == nullptr || *Handle == nullptr) return;
try {
(*Handle)->SetTargetFPS(intervalMs);
} catch (...) { }
}
extern "C" __declspec(dllexport) void SetSRTNV12FastPath(ANSCENTER::ANSSRTClient** Handle, int enable) {
if (Handle == nullptr || *Handle == nullptr) return;
try {
(*Handle)->SetNV12FastPath(enable != 0);
} catch (...) { }
}
// ============================================================================
// V2 entry points: accept uint64_t handleVal by value instead of Handle**