Skip to content

Commit

Permalink
Merged ApraNVR
Browse files Browse the repository at this point in the history
  • Loading branch information
=zaki committed Jun 5, 2024
1 parent c2bca33 commit 28c2215
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 230 deletions.
41 changes: 30 additions & 11 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# CMAKE_HOST_SYSTEM_PROCESSOR is not helpful because it outputs "unknown" on
# Linux on ARM.
execute_process(
COMMAND "uname" "--machine" OUTPUT_VARIABLE MACHINE_HARDWARE_NAME
COMMAND_ERROR_IS_FATAL LAST)
string(TOLOWER "${MACHINE_HARDWARE_NAME}" MACHINE_HARDWARE_NAME_LOWER)

# vcpkg: Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm,
# s390x, and ppc64le platforms.
# See https://github.com/microsoft/vcpkg-tool/blob/2022-02-24/src/vcpkg.cpp#L257-L266
if((MACHINE_HARDWARE_NAME_LOWER MATCHES "^arm"
OR MACHINE_HARDWARE_NAME_LOWER MATCHES "^aarch64"
OR MACHINE_HARDWARE_NAME_LOWER MATCHES "^s390x"
OR MACHINE_HARDWARE_NAME_LOWER MATCHES "^ppc64"
)
AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows"
AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(ENV{VCPKG_FORCE_SYSTEM_BINARIES} 1)
endif()
cmake_minimum_required(VERSION 3.22)

OPTION(ENABLE_LINUX "Use this switch to enable LINUX" ON)
Expand Down Expand Up @@ -498,10 +517,10 @@ target_include_directories ( aprapipes PRIVATE

# aprapipes Unit Tests

IF (ENABLE_ARM64)
SET(ARM64_UT_FILES
test/jpegencoderl4tm_tests.cpp
test/jpegdecoderl4tm_tests.cpp
# IF (ENABLE_ARM64)
# SET(ARM64_UT_FILES
# test/jpegencoderl4tm_tests.cpp
# test/jpegdecoderl4tm_tests.cpp
# test/l4tm_dec_enc_1_tests.cpp #todo this test needs to be improved to add to jetson suite
test/opencvresize_tests.cpp
test/h264encoderv4l2_tests.cpp
Expand Down Expand Up @@ -615,15 +634,15 @@ IF(ENABLE_LINUX)
ENDIF(ENABLE_LINUX)


add_executable(aprapipesut ${UT_FILES})
# add_executable(aprapipesut ${UT_FILES})

IF(ENABLE_ARM64)
target_include_directories ( aprapipesut PRIVATE ${JETSON_MULTIMEDIA_LIB_INCLUDE} ${FFMPEG_ROOT} ${JPEG_INCLUDE_DIR})
ENDIF(ENABLE_ARM64)
# IF(ENABLE_ARM64)
# target_include_directories ( aprapipesut PRIVATE ${JETSON_MULTIMEDIA_LIB_INCLUDE} ${FFMPEG_ROOT} ${JPEG_INCLUDE_DIR})
# ENDIF(ENABLE_ARM64)

IF (ENABLE_CUDA)
target_include_directories ( aprapipesut PRIVATE ${NVCODEC_INCLUDE_DIR})
ENDIF (ENABLE_CUDA)
# IF (ENABLE_CUDA)
# target_include_directories ( aprapipesut PRIVATE ${NVCODEC_INCLUDE_DIR})
# ENDIF (ENABLE_CUDA)


find_library(OPENH264_LIB NAMES openh264.lib libopenh264.a REQUIRED)
Expand Down
55 changes: 54 additions & 1 deletion base/include/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class Command {
/* NVR Commands */
NVRCommandExportView = 1000,
SendMMQTimestamps,
SendLastGTKGLRenderTS
SendLastGTKGLRenderTS,
DecoderPlaybackSpeed,
ReadyToRender
};

Command() { type = CommandType::None; }
Expand Down Expand Up @@ -372,4 +374,55 @@ class Mp4ErrorHandle : public Command {
ar & previousFile;
ar & nextFile;
}
};

class DecoderPlaybackSpeed : public Command
{
public:
DecoderPlaybackSpeed() : Command(Command::CommandType::DecoderPlaybackSpeed)
{
}

size_t getSerializeSize()
{
return Command::getSerializeSize() + sizeof(playbackFps) + sizeof(playbackSpeed) + sizeof(gop);
}

int playbackFps;
float playbackSpeed;
int gop;

private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* file_version */)
{
ar& boost::serialization::base_object<Command>(*this);
ar& playbackFps;
ar& playbackSpeed;
}
};

class ReadyToRender : public Command
{
public:
ReadyToRender() : Command(Command::CommandType::ReadyToRender)
{
}

size_t getSerializeSize()
{
return Command::getSerializeSize() + sizeof(ReadinessCounter);
}

int ReadinessCounter = 1;

private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* file_version */)
{
ar& boost::serialization::base_object<Command>(*this);
ar& ReadinessCounter;
}
};
36 changes: 18 additions & 18 deletions base/include/GtkGlRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

