Fix other ANSCV classes
This commit is contained in:
+61
-41
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace ANSCENTER
|
||||
std::string _lastJpegImage;
|
||||
int _imageWidth, _imageHeight;
|
||||
int64_t _pts;
|
||||
// Last currentPts seen from inner getImage(). Used for duplicate
|
||||
// detection separately from _pts so "same image -> same pts" holds.
|
||||
int64_t _lastInnerPts = -1;
|
||||
bool _isPlaying;
|
||||
bool _useNV12FastPath = false; // false = original stable CPU path, true = NV12 GPU fast path
|
||||
std::recursive_mutex _mutex;
|
||||
@@ -73,6 +76,10 @@ namespace ANSCENTER
|
||||
void SetDisplayResolution(int width, int height); // Set display output size; 0,0 = original (no resize)
|
||||
void SetImageQuality(int mode); // 0=fast (AI), 1=quality (display)
|
||||
void SetTargetFPS(double intervalMs); // Set min interval between processed frames in ms (0 = no limit, 100 = ~10 FPS, 200 = ~5 FPS)
|
||||
// Jitter buffer for the BGR delivery path (forwarded to CVideoPlayer).
|
||||
// 0 = no buffering (today's getLatest semantics). Default 200 ms.
|
||||
void SetJitterBufferMs(int ms);
|
||||
int GetJitterBufferMs() const;
|
||||
void SetNV12FastPath(bool enable); // true = NV12 GPU fast path, false = original CPU path (stable)
|
||||
bool IsNV12FastPath() const { return _useNV12FastPath; }
|
||||
AVFrame* GetNV12Frame(); // Returns cloned NV12 frame for GPU fast-path (caller must av_frame_free)
|
||||
@@ -114,4 +121,6 @@ extern "C" __declspec(dllexport) void SetFLVImageQuality(ANSCENTER::ANSFLVClient
|
||||
extern "C" __declspec(dllexport) void SetFLVDisplayResolution(ANSCENTER::ANSFLVClient** Handle, int width, int height);
|
||||
extern "C" __declspec(dllexport) void SetFLVTargetFPS(ANSCENTER::ANSFLVClient** Handle, double intervalMs);
|
||||
extern "C" __declspec(dllexport) void SetFLVNV12FastPath(ANSCENTER::ANSFLVClient** Handle, int enable);
|
||||
extern "C" __declspec(dllexport) void SetFLVJitterBuffer(ANSCENTER::ANSFLVClient** Handle, int jitterMs);
|
||||
extern "C" __declspec(dllexport) int GetFLVJitterBuffer(ANSCENTER::ANSFLVClient** Handle);
|
||||
#endif
|
||||
@@ -219,6 +219,14 @@ namespace ANSCENTER {
|
||||
_displayWidth = width;
|
||||
_displayHeight = height;
|
||||
}
|
||||
void ANSFILEPLAYER::SetJitterBufferMs(int ms) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (_playerClient) _playerClient->setJitterBufferMs(ms);
|
||||
ANS_DBG("FilePlayer_Lifecycle", "SetJitterBufferMs: ms=%d url=%s", ms, _url.c_str());
|
||||
}
|
||||
int ANSFILEPLAYER::GetJitterBufferMs() const {
|
||||
return _playerClient ? _playerClient->getJitterBufferMs() : 0;
|
||||
}
|
||||
cv::Mat ANSFILEPLAYER::GetInferenceImage() {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
return _inferenceImage;
|
||||
@@ -324,7 +332,7 @@ extern "C" __declspec(dllexport) int GetFilePlayerStrImage(ANSCENTER::ANSFILEPLA
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting image data from FilePlayer client: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -351,18 +359,18 @@ extern "C" __declspec(dllexport) int GetFilePlayerImage(ANSCENTER::ANSFILEPLAYER
|
||||
}
|
||||
else {
|
||||
// Return failure if there was an error in resizing the handle
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("FilePlayer_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 FilePlayer client." << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting image data from FilePlayer client: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -371,7 +379,7 @@ extern "C" __declspec(dllexport) int GetFilePlayerImage(ANSCENTER::ANSFILEPLAYER
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetFilePlayerCVImage(ANSCENTER::ANSFILEPLAYER** Handle, int& width, int& height, int64_t& timeStamp, cv::Mat** image) {
|
||||
if (!Handle || !(*Handle) || !image) {
|
||||
std::cerr << "Error: Invalid input parameters in GetFilePlayerCVImage." << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage invalid input parameters");
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
@@ -439,15 +447,15 @@ extern "C" __declspec(dllexport) int GetFilePlayerCVImage(ANSCENTER::ANSFILEPLAY
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetFilePlayerCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetFilePlayerCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetFilePlayerCVImage" << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -460,7 +468,7 @@ extern "C" __declspec(dllexport) int StartFilePlayer(ANSCENTER::ANSFILEPLAYER**
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "StartFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -475,7 +483,7 @@ extern "C" __declspec(dllexport) int ReconnectFilePlayer(ANSCENTER::ANSFILEPLAYE
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "ReconnectFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -490,7 +498,7 @@ extern "C" __declspec(dllexport) int StopFilePlayer(ANSCENTER::ANSFILEPLAYER** H
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "StopFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -505,7 +513,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerPaused(ANSCENTER::ANSFILEPLAYER
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is paused: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerPaused exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -520,7 +528,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerRunning(ANSCENTER::ANSFILEPLAYE
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is running: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerRunning exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -535,7 +543,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerRecording(ANSCENTER::ANSFILEPLA
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is recording: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerRecording exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -559,7 +567,7 @@ extern "C" __declspec(dllexport) void EnableFilePlayerAudioVolume(ANSCENTER::ANS
|
||||
(*Handle)->EnableAudio(audioStatus);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error enabling audio for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "EnableFilePlayerAudio exception: %s", e.what());
|
||||
}
|
||||
catch (...) { }
|
||||
}
|
||||
@@ -578,7 +586,7 @@ extern "C" __declspec(dllexport) int SetBBoxFilePlayer(ANSCENTER::ANSFILEPLAYER*
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error setting bounding box for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Cfg", "SetBBoxFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -594,7 +602,7 @@ extern "C" __declspec(dllexport) int SetCropFlagFilePlayer(ANSCENTER::ANSFILEPLA
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error setting crop flag for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Cfg", "SetCropFlagFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -621,17 +629,17 @@ extern "C" __declspec(dllexport) int GetFilePlayerImage_V2(uint64_t handleVal, i
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "No image data retrieved from FilePlayer client." << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting image data from FilePlayer client: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -704,15 +712,15 @@ extern "C" __declspec(dllexport) int GetFilePlayerCVImage_V2(uint64_t handleVal,
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetFilePlayerCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage_V2 OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetFilePlayerCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage_V2 exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetFilePlayerCVImage_V2" << std::endl;
|
||||
ANS_DBG("FilePlayer_GetImage", "GetFilePlayerCVImage_V2 unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -726,7 +734,7 @@ extern "C" __declspec(dllexport) int StartFilePlayer_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "StartFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -743,7 +751,7 @@ extern "C" __declspec(dllexport) int ReconnectFilePlayer_V2(uint64_t handleVal)
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "ReconnectFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -760,7 +768,7 @@ extern "C" __declspec(dllexport) int StopFilePlayer_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "StopFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -777,7 +785,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerPaused_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is paused: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerPaused exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -794,7 +802,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerRunning_V2(uint64_t handleVal)
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is running: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerRunning exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -811,7 +819,7 @@ extern "C" __declspec(dllexport) int IsFilePlayerRecording_V2(uint64_t handleVal
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error checking if file player is recording: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "IsFilePlayerRecording exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -837,7 +845,7 @@ extern "C" __declspec(dllexport) void EnableFilePlayerAudioVolume_V2(uint64_t ha
|
||||
h->EnableAudio(audioStatus);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error enabling audio for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Lifecycle", "EnableFilePlayerAudio exception: %s", e.what());
|
||||
}
|
||||
catch (...) { }
|
||||
}
|
||||
@@ -860,7 +868,7 @@ extern "C" __declspec(dllexport) int SetBBoxFilePlayer_V2(uint64_t handleVal, in
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error setting bounding box for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Cfg", "SetBBoxFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -878,7 +886,7 @@ extern "C" __declspec(dllexport) int SetCropFlagFilePlayer_V2(uint64_t handleVal
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error setting crop flag for file player: " << e.what() << std::endl;
|
||||
ANS_DBG("FilePlayer_Cfg", "SetCropFlagFilePlayer exception: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -892,3 +900,15 @@ extern "C" __declspec(dllexport) void SetFilePlayerDisplayResolution(ANSCENTER::
|
||||
(*Handle)->SetDisplayResolution(width, height);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetFilePlayerJitterBuffer(ANSCENTER::ANSFILEPLAYER** Handle, int jitterMs) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
(*Handle)->SetJitterBufferMs(jitterMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetFilePlayerJitterBuffer(ANSCENTER::ANSFILEPLAYER** Handle) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return -1;
|
||||
try {
|
||||
return (*Handle)->GetJitterBufferMs();
|
||||
} catch (...) { return -1; }
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ namespace ANSCENTER
|
||||
if (mode > 360) _imageRotateDeg = 360;
|
||||
};
|
||||
void SetDisplayResolution(int width, int height);
|
||||
// Jitter buffer for the BGR delivery path (forwarded to CFilePlayer ->
|
||||
// CVideoPlayer). 0 = no buffering. Default 200 ms (set by CVideoPlayer).
|
||||
void SetJitterBufferMs(int ms);
|
||||
int GetJitterBufferMs() const;
|
||||
[[nodiscard]] cv::Mat GetImage(int& width, int& height, int64_t& pts);
|
||||
[[nodiscard]] cv::Mat GetInferenceImage();
|
||||
[[nodiscard]] std::string GetJpegImage(int& width, int& height, int64_t& pts);
|
||||
@@ -99,6 +103,8 @@ extern "C" __declspec(dllexport) void SetFilePlayerImageRotation(ANSCENTER::ANSF
|
||||
extern "C" __declspec(dllexport) int SetBBoxFilePlayer(ANSCENTER::ANSFILEPLAYER** Handle, int x, int y, int width, int height);
|
||||
extern "C" __declspec(dllexport) int SetCropFlagFilePlayer(ANSCENTER::ANSFILEPLAYER** Handle, int cropFlag);
|
||||
extern "C" __declspec(dllexport) void SetFilePlayerDisplayResolution(ANSCENTER::ANSFILEPLAYER** Handle, int width, int height);
|
||||
extern "C" __declspec(dllexport) void SetFilePlayerJitterBuffer(ANSCENTER::ANSFILEPLAYER** Handle, int jitterMs);
|
||||
extern "C" __declspec(dllexport) int GetFilePlayerJitterBuffer(ANSCENTER::ANSFILEPLAYER** Handle);
|
||||
|
||||
// V2 functions: accept uint64_t handleVal by value (LabVIEW-safe)
|
||||
extern "C" __declspec(dllexport) int GetFilePlayerImage_V2(uint64_t handleVal, int& width, int& height, int64_t& timeStamp, LStrHandle jpegImage);
|
||||
|
||||
+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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace ANSCENTER
|
||||
std::string _lastJpegImage;
|
||||
int _imageWidth, _imageHeight;
|
||||
int64_t _pts;
|
||||
// Last currentPts seen from inner getImage(). Used for duplicate
|
||||
// detection separately from _pts so "same image -> same pts" holds.
|
||||
int64_t _lastInnerPts = -1;
|
||||
bool _isPlaying;
|
||||
bool _useNV12FastPath = false;
|
||||
std::recursive_mutex _mutex;
|
||||
@@ -72,6 +75,10 @@ namespace ANSCENTER
|
||||
void SetDisplayResolution(int width, int height); // Set display output size; 0,0 = original (no resize)
|
||||
void SetImageQuality(int mode); // 0=fast (AI), 1=quality (display)
|
||||
void SetTargetFPS(double intervalMs); // Set min interval between processed frames in ms (0 = no limit, 100 = ~10 FPS, 200 = ~5 FPS)
|
||||
// Jitter buffer for the BGR delivery path (forwarded to CVideoPlayer).
|
||||
// 0 = no buffering (today's getLatest semantics). Default 200 ms.
|
||||
void SetJitterBufferMs(int ms);
|
||||
int GetJitterBufferMs() const;
|
||||
void SetNV12FastPath(bool enable); // true = NV12 GPU fast path, false = original CPU path (stable)
|
||||
bool IsNV12FastPath() const { return _useNV12FastPath; }
|
||||
AVFrame* GetNV12Frame(); // Returns cloned NV12 frame for GPU fast-path (caller must av_frame_free)
|
||||
@@ -114,4 +121,6 @@ extern "C" __declspec(dllexport) void SetMJPEGImageQuality(ANSCENTER::ANSMJPEGCl
|
||||
extern "C" __declspec(dllexport) void SetMJPEGDisplayResolution(ANSCENTER::ANSMJPEGClient** Handle, int width, int height);
|
||||
extern "C" __declspec(dllexport) void SetMJPEGTargetFPS(ANSCENTER::ANSMJPEGClient** Handle, double intervalMs);
|
||||
extern "C" __declspec(dllexport) void SetMJPEGNV12FastPath(ANSCENTER::ANSMJPEGClient** Handle, int enable);
|
||||
extern "C" __declspec(dllexport) void SetMJPEGJitterBuffer(ANSCENTER::ANSMJPEGClient** Handle, int jitterMs);
|
||||
extern "C" __declspec(dllexport) int GetMJPEGJitterBuffer(ANSCENTER::ANSMJPEGClient** Handle);
|
||||
#endif
|
||||
+76
-41
@@ -219,14 +219,23 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
// Honest image-equality check. Returns true iff the two Mats refer to the
|
||||
// same pixels. Used by callers who want to know "did I just get the same
|
||||
// frame back?" — typical pattern after GetImage to skip downstream work
|
||||
// on rate-limited / buffered duplicates.
|
||||
//
|
||||
// Camera-aliveness ("did the decoder go silent?") is a separate concern;
|
||||
// use GetRTMPLastFrameAgeMs (or _playerClient->getLastFrameAgeMs()) for
|
||||
// that. With the new pts discipline (same image -> same pts), most callers
|
||||
// can simply compare pts instead of calling this function at all.
|
||||
bool ANSRTMPClient::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;
|
||||
|
||||
// Fast path — same buffer pointer. With the new GetImage discipline,
|
||||
// the duplicate path returns _pLastFrame so this branch hits and we
|
||||
// are done in O(1).
|
||||
if (img1.data == img2.data) return true;
|
||||
|
||||
if (img1.isContinuous() && img2.isContinuous()) {
|
||||
@@ -282,19 +291,25 @@ 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-frame detection. Track the inner player's currentPts in
|
||||
// _lastInnerPts (separate from our own _pts). On a duplicate, return
|
||||
// _pLastFrame and DO NOT advance _pts — the invariant is:
|
||||
// same image -> same pts
|
||||
// so a caller comparing pts (or calling areImagesIdentical()) can
|
||||
// recognise rate-limited / buffered duplicates.
|
||||
// Camera-alive detection should use getLastFrameAgeMs() instead.
|
||||
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 the duplicate cursor and bump
|
||||
// _pts monotonically (each ++ corresponds to a unique frame).
|
||||
_lastInnerPts = currentPts;
|
||||
_pts++;
|
||||
pts = _pts;
|
||||
|
||||
// Handle non-rotated case
|
||||
if (_imageRotateDeg == 0) {
|
||||
@@ -648,6 +663,14 @@ namespace ANSCENTER {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setTargetFPS(intervalMs); // 0=no limit, 100=~10FPS, 200=~5FPS
|
||||
}
|
||||
void ANSRTMPClient::SetJitterBufferMs(int ms) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_playerClient->setJitterBufferMs(ms);
|
||||
ANS_DBG("RTMP_Lifecycle", "SetJitterBufferMs: ms=%d url=%s", ms, _url.c_str());
|
||||
}
|
||||
int ANSRTMPClient::GetJitterBufferMs() const {
|
||||
return _playerClient->getJitterBufferMs();
|
||||
}
|
||||
void ANSRTMPClient::SetNV12FastPath(bool enable) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
_useNV12FastPath = enable;
|
||||
@@ -742,11 +765,11 @@ extern "C" __declspec(dllexport) int GetRTMPtrImage(ANSCENTER::ANSRTMPClient * *
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting RTMP image: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting RTMP image: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -770,22 +793,22 @@ extern "C" __declspec(dllexport) int GetRTMPImage(ANSCENTER::ANSRTMPClient * *Ha
|
||||
}
|
||||
else {
|
||||
// Return failure if there was an error in resizing the handle
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("RTMP_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 RTMP client." << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting RTMP image: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting RTMP image: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -793,7 +816,7 @@ extern "C" __declspec(dllexport) int GetRTMPImage(ANSCENTER::ANSRTMPClient * *Ha
|
||||
extern "C" __declspec(dllexport) int GetRTMPCVImage(ANSCENTER::ANSRTMPClient** 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 GetRTMPCVImage" << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "invalid input parameters");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -835,15 +858,15 @@ extern "C" __declspec(dllexport) int GetRTMPCVImage(ANSCENTER::ANSRTMPClient** H
|
||||
return 1; // Success
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetRTMPCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetRTMPCVImage: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "GetRTMPCVImage exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetRTMPCVImage" << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "GetRTMPCVImage unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -855,11 +878,11 @@ extern "C" __declspec(dllexport) int StartRTMP(ANSCENTER::ANSRTMPClient * *Handl
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StartRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StartRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -871,11 +894,11 @@ extern "C" __declspec(dllexport) int ReconnectRTMP(ANSCENTER::ANSRTMPClient * *H
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "ReconnectRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "ReconnectRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -887,11 +910,11 @@ extern "C" __declspec(dllexport) int StopRTMP(ANSCENTER::ANSRTMPClient * *Handle
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StopRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StopRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1007,6 +1030,18 @@ extern "C" __declspec(dllexport) void SetRTMPTargetFPS(ANSCENTER::ANSRTMPClient*
|
||||
(*Handle)->SetTargetFPS(intervalMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetRTMPJitterBuffer(ANSCENTER::ANSRTMPClient** Handle, int jitterMs) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
(*Handle)->SetJitterBufferMs(jitterMs);
|
||||
} catch (...) { }
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetRTMPJitterBuffer(ANSCENTER::ANSRTMPClient** Handle) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return -1;
|
||||
try {
|
||||
return (*Handle)->GetJitterBufferMs();
|
||||
} catch (...) { return -1; }
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetRTMPNV12FastPath(ANSCENTER::ANSRTMPClient** Handle, int enable) {
|
||||
if (Handle == nullptr || *Handle == nullptr) return;
|
||||
try {
|
||||
@@ -1033,21 +1068,21 @@ extern "C" __declspec(dllexport) int GetRTMPImage_V2(uint64_t handleVal, int& wi
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error resizing jpegImage handle: " << error << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "DSSetHandleSize failed: error=%d", (int)error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "No image data retrieved from RTMP client." << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "no image data retrieved (jpegString empty)");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error getting RTMP image: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error getting RTMP image: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1086,15 +1121,15 @@ extern "C" __declspec(dllexport) int GetRTMPCVImage_V2(uint64_t handleVal, int&
|
||||
return 1;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "OpenCV exception in GetRTMPCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "GetRTMPCVImage_V2 OpenCV exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Exception in GetRTMPCVImage_V2: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "GetRTMPCVImage_V2 exception: %s", e.what());
|
||||
return -2;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception in GetRTMPCVImage_V2" << std::endl;
|
||||
ANS_DBG("RTMP_GetImage", "GetRTMPCVImage_V2 unknown exception");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -1107,11 +1142,11 @@ extern "C" __declspec(dllexport) int StartRTMP_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error starting RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StartRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error starting RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StartRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1124,11 +1159,11 @@ extern "C" __declspec(dllexport) int ReconnectRTMP_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error reconnecting RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "ReconnectRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error reconnecting RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "ReconnectRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1141,11 +1176,11 @@ extern "C" __declspec(dllexport) int StopRTMP_V2(uint64_t handleVal) {
|
||||
else return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error stopping RTMP client: " << e.what() << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StopRTMP exception: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Error stopping RTMP client: Unknown exception." << std::endl;
|
||||
ANS_DBG("RTMP_Lifecycle", "StopRTMP unknown exception");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ namespace ANSCENTER
|
||||
std::string _lastJpegImage;
|
||||
int _imageWidth, _imageHeight;
|
||||
int64_t _pts;
|
||||
// Last currentPts seen from the inner getImage(). Used for duplicate
|
||||
// detection separately from _pts so the invariant
|
||||
// same image -> same pts
|
||||
// holds for callers comparing pts (or calling areImagesIdentical()).
|
||||
int64_t _lastInnerPts = -1;
|
||||
bool _isPlaying;
|
||||
bool _useNV12FastPath = false;
|
||||
std::recursive_mutex _mutex;
|
||||
@@ -73,6 +78,11 @@ namespace ANSCENTER
|
||||
void SetDisplayResolution(int width, int height); // Set display output size; 0,0 = original (no resize)
|
||||
void SetImageQuality(int mode); // 0=fast (AI), 1=quality (display)
|
||||
void SetTargetFPS(double intervalMs); // Set min interval between processed frames in ms (0 = no limit, 100 = ~10 FPS, 200 = ~5 FPS)
|
||||
// Jitter buffer for the BGR delivery path (forwarded to CVideoPlayer).
|
||||
// 0 = no buffering (today's getLatest semantics). Default 200 ms (set
|
||||
// inside CVideoPlayer constructor). Adaptive: slow consumers bypass it.
|
||||
void SetJitterBufferMs(int ms);
|
||||
int GetJitterBufferMs() const;
|
||||
void SetNV12FastPath(bool enable); // true = NV12 GPU fast path, false = original CPU path (stable)
|
||||
bool IsNV12FastPath() const { return _useNV12FastPath; }
|
||||
AVFrame* GetNV12Frame(); // Returns cloned NV12 frame for GPU fast-path (caller must av_frame_free)
|
||||
@@ -113,4 +123,6 @@ extern "C" __declspec(dllexport) void SetRTMPImageQuality(ANSCENTER::ANSRTMPClie
|
||||
extern "C" __declspec(dllexport) void SetRTMPDisplayResolution(ANSCENTER::ANSRTMPClient** Handle, int width, int height);
|
||||
extern "C" __declspec(dllexport) void SetRTMPTargetFPS(ANSCENTER::ANSRTMPClient** Handle, double intervalMs);
|
||||
extern "C" __declspec(dllexport) void SetRTMPNV12FastPath(ANSCENTER::ANSRTMPClient** Handle, int enable);
|
||||
extern "C" __declspec(dllexport) void SetRTMPJitterBuffer(ANSCENTER::ANSRTMPClient** Handle, int jitterMs);
|
||||
extern "C" __declspec(dllexport) int GetRTMPJitterBuffer(ANSCENTER::ANSRTMPClient** Handle);
|
||||
#endif
|
||||
+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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace ANSCENTER
|
||||
std::string _lastJpegImage;
|
||||
int _imageWidth, _imageHeight;
|
||||
int64_t _pts;
|
||||
// Last currentPts seen from inner getImage(). Used for duplicate
|
||||
// detection separately from _pts so "same image -> same pts" holds.
|
||||
int64_t _lastInnerPts = -1;
|
||||
bool _isPlaying;
|
||||
bool _useNV12FastPath = false;
|
||||
std::recursive_mutex _mutex;
|
||||
@@ -72,6 +75,10 @@ namespace ANSCENTER
|
||||
void SetDisplayResolution(int width, int height); // Set display output size; 0,0 = original (no resize)
|
||||
void SetImageQuality(int mode); // 0=fast (AI), 1=quality (display)
|
||||
void SetTargetFPS(double intervalMs); // Set min interval between processed frames in ms (0 = no limit, 100 = ~10 FPS, 200 = ~5 FPS)
|
||||
// Jitter buffer for the BGR delivery path (forwarded to CVideoPlayer).
|
||||
// 0 = no buffering (today's getLatest semantics). Default 200 ms.
|
||||
void SetJitterBufferMs(int ms);
|
||||
int GetJitterBufferMs() const;
|
||||
void SetNV12FastPath(bool enable); // true = NV12 GPU fast path, false = original CPU path (stable)
|
||||
bool IsNV12FastPath() const { return _useNV12FastPath; }
|
||||
AVFrame* GetNV12Frame(); // Returns cloned NV12 frame for GPU fast-path (caller must av_frame_free)
|
||||
@@ -113,4 +120,6 @@ extern "C" __declspec(dllexport) void SetSRTImageQuality(ANSCENTER::ANSSRTClient
|
||||
extern "C" __declspec(dllexport) void SetSRTDisplayResolution(ANSCENTER::ANSSRTClient** Handle, int width, int height);
|
||||
extern "C" __declspec(dllexport) void SetSRTTargetFPS(ANSCENTER::ANSSRTClient** Handle, double intervalMs);
|
||||
extern "C" __declspec(dllexport) void SetSRTNV12FastPath(ANSCENTER::ANSSRTClient** Handle, int enable);
|
||||
extern "C" __declspec(dllexport) void SetSRTJitterBuffer(ANSCENTER::ANSSRTClient** Handle, int jitterMs);
|
||||
extern "C" __declspec(dllexport) int GetSRTJitterBuffer(ANSCENTER::ANSSRTClient** Handle);
|
||||
#endif
|
||||
Reference in New Issue
Block a user