Skip to content

Commit

Permalink
Health & Error Callback Implementation , Improved Abs Control Module (#…
Browse files Browse the repository at this point in the history
…377)

* Added Error & Health  Status Objects

* Added Error & Health Callbacks

* Removed unwanted Header Declarartion

* Added Health & Error Callback Listener

* Fixed Build Issue

* -> Added Virtual Function to register error callback
-> Added Health Callback strategy

* Added Error & Health Callback in ImageEncoder Module

* control module changes wip

* 1. defined Control module type at framework level 2. enforced data frame checks for control modules

* added a virtual method to add control module so that it can be overriden for custom behaviour in some modules

* resolved conflict

* Fixed Build Issue

* Fixed Linking Error

* Fixed Typo

* revert the multiple pipelines with  control module idea

* Do not allow roles to be updated once registered

* Added COndition to check for input and output pins

* Updated handleError and Callback as a virtual function

* Added handle Error & Healthback method in Simple Control Module

* Removed Dummy Error Callbacks from ImageEncoder Module

* USing Simple Control Module in ImageEncoder Tests

* Fixed Indentation and typo

* Renamed Error, Health and Callback class

* Code Cleanup

* Fixed warning

* Using Updated Health & Error Object class

* -> Fixed Formatting
->  Added Register Error callback
-> Sending Error Callback when frame is not there to render

* Renamed Health & ErrorCallback function

* Updated GtkGL to use updated APErrorCallback method

* Update Module.h

* Added Generic Implementation of Error Callback

* Formatted APErrorObject class

* Updated GtkGLRenderer to Use Generic Error Callbacks, Added Test for same

* Removed Unwanted errors

* Added healthUpdateIntervalInSec in ModuleProps, To make HealtCallback Frequency configurable

* Added Defination of getCurrentTimestamp

---------

Co-authored-by: mradul <mradul@apra.in>
  • Loading branch information
2 people authored and Vinayak-YB committed Aug 7, 2024
1 parent e9dab6f commit 52980cc
Show file tree
Hide file tree
Showing 25 changed files with 2,275 additions and 1,718 deletions.
7 changes: 7 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ SET(CORE_FILES
src/MotionVectorExtractor.cpp
src/OverlayModule.cpp
src/OrderedCacheOfFiles.cpp
src/SimpleControlModule.cpp
src/APErrorObject.cpp
src/APHealthObject.cpp
)

