From 02f3de2b8c7cbba1930255067404caa557938bfa Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Mon, 20 May 2024 15:37:38 +0300 Subject: [PATCH 1/5] make --version to be full and -V to be short #91 --- Capture/capturelib/include/reprostim/CaptureApp.h | 2 +- Capture/capturelib/src/CaptureApp.cpp | 14 +++++++++----- Capture/screencapture/src/ScreenCapture.cpp | 11 ++++++++--- Capture/version.txt | 2 +- Capture/videocapture/src/VideoCapture.cpp | 11 ++++++++--- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Capture/capturelib/include/reprostim/CaptureApp.h b/Capture/capturelib/include/reprostim/CaptureApp.h index 1e3bedf..5d27a70 100644 --- a/Capture/capturelib/include/reprostim/CaptureApp.h +++ b/Capture/capturelib/include/reprostim/CaptureApp.h @@ -119,7 +119,7 @@ namespace reprostim { virtual void onUsbDevArrived(const std::string& devPath); virtual void onUsbDevLeft(const std::string& devPath); virtual int parseOpts(AppOpts& opts, int argc, char* argv[]); - void printVersion(); + void printVersion(bool fExpanded = false); int run(int argc, char* argv[]); }; diff --git a/Capture/capturelib/src/CaptureApp.cpp b/Capture/capturelib/src/CaptureApp.cpp index 38607b8..5b5f181 100644 --- a/Capture/capturelib/src/CaptureApp.cpp +++ b/Capture/capturelib/src/CaptureApp.cpp @@ -242,11 +242,15 @@ namespace reprostim { return EX_OK; } - void CaptureApp::printVersion() { - _INFO(appName << " " << CAPTURE_VERSION_STRING); - _INFO(" Build Type : " << CAPTURE_BUILD_TYPE); - _INFO(" Build Date : " << CAPTURE_VERSION_DATE); - _INFO(" Build Tag : " << CAPTURE_VERSION_TAG); + void CaptureApp::printVersion(bool fExpanded) { + if( fExpanded ) { + _INFO(appName << " " << CAPTURE_VERSION_STRING); + _INFO(" Build Type : " << CAPTURE_BUILD_TYPE); + _INFO(" Build Date : " << CAPTURE_VERSION_DATE); + _INFO(" Build Tag : " << CAPTURE_VERSION_TAG); + } else { + _INFO(CAPTURE_VERSION_STRING); + } } int CaptureApp::run(int argc, char* argv[]) { diff --git a/Capture/screencapture/src/ScreenCapture.cpp b/Capture/screencapture/src/ScreenCapture.cpp index 213064d..1e1b698 100644 --- a/Capture/screencapture/src/ScreenCapture.cpp +++ b/Capture/screencapture/src/ScreenCapture.cpp @@ -88,8 +88,10 @@ int ScreenCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { "\t \tVerbose, provides detailed information to stdout\n" "\t-l, --list-devices\n" "\t \tList devices, only audio is supported\n" - "\t-V, --version\n" - "\t \tPrint version information\n" + "\t-V\n" + "\t \tPrint version number only\n" + "\t--version\n" + "\t \tPrint expanded version information\n" "\t-h, --help\n" "\t \tPrint this help string\n"; @@ -103,7 +105,7 @@ int ScreenCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { struct option longOpts[] = { {"help", no_argument, nullptr, 'h'}, {"verbose", no_argument, nullptr, 'v'}, - {"version", no_argument, nullptr, 'V'}, + {"version", no_argument, nullptr, 1000}, {"list-devices", no_argument, nullptr, 'l'}, {"file-log", required_argument, nullptr, 'f'}, {nullptr, 0, nullptr, 0} @@ -129,6 +131,9 @@ int ScreenCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { case 'v': opts.verbose = true; break; + case 1000: + printVersion(true); + return 1; case 'V': printVersion(); return 1; diff --git a/Capture/version.txt b/Capture/version.txt index 7f45624..40b3241 100644 --- a/Capture/version.txt +++ b/Capture/version.txt @@ -1 +1 @@ -1.7.0.215 \ No newline at end of file +1.8.0.217 \ No newline at end of file diff --git a/Capture/videocapture/src/VideoCapture.cpp b/Capture/videocapture/src/VideoCapture.cpp index d04d5f7..7225b5b 100644 --- a/Capture/videocapture/src/VideoCapture.cpp +++ b/Capture/videocapture/src/VideoCapture.cpp @@ -187,8 +187,10 @@ int VideoCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { "\t \tDefaults to console output\n" "\t-v, --verbose\n" "\t \tVerbose, provides detailed information to stdout\n" - "\t-V, --version\n" - "\t \tPrint version information\n" + "\t-V\n" + "\t \tPrint version number only\n" + "\t--version\n" + "\t \tPrint expanded version information\n" "\t-l, --list-devices\n" "\t \tList devices, only audio is supported\n" "\t-h, --help\n" @@ -204,7 +206,7 @@ int VideoCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { struct option longOpts[] = { {"help", no_argument, nullptr, 'h'}, {"verbose", no_argument, nullptr, 'v'}, - {"version", no_argument, nullptr, 'V'}, + {"version", no_argument, nullptr, 1000}, {"list-devices", no_argument, nullptr, 'l'}, {"file-log", required_argument, nullptr, 'f'}, {nullptr, 0, nullptr, 0} @@ -230,6 +232,9 @@ int VideoCaptureApp::parseOpts(AppOpts& opts, int argc, char* argv[]) { case 'v': opts.verbose = true; break; + case 1000: + printVersion(true); + return 1; case 'V': printVersion(); return 1; From de1dcd1925b477d8cc05c34e8a34d7c19584bbc3 Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Mon, 20 May 2024 16:08:26 +0300 Subject: [PATCH 2/5] Kill ffmpeg gracefully first (SIGINT, then may be SIGTERM) and only then -9 if it refuses to die #92 --- Capture/version.txt | 2 +- Capture/videocapture/src/VideoCapture.cpp | 37 +++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Capture/version.txt b/Capture/version.txt index 40b3241..1775070 100644 --- a/Capture/version.txt +++ b/Capture/version.txt @@ -1 +1 @@ -1.8.0.217 \ No newline at end of file +1.8.0.221 \ No newline at end of file diff --git a/Capture/videocapture/src/VideoCapture.cpp b/Capture/videocapture/src/VideoCapture.cpp index 7225b5b..f502c2e 100644 --- a/Capture/videocapture/src/VideoCapture.cpp +++ b/Capture/videocapture/src/VideoCapture.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include "VideoCapture.h" using namespace reprostim; @@ -66,6 +67,25 @@ inline std::string buildVideoFile( return std::filesystem::path(outPath) / (name + "." + out_fmt); } +bool killProc(const std::string& procName, + int sig = SIGKILL, + float timeoutSec = 1.5, + bool waitInCycle = true) { + std::string pid = exec("pidof " + procName); + _INFO(procName+" pid: " << pid.c_str()); + while ( pid.length() > 0 ) { + _INFO("<> PID of " << procName <<"\t===> " << pid.c_str()); + std::string killCmd = "kill -" + std::to_string(sig) + " " + pid; + system(killCmd.c_str()); + // + SLEEP_SEC(timeoutSec); // Allow time for process to stop + pid = exec("pidof " + procName); + if( !waitInCycle ) + break; + } + return pid.length()==0?true:false; +} + std::string renameVideoFile( const std::string& outVideoFile, const std::string& outPath, @@ -346,15 +366,14 @@ void VideoCaptureApp::stopRecording(const std::string& start_ts, const std::string& message) { std::string out_fmt = cfg.ffm_opts.out_fmt; std::string oldname = buildVideoFile(vpath, start_ts + "_", out_fmt); - std::string ffmpid = exec("pidof ffmpeg"); - _INFO("stop record says: " << ffmpid.c_str()); - while ( ffmpid.length() > 0 ) { - _INFO("<> PID of ffmpeg\t===> " << ffmpid.c_str()); - std::string killCmd = "kill -9 " + ffmpid; - system(killCmd.c_str()); - // - SLEEP_SEC(1.5); // Allow time for ffmpeg to stop - ffmpid = exec("pidof ffmpeg"); + + _INFO("stop record says: " << "terminating ffmpeg with SIGINT"); + if( !killProc("ffmpeg", SIGINT, 5, false) ) { + _INFO("stop record says: " << "terminating ffmpeg with SIGTERM"); + if( !killProc("ffmpeg", SIGTERM, 1.5, false) ) { + _INFO("stop record says: " << "terminating ffmpeg with SIGKILL"); + killProc("ffmpeg", SIGKILL, 1.5, true); + } } _SESSION_LOG_END(); From df47e76c2fcb420bfd59e446ca47820d15017d35 Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Mon, 20 May 2024 23:07:56 +0300 Subject: [PATCH 3/5] cmake: Add install target to install binaries #90 --- Capture/CMakeLists.txt | 12 ++++++++++++ Capture/README.md | 10 ++++++++++ Capture/screencapture/CMakeLists.txt | 4 ++++ Capture/version.txt | 2 +- Capture/videocapture/CMakeLists.txt | 3 +++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Capture/CMakeLists.txt b/Capture/CMakeLists.txt index 5b3d80b..637d2e0 100644 --- a/Capture/CMakeLists.txt +++ b/Capture/CMakeLists.txt @@ -51,6 +51,9 @@ execute_process( set(ARCH x64) set(MWCAPTURE_SDK_HOME 3rdparty/MWCapture_SDK_Linux-3_3_1_1313) +# capture utilities installation directory +set(CAPTURE_INSTALL_DIR /usr/local/bin) + # Add MWCapture SDK include/lib paths include_directories(${MWCAPTURE_SDK_HOME}/Include) link_directories(${MWCAPTURE_SDK_HOME}/Lib/${ARCH}) @@ -60,6 +63,15 @@ add_subdirectory(capturelib) add_subdirectory(screencapture) add_subdirectory(videocapture) +# Optionally install nosignal Python script +if(EXISTS "${CMAKE_SOURCE_DIR}/nosignal/reprostim/nosignal") + # Install the optional file to /usr/local/bin + install(FILES "${CMAKE_SOURCE_DIR}/nosignal/reprostim/nosignal" + DESTINATION ${CAPTURE_INSTALL_DIR}) +else() + message(STATUS "Python 'nosignal' script not found.") +endif() + # Add tests optionally if(CTEST_ENABLED) message(STATUS "CTests are ENABLED") diff --git a/Capture/README.md b/Capture/README.md index c02586c..537275d 100644 --- a/Capture/README.md +++ b/Capture/README.md @@ -43,6 +43,16 @@ Capture uses CMake as build system. To build the project, run the following comm cmake .. make +## Install + +To install the project, once the build done, run the following command: + + cd Capture + + sudo cmake --install build + +It will copy all necessary files to the /usr/local/bin location (reprostim-videocapture, +reprostim-screencapture, nosignal). ## Project Structure diff --git a/Capture/screencapture/CMakeLists.txt b/Capture/screencapture/CMakeLists.txt index 6a23fa5..f26eacb 100644 --- a/Capture/screencapture/CMakeLists.txt +++ b/Capture/screencapture/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(${PROJECT_NAME} # Copy config.yaml to out folder as well configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.yaml ${CMAKE_CURRENT_BINARY_DIR}/config.yaml COPYONLY) +# Install the executable to /usr/local/bin +install(TARGETS reprostim-screencapture + RUNTIME DESTINATION ${CAPTURE_INSTALL_DIR}) + find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) diff --git a/Capture/version.txt b/Capture/version.txt index 1775070..41157c4 100644 --- a/Capture/version.txt +++ b/Capture/version.txt @@ -1 +1 @@ -1.8.0.221 \ No newline at end of file +1.8.0.223 \ No newline at end of file diff --git a/Capture/videocapture/CMakeLists.txt b/Capture/videocapture/CMakeLists.txt index 81060f4..9ea5909 100644 --- a/Capture/videocapture/CMakeLists.txt +++ b/Capture/videocapture/CMakeLists.txt @@ -10,6 +10,9 @@ add_executable(${PROJECT_NAME} # Copy config.yaml to out folder as well configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.yaml ${CMAKE_CURRENT_BINARY_DIR}/config.yaml COPYONLY) +# Install the executable to /usr/local/bin +install(TARGETS reprostim-videocapture + RUNTIME DESTINATION ${CAPTURE_INSTALL_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC "Include") From 4f53bdf7dcd1e6c1d911b48c12fdeff5b09036dc Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Mon, 20 May 2024 23:38:37 +0300 Subject: [PATCH 4/5] cmake: Add install target to install binaries #90 --- Capture/CMakeLists.txt | 4 +++- Capture/README.md | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Capture/CMakeLists.txt b/Capture/CMakeLists.txt index 637d2e0..728db2b 100644 --- a/Capture/CMakeLists.txt +++ b/Capture/CMakeLists.txt @@ -67,7 +67,9 @@ add_subdirectory(videocapture) if(EXISTS "${CMAKE_SOURCE_DIR}/nosignal/reprostim/nosignal") # Install the optional file to /usr/local/bin install(FILES "${CMAKE_SOURCE_DIR}/nosignal/reprostim/nosignal" - DESTINATION ${CAPTURE_INSTALL_DIR}) + DESTINATION ${CAPTURE_INSTALL_DIR} + RENAME reprostim-nosignal + ) else() message(STATUS "Python 'nosignal' script not found.") endif() diff --git a/Capture/README.md b/Capture/README.md index 537275d..dfc42a8 100644 --- a/Capture/README.md +++ b/Capture/README.md @@ -43,7 +43,7 @@ Capture uses CMake as build system. To build the project, run the following comm cmake .. make -## Install +## Installation To install the project, once the build done, run the following command: @@ -51,8 +51,8 @@ To install the project, once the build done, run the following command: sudo cmake --install build -It will copy all necessary files to the /usr/local/bin location (reprostim-videocapture, -reprostim-screencapture, nosignal). +It will copy all necessary files to the `/usr/local/bin` location (`reprostim-videocapture`, +`reprostim-screencapture`, `reprostim-nosignal`). ## Project Structure From 66992d5e1fe31eb3bdee9708e91b5b6cd7846010 Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Fri, 24 May 2024 13:39:45 +0300 Subject: [PATCH 5/5] cmake: Add install target to install binaries #90 --- Capture/CMakeLists.txt | 5 ++++- Capture/version.txt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Capture/CMakeLists.txt b/Capture/CMakeLists.txt index 728db2b..9faeb75 100644 --- a/Capture/CMakeLists.txt +++ b/Capture/CMakeLists.txt @@ -52,7 +52,7 @@ set(ARCH x64) set(MWCAPTURE_SDK_HOME 3rdparty/MWCapture_SDK_Linux-3_3_1_1313) # capture utilities installation directory -set(CAPTURE_INSTALL_DIR /usr/local/bin) +set(CAPTURE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) # Add MWCapture SDK include/lib paths include_directories(${MWCAPTURE_SDK_HOME}/Include) @@ -89,3 +89,6 @@ if(CTEST_ENABLED) else() message(STATUS "CTests are DISABLED") endif() + +# Output addition install information +install(CODE "message(STATUS \"Installing ReproStim ${CAPTURE_VERSION_STRING} to: ${CAPTURE_INSTALL_DIR}\")") diff --git a/Capture/version.txt b/Capture/version.txt index 41157c4..35f6398 100644 --- a/Capture/version.txt +++ b/Capture/version.txt @@ -1 +1 @@ -1.8.0.223 \ No newline at end of file +1.8.0.225 \ No newline at end of file