Fix other ANSCV classes
This commit is contained in:
+62
-42
@@ -227,11 +227,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 ANSSRTClient::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;
|
||||
@@ -290,19 +290,19 @@ namespace ANSCENTER {
|
||||
return _pLastFrame;
|
||||
}
|
||||
|
||||
// Use PTS to detect duplicate frames (much faster than pixel comparison)
|
||||
// The sequence-based check in getImage() already skips conversion for same frames,
|
||||
// so if PTS hasn't changed, it's the same frame — no need for expensive memcmp
|
||||
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) {
|
||||
@@ -666,6 +666,14 @@ namespace ANSCENTER {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setTargetFPS(intervalMs); // 0=no limit, 100=~10FPS, 200=~5FPS
|
||||
}
|
||||
void ANSSRTClient::SetJitterBufferMs(int ms) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setJitterBufferMs(ms);
|
||||
ANS_DBG("SRT_Lifecycle", "SetJitterBufferMs: ms=%d url=%s", ms, _url.c_str());
|
||||
}
|
||||
int ANSSRTClient::GetJitterBufferMs() const {
|
||||
return _playerClient->getJitterBufferMs();
|
||||
}
|
||||
void ANSSRTClient::SetNV12FastPath(bool enable) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_useNV12FastPath = enable;
|
||||
@@ -760,11 +768,11 @@ extern "C" __declspec(dllexport) int GetSRTStrImage(ANSCENTER::ANSSRTClient * *H
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting SRT image: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting SRT image: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -788,22 +796,22 @@ extern "C" __declspec(dllexport) int GetSRTImage(ANSCENTER::ANSSRTClient * *Hand
|
||||
}
|
||||
else {
|
||||
// Return failure if there was an error in resizing the handle
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If the JPEG image string is empty, return failure
|
||||
std::cerr << "No image data retrieved from SRT client." << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting SRT image: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting SRT image: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -811,7 +819,7 @@ extern "C" __declspec(dllexport) int GetSRTImage(ANSCENTER::ANSSRTClient * *Hand
|
||||
extern "C" __declspec(dllexport) int GetSRTCVImage(ANSCENTER::ANSSRTClient** Handle, int& width, int& height, int64_t& timeStamp, cv::Mat** image) {
|
||||
// Validate input parameters
|
||||
if (!Handle || !*Handle || !image) {
|
||||
std::cerr << "Error: Invalid input parameters in GetSRTCVImage" << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage invalid input parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -853,15 +861,15 @@ extern "C" __declspec(dllexport) int GetSRTCVImage(ANSCENTER::ANSSRTClient** Han
|
||||
return 1; // Success
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetSRTCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetSRTCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetSRTCVImage" << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -873,11 +881,11 @@ extern "C" __declspec(dllexport) int StartSRT(ANSCENTER::ANSSRTClient * *Handle)
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StartSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StartSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -889,11 +897,11 @@ extern "C" __declspec(dllexport) int ReconnectSRT(ANSCENTER::ANSSRTClient * *Han
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "ReconnectSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "ReconnectSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -905,11 +913,11 @@ extern "C" __declspec(dllexport) int StopSRT(ANSCENTER::ANSSRTClient * *Handle)
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StopSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StopSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1024,6 +1032,18 @@ extern "C" __declspec(dllexport) void SetSRTTargetFPS(ANSCENTER::ANSSRTClient**
|
||||
(*Handle)->SetTargetFPS(intervalMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetSRTJitterBuffer(ANSCENTER::ANSSRTClient** Handle, int jitterMs) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
(*Handle)->SetJitterBufferMs(jitterMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetSRTJitterBuffer(ANSCENTER::ANSSRTClient** Handle) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return -1;
|
||||
try {
|
||||
return (*Handle)->GetJitterBufferMs();
|
||||
} catch (...) { return -1; }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetSRTNV12FastPath(ANSCENTER::ANSSRTClient** Handle, int enable) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
@@ -1051,21 +1071,21 @@ extern "C" __declspec(dllexport) int GetSRTImage_V2(uint64_t handleVal, int& wid
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "No image data retrieved from SRT client." << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting SRT image: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting SRT image: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1073,7 +1093,7 @@ extern "C" __declspec(dllexport) int GetSRTImage_V2(uint64_t handleVal, int& wid
|
||||
extern "C" __declspec(dllexport) int GetSRTCVImage_V2(uint64_t handleVal, int& width, int& height, int64_t& timeStamp, cv::Mat** image) {
|
||||
auto* h = reinterpret_cast<ANSCENTER::ANSSRTClient*>(handleVal); if (!h) return -1;
|
||||
if (!image) {
|
||||
std::cerr << "Error: Invalid input parameters in GetSRTCVImage_V2" << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage_V2 invalid input parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1110,15 +1130,15 @@ extern "C" __declspec(dllexport) int GetSRTCVImage_V2(uint64_t handleVal, int& w
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetSRTCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage_V2 OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetSRTCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage_V2 exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetSRTCVImage_V2" << std::endl;
|
||||
ANS_DBG("SRT_GetImage", "GetSRTCVImage_V2 unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -1131,11 +1151,11 @@ extern "C" __declspec(dllexport) int StartSRT_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StartSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StartSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1148,11 +1168,11 @@ extern "C" __declspec(dllexport) int ReconnectSRT_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "ReconnectSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "ReconnectSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1165,11 +1185,11 @@ extern "C" __declspec(dllexport) int StopSRT_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping SRT client: " << e.what() << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StopSRT exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping SRT client: Unknown exception." << std::endl;
|
||||
ANS_DBG("SRT_Lifecycle", "StopSRT unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user