From: Adrian Iain Lam Date: Sun, 5 Mar 2023 21:23:43 +0000 (+0000) Subject: Add Win32 support. X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8053891b5cdc72f2df7528bdea9555c1c8886e41;p=facial-landmarks-for-cubism.git Add Win32 support. Contributed by @Arkueid on #5. --- diff --git a/src/facial_landmark_detector.cpp b/src/facial_landmark_detector.cpp index f214d29..5d109fb 100644 --- a/src/facial_landmark_detector.cpp +++ b/src/facial_landmark_detector.cpp @@ -26,11 +26,18 @@ SOFTWARE. #include #include +#include #include -#include -#include -#include -#include +#ifdef _WIN32 +# include +# include +# include +#else +# include +# include +# include +# include +#endif #include "facial_landmark_detector.h" #include "math_utils.h" @@ -51,6 +58,14 @@ FacialLandmarkDetector::FacialLandmarkDetector(std::string cfgPath) { parseConfig(cfgPath); +#ifdef _WIN32 // WinSock2 should be initialized before using + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + { + return; + } +#endif + struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(m_cfg.osfPort); @@ -71,7 +86,11 @@ FacialLandmarkDetector::FacialLandmarkDetector(std::string cfgPath) FacialLandmarkDetector::~FacialLandmarkDetector() { +#ifdef _WIN32 + closesocket(m_sock); +#else close(m_sock); +#endif } FacialLandmarkDetector::Params FacialLandmarkDetector::getParams(void) const @@ -156,8 +175,8 @@ void FacialLandmarkDetector::mainLoop(void) static const int landmarksOffset = 8 + 4 + 2 * 4 + 2 * 4 + 1 + 4 + 3 * 4 + 3 * 4 + 4 * 4 + 4 * 68; - uint8_t buf[packetFrameSize]; - ssize_t recvSize = recv(m_sock, buf, sizeof buf, 0); + char buf[packetFrameSize]; + auto recvSize = recv(m_sock, buf, sizeof buf, 0); if (recvSize != packetFrameSize) continue; // Note: This is dependent on endianness, and we would assume that