Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Verstraeten committed Aug 17, 2017
2 parents 212054c + b7c8cfb commit 89c7c8c
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 124 deletions.
5 changes: 3 additions & 2 deletions cmake/External-Googletest.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
message("External project: Googletest")

ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG 673c975a963f356b19fea90cb57b69192253da2a
SOURCE_DIR googletest
BUILD_IN_SOURCE 1
UPDATE_COMMAND ""
Expand All @@ -20,4 +21,4 @@ set(GOOGLETEST_LIBRARY_DIR ${CMAKE_BINARY_DIR}/googletest/)
include_directories(${GOOGLETEST_INCLUDE_DIR})
link_directories(${GOOGLETEST_LIBRARY_DIR})

set(GOOGLETEST_LIBRARIES "${GOOGLETEST_LIBRARY_DIR}googlemock/libgmock.a" "${GOOGLETEST_LIBRARY_DIR}googlemock/libgmock_main.a")
set(GOOGLETEST_LIBRARIES "${GOOGLETEST_LIBRARY_DIR}googlemock/libgmock.a" "${GOOGLETEST_LIBRARY_DIR}googlemock/libgmock_main.a")
35 changes: 27 additions & 8 deletions exceptions/KerberosException.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// The copyright to the computer program(s) herein
// is the property of Verstraeten.io, Belgium.
// The program(s) may be used and/or copied under
// The program(s) may be used and/or copied under
// the CC-NC-ND license model.
//
// https://doc.kerberos.io/license
Expand All @@ -26,12 +26,16 @@ namespace kerberos
class KerberosException : public Exception
{
public:
KerberosException(const char * msg):message(msg){};
virtual const char* what() const throw()
{
char * output = new char[300];
strcpy (output, "Kerberos : A problem occured in the kerberos source.");
strcpy (output, "Kerberos : General : A problem occured : ");
strcat (output, message);
return output;
};
private:
const char * message;
};

class KerberosFactoryCouldNotCreateException : public Exception
Expand All @@ -40,15 +44,15 @@ namespace kerberos
KerberosFactoryCouldNotCreateException(const char * message):message(message){};
virtual const char * what() const throw()
{
char * output = new char[300];
strcpy (output, "Kerberos : Factory : Could not create an instance of message: ");
strcat (output, message);
return output;
char * output = new char[300];
strcpy (output, "Kerberos : Factory : Could not create an instance of message: ");
strcat (output, message);
return output;
};
private:
const char * message;
};

class KerberosCouldNotOpenCamera : public Exception
{
public:
Expand All @@ -62,6 +66,21 @@ namespace kerberos
};
private:
const char * message;
};

class KerberosCouldNotGrabFromCamera : public Exception
{
public:
KerberosCouldNotGrabFromCamera(const char * message):message(message){};
virtual const char* what() const throw()
{
char * output = new char[300];
strcpy (output, "Kerberos : Capture : Could not grab from capture: ");
strcat (output, message);
return output;
};
private:
const char * message;
};
}
#endif
#endif
2 changes: 1 addition & 1 deletion include/kerberos/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef __Version_H_INCLUDED__ // if Version.h hasn't been included yet...
#define __Version_H_INCLUDED__ // #define this so the compiler knows it has been included

#define VERSION "2.3.0"
#define VERSION "2.3.1"
#define HADES "https://hades.kerberos.io"
#define CLOUD "https://cloud.kerberos.io"
#define SYMBOL_DIRECTORY "/etc/opt/kerberosio/symbols/"
Expand Down
1 change: 1 addition & 0 deletions include/kerberos/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace kerberos
kerberos::StringMap getSettingsFromXML(const std::string & path);
std::string printStringMap(const std::string & prefix, const kerberos::StringMap & map);
bool replace(std::string& str, const std::string& from, const std::string& to);
void replaceAll(std::string& str, const std::string& from, const std::string& to);
std::string to_string (const int & t);
std::string generatePath(const std::string timezone, const std::string & subDirectory = "");
std::string getTimestamp();
Expand Down
8 changes: 7 additions & 1 deletion include/kerberos/capture/Capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include<arpa/inet.h> //inet_addr
#include<unistd.h> //write
#include<pthread.h> //for threading , link with lpthread
#include <atomic>

namespace kerberos
{
Expand All @@ -40,15 +41,18 @@ namespace kerberos
public:
pthread_mutex_t m_lock;
pthread_t m_captureThread;
pthread_t m_healthThread;
std::atomic<int> healthCounter; // increment to check if capture is still grabbing images.

int m_frameWidth, m_frameHeight;
int m_angle; // 90, 180, 270
int m_delay; // msec
int m_framerate;
bool m_onBoardRecording;
bool m_onFFMPEGrecording;
bool m_hardwareMJPEGEncoding;

Capture():m_framerate(30),m_onBoardRecording(false),m_hardwareMJPEGEncoding(false){};
Capture():m_framerate(30),m_onBoardRecording(false),m_onFFMPEGrecording(false),m_hardwareMJPEGEncoding(false){};
virtual ~Capture(){};
virtual void setup(kerberos::StringMap & settings) = 0;
void setup(kerberos::StringMap & settings, int width, int height, int angle);
Expand All @@ -74,6 +78,8 @@ namespace kerberos

void startGrabThread();
void stopGrabThread();
void startHealthThread();
void stopHealthThread();
};

template<const char * Alias, typename Class>
Expand Down
1 change: 1 addition & 0 deletions include/kerberos/capture/RaspiCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace kerberos
Image * takeImage();
void startRecord(std::string path);
void stopRecord();
void stopThreads();