class GtkGlRendererProps : public ModuleProps {
public:
GtkGlRendererProps(GtkWidget *_glArea, int _windowWidth, int _windowHeight)
: ModuleProps() // take gtk string
{
glArea = _glArea;
windowWidth = _windowWidth;
windowHeight = _windowHeight;
}
GtkWidget *glArea;
int windowWidth = 0;
int windowHeight = 0;
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;
int windowWidth = 0;
int windowHeight = 0;
bool isPlaybackRenderer = true;
};

class GtkGlRenderer : public Module {
Expand All @@ -28,14 +30,12 @@ class GtkGlRenderer : public Module {
bool changeProps(GtkWidget *glArea, int windowWidth, int windowHeight);

protected:
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);
void processQueue();

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;
Expand Down
12 changes: 12 additions & 0 deletions base/include/H264Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class H264Decoder : public Module
bool validateOutputPins();
bool shouldTriggerSOS();
void flushQue();
bool handleCommand(Command::CommandType type, frame_sp& frame);

private:
void bufferDecodedFrames(frame_sp& frame);
Expand Down Expand Up @@ -74,4 +75,15 @@ class H264Decoder : public Module
boost::asio::const_buffer spsBuffer;
boost::asio::const_buffer ppsBuffer;
std::mutex m;
int framesToSkip = 0;
int iFramesToSkip = 0;
int currentFps = 24;
int previousFps = 24;
float playbackSpeed = 1;
int gop;
uint64_t lastFrameSent;
bool resumeFwdPlayback = true;
bool resumeBwdPlayback = true;
bool resumePlayback = true;
int incomingFramesTSQSize = 0;
};
1 change: 1 addition & 0 deletions base/include/Mp4ReaderSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Mp4ReaderSource : public Module
double getOpenVideoFPS();
double getOpenVideoDurationInSecs();
int32_t getOpenVideoFrameCount();
void setPlaybackSpeed(float _playbckSpeed);
void getResolution(uint32_t& width, uint32_t& height)
{
width = mWidth;
Expand Down
29 changes: 29 additions & 0 deletions base/include/MultimediaQueueXform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ class MultimediaQueueXformProps : public ModuleProps
uint32_t upperWaterMark; //Length of the multimedia queue when the next module queue is full
bool isMapDelayInTime;
int mmqFps;

size_t getSerializeSize()
{
return ModuleProps::getSerializeSize() + sizeof(lowerWaterMark) + sizeof(upperWaterMark) + sizeof(isMapDelayInTime) + sizeof(mmqFps);
}

int startIndex;
int maxIndex;
string strFullFileNameWithPattern;
bool readLoop;

private:
friend class boost::serialization::access;

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & boost::serialization::base_object<ModuleProps>(*this);
ar & lowerWaterMark;
ar & upperWaterMark;
ar & isMapDelayInTime;
ar & mmqFps;
}
};

