#ifndef TRANSJPEGWEB_H #define TRANSJPEGWEB_H #include "CivetServer.h" #include #include #include #ifdef _WIN32 #include #else #include #endif #include "rtspclientdown.h" #include "ivh264framedecode.h" #include #define NUM_CAM 4 #ifdef USE_WEBSOCKET class WebSocketHandler : public CivetWebSocketHandler { std::vector mvectorconn; std::mutex mMutex; int mnwscount = 0; public: int GetCount() { return mnwscount; } void BroadData(const char * strdata,int ndata) { int i; mMutex.lock(); for(i=0;i<(int)mvectorconn.size();i++) { std::cout<<" send frame data . size : "< mpstr_data; int mnpicsize; std::mutex mmutexdata; int mnpiccount = 0; public: int GetCount() { return mnpiccount; } void SetData(std::shared_ptr pstr_ptr,int ndatasize) { mmutexdata.lock(); mnpicsize = ndatasize; mpstr_data = pstr_ptr; mnpicuptime = std::chrono::system_clock::now().time_since_epoch().count(); mmutexdata.unlock(); } bool handleGet(CivetServer *server, struct mg_connection *conn) { std::shared_ptr pstr_ptr; int npicsize; int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count(); int64_t ndiff = nnow - mnpicuptime; if(abs(ndiff/1000000)>3000) { return false; } else { mmutexdata.lock(); pstr_ptr = mpstr_data; npicsize = mnpicsize; mmutexdata.unlock(); } static int ncount; mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Connection: close\r\n" "Max-Age: 0\r\n" "Expires: 0\r\n" "Cache-Control: no-cache, no-store, must-revalidate, private\r\n" "Pragma: no-cache\r\n" "Content-Type: multipart/x-mixed-replace; " "boundary=--BoundaryString\r\n" "\r\n"); mg_printf(conn,""); mg_printf(conn, "\r\n"); mg_printf(conn, "--BoundaryString\r\n" "Content-type: image/jpeg\r\n" "Content-Length: %zu\r\n" "\r\n", npicsize); mg_write(conn, pstr_ptr.get(), npicsize); mg_printf(conn, "\r\n\r\n"); ncount++; // printf("send pic. %d\n",ncount); mnpiccount++; return true; } }; class WsStartHandler : public CivetHandler { private: int mnIndexHtmlMode = 0; //if 0 use indexpic.html, if 1 use websocket. public: void SetIndexMode(int nmode) { if(nmode == 0)mnIndexHtmlMode = 0; else mnIndexHtmlMode = 1; } bool handleGet(CivetServer *server, struct mg_connection *conn) { mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: " "close\r\n\r\n"); mg_printf(conn, "\n"); mg_printf(conn, "\n\n"); mg_printf(conn, "\n"); mg_printf(conn, "ADC IV Web UI\n"); QFile xFile; if(mnIndexHtmlMode == 0) { xFile.setFileName(":/indexpic.html"); } else { xFile.setFileName(":/indexws.html"); } if(xFile.open(QIODevice::ReadOnly)) { QByteArray ba = xFile.readAll(); mg_printf(conn,ba.data()); } return 1; } }; namespace iv { struct transjpegcount { int nrtspretry; int nframecount; int njpegcount; int npicreqcount; int nwsreqcount; }; } class transjpegweb { public: transjpegweb(std::string strip,std::string strport,std::string strvin,std::string strpass,std::string strwebmode); private: CivetServer * mpserver; std::string mstrrtspserverport = "9554"; std::string mstrrtspserverip = "111.33.136.149"; std::string mstrvin = "AAAAAAAAAAAAAAAAA"; std::string mstrrtsppass = "hello"; rtspclientdown * mprtspdown[4]; ivh264framedecode * mph264decode[NUM_CAM]; std::thread * mpthreadframe[NUM_CAM]; std::thread * mpthreadpic[NUM_CAM]; int mnframewidth = 1920; int mnframeheight = 1080; void threadframe(int ncam); void threadpic(int ncam); bool mbthreadrun = true; WebSocketHandler * mpws[NUM_CAM]; PicHandler * mppichandler[NUM_CAM]; WsStartHandler * mphandleindex; iv::transjpegcount mtjcount[NUM_CAM]; std::string mstrrtspstring[NUM_CAM]; public: std::string GetStatics(); }; #endif // TRANSJPEGWEB_H