Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apra nvr #342

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ find_package(ZXing CONFIG REQUIRED)
find_package(bigint CONFIG REQUIRED)
find_package(SFML COMPONENTS system window audio graphics CONFIG REQUIRED)

pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(GDK3 REQUIRED gdk-3.0)

IF(ENABLE_CUDA)
if((NOT DEFINED CMAKE_CUDA_ARCHITECTURES) OR (CMAKE_CUDA_ARCHITECTURES STREQUAL ""))
set(CMAKE_CUDA_ARCHITECTURES 52 60 70 75)
Expand Down Expand Up @@ -90,6 +93,20 @@ IF(ENABLE_CUDA)
${NVARGUS_SOCKETCLINET_LIB}
)
include_directories(AFTER SYSTEM /usr/local/cuda/include)
include_directories(AFTER SYSTEM /usr/include/gtk-3.0/)
include_directories(AFTER SYSTEM /usr/include/glib-2.0/)
include_directories(AFTER SYSTEM /usr/local/cuda/include)
include_directories(AFTER SYSTEM /usr/include/gtk-3.0/)
include_directories(AFTER SYSTEM /usr/include/glib-2.0/)
include_directories(AFTER SYSTEM /usr/lib/aarch64-linux-gnu/glib-2.0/include/)
include_directories(AFTER SYSTEM /usr/include/pango-1.0/)
include_directories(AFTER SYSTEM /usr/include/harfbuzz/)
include_directories(AFTER SYSTEM /usr/include/cairo/)
include_directories(AFTER SYSTEM /usr/include/atk-1.0/)
include_directories(AFTER SYSTEM /usr/include/gdk-pixbuf-2.0/)
include_directories(AFTER SYSTEM /usr/local/cuda/samples/common/inc/)
include_directories(AFTER SYSTEM /usr/include/)
include_directories(AFTER SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ApraGTKUtils/includes/)
ELSEIF(ENABLE_LINUX)
find_library(LIBNVCUVID libnvcuvid.so PATHS ../thirdparty/Video_Codec_SDK_10.0.26/Lib/linux/stubs/x86_64 NO_DEFAULT_PATH)
find_library(LIBNVENCODE libnvidia-encode.so PATHS ../thirdparty/Video_Codec_SDK_10.0.26/Lib/linux/stubs/x86_64 NO_DEFAULT_PATH)
Expand Down Expand Up @@ -222,6 +239,7 @@ SET(CORE_FILES_H
include/OverlayModule.h
include/OrderedCacheOfFiles.h
include/TestSignalGeneratorSrc.h
include/AbsControlModule.h
)

IF(ENABLE_WINDOWS)
Expand Down Expand Up @@ -280,6 +298,8 @@ SET(IP_FILES
src/OverlayFactory.h
src/OverlayFactory.cpp
src/TestSignalGeneratorSrc.cpp
src/AbsControlModule.cpp
src/ThumbnailListGenerator.cpp
)


Expand All @@ -306,6 +326,7 @@ SET(IP_FILES_H
include/TextOverlayXForm.h
include/ColorConversionXForm.h
include/Overlay.h
include/ThumbnailListGenerator.h
)


Expand Down Expand Up @@ -370,6 +391,12 @@ IF(ENABLE_ARM64)
src/DMAFDToHostCopy.cpp
src/H264DecoderV4L2Helper.cpp
src/H264DecoderV4L2Helper.h
src/Background.cpp
src/GtkGlRenderer.cpp
src/Matrix.cpp
src/Model.cpp
src/Program.cpp
src/View.cpp
)
ELSE()
SET(CUDA_IP_FILES ${CUDA_IP_FILES} # following modules and related files do not work on ARM64
Expand Down Expand Up @@ -420,6 +447,13 @@ IF(ENABLE_ARM64)
include/ApraEGLDisplay.h
include/DMAFrameUtils.h
include/DMAFDToHostCopy.h
include/Background.h
include/GLUtils.h
include/GtkGlRenderer.h
include/Matrix.h
include/Model.h
include/Program.h
include/View.h
)
ELSE()
SET(CUDA_IP_FILES_H ${CUDA_IP_FILES_H} # following modules and related files do not work on ARM64
Expand Down Expand Up @@ -478,6 +512,7 @@ IF (ENABLE_ARM64)
test/apraegldisplay_tests.cpp
test/frame_factory_test_dma.cpp
test/h264decoder_tests.cpp
test/gtkglrenderer_tests.cpp
)
ENDIF(ENABLE_ARM64)

