diff --git a/lib/local/Utilities/include/RecorderOpenFace.h b/lib/local/Utilities/include/RecorderOpenFace.h index 0b9505a1..3b87de52 100644 --- a/lib/local/Utilities/include/RecorderOpenFace.h +++ b/lib/local/Utilities/include/RecorderOpenFace.h @@ -49,6 +49,12 @@ #include #include +#ifdef _WIN32 + +#else + #include +#endif + namespace Utilities { @@ -178,11 +184,14 @@ namespace Utilities cv::Mat aligned_face; tbb::concurrent_bounded_queue > aligned_face_queue; +#ifdef _WIN32 // For keeping track of tasks tbb::task_group writing_threads; +#else + std::thread video_writing_thread; + std::thread aligned_writing_thread; +#endif - // TODO rem - bool closed = false; }; } diff --git a/lib/local/Utilities/src/RecorderOpenFace.cpp b/lib/local/Utilities/src/RecorderOpenFace.cpp index 596f7526..2b364eab 100644 --- a/lib/local/Utilities/src/RecorderOpenFace.cpp +++ b/lib/local/Utilities/src/RecorderOpenFace.cpp @@ -215,7 +215,6 @@ void RecorderOpenFace::PrepareRecording(const std::string& in_filename) } this->frame_number = 0; - closed = false; } RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::vector& arguments):video_writer(), params(parameters) @@ -278,7 +277,7 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const Recorder } -RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::string output_directory):video_writer(), params(parameters), closed(false) +RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::string output_directory):video_writer(), params(parameters) { // From the filename, strip out the name without directory and extension if (boost::filesystem::is_directory(in_filename)) @@ -374,7 +373,13 @@ void RecorderOpenFace::WriteObservation() aligned_face_queue.set_capacity(capacity); // Start the alignment output thread +#ifdef _WIN32 + // For keeping track of tasks writing_threads.run([&] {AlignedImageWritingTask(&aligned_face_queue); }); +#else + // Start the alignment output thread + aligned_writing_thread = std::thread(&AlignedImageWritingTask, &aligned_face_queue); +#endif } char name[100]; @@ -406,12 +411,9 @@ void RecorderOpenFace::WriteObservation() void RecorderOpenFace::WriteObservationTracked() { - cout << "WriteObservationTracked called" << endl; if (params.outputTracked()) { - cout << "Track should be output" << endl; - // To support both video and image input if ((!params.isSequence() && frame_number == 0) || (params.isSequence() && frame_number == 1)) { @@ -439,8 +441,13 @@ void RecorderOpenFace::WriteObservationTracked() } // Start the video and tracked image writing thread - cout << "About to create a writing thread" << endl; +#ifdef _WIN32 + // For keeping track of tasks writing_threads.run([&] {VideoWritingTask(&vis_to_out_queue, params.isSequence(), &video_writer); }); +#else + video_writing_thread = std::thread(&VideoWritingTask, &vis_to_out_queue, params.isSequence(), &video_writer); +#endif + } @@ -528,22 +535,25 @@ RecorderOpenFace::~RecorderOpenFace() void RecorderOpenFace::Close() { - if(!closed) - { + // Insert terminating frames to the queues + vis_to_out_queue.push(std::pair("", cv::Mat())); + aligned_face_queue.push(std::pair("", cv::Mat())); - // Insert terminating frames to the queues - vis_to_out_queue.push(std::pair("", cv::Mat())); - aligned_face_queue.push(std::pair("", cv::Mat())); + // Make sure the recording threads complete +#ifdef _WIN32 + writing_threads.wait(); +#else + if (video_writing_thread.joinable()) + video_writing_thread.join(); + if (aligned_writing_thread.joinable()) + aligned_writing_thread.join(); +#endif - // Make sure the recording threads complete - writing_threads.wait(); - hog_recorder.Close(); - csv_recorder.Close(); - video_writer.release(); - metadata_file.close(); - closed = true; - } + hog_recorder.Close(); + csv_recorder.Close(); + video_writer.release(); + metadata_file.close(); }