Fix other ANSCV classes

This commit is contained in:
2026-05-09 16:47:46 +10:00
parent aa323a07a3
commit a94bf88a5b
16 changed files with 1197 additions and 197 deletions
+61 -41
View File
@@ -224,13 +224,11 @@ namespace ANSCENTER {
}
}
// Honest image-equality check. Same buffer pointer (fast path) or pixel
// compare (fallback). Camera-aliveness uses getLastFrameAgeMs() — separate
// concern. With "same image -> same pts" invariant, callers usually just
// compare pts and skip this function entirely.
bool ANSFLVClient::areImagesIdentical(const cv::Mat& img1, const cv::Mat& img2) {
// Use decoder frame age — returns "stale" only if no decoder output for 5+ seconds.
double ageMs = _playerClient->getLastFrameAgeMs();
if (ageMs > 5000.0) return true; // Truly stale
if (ageMs > 0.0) return false; // Decoder alive
// Fallback for startup (no frame decoded yet)
if (img1.empty() && img2.empty()) return true;
if (img1.empty() || img2.empty()) return false;
if (img1.size() != img2.size() || img1.type() != img2.type()) return false;
@@ -288,17 +286,19 @@ namespace ANSCENTER {
return _pLastFrame;
}
// Use PTS to detect duplicate frames (much faster than pixel comparison)
if (currentPts == _pts && !_pLastFrame.empty()) {
// Duplicate detection via _lastInnerPts (separate from _pts). Invariant:
// same image -> same pts. Camera-alive check uses getLastFrameAgeMs().
if (currentPts == _lastInnerPts && !_pLastFrame.empty()) {
width = _imageWidth;
height = _imageHeight;
pts = _pts;
pts = _pts; // unchanged
return _pLastFrame;
}
// Update PTS first
_pts = currentPts;
pts = currentPts;
// Inner advanced — real new frame. Sync cursor and bump _pts monotonically.
_lastInnerPts = currentPts;
_pts++;
pts = _pts;
// Handle non-rotated case
if (_imageRotateDeg == 0) {
@@ -636,6 +636,14 @@ namespace ANSCENTER {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_playerClient->setTargetFPS(intervalMs); // 0=no limit, 100=~10FPS, 200=~5FPS
}
void ANSFLVClient::SetJitterBufferMs(int ms) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_playerClient->setJitterBufferMs(ms);
ANS_DBG("FLV_Lifecycle", "SetJitterBufferMs: ms=%d url=%s", ms, _url.c_str());
}
int ANSFLVClient::GetJitterBufferMs() const {
return _playerClient->getJitterBufferMs();
}
void ANSFLVClient::SetNV12FastPath(bool enable) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
_useNV12FastPath = enable;
@@ -730,11 +738,11 @@ extern "C" __declspec(dllexport) int GetFLVStrImage(ANSCENTER::ANSFLVClient * *H
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error getting FLV image: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error getting FLV image: Unknown exception." << std::endl;
ANS_DBG("FLV_GetImage", "unknown exception");
return 0;
}
}
@@ -752,27 +760,27 @@ extern "C" __declspec(dllexport) int GetFLVImage(ANSCENTER::ANSFLVClient * *Hand
return 1;
}
else {
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
ANS_DBG("FLV_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
return 0;
}
}
else {
std::cerr << "No image data retrieved from FLV client." << std::endl;
ANS_DBG("FLV_GetImage", "no image data retrieved (jpegString empty)");
return 0;
}
}
catch (const std::exception& e) {
std::cerr << "Error getting FLV image: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error getting FLV image: Unknown exception." << std::endl;
ANS_DBG("FLV_GetImage", "unknown exception");
return 0;
}
}
extern "C" __declspec(dllexport) int GetFLVCVImage(ANSCENTER::ANSFLVClient** Handle, int& width, int& height, int64_t& timeStamp, cv::Mat** image) {
if (!Handle || !*Handle || !image) {
std::cerr << "Error: Invalid input parameters in GetFLVCVImage" << std::endl;
ANS_DBG("FLV_GetImage", "invalid input parameters");
return -1;
}
@@ -812,15 +820,15 @@ extern "C" __declspec(dllexport) int GetFLVCVImage(ANSCENTER::ANSFLVClient** Han
return 1;
}
catch (const cv::Exception& e) {
std::cerr << "OpenCV exception in GetFLVCVImage: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "OpenCV exception: %s", e.what());
return -2;
}
catch (const std::exception& e) {
std::cerr << "Exception in GetFLVCVImage: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "GetFLVCVImage exception: %s", e.what());
return -2;
}
catch (...) {
std::cerr << "Unknown exception in GetFLVCVImage" << std::endl;
ANS_DBG("FLV_GetImage", "GetFLVCVImage unknown exception");
return -2;
}
}
@@ -833,11 +841,11 @@ extern "C" __declspec(dllexport) int StartFLV(ANSCENTER::ANSFLVClient * *Handle)
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error starting FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "StartFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error starting FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "StartFLV unknown exception");
return 0;
}
}
@@ -849,11 +857,11 @@ extern "C" __declspec(dllexport) int ReconnectFLV(ANSCENTER::ANSFLVClient * *Han
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error reconnecting FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "ReconnectFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error reconnecting FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "ReconnectFLV unknown exception");
return 0;
}
}
@@ -865,11 +873,11 @@ extern "C" __declspec(dllexport) int StopFLV(ANSCENTER::ANSFLVClient * *Handle)
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error stopping FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "StopFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error stopping FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "StopFLV unknown exception");
return 0;
}
}
@@ -980,6 +988,18 @@ extern "C" __declspec(dllexport) void SetFLVDisplayResolution(ANSCENTER::ANSFLVC
(*Handle)->SetDisplayResolution(width, height);
} catch (...) { }
}
extern "C" __declspec(dllexport) void SetFLVJitterBuffer(ANSCENTER::ANSFLVClient** Handle, int jitterMs) {
if (Handle == nullptr || *Handle == nullptr) return;
try {
(*Handle)->SetJitterBufferMs(jitterMs);
} catch (...) { }
}
extern "C" __declspec(dllexport) int GetFLVJitterBuffer(ANSCENTER::ANSFLVClient** Handle) {
if (Handle == nullptr || *Handle == nullptr) return -1;
try {
return (*Handle)->GetJitterBufferMs();
} catch (...) { return -1; }
}
extern "C" __declspec(dllexport) void SetFLVTargetFPS(ANSCENTER::ANSFLVClient** Handle, double intervalMs) {
if (Handle == nullptr || *Handle == nullptr) return;
try {
@@ -1012,21 +1032,21 @@ extern "C" __declspec(dllexport) int GetFLVImage_V2(uint64_t handleVal, int& wid
return 1;
}
else {
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
ANS_DBG("FLV_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
return 0;
}
}
else {
std::cerr << "No image data retrieved from FLV client." << std::endl;
ANS_DBG("FLV_GetImage", "no image data retrieved (jpegString empty)");
return 0;
}
}
catch (const std::exception& e) {
std::cerr << "Error getting FLV image: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error getting FLV image: Unknown exception." << std::endl;
ANS_DBG("FLV_GetImage", "unknown exception");
return 0;
}
}
@@ -1065,15 +1085,15 @@ extern "C" __declspec(dllexport) int GetFLVCVImage_V2(uint64_t handleVal, int& w
return 1;
}
catch (const cv::Exception& e) {
std::cerr << "OpenCV exception in GetFLVCVImage_V2: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "GetFLVCVImage_V2 OpenCV exception: %s", e.what());
return -2;
}
catch (const std::exception& e) {
std::cerr << "Exception in GetFLVCVImage_V2: " << e.what() << std::endl;
ANS_DBG("FLV_GetImage", "GetFLVCVImage_V2 exception: %s", e.what());
return -2;
}
catch (...) {
std::cerr << "Unknown exception in GetFLVCVImage_V2" << std::endl;
ANS_DBG("FLV_GetImage", "GetFLVCVImage_V2 unknown exception");
return -2;
}
}
@@ -1086,11 +1106,11 @@ extern "C" __declspec(dllexport) int StartFLV_V2(uint64_t handleVal) {
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error starting FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "StartFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error starting FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "StartFLV unknown exception");
return 0;
}
}
@@ -1103,11 +1123,11 @@ extern "C" __declspec(dllexport) int ReconnectFLV_V2(uint64_t handleVal) {
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error reconnecting FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "ReconnectFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error reconnecting FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "ReconnectFLV unknown exception");
return 0;
}
}
@@ -1120,11 +1140,11 @@ extern "C" __declspec(dllexport) int StopFLV_V2(uint64_t handleVal) {
else return 0;
}
catch (const std::exception& e) {
std::cerr << "Error stopping FLV client: " << e.what() << std::endl;
ANS_DBG("FLV_Lifecycle", "StopFLV exception: %s", e.what());
return 0;
}
catch (...) {
std::cerr << "Error stopping FLV client: Unknown exception." << std::endl;
ANS_DBG("FLV_Lifecycle", "StopFLV unknown exception");
return 0;
}
}