Skip to content

Commit

Permalink
Merge pull request #93 from ReproNim/nf-capture-issue90_91_92
Browse files Browse the repository at this point in the history
Aggregated capture issues #90, #91 and #92 PR
  • Loading branch information
vmdocua authored May 24, 2024
2 parents 3c8d0a6 + 66992d5 commit a0dfcc8
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 22 deletions.
17 changes: 17 additions & 0 deletions Capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${CMAKE_INSTALL_PREFIX}/bin)

# Add MWCapture SDK include/lib paths
include_directories(${MWCAPTURE_SDK_HOME}/Include)
link_directories(${MWCAPTURE_SDK_HOME}/Lib/${ARCH})
Expand All @@ -60,6 +63,17 @@ 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}
RENAME reprostim-nosignal
)
else()
message(STATUS "Python 'nosignal' script not found.")
endif()

# Add tests optionally
if(CTEST_ENABLED)
message(STATUS "CTests are ENABLED")
Expand All @@ -75,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}\")")
10 changes: 10 additions & 0 deletions Capture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ Capture uses CMake as build system. To build the project, run the following comm
cmake ..
make

## Installation

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`, `reprostim-nosignal`).

## Project Structure

Expand Down
2 changes: 1 addition & 1 deletion Capture/capturelib/include/reprostim/CaptureApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
};

Expand Down
14 changes: 9 additions & 5 deletions Capture/capturelib/src/CaptureApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
4 changes: 4 additions & 0 deletions Capture/screencapture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
11 changes: 8 additions & 3 deletions Capture/screencapture/src/ScreenCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Capture/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0.215
1.8.0.225
3 changes: 3 additions & 0 deletions Capture/videocapture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
48 changes: 36 additions & 12 deletions Capture/videocapture/src/VideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <thread>
#include <sysexits.h>
#include <getopt.h>
#include <csignal>
#include "VideoCapture.h"

using namespace reprostim;
Expand All @@ -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,
Expand Down Expand Up @@ -187,8 +207,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"
Expand All @@ -204,7 +226,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}
Expand All @@ -230,6 +252,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;
Expand Down Expand Up @@ -341,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();
Expand Down

0 comments on commit a0dfcc8

Please sign in to comment.