123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #pragma once
- #include "websocketpp/config/asio_no_tls.hpp"
- #include "websocketpp/config/asio.hpp"
- #include "websocketpp/server.hpp"
- #include <boost/asio.hpp>
- #include <boost/thread/mutex.hpp>
- #include <functional>
- #include <memory>
- #include <vector>
- #ifdef _WIN32
- #include <Windows.h>
- #include <process.h>
- #else
- #include <semaphore.h>
- #endif
- #ifndef RVC_LIVENESS_WS_PORT
- #define RVC_LIVENESS_WS_PORT 9100
- #endif
- #ifndef RVC_WS_INIT_STR
- #define RVC_WS_INIT_STR "rvc wbsocket trans init"
- #endif
- #ifndef RVC_WS_START_TRANS_STR
- #define RVC_WS_START_TRANS_STR "rvc wbsocket start trans"
- #endif
- #ifndef RVC_WS_STOP_TRANS_STR
- #define RVC_WS_STOP_TRANS_STR "rvc wbsocket stop trans"
- #endif
- #ifndef RVC_WS_CHANGE_CAMERA_STR
- #define RVC_WS_CHANGE_CAMERA_STR "rvc wbsocket change camera"
- #endif
- #ifndef RVC_WS_START_CAPTURE_STR
- #define RVC_WS_START_CAPTURE_STR "rvc wbsocket start capture"
- #endif
- #ifndef RVC_WS_CONNECT_IDENTIFIER
- #define RVC_WS_CONNECT_IDENTIFIER "+"
- #endif
- #ifndef RVC_DEFAULT_FPS
- #define RVC_DEFAULT_FPS 5
- #endif
- #ifndef RVC_MIN_FPS
- #define RVC_MIN_FPS 1
- #endif
- #ifndef RVC_MAX_FPS
- #define RVC_MAX_FPS 30
- #endif
- namespace LivenessDetection{
- enum eVideoType{
- ePreview_Type,
- eCapture_Type
- };
- enum eCameraType{
- eCamera_Env,
- eCamera_Opt
- };
- typedef websocketpp::server<websocketpp::config::asio> server;
- typedef struct websocket_callback_s {
- int (*on_get_videodata)(eVideoType eType, eCameraType ecameraid, int* width, int* height, unsigned char* bmpdata, int isize, void* user_data);
- void *user_data;
- }websocket_callback_t;
- typedef struct rvc_video_param_s{
- int iwidth;
- int iheight;
- int icapwidth;
- int icapheight;
- }rvc_video_param_t;
- class RvcWsServer
- {
- public:
- RvcWsServer(void);
- ~RvcWsServer(void);
- int Init_WsServer(websocket_callback_t* pcallback, rvc_video_param_t* pparam, int iport = RVC_LIVENESS_WS_PORT);
- int StartVideoTransmit();
- int StopVideoTransmit();
- int StartVideoCapTransmit();
- private:
- bool validate(websocketpp::connection_hdl hdl);
- void on_http(websocketpp::connection_hdl hdl);
- void on_fail(websocketpp::connection_hdl hdl);
- void on_open(websocketpp::connection_hdl hdl);
- void on_close(websocketpp::connection_hdl hdl);
- void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg);
- int handle_initial_instructions(websocketpp::connection_hdl hdl, std::string strinstrut);
- int handle_change_camera_instructions(std::string strinstrut);
- public:
- volatile bool m_bconnected; // connect flag
- volatile bool m_bstarttrans; // start transmit
- volatile eCameraType m_ecameraid; // camera id
- long m_lstarttime;
- #if defined(_WIN32)
- HANDLE m_work_thread;
- HANDLE m_evt;
- #else
- pthread_t m_work_threadid;
- sem_t m_semt;
- #endif //RVC_OS_WIN
- websocket_callback_t m_callback;
- server m_wsserver; // websocket server,用于和业务层传输视频流,默认端口9100
- websocketpp::connection_hdl m_hdl;
- int m_cameraid;
- int m_fps;
- unsigned char* m_buffer;
- uint32_t m_ubuffer_size;
- unsigned char* m_capbuffer;
- uint32_t m_ucapbuffer_size;
- unsigned int m_utranstime;
- bool m_preview_error_log;
- bool m_capture_error_log;
- private:
- int m_listenport; // websocket server监听端口
- std::string m_struuid; // websocket connet flag
- };
- }
|