diff --git a/samples/AiMaskStreamApp/AiMaskStreamApp.cpp b/samples/AiMaskStreamApp/AiMaskStreamApp.cpp index 8df2dd3..cc1534b 100644 --- a/samples/AiMaskStreamApp/AiMaskStreamApp.cpp +++ b/samples/AiMaskStreamApp/AiMaskStreamApp.cpp @@ -39,11 +39,11 @@ #include "../../../utils/httplib.h" -enum FrameType { - TYPE_ORIGINAL, - TYPE_OUTLINE, - TYPE_PROCESSED, - TYPE_MAX +enum StreamType { + ST_ORIGINAL, + ST_MASKED, + ST_PROCESSED, // testing + ST_MAX }; struct FrameQueue { @@ -51,7 +51,7 @@ struct FrameQueue { std::mutex frameMutex; }; -std::vector frameQueues(TYPE_MAX); +std::vector frameQueues(ST_MAX); // Convert cv::Mat to JPEG buffer std::vector matToBytes(const cv::Mat& img) { @@ -1029,16 +1029,15 @@ FXApp::Err FXApp::processMovie(const char *inFile, const char *outFile) { } } - pushToFrameQueue(0, originalImg); - pushToFrameQueue(1, result); - pushToFrameQueue(2, outlineResult); + pushToFrameQueue(ST_ORIGINAL, originalImg); + pushToFrameQueue(ST_MASKED, result); + pushToFrameQueue(ST_PROCESSED, outlineResult); // Display the results cv::imshow("Original", originalImg); cv::imshow("Overlay", result); cv::imshow("OutlineTest", outlineResult); - int key = cv::waitKey(1); if (key > 0) { appErr = processKey(key); @@ -1093,18 +1092,18 @@ bool isCompModeEnumValid(const FXApp::CompMode& mode) void startHttpServer() { httplib::Server svr; - auto streamHandler = [](FrameType frameType) { - return [frameType](const httplib::Request&, httplib::Response& res) { + auto streamHandler = [](StreamType streamType) { + return [streamType](const httplib::Request&, httplib::Response& res) { res.set_content_provider( "multipart/x-mixed-replace; boundary=frame", - [frameType](size_t offset, httplib::DataSink& sink) { + [streamType](size_t offset, httplib::DataSink& sink) { while (true) { cv::Mat frame; { - std::lock_guard lock(frameQueues[frameType].frameMutex); - if (!frameQueues[frameType].frameQueue.empty()) { - frame = frameQueues[frameType].frameQueue.front(); - frameQueues[frameType].frameQueue.pop(); + std::lock_guard lock(frameQueues[streamType].frameMutex); + if (!frameQueues[streamType].frameQueue.empty()) { + frame = frameQueues[streamType].frameQueue.front(); + frameQueues[streamType].frameQueue.pop(); } } @@ -1128,15 +1127,16 @@ void startHttpServer() { }; }; - // Array of route names corresponding to FrameType enum - const std::array routeNames = { - "original", "outline", "processed" + // Array of route names corresponding to StreamType enum + const std::array routeNames = { + "original", "masked", "processed" }; // Set up routes for each frame type - for (int i = 0; i < TYPE_MAX; ++i) { + for (int i = 0; i < ST_MAX; ++i) { std::string route = "/video_" + routeNames[i]; - svr.Get(route, streamHandler(static_cast(i))); + svr.Get(route, streamHandler((StreamType)i)); + printf("Streaming %s at http://localhost:8080%s\n", routeNames[i].c_str(), route.c_str()); } svr.listen("0.0.0.0", 8080); // Start server on port 8080