Expand Down Expand Up @@ -561,6 +596,8 @@ SET(UT_FILES
test/mp4_dts_strategy_tests.cpp
test/overlaymodule_tests.cpp
test/testSignalGeneratorSrc_tests.cpp
test/abscontrolmodule_tests.cpp
test/thumbnailgenerator_tests.cpp
${ARM64_UT_FILES}
${CUDA_UT_FILES}
)
Expand Down Expand Up @@ -589,6 +626,15 @@ find_library(LIBMP4_LIB NAMES mp4lib.lib libmp4lib.a REQUIRED)

target_link_libraries(aprapipesut
aprapipes
/usr/lib/aarch64-linux-gnu/libgtk-3-0
/usr/lib/aarch64-linux-gnu/libGLEW.so
/usr/lib/aarch64-linux-gnu/libgdk-3.so
/usr/lib/aarch64-linux-gnu/libGL.so.1
/usr/lib/aarch64-linux-gnu/libgdk_pixbuf-2.0.so.0
/usr/lib/aarch64-linux-gnu/libgio-2.0.so.0
/usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0
${GTK3_LIBRARIES}
${GDK3_LIBRARIES}
${JPEG_LIBRARIES}
${LIBMP4_LIB}
${OPENH264_LIB}
Expand Down
120 changes: 66 additions & 54 deletions base/include/AIPExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,66 +45,78 @@

class AIP_Exception : public std::runtime_error
{
public:
/** Constructor (C++ STL strings).
* @param message The error message.
*/
explicit AIP_Exception(int type,const std::string file,int line,const std::string logMessage) :
runtime_error(std::to_string(type))
{
if (type > AIP_FATAL)
{
AIPException_LOG_SEV(boost::log::trivial::severity_level::fatal,type) << file << ":" << line << ":" << logMessage.c_str();
}
else
{
AIPException_LOG_SEV(boost::log::trivial::severity_level::error,type) << file << ":" << line << ":" << logMessage.c_str();
}

message = logMessage;
}

/** Destructor.
* Virtual to allow for subclassing.
*/
virtual ~AIP_Exception() throw () {}

int getCode()
{
return atoi(what());
}

std::string getError()
{
return message;
}

public:
/** Constructor (C++ STL strings).
* @param message The error message.
*/
explicit AIP_Exception(int type,const std::string file,int line,const std::string logMessage) :
runtime_error(std::to_string(type))
{
if (type > AIP_FATAL)
{
AIPException_LOG_SEV(boost::log::trivial::severity_level::fatal,type) << file << ":" << line << ":" << logMessage.c_str();
}
else
{
AIPException_LOG_SEV(boost::log::trivial::severity_level::error,type) << file << ":" << line << ":" << logMessage.c_str();
}
message = logMessage;
}
explicit AIP_Exception(int type,const std::string file,int line,const std::string logMessage, std::string _previosFile, std::string _nextFile) :
runtime_error(std::to_string(type))
{
previousFile = _previosFile;
nextFile = _nextFile;
AIPException_LOG_SEV(boost::log::trivial::severity_level::error,type) << file << ":" << line << ":" << previousFile.c_str() << ":" << nextFile.c_str() << ":" << logMessage.c_str();
}
/** Destructor.
* Virtual to allow for subclassing.
*/
virtual ~AIP_Exception() throw () {}
int getCode()
{
return atoi(what());
}
std::string getError()
{
return message;
}
std::string getPreviousFile()
{
return previousFile;
}
std::string getNextFile()
{
return nextFile;
}
private:
std::string message;
std::string message;
std::string previousFile;
std::string nextFile;
};

class Mp4_Exception : public AIP_Exception
{
public:
explicit Mp4_Exception(int type, const std::string file, int line, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
}

explicit Mp4_Exception(int type, const std::string file, int line, int _openFileErrorCode, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
openFileErrorCode = _openFileErrorCode;
}

int getOpenFileErrorCode()
{
return openFileErrorCode;
}

explicit Mp4_Exception(int type, const std::string file, int line, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
}
explicit Mp4_Exception(int type, const std::string file, int line, int _openFileErrorCode, const std::string logMessage) :
AIP_Exception(type, file, line, logMessage)
{
openFileErrorCode = _openFileErrorCode;
}
explicit Mp4_Exception(int type, const std::string file, int line, const std::string logMessage, std::string previosFile, std::string nextFile) :
AIP_Exception(type, file, line, logMessage, previosFile, nextFile)
{
}
int getOpenFileErrorCode()
{
return openFileErrorCode;
}
private:
int openFileErrorCode = 0;
int openFileErrorCode = 0;
};

#define AIPException(_type,_message) AIP_Exception(_type,__FILE__,__LINE__,_message)
#define Mp4Exception(_type,_message) Mp4_Exception(_type,__FILE__,__LINE__,_message)
#define Mp4ExceptionNoVideoTrack(_type,_message, _previosFile, _nextFile) Mp4_Exception(_type,__FILE__,__LINE__,_message,_previosFile,_nextFile)
40 changes: 40 additions & 0 deletions base/include/AbsControlModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <map>
#include "Module.h"

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

class AbsControlModule : public Module
{
public:
AbsControlModule(AbsControlModuleProps _props);
~AbsControlModule();
bool init();
bool term();
void setProps(AbsControlModuleProps& props);
bool enrollModule(std::string role, boost::shared_ptr<Module> module);
boost::shared_ptr<Module> getModuleofRole(std::string role);
AbsControlModuleProps getProps();
boost::container::deque<boost::shared_ptr<Module>> pipelineModules;
std::map<std::string, boost::shared_ptr<Module>> moduleRoles;

protected:
bool process(frame_container& frames);
bool validateInputPins();
bool validateOutputPins();
bool validateInputOutputPins();
void addInputPin(framemetadata_sp& metadata, string& pinId);
bool handleCommand(Command::CommandType type, frame_sp& frame);
bool handlePropsChange(frame_sp& frame);

private:
void setMetadata(framemetadata_sp& metadata);
class Detail;
boost::shared_ptr<Detail> mDetail;
};
16 changes: 13 additions & 3 deletions base/include/ApraNvEglRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class NvEglRenderer
* @return 0 for success, -1 otherwise.
*/
static int getDisplayResolution(uint32_t &width, uint32_t &height);

bool renderAndDrawLoop();
bool windowDrag();
/**
* Sets the overlay string.
*
Expand All @@ -149,13 +150,22 @@ class NvEglRenderer
* @return 0 for success, -1 otherwise.
*/
int setOverlayText(char *str, uint32_t x, uint32_t y);

private:
public:
Display * x_display; /**< Connection to the X server created using
XOpenDisplay(). */
Window x_window; /**< Holds the window to be used for rendering created using
XCreateWindow(). */

uint32_t mWidth,mHeight;

int drag_start_x = 0;
int drag_start_y = 0;
bool is_dragging = false;
uint32_t _x_offset = 0;
uint32_t _y_offset = 0;
XEvent event;
bool drawBorder = false;

EGLDisplay egl_display; /**< Holds the EGL Display connection. */
EGLContext egl_context; /**< Holds the EGL rendering context. */
EGLSurface egl_surface; /**< Holds the EGL Window render surface. */
Expand Down
3 changes: 3 additions & 0 deletions base/include/Background.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void background_draw (void);
void background_init (void);
void background_set_window (int width, int height);
30 changes: 30 additions & 0 deletions base/include/BoundBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/thread/thread.hpp>
#include <boost/call_traits.hpp>
#include <boost/bind/bind.hpp>
#include <iostream>
using namespace boost::placeholders;

template <class T>
Expand Down Expand Up @@ -38,6 +39,26 @@ class bounded_buffer
}
}

void push_back(typename boost::call_traits<value_type>::param_type item)
{ // `param_type` represents the "best" way to pass a parameter of type `value_type` to a method.

boost::mutex::scoped_lock lock(m_mutex);
bool isCommandQueueNotFull = m_unread < m_capacity * 2;
if (m_accept && isCommandQueueNotFull)
{
std::cout << "command pushed" << std::endl;
m_container.push_back(item);
++m_unread;
lock.unlock();
m_not_empty.notify_one();
}
else
{
// check and remove if explicit unlock is required
lock.unlock();
}
}

void push_drop_oldest(typename boost::call_traits<value_type>::param_type item)
{
boost::mutex::scoped_lock lock(m_mutex);
Expand Down Expand Up @@ -93,6 +114,15 @@ class bounded_buffer
return ret;
}

value_type peek() {
boost::mutex::scoped_lock lock(m_mutex);
if (is_not_empty())
{
value_type ret = m_container.back();
return ret;
}
}

value_type try_pop() {
boost::mutex::scoped_lock lock(m_mutex);
if (is_not_empty())
Expand Down
Loading