SET(CORE_FILES_H
Expand Down Expand Up @@ -253,6 +256,10 @@ SET(CORE_FILES_H
include/OrderedCacheOfFiles.h
include/TestSignalGeneratorSrc.h
include/AbsControlModule.h
include/SimpleControlModule.h
include/APErrorObject.h
include/APCallback.h
include/APHealthObject.h
)

IF(ENABLE_WINDOWS)
Expand Down
1 change: 1 addition & 0 deletions base/include/AIPExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define MP4_OCOF_INVALID_DUR 7823
#define MP4_UNEXPECTED_STATE 7824
#define MODULE_ENROLLMENT_FAILED 7825
#define CTRL_MODULE_INVALID_STATE 7826


#define AIPException_LOG_SEV(severity,type) for(std::ostringstream stream; Logger::getLogger()->push(severity, stream);) Logger::getLogger()->aipexceptionPre(stream, severity,type)
Expand Down
7 changes: 7 additions & 0 deletions base/include/APCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "APErrorObject.h"
#include "APHealthObject.h"
#include <functional>

using APErrorCallback = std::function<void(const APErrorObject &)>;
using APHealthCallback = std::function<void(const APHealthObject &)>;
28 changes: 28 additions & 0 deletions base/include/APErrorObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <string>

class APErrorObject {
private:
int mErrorCode;
std::string mErrorMessage;
std::string mModuleName;
std::string mModuleId;
std::string mTimestamp;

std::string getCurrentTimestamp() const;

public:
APErrorObject(int errCode, const std::string &errorMsg);

int getErrorCode() const;
std::string getErrorMessage() const;
std::string getModuleName() const;
std::string getModuleId() const;
std::string getTimestamp() const;

void displayError() const;
void setErrorCode(int errCode);
void setErrorMessage(const std::string &errorMsg);
void setModuleName(const std::string &modName);
void setModuleId(const std::string &modId);
};
19 changes: 19 additions & 0 deletions base/include/APHealthObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <string>

class APHealthObject
{
private:
std::string mModuleId;
std::string mTimestamp;

std::string getCurrentTimestamp() const;

public:
APHealthObject(const std::string &modId);

std::string getModuleId() const;
std::string getTimestamp() const;

void setModuleId(const std::string &modId);
};
59 changes: 28 additions & 31 deletions base/include/AbsControlModule.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
#pragma once
#include "APCallback.h"
#include "Command.h"
#include "Module.h"
#include <map>

class PipeLine;
class AbsControlModuleProps : public ModuleProps {
public:
AbsControlModuleProps() {}
AbsControlModuleProps() {}
};

class AbsControlModule : public Module {
public:
AbsControlModule(AbsControlModuleProps _props);
~AbsControlModule();
bool init();
bool term();
std::string enrollModule(std::string pName, std::string role,
boost::shared_ptr<Module> module);
std::pair<bool, boost::shared_ptr<Module>> getModuleofRole(std::string pName,
std::string role);
virtual void handleMp4MissingVideotrack(std::string previousVideoFile,
std::string nextVideoFile) {}
virtual void handleMMQExport(Command cmd, bool priority = false) {}
virtual void handleMMQExportView(uint64_t startTS,
uint64_t endTS = 9999999999999,
bool playabckDirection = true,
bool Mp4ReaderExport = false,
bool priority = false) {}
virtual void handleSendMMQTSCmd(uint64_t mmqBeginTS, uint64_t mmqEndTS,
bool priority = false) {}
virtual void handleLastGtkGLRenderTS(uint64_t latestGtkGlRenderTS,
bool priority) {}
virtual void handleGoLive(bool goLive, bool priority) {}
virtual void handlePusherPauseTS(uint64_t keyFrameTS) {}
virtual void handleDecoderSpeed(DecoderPlaybackSpeed cmd, bool priority) {}
boost::container::deque<boost::shared_ptr<Module>> pipelineModules;
std::map<std::string, boost::shared_ptr<Module>> moduleRoles;
AbsControlModule(AbsControlModuleProps _props);
~AbsControlModule();
bool init();
bool term();
bool enrollModule(std::string role, boost::shared_ptr<Module> module);
boost::shared_ptr<Module> getModuleofRole(std::string role);
virtual void handleMp4MissingVideotrack(std::string previousVideoFile, std::string nextVideoFile) {}
virtual void handleMMQExport(Command cmd, bool priority = false) {}
virtual void handleMMQExportView(uint64_t startTS, uint64_t endTS = 9999999999999, bool playabckDirection = true, bool Mp4ReaderExport = false, bool priority = false) {}
virtual void handleSendMMQTSCmd(uint64_t mmqBeginTS, uint64_t mmqEndTS, bool priority = false) {}
virtual void handleLastGtkGLRenderTS(uint64_t latestGtkGlRenderTS, bool priority) {}
virtual void handleGoLive(bool goLive, bool priority) {}
virtual void handleDecoderSpeed(DecoderPlaybackSpeed cmd, bool priority) {}
boost::container::deque<boost::shared_ptr<Module>> pipelineModules;
std::map<std::string, boost::shared_ptr<Module>> moduleRoles;
virtual void handleError(const APErrorObject &error) {}
virtual void handleHealthCallback(const APHealthObject &healthObj) {}


protected:
bool process(frame_container &frames);
bool handleCommand(Command::CommandType type, frame_sp &frame);
bool handlePropsChange(frame_sp &frame);
bool process(frame_container& frames);
bool handleCommand(Command::CommandType type, frame_sp& frame);
bool handlePropsChange(frame_sp& frame);
virtual void sendEOS() {}
virtual void sendEOS(frame_sp& frame) {}
virtual void sendEOPFrame() {}

private:
class Detail;
boost::shared_ptr<Detail> mDetail;
class Detail;
boost::shared_ptr<Detail> mDetail;
};
1 change: 0 additions & 1 deletion base/include/BrightnessContrastControlXform.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class BrightnessContrastControl : public Module
bool validateInputPins();
bool validateOutputPins();
void addInputPin(framemetadata_sp &metadata, string &pinId);
void setProps(BrightnessContrastControl);
bool handlePropsChange(frame_sp &frame);

private:
Expand Down
37 changes: 19 additions & 18 deletions base/include/GtkGlRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@
#include <chrono>
#include <gtk/gtk.h>

class GtkGlRendererProps : public ModuleProps {
class GtkGlRendererProps : public ModuleProps
{
public:
GtkGlRendererProps(GtkWidget* _glArea, int _windowWidth, int _windowHeight, bool _isPlaybackRenderer = true) : ModuleProps() // take gtk string
GtkGlRendererProps(GtkWidget *_glArea, int _windowWidth, int _windowHeight, bool _isPlaybackRenderer = true) : ModuleProps() // take gtk string
{
// gladeFileName = _gladeFileName;
glArea = _glArea;
windowWidth = _windowWidth;
windowHeight = _windowHeight;
isPlaybackRenderer = _isPlaybackRenderer;
}
GtkWidget* glArea;
GtkWidget *glArea;
int windowWidth = 0;
int windowHeight = 0;
bool isPlaybackRenderer = true;
};

class GtkGlRenderer : public Module {
class GtkGlRenderer : public Module
{
public:
GtkGlRenderer(GtkGlRendererProps props);
~GtkGlRenderer();

bool init();
bool term();
bool changeProps(GtkWidget *glArea, int windowWidth, int windowHeight);

GtkGlRenderer(GtkGlRendererProps props);
~GtkGlRenderer();
bool init();
bool term();
bool changeProps(GtkWidget *glArea, int windowWidth, int windowHeight);
protected:
bool process(frame_container& frames);
bool process(frame_container &frames);
bool processSOS(frame_sp &frame);
bool validateInputPins();
bool shouldTriggerSOS();
bool handleCommand(Command::CommandType type, frame_sp &frame);
void pushFrame(frame_sp frame);

private:
class Detail;
boost::shared_ptr<Detail> mDetail;
std::chrono::steady_clock::time_point lastFrameTime =
std::chrono::steady_clock::now();
std::queue<frame_sp> frameQueue;
std::mutex queueMutex;
class Detail;
boost::shared_ptr<Detail> mDetail;
std::chrono::steady_clock::time_point lastFrameTime =
std::chrono::steady_clock::now();
std::queue<frame_sp> frameQueue;
std::mutex queueMutex;
};
2 changes: 0 additions & 2 deletions base/include/ImageEncoderCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ class ImageEncoderCV : public Module
virtual ~ImageEncoderCV();
bool init();
bool term();

protected:
bool process(frame_container& frames);
bool processSOS(frame_sp& frame);
bool validateInputPins();
bool validateOutputPins();

private:
void setMetadata(framemetadata_sp& metadata);
int mFrameType;
ImageEncoderCVProps props;
class Detail;
Expand Down
Loading

0 comments on commit 52980cc

Please sign in to comment.