#ifndef ANSSRT_H #define ANSSRT_H #define ANSSRT_API __declspec(dllexport) #include #include "ANSLicense.h" #include "LabVIEWHeader/extcode.h" #include #include "sys_inc.h" #include "srt_cln.h" #include "hqueue.h" #include "http.h" #include "http_parse.h" #include "video_decoder.h" #include "audio_decoder.h" #include "srt_player.h" #include #include #include namespace ANSCENTER { class ANSSRT_API ANSSRTClient { protected: std::unique_ptr _playerClient = std::make_unique(); std::string _username; std::string _password; std::string _url; bool _useFullURL; int _imageRotateDeg = 0; int _displayWidth = 0; // 0 = no resize (return original resolution) int _displayHeight = 0; cv::Mat _pLastFrame; std::string _lastJpegImage; int _imageWidth, _imageHeight; int64_t _pts; bool _isPlaying; bool _useNV12FastPath = false; std::recursive_mutex _mutex; public: ANSSRTClient(); ~ANSSRTClient() noexcept; [[nodiscard]] bool Init(std::string licenseKey, std::string url); [[nodiscard]] bool Init(std::string licenseKey, std::string username, std::string password, std::string url); [[nodiscard]] bool Setup(); [[nodiscard]] bool Reconnect(); [[nodiscard]] bool Start(); [[nodiscard]] bool IsPaused(); [[nodiscard]] bool IsPlaying(); [[nodiscard]] bool IsRecording(); [[nodiscard]] bool Stop(); [[nodiscard]] bool Pause(); void Destroy(); void SetBBox(cv::Rect bbox); void SetCrop(bool crop); void EnableAudio(bool status); void SetAudioVolume(int volume); [[nodiscard]] cv::Mat GetImage(int& width, int& height, int64_t& pts); [[nodiscard]] std::string MatToBinaryData(const cv::Mat& image); [[nodiscard]] std::string GetJpegImage(int& width, int& height, int64_t& pts); bool areImagesIdentical(const cv::Mat& img1, const cv::Mat& img2); void SetImageRotate(int mode) { std::lock_guard lock(_mutex); _imageRotateDeg = mode; if (mode > 360) _imageRotateDeg = 360; }; static void SetMaxHWDecoders(int maxDecoders); static int AutoConfigureHWDecoders(int maxPerGpuOverride = 0); void SetHWDecoding(int hwMode, int preferredGpu = -1); bool IsHWDecodingActive(); int GetHWDecodingGpuIndex(); 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) 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) AVFrame* GetCudaHWFrame(); // Returns CUDA HW frame (device ptrs) for zero-copy inference bool IsCudaHWAccel(); // true when decoder uses CUDA (NV12 stays in GPU VRAM) public: void CheckLicense(); SPDLogger& _logger = SPDLogger::GetInstance("ANSSRT", false); bool _licenseValid{ false }; std::string _licenseKey; //std::once_flag licenseOnceFlag; }; } extern "C" __declspec(dllexport) int CreateANSSRTHandle(ANSCENTER::ANSSRTClient * *Handle, const char* licenseKey, const char* username, const char* password, const char* url); extern "C" __declspec(dllexport) int ReleaseANSSRTHandle(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int GetSRTImage(ANSCENTER::ANSSRTClient * *Handle, int& width, int& height, int64_t& timeStamp, LStrHandle jpegImage); extern "C" __declspec(dllexport) int GetSRTStrImage(ANSCENTER::ANSSRTClient * *Handle, int& width, int& height, int64_t & timeStamp, std::string & jpegImage); extern "C" __declspec(dllexport) int GetSRTCVImage(ANSCENTER::ANSSRTClient** Handle, int& width, int& height, int64_t& timeStamp, cv::Mat** image); extern "C" __declspec(dllexport) int StartSRT(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int ReconnectSRT(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int StopSRT(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int PauseSRT(ANSCENTER::ANSSRTClient** Handle); extern "C" __declspec(dllexport) int IsSRTPaused(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int IsSRTRunning(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) int IsSRTRecording(ANSCENTER::ANSSRTClient * *Handle); extern "C" __declspec(dllexport) void SetSRTAudioVolume(ANSCENTER::ANSSRTClient * *Handle, int volume); extern "C" __declspec(dllexport) void EnableSRTAudioVolume(ANSCENTER::ANSSRTClient * *Handle, int status); extern "C" __declspec(dllexport) void SetSRTImageRotation(ANSCENTER::ANSSRTClient * *Handle, double rotationAngle); extern "C" __declspec(dllexport) int SetBBoxSRT(ANSCENTER::ANSSRTClient** Handle, int x, int y, int width, int height); extern "C" __declspec(dllexport) int SetCropFlagSRT(ANSCENTER::ANSSRTClient** Handle, int cropFlag); extern "C" __declspec(dllexport) void SetSRTMaxHWDecoders(int maxDecoders); extern "C" __declspec(dllexport) int AutoConfigureSRTHWDecoders(int maxPerGpuOverride); extern "C" __declspec(dllexport) void SetSRTHWDecoding(ANSCENTER::ANSSRTClient** Handle, int hwMode, int preferredGpu = -1); extern "C" __declspec(dllexport) int IsSRTHWDecodingActive(ANSCENTER::ANSSRTClient** Handle); extern "C" __declspec(dllexport) int GetSRTHWDecodingGpuIndex(ANSCENTER::ANSSRTClient** Handle); extern "C" __declspec(dllexport) void SetSRTImageQuality(ANSCENTER::ANSSRTClient** Handle, int mode); 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); #endif