Fix other ANSCV classes
This commit is contained in:
+61
-39
@@ -214,11 +214,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 ANSMJPEGClient::areImagesIdentical(const cv::Mat& img1, const cv::Mat& img2) {
|
||||
double ageMs = _playerClient->getLastFrameAgeMs();
|
||||
if (ageMs > 5000.0) return true;
|
||||
if (ageMs > 0.0) return false;
|
||||
|
||||
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;
|
||||
@@ -276,17 +276,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) {
|
||||
@@ -634,6 +636,14 @@ namespace ANSCENTER {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setTargetFPS(intervalMs); // 0=no limit, 100=~10FPS, 200=~5FPS
|
||||
}
|
||||
void ANSMJPEGClient::SetJitterBufferMs(int ms) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setJitterBufferMs(ms);
|
||||
ANS_DBG("MJPEG_Lifecycle", "SetJitterBufferMs: ms=%d url=%s", ms, _url.c_str());
|
||||
}
|
||||
int ANSMJPEGClient::GetJitterBufferMs() const {
|
||||
return _playerClient->getJitterBufferMs();
|
||||
}
|
||||
void ANSMJPEGClient::SetNV12FastPath(bool enable) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_useNV12FastPath = enable;
|
||||
@@ -728,11 +738,11 @@ extern "C" __declspec(dllexport) int GetMJPEGStrImage(ANSCENTER::ANSMJPEGClient
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting MJPEG image: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting MJPEG image: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -750,28 +760,28 @@ extern "C" __declspec(dllexport) int GetMJPEGImage(ANSCENTER::ANSMJPEGClient * *
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "No image data retrieved from MJPEG client." << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting MJPEG image: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting MJPEG image: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int GetMJPEGCVImage(ANSCENTER::ANSMJPEGClient** Handle, int& width, int& height, int64_t& timeStamp, cv::Mat** image) {
|
||||
if (!Handle || !*Handle || !image) {
|
||||
std::cerr << "Error: Invalid input parameters in GetMJPEGCVImage" << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "invalid input parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -811,15 +821,15 @@ extern "C" __declspec(dllexport) int GetMJPEGCVImage(ANSCENTER::ANSMJPEGClient**
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetMJPEGCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetMJPEGCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "GetMJPEGCVImage exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetMJPEGCVImage" << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "GetMJPEGCVImage unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -831,11 +841,11 @@ extern "C" __declspec(dllexport) int StartMJPEG(ANSCENTER::ANSMJPEGClient * *Han
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StartMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StartMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -847,11 +857,11 @@ extern "C" __declspec(dllexport) int ReconnectMJPEG(ANSCENTER::ANSMJPEGClient *
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "ReconnectMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "ReconnectMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -863,11 +873,11 @@ extern "C" __declspec(dllexport) int StopMJPEG(ANSCENTER::ANSMJPEGClient * *Hand
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StopMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StopMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -979,6 +989,18 @@ extern "C" __declspec(dllexport) void SetMJPEGDisplayResolution(ANSCENTER::ANSMJ
|
||||
(*Handle)->SetDisplayResolution(width, height);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetMJPEGJitterBuffer(ANSCENTER::ANSMJPEGClient** Handle, int jitterMs) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
(*Handle)->SetJitterBufferMs(jitterMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetMJPEGJitterBuffer(ANSCENTER::ANSMJPEGClient** Handle) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return -1;
|
||||
try {
|
||||
return (*Handle)->GetJitterBufferMs();
|
||||
} catch (...) { return -1; }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetMJPEGTargetFPS(ANSCENTER::ANSMJPEGClient** Handle, double intervalMs) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
@@ -1010,21 +1032,21 @@ extern "C" __declspec(dllexport) int GetMJPEGImage_V2(uint64_t handleVal, int& w
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "No image data retrieved from MJPEG client." << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting MJPEG image: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting MJPEG image: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1063,15 +1085,15 @@ extern "C" __declspec(dllexport) int GetMJPEGCVImage_V2(uint64_t handleVal, int&
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetMJPEGCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "GetMJPEGCVImage_V2 OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetMJPEGCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "GetMJPEGCVImage_V2 exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetMJPEGCVImage_V2" << std::endl;
|
||||
ANS_DBG("MJPEG_GetImage", "GetMJPEGCVImage_V2 unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -1084,11 +1106,11 @@ extern "C" __declspec(dllexport) int StartMJPEG_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StartMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StartMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1101,11 +1123,11 @@ extern "C" __declspec(dllexport) int ReconnectMJPEG_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "ReconnectMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "ReconnectMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1118,11 +1140,11 @@ extern "C" __declspec(dllexport) int StopMJPEG_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping MJPEG client: " << e.what() << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StopMJPEG exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping MJPEG client: Unknown exception." << std::endl;
|
||||
ANS_DBG("MJPEG_Lifecycle", "StopMJPEG unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user