123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656 |
- #include <stdint.h>
- #include "RvcWsServer.h"
- #include <boost/thread/thread.hpp>
- #include <vector>
- #include <boost/thread/lock_guard.hpp>
- #include "SpBase.h"
- #include "jpeglib.h"
- #include "Event.h"
- #include "y2k_time.h"
- #include "CommEntityUtil.hpp"
- namespace LivenessDetection {
- #ifndef RVC_JPEG_QUALITY
- #define RVC_JPEG_QUALITY 100 //图片质量
- #endif
- #ifndef RVC_COLOR_PEPTH
- #define RVC_COLOR_PEPTH 3
- #endif
- #ifndef RVC_MAX_JPEG_SIZE
- #define RVC_MAX_JPEG_SIZE 256*1024
- #endif
- #ifndef RVC_PICTURE_TYPE_LEN
- #define RVC_PICTURE_TYPE_LEN 1
- #endif
- #ifndef RVC_MIN_VIDEO_TRANS_TIME
- #define RVC_MIN_VIDEO_TRANS_TIME 2
- #endif
- #ifndef RVC_MAX_VIDEO_TRANS_TIME
- #define RVC_MAX_VIDEO_TRANS_TIME 15
- #endif
- static int rgb2jpg_action(struct jpeg_compress_struct* pCinfo, const unsigned char* pRgbData, const int width, const int height)
- {
- int depth = RVC_COLOR_PEPTH;
- JSAMPROW row_pointer[1] = { 0 };
- pCinfo->image_width = width;
- pCinfo->image_height = height;
- pCinfo->input_components = depth;
- pCinfo->in_color_space = JCS_RGB;
- jpeg_set_defaults(pCinfo);
- jpeg_set_quality(pCinfo, RVC_JPEG_QUALITY, true);
- jpeg_start_compress(pCinfo, true);
- int row_stride = width * depth;
- while (pCinfo->next_scanline < pCinfo->image_height) {
- row_pointer[0] = (JSAMPROW)(pRgbData + pCinfo->next_scanline * row_stride);
- jpeg_write_scanlines(pCinfo, row_pointer, 1);
- }
- jpeg_finish_compress(pCinfo);
- jpeg_destroy_compress(pCinfo);
- return 0;
- }
- static int bgr2rgb(const unsigned char* bgr_image, const int image_width, const int image_height, unsigned char* rgb_image)
- {
- if (!bgr_image || !rgb_image) {
- return 1;
- }
- for (int i = 0; i < image_width * image_height; i++) {
- unsigned char b_value = *bgr_image++;
- unsigned char g_value = *bgr_image++;
- unsigned char r_value = *bgr_image++;
- *rgb_image++ = r_value;
- *rgb_image++ = g_value;
- *rgb_image++ = b_value;
- }
- return 0;
- }
- static int gbr2jpg(const unsigned char* pRgbData, const int width, const int height, char* pDest, unsigned long* pSize, int reverseFlag = 0)
- {
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_compress(&cinfo);
- jpeg_mem_dest(&cinfo, (unsigned char**)&pDest, (unsigned long*)pSize);
- unsigned char* prgb = new unsigned char[width * height * 3];
- bgr2rgb(pRgbData, width, height, prgb);
- #if defined(RVC_OS_WIN)
- rgb2jpg_action(&cinfo, prgb, width, height);
- #else
- unsigned char* reversePrgb = new unsigned char[width * height * 3];
- if (reverseFlag == 0)
- {
- for (int i = 0; i < height; i++) {
- memcpy(reversePrgb + (i * width * 3),
- prgb + (3 * width * (height - (i + 1))), width * 3);
- }
- }
- else if (reverseFlag == 1)
- {
- for (int i = 0; i < height; i++) {
- for (int j = 0; j < width; j++) {
- memcpy(reversePrgb + (3 * ((width * i) + j)),
- prgb + (3 * ((width * i) + (width - (j + 1)))), 3);
- }
- }
- }
- rgb2jpg_action(&cinfo, reversePrgb, width, height);
- delete reversePrgb;
- reversePrgb = NULL;
- #endif //RVC_OS_WIN
- delete prgb;
- prgb = NULL;
- return 0;
- }
- static int on_send(RvcWsServer* webserver, eVideoType eType)
- {
- int iwidth = 0;
- int iheight = 0;
- int isize = 0;
- if (webserver->m_callback.on_get_videodata) {
- if (ePreview_Type == eType) {
- isize = webserver->m_callback.on_get_videodata(ePreview_Type, webserver->m_ecameraid, &iwidth, &iheight, webserver->m_buffer, webserver->m_ubuffer_size, webserver->m_callback.user_data);
- }
- else {
- isize = webserver->m_callback.on_get_videodata(eCapture_Type, webserver->m_ecameraid, &iwidth, &iheight, webserver->m_capbuffer, webserver->m_ucapbuffer_size, webserver->m_callback.user_data);
- }
- if (isize > 0) {
- char pDest[RVC_MAX_JPEG_SIZE] = { 0 };
- unsigned long size = RVC_MAX_JPEG_SIZE;
- if (ePreview_Type == eType) {
- pDest[0] = 0x01;
- #if defined(RVC_OS_WIN)
- gbr2jpg(webserver->m_buffer, iwidth, iheight, pDest + RVC_PICTURE_TYPE_LEN, &size);
- #else
- if (webserver->m_ecameraid == 0)
- {
- gbr2jpg(webserver->m_buffer, iwidth, iheight, pDest + RVC_PICTURE_TYPE_LEN, &size, 0);
- }
- else if (webserver->m_ecameraid == 1)
- {
- gbr2jpg(webserver->m_buffer, iwidth, iheight, pDest + RVC_PICTURE_TYPE_LEN, &size, 1);
- }
- #endif //RVC_OS_WIN
- }
- else {
- pDest[0] = 0x02;
- gbr2jpg(webserver->m_capbuffer, iwidth, iheight, pDest + RVC_PICTURE_TYPE_LEN, &size);
- }
- if (webserver->m_bconnected && webserver->m_bstarttrans) {
- if (false == webserver->m_hdl.expired()) {
- webserver->m_wsserver.send(webserver->m_hdl, (const void*)pDest, size + RVC_PICTURE_TYPE_LEN, websocketpp::frame::opcode::value::binary);
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send picture size is %u.", size+1);
- }
- }
- }
- else {
- if (ePreview_Type == eType) {
- if (false == webserver->m_preview_error_log) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E06")("视频流传输获取预览图像失败");
- webserver->m_preview_error_log = true;
- }
- }
- else {
- if (false == webserver->m_capture_error_log) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E07")("视频流传输获取抓拍图像失败");
- webserver->m_capture_error_log = true;
- }
- }
- }
- }
- return 0;
- }
- static void process(RvcWsServer* webserver)
- {
- while (webserver->m_bconnected && webserver->m_bstarttrans)
- {
- #ifdef RVC_OS_WIN
- DWORD dwRet = WaitForSingleObject(webserver->m_evt, 1000 / webserver->m_fps);
- if (dwRet == WAIT_OBJECT_0) {
- break;
- }
- else if (dwRet == WAIT_TIMEOUT) {
- if (webserver->m_bconnected && webserver->m_bstarttrans) {
- on_send(webserver, ePreview_Type);
- }
- }
- #else
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- long unsec = ts.tv_nsec + (1000 * 1000 * (1000 / webserver->m_fps));
- ts.tv_sec += (unsec / 1000000000);
- ts.tv_nsec = (unsec % 1000000000);
- if (0 != sem_timedwait(&webserver->m_semt, &ts) && (ETIMEDOUT == errno)) {
- if (webserver->m_bconnected && webserver->m_bstarttrans) {
- on_send(webserver, ePreview_Type);
- }
- }
- else
- {
- break;
- }
- #endif // RVC_OS_WIN
- }
- webserver->m_bstarttrans = false;
- }
- #if defined(RVC_OS_WIN)
- static unsigned int __stdcall work_proc(void* arg)
- #else
- static void* work_proc(void* arg)
- #endif //RVC_OS_WIN
- {
- RvcWsServer* webserver = (RvcWsServer*)arg;
- process(webserver);
- return 0;
- }
- RvcWsServer::RvcWsServer(void) :m_wsserver()
- {
- m_bconnected = false;
- m_struuid = "";
- m_bstarttrans = false;
- #if defined(RVC_OS_WIN)
- m_work_thread = NULL;
- #else
- m_work_threadid = 0;
- #endif //RVC_OS_WIN
- m_cameraid = 0;
- m_fps = RVC_DEFAULT_FPS;
- m_buffer = NULL;
- m_ubuffer_size = 0;
- m_capbuffer = NULL;
- m_ucapbuffer_size = 0;
- m_ecameraid = eCamera_Env;
- m_lstarttime = 0;
- m_preview_error_log = false;
- m_capture_error_log = false;
- }
- RvcWsServer::~RvcWsServer(void)
- {
- m_bconnected = false;
- m_struuid = "";
- m_bstarttrans = false;
- #if defined(RVC_OS_WIN)
- m_work_thread = NULL;
- #else
- m_work_threadid = 0;
- #endif //RVC_OS_WIN
- m_cameraid = 0;
- m_fps = RVC_DEFAULT_FPS;
- if (NULL != m_buffer) {
- delete m_buffer;
- m_buffer = NULL;
- }
- m_ubuffer_size = 0;
- if (NULL != m_capbuffer) {
- delete m_capbuffer;
- m_capbuffer = NULL;
- }
- m_ucapbuffer_size = 0;
- m_preview_error_log = false;
- m_capture_error_log = false;
- }
- void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket& s)
- {
- boost::asio::ip::tcp::no_delay option(true);
- s.set_option(option);
- }
- int RvcWsServer::Init_WsServer(websocket_callback_t* pcallback, rvc_video_param_t* pparam, int iport)
- {
- int iret = -1;
- if (NULL == pcallback) {
- return iret;
- }
- if (iport <= 0) {
- m_listenport = RVC_LIVENESS_WS_PORT;
- }
- else {
- m_listenport = iport;
- }
- m_cameraid = 0;
- m_fps = RVC_DEFAULT_FPS;
- memcpy(&m_callback, pcallback, sizeof(websocket_callback_t));
- #ifdef _MSC_VER
- m_evt = CreateEventA(NULL, FALSE, FALSE, NULL);
- #else
- sem_init(&m_semt, 0, 0);
- #endif //_MSC_VER
- m_ubuffer_size = pparam->iwidth * pparam->iheight * 3;
- m_buffer = new unsigned char[m_ubuffer_size];
- memset(m_buffer, 0, m_ubuffer_size);
- m_ucapbuffer_size = pparam->icapwidth * pparam->icapheight * 3;
- m_capbuffer = new unsigned char[m_ucapbuffer_size];
- memset(m_capbuffer, 0, m_ucapbuffer_size);
- m_ecameraid = eCamera_Env;
- try {
- // Set logging settings
- m_wsserver.set_access_channels(websocketpp::log::alevel::all);
- m_wsserver.set_error_channels(websocketpp::log::elevel::all);
- // Register our message handler
- m_wsserver.set_message_handler(websocketpp::lib::bind(&RvcWsServer::on_message, this, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2));
- m_wsserver.set_http_handler(websocketpp::lib::bind(&RvcWsServer::on_http, this, websocketpp::lib::placeholders::_1));
- m_wsserver.set_fail_handler(websocketpp::lib::bind(&RvcWsServer::on_fail, this, websocketpp::lib::placeholders::_1));
- m_wsserver.set_open_handler(websocketpp::lib::bind(&RvcWsServer::on_open, this, websocketpp::lib::placeholders::_1));
- m_wsserver.set_close_handler(websocketpp::lib::bind(&RvcWsServer::on_close, this, websocketpp::lib::placeholders::_1));
- m_wsserver.set_validate_handler(websocketpp::lib::bind(&RvcWsServer::validate, this, websocketpp::lib::placeholders::_1));
- // Initialize ASIO
- m_wsserver.init_asio();
- m_wsserver.set_reuse_addr(true);
- m_wsserver.set_socket_init_handler(&on_socket_init);
- m_wsserver.listen(m_listenport);
- // Start the server accept loop
- m_wsserver.start_accept();
- iret = 0;
- // Start the ASIO io_service run loop
- m_wsserver.run();
- //stop
- m_wsserver.stop();
- }
- catch (websocketpp::exception const& e) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(e.what());
- }
- catch (const std::exception& e) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(e.what());
- }
- catch (...) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("other exception");
- }
- return iret;
- }
- bool RvcWsServer::validate(websocketpp::connection_hdl hdl)
- {
- return true;
- }
- void RvcWsServer::on_http(websocketpp::connection_hdl hdl)
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on_http");
- server::connection_ptr con = m_wsserver.get_con_from_hdl(hdl);
- std::string res = con->get_request_body();
- std::stringstream ss;
- ss << "got HTTP request with " << res.size() << " bytes of body data.";
- con->set_body(ss.str());
- con->set_status(websocketpp::http::status_code::ok);
- }
- void RvcWsServer::on_fail(websocketpp::connection_hdl hdl)
- {
- server::connection_ptr con = m_wsserver.get_con_from_hdl(hdl);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail handler: %d, %s.", con->get_ec().value(), con->get_ec().message());
- }
- void RvcWsServer::on_open(websocketpp::connection_hdl hdl)
- {
- server::connection_ptr con = m_wsserver.get_con_from_hdl(hdl);
- websocketpp::config::core::request_type requestClient = con->get_request();
- std::string strMethod = requestClient.get_method();
- std::string strUri = requestClient.get_uri();
- }
- void RvcWsServer::on_close(websocketpp::connection_hdl hdl)
- {
- m_bconnected = false;
- if (m_bstarttrans) {
- m_bstarttrans = false;
- unsigned int utranstime = y2k_time_now() - m_utranstime;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOPVIDEOTRANS, CSimpleStringA::Format("stop video trans for session close, and transmit time is %us.", utranstime).GetData());
- if (RVC_MIN_VIDEO_TRANS_TIME >= utranstime) {
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_AUTO_FACE_FAILED, CSimpleStringA::Format("auto face failed and transmit time is %us.", utranstime).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E04")("流媒体传输时长不大于2秒.");
- }
- if (RVC_MAX_VIDEO_TRANS_TIME <= utranstime) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_AUTO_FACE_TIMEOUT, CSimpleStringA::Format("auto face timeout and transmit time is %us.", utranstime).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E05")("流媒体传输时长不小于15秒.");
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402314L6")("断开流媒体传输连接");
- m_preview_error_log = false;
- m_capture_error_log = false;
- }
- // Define a callback to handle incoming messages
- void RvcWsServer::on_message(websocketpp::connection_hdl hdl, server::message_ptr msg)
- {
- try {
- if (m_bconnected == false) {
- m_struuid = "";
- if (0 == msg->get_payload().compare(0, strlen(RVC_WS_INIT_STR), RVC_WS_INIT_STR)) {
- handle_initial_instructions(hdl, msg->get_payload());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402314L1")("流媒体传输连接初始化");
- }
- }
- else {
- if (0 == msg->get_payload().compare(0, m_struuid.length(), m_struuid)) {
- if (0 == msg->get_payload().compare(m_struuid.length() + strlen(RVC_WS_CONNECT_IDENTIFIER), strlen(RVC_WS_START_TRANS_STR), RVC_WS_START_TRANS_STR)) {
- m_bstarttrans = true;
- m_hdl = hdl;
- if (0 != StartVideoTransmit()) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402314L2").setResultCode("RTA3E01")("start video transmit failed.");
- }
- else {
- m_lstarttime = SP::Module::Comm::RVCGetTickCount();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402314L2")("start video transmit success.");
- }
- }
- else if (0 == msg->get_payload().compare(m_struuid.length() + strlen(RVC_WS_CONNECT_IDENTIFIER), strlen(RVC_WS_STOP_TRANS_STR), RVC_WS_STOP_TRANS_STR)) {
- long costtime = SP::Module::Comm::RVCGetTickCount() - m_lstarttime;
- if (0 != StopVideoTransmit()) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setCostTime(costtime).setLogCode("QLR0402314L5").setResultCode("RTA3E02")("stop video transmit failed.");
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setCostTime(costtime).setLogCode("QLR0402314L5")("stop video transmit success.");
- }
- m_bstarttrans = false;
- }
- else if (0 == msg->get_payload().compare(m_struuid.length() + strlen(RVC_WS_CONNECT_IDENTIFIER), strlen(RVC_WS_CHANGE_CAMERA_STR), RVC_WS_CHANGE_CAMERA_STR)) {
- if (0 != handle_change_camera_instructions(msg->get_payload())) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402314L3").setResultCode("RTA3E03")("change transmit camera failed.");
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402314L3")("change transmit camera success.");
- }
- }
- else if (0 == msg->get_payload().compare(m_struuid.length() + strlen(RVC_WS_CONNECT_IDENTIFIER), strlen(RVC_WS_START_CAPTURE_STR), RVC_WS_START_CAPTURE_STR)) {
- StartVideoCapTransmit();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402314L4")("start video capture transmit success.");
- }
- else{
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown request.");
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv invalid request is %s.", msg->get_payload().c_str());
- }
- }
- }
- catch (websocketpp::exception const& e) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send failed because: %s", e.what());
- }
- }
- int RvcWsServer::StartVideoTransmit()
- {
- int iRet = -1;
- #if defined(RVC_OS_WIN)
- m_work_thread = (HANDLE)_beginthreadex(NULL, 0, &work_proc, this, 0, NULL);
- if (!m_work_thread) {
- #else
- if (0 != pthread_create(&m_work_threadid, NULL, work_proc, (void*)this)) {
- #endif //RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create start video transmit thread failed.");
- return iRet;
- }
- iRet = 0;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STARTVIDEOTRANS, "start video trans.");
- m_utranstime = y2k_time_now();
- return iRet;
- }
- int RvcWsServer::StopVideoTransmit()
- {
- int iRet = -1;
- if (m_bconnected && m_bstarttrans) {
- #if defined(RVC_OS_WIN)
- SetEvent(m_evt);
- if (NULL != m_work_thread) {
- WaitForSingleObject(m_work_thread, INFINITE);
- CloseHandle(m_work_thread);
- m_work_thread = NULL;
- }
- #else
- sem_post(&m_semt);
- if (0 == pthread_join(m_work_threadid, NULL)) {
- m_work_threadid = 0;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("thread join video transmit thread failed!");
- }
- #endif //RVC_OS_WIN
- unsigned int utranstime = y2k_time_now() - m_utranstime;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOPVIDEOTRANS, CSimpleStringA::Format("stop video trans for user operation, and transmit time is %us.", utranstime).GetData());
- if (RVC_MIN_VIDEO_TRANS_TIME >= utranstime) {
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_AUTO_FACE_FAILED, CSimpleStringA::Format("auto face failed and transmit time is %us.", utranstime).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E04")("流媒体传输时长不大于2秒.");
- }
- if (RVC_MAX_VIDEO_TRANS_TIME <= utranstime) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_AUTO_FACE_TIMEOUT, CSimpleStringA::Format("auto face timeout and transmit time is %us.", utranstime).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA3E05")("流媒体传输时长不小于15秒.");
- }
- }
-
- iRet = 0;
- return iRet;
- }
- int RvcWsServer::StartVideoCapTransmit()
- {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STARTVIDEOCAPTURE, "start video capture transmit.");
- return on_send(this, eCapture_Type);
- }
- static bool allisnum(std::string str)
- {
- for (int i = 0; i < str.size(); i++) {
- int tmp = (int)str[i];
- if (tmp >= '0' && tmp <= '9') {
- continue;
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- int RvcWsServer::handle_initial_instructions(websocketpp::connection_hdl hdl, std::string strinstrut)
- {
- int iret = -1;
- m_bconnected = true;
- m_ecameraid = eCamera_Env;
- CUUID struuid = CUUID::Create(struuid);
- m_struuid = struuid.ToString();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("new connect and uuid is %s.", m_struuid.c_str());
- m_wsserver.send(hdl, m_struuid, websocketpp::frame::opcode::value::text);
- int index = strinstrut.find_first_of(RVC_WS_CONNECT_IDENTIFIER);
- if (std::string::npos != index) {
- std::string strfps = strinstrut.substr(index + strlen(RVC_WS_CONNECT_IDENTIFIER));
- if (allisnum(strfps)) {
- int ifps = atoi(strfps.c_str());
- if (ifps > RVC_MAX_FPS) {
- ifps = RVC_MAX_FPS;
- }
- if (ifps < RVC_MIN_FPS) {
- ifps = RVC_MIN_FPS;
- }
- m_fps = ifps;
- }
- }
- iret = 0;
- return iret;
- }
- int RvcWsServer::handle_change_camera_instructions(std::string strinstrut)
- {
- int iret = -1;
- if (m_bstarttrans) {
- int index = strinstrut.find_first_of(RVC_WS_CHANGE_CAMERA_STR);
- if (std::string::npos != index) {
- std::string strcamera = strinstrut.substr(index + strlen(RVC_WS_CHANGE_CAMERA_STR));
- index = strcamera.find_first_of(RVC_WS_CONNECT_IDENTIFIER);
- if (std::string::npos != index) {
- std::string strid = strcamera.substr(index + strlen(RVC_WS_CONNECT_IDENTIFIER));
- if (allisnum(strid)) {
- int icameraid = atoi(strid.c_str());
- if (eCamera_Env == icameraid || eCamera_Opt == icameraid) {
- m_ecameraid = (eCameraType)icameraid;
- }
- }
- }
- }
- iret = 0;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("current is not in data transmitting.");
- }
- return iret;
- }
- }
|