Skip to content

Commit

Permalink
Merge pull request #94 from AxisCommunications/raii-capture
Browse files Browse the repository at this point in the history
Follow RAII in Capture class
  • Loading branch information
killenheladagen authored Sep 9, 2024
2 parents 5b8c56a + d0e5c94 commit 1c6ffde
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/acap_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ int RunServer(const string& address,
builder.RegisterService(&parameter);

// Register video capture service
Capture capture;
if (!capture.Init(_verbose)) {
syslog(LOG_ERR, "Could not initialize VideoCapture service");
return EXIT_FAILURE;
}
Capture capture{_verbose};
builder.RegisterService(&capture);

Inference inference{_verbose, chipId, models, &capture};
Expand Down
7 changes: 2 additions & 5 deletions src/video_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ using namespace videocapture::v1;
namespace acap_runtime {

// Initialize the capture service
bool Capture::Init(const bool verbose) {
this->_verbose = verbose;
Capture::Capture(const bool verbose) : _verbose(verbose) {
TRACELOG << "Init" << endl;

if (pthread_mutex_init(&_mutex, NULL) != 0) {
ERRORLOG << "Init mutex failed" << endl;
return false;
throw runtime_error("Could not initialize VideoCapture service");
}

return true;
}

// Create a new stream
Expand Down
2 changes: 1 addition & 1 deletion src/video_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Capture final : public videocapture::v1::VideoCapture::Service {
using Status = grpc::Status;
using StatusCode = grpc::StatusCode;

bool Init(const bool verbose);
Capture(bool verbose);

Status NewStream(ServerContext* context,
const NewStreamRequest* request,
Expand Down
2 changes: 1 addition & 1 deletion test/inference_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const uint64_t cpuChipId = 2;
const uint64_t tpuChipId = 4;
const uint64_t dlpuChipId = 12;
const char* sharedFile = "/test.bmp";
Capture capture;
Capture capture{true};

void PredictModel1(Inference& inference,
string modelName,
Expand Down

0 comments on commit 1c6ffde

Please sign in to comment.