class State;
Expand All @@ -49,6 +72,8 @@ class MultimediaQueueXform : public Module {
boost::shared_ptr<FrameContainerQueue> getQue();
void extractFramesAndEnqueue(boost::shared_ptr<FrameContainerQueue>& FrameQueue);
void setMmqFps(int fps);
void setPlaybackSpeed(float playbackSpeed);
void stopExportFrames();
protected:
bool process(frame_container& frames);
bool validateInputPins();
Expand All @@ -73,4 +98,8 @@ class MultimediaQueueXform : public Module {
uint64_t latestFrameExportedFromHandleCmd = 0;
uint64_t latestFrameExportedFromProcess = 0;
bool initDone = false;
int framesToSkip = 0;
int initialFps = 0;
float speed = 1;
bool exportFrames;
};
2 changes: 1 addition & 1 deletion base/include/ValveModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ValveModuleProps : public ModuleProps
{
public:
ValveModuleProps()
ValveModuleProps()
{

}
Expand Down
105 changes: 34 additions & 71 deletions base/src/GtkGlRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,28 @@ class GtkGlRenderer::Detail {
return true;
}

GtkWidget *glarea;
int windowWidth, windowHeight;
uint64_t frameWidth, frameHeight;
frame_sp cachedFrame, renderFrame;
void *frameToRender;
bool isDmaMem;
bool isMetadataSet;
GtkGlRendererProps mProps;
guint realizeId;
guint renderId;
guint resizeId;
GtkWidget *glarea;
int windowWidth, windowHeight;
uint64_t frameWidth, frameHeight;
frame_sp cachedFrame, renderFrame;
void *frameToRender;
bool isDmaMem;
bool isMetadataSet;
GtkGlRendererProps mProps;
guint realizeId;
guint renderId;
guint resizeId;
bool isPlaybackRenderer = true;
};

GtkGlRenderer::GtkGlRenderer(GtkGlRendererProps props)
: Module(SINK, "GtkGlRenderer", props) {
mDetail.reset(new Detail(props));
mDetail->glarea = props.glArea;
mDetail->windowWidth = props.windowWidth;
mDetail->windowHeight = props.windowHeight;
GtkGlRenderer::GtkGlRenderer(GtkGlRendererProps props) : Module(SINK, "GtkGlRenderer", props)
{
mDetail.reset(new Detail(props));
mDetail->glarea = props.glArea;
mDetail->windowWidth = props.windowWidth;
mDetail->windowHeight = props.windowHeight;
mDetail->isPlaybackRenderer = props.isPlaybackRenderer;
//LOG_ERROR<<"i am creating gtkgl renderer width and height is "<<mDetail->mProps.windowWidth;
}

GtkGlRenderer::~GtkGlRenderer() {}
Expand All @@ -227,68 +230,28 @@ bool GtkGlRenderer::init() {
bool GtkGlRenderer::process(frame_container &frames)

{
auto myId = Module::getId();
auto frame = frames.cbegin()->second;
mDetail->cachedFrame = frame;
size_t underscorePos = myId.find('_');
std::string numericPart = myId.substr(underscorePos + 1);
int myNumber = std::stoi(numericPart);

if ((controlModule != nullptr) && (myNumber % 2 == 1)) {
SendLastGTKGLRenderTS cmd;
auto myTime = frames.cbegin()->second->timestamp;
cmd.currentTimeStamp = myTime;
// Stubbing the eventual application's control module & the
// handleLastGtkGLRenderTS method
boost::shared_ptr<AbsControlModule> ctl =
boost::dynamic_pointer_cast<AbsControlModule>(controlModule);
ctl->handleLastGtkGLRenderTS();
auto myId = Module::getId();
auto frame = frames.cbegin()->second;
mDetail->cachedFrame = frame;


if ((controlModule != nullptr && mDetail->isPlaybackRenderer == true))
{
Rendertimestamp cmd;
auto myTime = frames.cbegin()->second->timestamp;
cmd.currentTimeStamp = myTime;
controlModule->queueCommand(cmd);
LOG_INFO << "sending timestamp "<<myTime;
return true;
}
return true;
}
return true;
}

void GtkGlRenderer::pushFrame(frame_sp frame) {
std::lock_guard<std::mutex> lock(queueMutex);
frameQueue.push(frame);
}

void GtkGlRenderer::processQueue() {
auto currentTime = std::chrono::steady_clock::now();
auto timeDiff = std::chrono::duration_cast<std::chrono::milliseconds>(
currentTime - lastFrameTime)
.count();
std::lock_guard<std::mutex> lock(queueMutex);
if (!frameQueue.empty()) {
auto frame = frameQueue.front();
frameQueue.pop();
auto myId = Module::getId();
if (myId == "GtkGlRenderer_35") {
// LOG_INFO << "time diff is = " << timeDiff << "Timestamp is = " <<
// frame->timestamp;
}

if (timeDiff >= 33) {
mDetail->cachedFrame = frame;
size_t underscorePos = myId.find('_');
std::string numericPart = myId.substr(underscorePos + 1);
int myNumber = std::stoi(numericPart);

if ((controlModule != nullptr) && (myNumber % 2 == 1)) {
SendLastGTKGLRenderTS cmd;
auto myTime = frame->timestamp;
cmd.currentTimeStamp = myTime;
// Stubbing the eventual application's control module & the
// handleLastGtkGLRenderTS method
boost::shared_ptr<AbsControlModule> ctl =
boost::dynamic_pointer_cast<AbsControlModule>(controlModule);
ctl->handleLastGtkGLRenderTS();
}
lastFrameTime = currentTime;
}
}
}

// Need to check on Mem Type Supported
// Already Checked With CPU , Need to check with
// framemetadata_sp metadata = getFirstInputMetadata();
Expand Down
Loading

0 comments on commit 28c2215

Please sign in to comment.