void open();
void close();
Expand Down
3 changes: 3 additions & 0 deletions include/kerberos/machinery/io/IoVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ namespace kerberos
pthread_t m_recordThread;
pthread_t m_retrieveThread;
pthread_t m_recordOnboardThread;
pthread_t m_recordOnFFMPEGThread;
pthread_t m_convertThread;
double m_timeStartedRecording;

void startOnboardRecordThread();
void stopOnboardRecordThread();
void startFFMPEGRecordThread();
void stopFFMPEGRecordThread();
void startRecordThread();
void stopRecordThread();
void startRetrieveThread();
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Cédric Verstraeten")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Kerberos is a low-budget surveillance solution, that uses computer vision algorithms to detect changes, and that can trigger other devices. Kerberos is open source so you, but also other people, can customize the source to your needs and share it with our community. It has a green footprint when deploying on the Raspberry Pi and it's easy to install, you only need to transfer the image to the SD card and you're done.")

set(CPACK_PACKAGE_VERSION "2.3.0")
set(CPACK_PACKAGE_VERSION "2.3.1")
set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "3")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION_PATCH "1")

string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
Expand Down
10 changes: 10 additions & 0 deletions src/kerberos/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ namespace kerberos
return true;
}

void replaceAll(std::string& str, const std::string& from, const std::string& to)
{
size_t start_pos = 0;
while((start_pos = str.find(from)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}

std::string generatePath(const std::string timezone, const std::string & subDirectory)
{
srand(int(time(NULL)));
Expand Down
5 changes: 4 additions & 1 deletion src/kerberos/Kerberos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace kerberos

setParameters(parameters);


// ---------------------
// initialize RestClient

Expand Down Expand Up @@ -213,6 +212,7 @@ namespace kerberos
{
machinery->disableCapture();
capture->stopGrabThread();
capture->stopHealthThread();
capture->close();
}
delete capture;
Expand All @@ -226,6 +226,7 @@ namespace kerberos
capture = Factory<Capture>::getInstance()->create(settings.at("capture"));
capture->setup(settings);
capture->startGrabThread();
capture->startHealthThread();

// ------------------
// Initialize stream
Expand Down Expand Up @@ -313,6 +314,7 @@ namespace kerberos
}

pthread_create(&m_streamThread, NULL, streamContinuously, this);
pthread_detach(m_streamThread);
}

void Kerberos::stopStreamThread()
Expand Down Expand Up @@ -395,6 +397,7 @@ namespace kerberos
// Start a new thread that cheks for detections

pthread_create(&m_ioThread, NULL, checkDetectionsContinuously, this);
pthread_detach(m_ioThread);
}

void Kerberos::stopIOThread()
Expand Down
78 changes: 60 additions & 18 deletions src/kerberos/capture/Capture.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#include "capture/Capture.h"

namespace kerberos
{
void Capture::setup(kerberos::StringMap & settings, int width, int height, int angle)
{
// --------------------------
// Make width & height global.

settings["capture.width"] = helper::to_string(width);
settings["capture.height"] = helper::to_string(height);
settings["capture.angle"] = helper::to_string(angle);

// ----------------
// Initialize mutex

pthread_mutex_init(&m_lock, NULL);
}

void Capture::setImageSize(int width, int height)
{
m_frameWidth = width;
m_frameHeight = height;
}

void Capture::setRotation(int angle)
{
m_angle = angle;
}

void Capture::setDelay(int msec)
{
m_delay = msec;
m_delay = msec;
}

ImageVector & Capture::takeImages(int numberOfImages)
{
m_images.resize(numberOfImages);
Expand Down Expand Up @@ -68,18 +68,18 @@ namespace kerberos

// -------------
// Take images

for(int i = m_images.size()-numberOfImages; i < m_images.size(); i++)
{
m_images[i] = takeImage();
}
return m_images;
}

// -------------------------------------------
// Function ran in a thread, which continously
// grabs frames.

void * grabContinuously(void * self)
{
Capture * capture = (Capture *) self;
Expand All @@ -100,22 +100,64 @@ namespace kerberos
usleep(333*100);
}
}

void Capture::startGrabThread()
{
// ------------------------------------------------
// Start a new thread that grabs images continously.
// This is needed to clear the buffer of the capture device.

pthread_create(&m_captureThread, NULL, grabContinuously, this);

pthread_create(&m_captureThread, NULL, grabContinuously, this);
pthread_detach(m_captureThread);
}

void Capture::stopGrabThread()
{
// ----------------------------------
// Cancel the existing capture thread,
// before deleting the device.

pthread_cancel(m_captureThread);
}
}


// -------------------------------------------
// Function ran in a thread, which continously
// checkes the health of the camera.

void * healthContinuously(void * self)
{
Capture * capture = (Capture *) self;

int healthCounter = capture->healthCounter.load();
for(;;)
{
usleep(30000*1000); // every 30s.
LINFO << "Capture: checking health status of camera.";

if(healthCounter == capture->healthCounter.load())
{
LINFO << "Capture: devices is blocking, and not grabbing any more frames.";
throw KerberosCouldNotGrabFromCamera("devices is blocking, and not grabbin any more frames.");
}
}
}

void Capture::startHealthThread()
{
// ------------------------------------------------
// Start a new thread that verifies the health of the camera.

pthread_create(&m_healthThread, NULL, healthContinuously, this);
pthread_detach(m_healthThread);
}

void Capture::stopHealthThread()
{
// ----------------------------------
// Cancel the existing health thread,
// before deleting the device.

pthread_cancel(m_healthThread);
}
}
Loading

0 comments on commit 89c7c8c

Please sign in to comment.