From 8053891b5cdc72f2df7528bdea9555c1c8886e41 Mon Sep 17 00:00:00 2001 From: Adrian Iain Lam Date: Sun, 5 Mar 2023 21:23:43 +0000 Subject: [PATCH] Add Win32 support. Contributed by @Arkueid on #5. --- src/facial_landmark_detector.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) 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 -- 2.7.4