From 130ee2d62e03be2edc88482ba9d497a5fb8b06dd Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Wed, 4 Sep 2024 13:40:40 +0530 Subject: [PATCH 01/11] remove libre & baresip --- base/CMakeLists.txt | 6 ------ base/vcpkg.json | 8 -------- 2 files changed, 14 deletions(-) diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index a0891c043..a463baed0 100755 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -92,8 +92,6 @@ IF(ENABLE_CUDA) find_library(NVBUFUTILSLIB nvbuf_utils REQUIRED) find_library(EGLSTREAM_CAMCONSUMER_LIB nveglstream_camconsumer REQUIRED) find_library(NVARGUS_SOCKETCLINET_LIB nvargus_socketclient REQUIRED) - find_library(LIBRE_LIB NAMES libre.so libre.a REQUIRED) - find_library(BARESIP_LIB NAMES libbaresip.so REQUIRED) find_package(Curses REQUIRED) set(VCPKG_GTK_INCLUDE_DIRS @@ -127,8 +125,6 @@ IF(ENABLE_CUDA) ELSEIF(ENABLE_LINUX) find_library(LIBNVCUVID libnvcuvid.so PATHS /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) find_library(LIBNVENCODE libnvidia-encode.so PATHS /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) - find_library(LIBRE_LIB NAMES libre.so libre.a REQUIRED) - find_library(BARESIP_LIB NAMES libbaresip.so REQUIRED) SET(NVCODEC_LIB ${LIBNVCUVID} ${LIBNVENCODE}) SET(NVCUDAToolkit_LIBS libcuda.so @@ -512,8 +508,6 @@ target_include_directories ( aprapipes PRIVATE ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${LIBMP4_INC_DIR} - ${BARESIP_INC_DIR} - ${LIBRE_INC_DIR} ${NVCODEC_INCLUDE_DIR} ) diff --git a/base/vcpkg.json b/base/vcpkg.json index b030aaefb..86632fbed 100644 --- a/base/vcpkg.json +++ b/base/vcpkg.json @@ -85,14 +85,6 @@ "name": "redis-plus-plus", "platform": "!arm64" }, - { - "name": "re", - "platform": "!windows" - }, - { - "name": "baresip", - "platform": "!windows" - }, { "name": "libmp4" } From 39c24b6c56c08de5469b14db71ef1b80153b3ca9 Mon Sep 17 00:00:00 2001 From: Kushal Jain <155632770+kushaljain-apra@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:44:55 +0530 Subject: [PATCH 02/11] Update H264EncoderNVCodecHelper.cpp --- base/src/H264EncoderNVCodecHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/H264EncoderNVCodecHelper.cpp b/base/src/H264EncoderNVCodecHelper.cpp index c1463b240..6f1226258 100644 --- a/base/src/H264EncoderNVCodecHelper.cpp +++ b/base/src/H264EncoderNVCodecHelper.cpp @@ -603,7 +603,7 @@ class H264EncoderNVCodecHelper::Detail LOG_INFO << "Allocated <" << bufferLength << "> outputbitstreams to the encoder buffer."; m_nvcodecResources->m_nFreeOutputBitstreams += bufferLength; } - else + else if(!m_nvcodecResources->m_nFreeOutputBitstreams) { LOG_INFO << "waiting for free outputbitstream<> busy streams<" << m_nvcodecResources->m_nBusyOutputBitstreams << ">"; } @@ -715,4 +715,4 @@ void H264EncoderNVCodecHelper::endEncode() bool H264EncoderNVCodecHelper::getSPSPPS(void*& buffer, size_t& size, int& width, int& height) { return mDetail->getSPSPPS(buffer, size, width, height); -} \ No newline at end of file +} From e451b0579ea2c9816701159e48cff772a63851d8 Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Tue, 17 Sep 2024 11:43:09 +0530 Subject: [PATCH 03/11] added fix to terminate the control module with the pipeline --- base/src/PipeLine.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index 0bc0f9d79..99f289d99 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -247,6 +247,12 @@ void PipeLine::wait_for_all(bool ignoreStatus) Module& m = *(i->get()); m.myThread.join(); } + + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } } @@ -264,11 +270,24 @@ void PipeLine::interrup_wait_for_all() m.myThread.interrupt(); } + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.interrupt(); + } + for (auto i = modules.begin(); i != modules.end(); i++) { Module& m = *(i->get()); m.myThread.join(); } + + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } + myStatus = PL_STOPPED; } From 94c9c0f8037560cd9c6bb44c95d0a95c90f231ec Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Tue, 17 Sep 2024 12:28:15 +0530 Subject: [PATCH 04/11] fix typo --- base/include/PipeLine.h | 2 +- base/src/PipeLine.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/base/include/PipeLine.h b/base/include/PipeLine.h index b47b0d035..f15dad608 100755 --- a/base/include/PipeLine.h +++ b/base/include/PipeLine.h @@ -47,7 +47,7 @@ class PipeLine { void stop(); void term(); void wait_for_all(bool ignoreStatus = false); - void interrup_wait_for_all(); + void interrupt_wait_for_all(); void flushAllQueues(); const char* getStatus(); }; diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index 99f289d99..dc128efdc 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -161,7 +161,7 @@ void PipeLine::run_all_threaded() } if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule); + Module& m = *(modules[0]->controlModule->get()); m.myThread = boost::thread(ref(m)); } mPlay = true; @@ -250,13 +250,13 @@ void PipeLine::wait_for_all(bool ignoreStatus) if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule); + Module& m = *(modules[0]->controlModule->get()); m.myThread.join(); } } -void PipeLine::interrup_wait_for_all() +void PipeLine::interrupt_wait_for_all() { if (myStatus > PL_STOPPING) { @@ -272,7 +272,7 @@ void PipeLine::interrup_wait_for_all() if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule); + Module& m = *(modules[0]->controlModule->get()); m.myThread.interrupt(); } @@ -284,7 +284,7 @@ void PipeLine::interrup_wait_for_all() if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule); + Module& m = *(modules[0]->controlModule->get()); m.myThread.join(); } From b9a5ea2ca59f1f42d9cc50eb4e802a1071357fe9 Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Tue, 17 Sep 2024 12:52:14 +0530 Subject: [PATCH 05/11] revert changes --- base/src/PipeLine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index dc128efdc..ac71af661 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -161,7 +161,7 @@ void PipeLine::run_all_threaded() } if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule->get()); + Module& m = *(modules[0]->controlModule); m.myThread = boost::thread(ref(m)); } mPlay = true; @@ -250,7 +250,7 @@ void PipeLine::wait_for_all(bool ignoreStatus) if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule->get()); + Module& m = *(modules[0]->controlModule); m.myThread.join(); } } @@ -272,7 +272,7 @@ void PipeLine::interrupt_wait_for_all() if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule->get()); + Module& m = *(modules[0]->controlModule); m.myThread.interrupt(); } @@ -284,7 +284,7 @@ void PipeLine::interrupt_wait_for_all() if ((modules[0]->controlModule) != nullptr) { - Module& m = *(modules[0]->controlModule->get()); + Module& m = *(modules[0]->controlModule); m.myThread.join(); } From 42550e305c609d0e9fd7f368db5a1f489607e9ae Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Tue, 17 Sep 2024 18:00:36 +0530 Subject: [PATCH 06/11] update pipeline.cpp to stop and terminate control module with pipeline --- base/src/PipeLine.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index ac71af661..2a5ae6382 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -232,6 +232,11 @@ void PipeLine::stop() i->get()->stop(); } } + + if ((modules[0]->controlModule) != nullptr) + { + modules[0]->controlModule->stop(); + } } void PipeLine::wait_for_all(bool ignoreStatus) @@ -242,15 +247,15 @@ void PipeLine::wait_for_all(bool ignoreStatus) return; } - for (auto i = modules.begin(); i != modules.end(); i++) + if ((modules[0]->controlModule) != nullptr) { - Module& m = *(i->get()); + Module& m = *(modules[0]->controlModule); m.myThread.join(); } - if ((modules[0]->controlModule) != nullptr) + for (auto i = modules.begin(); i != modules.end(); i++) { - Module& m = *(modules[0]->controlModule); + Module& m = *(i->get()); m.myThread.join(); } } @@ -264,12 +269,6 @@ void PipeLine::interrupt_wait_for_all() return; } - for (auto i = modules.begin(); i != modules.end(); i++) - { - Module& m = *(i->get()); - m.myThread.interrupt(); - } - if ((modules[0]->controlModule) != nullptr) { Module& m = *(modules[0]->controlModule); @@ -279,7 +278,7 @@ void PipeLine::interrupt_wait_for_all() for (auto i = modules.begin(); i != modules.end(); i++) { Module& m = *(i->get()); - m.myThread.join(); + m.myThread.interrupt(); } if ((modules[0]->controlModule) != nullptr) @@ -288,6 +287,12 @@ void PipeLine::interrupt_wait_for_all() m.myThread.join(); } + for (auto i = modules.begin(); i != modules.end(); i++) + { + Module& m = *(i->get()); + m.myThread.join(); + } + myStatus = PL_STOPPED; } From 65dd52abcd768a2f47d95a73b7bdf344c024b8f8 Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Thu, 26 Sep 2024 12:32:59 +0530 Subject: [PATCH 07/11] uncomment nvr related comments --- base/src/H264Decoder.cpp | 8 ++++---- base/src/NvTransform.cpp | 2 +- base/src/PipeLine.cpp | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/base/src/H264Decoder.cpp b/base/src/H264Decoder.cpp index 44c434a7b..8276b7c87 100644 --- a/base/src/H264Decoder.cpp +++ b/base/src/H264Decoder.cpp @@ -735,10 +735,10 @@ bool H264Decoder::processEOS(string& pinId) { //THIS HAS BEEN COMMENTED IN NVR - BECAUSE EOS IS SENT FROM MP4READER WHICH COMES TO DECODER AND THE FOLLOWING PROCESS IS NOT REQUIRED IN NVR. - // auto frame = frame_sp(new EmptyFrame()); - // mDetail->compute(frame->data(), frame->size(), frame->timestamp); - // LOG_ERROR << "processes sos " ; - //mShouldTriggerSOS = true; + auto frame = frame_sp(new EmptyFrame()); + mDetail->compute(frame->data(), frame->size(), frame->timestamp); + LOG_ERROR << "processes sos " ; + mShouldTriggerSOS = true; return true; } diff --git a/base/src/NvTransform.cpp b/base/src/NvTransform.cpp index 9e194e080..299d809a8 100644 --- a/base/src/NvTransform.cpp +++ b/base/src/NvTransform.cpp @@ -260,6 +260,6 @@ void NvTransform::setMetadata(framemetadata_sp &metadata) bool NvTransform::processEOS(string &pinId) { //THE FOLLOWING LINE IS COMMENTED FOR SPECIFIC USE IN NVR - MP4READER PASSING EOS WAS COMING HERE AND CAUSING EOS WHICH IS NOT REQUIRED FOR NVR - // mDetail->outputMetadata.reset(); + mDetail->outputMetadata.reset(); return true; } \ No newline at end of file diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index 2a5ae6382..ab36aee64 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -163,6 +163,7 @@ void PipeLine::run_all_threaded() { Module& m = *(modules[0]->controlModule); m.myThread = boost::thread(ref(m)); + Utils::setModuleThreadName(m.myThread, m.getId()); } mPlay = true; } From debf2b98468194ab87fa5f7b4ae862e26991a285 Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Thu, 26 Sep 2024 14:05:21 +0530 Subject: [PATCH 08/11] remove pipeline modules in pipeline.cpp --- base/src/H264DecoderNvCodecHelper.cpp | 1 - base/src/H264Utils.cpp | 2 ++ base/src/PipeLine.cpp | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/H264DecoderNvCodecHelper.cpp b/base/src/H264DecoderNvCodecHelper.cpp index 562d6326b..5f520aadc 100644 --- a/base/src/H264DecoderNvCodecHelper.cpp +++ b/base/src/H264DecoderNvCodecHelper.cpp @@ -1,4 +1,3 @@ -#pragma once #include #include #include diff --git a/base/src/H264Utils.cpp b/base/src/H264Utils.cpp index 2885a22d4..9a1fb3c1e 100644 --- a/base/src/H264Utils.cpp +++ b/base/src/H264Utils.cpp @@ -111,4 +111,6 @@ H264Utils::H264_NAL_TYPE H264Utils::getNalTypeAfterSpsPps(void* frameData, size_ } } } + + return typeFound; } diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index ab36aee64..d1f476d87 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -37,7 +37,6 @@ bool PipeLine::addControlModule(boost::shared_ptr cModule) for (int i = 0; i < modules.size(); i++) { modules[i]->addControlModule(cModule); - cModule->pipelineModules.push_back(modules[i]); } return true; } From 405891dce4993f49f28c5d88218ec052ddd5db96 Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Thu, 26 Sep 2024 14:40:09 +0530 Subject: [PATCH 09/11] revert decoder changes --- base/src/H264Decoder.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/src/H264Decoder.cpp b/base/src/H264Decoder.cpp index 8276b7c87..c83570269 100644 --- a/base/src/H264Decoder.cpp +++ b/base/src/H264Decoder.cpp @@ -735,10 +735,10 @@ bool H264Decoder::processEOS(string& pinId) { //THIS HAS BEEN COMMENTED IN NVR - BECAUSE EOS IS SENT FROM MP4READER WHICH COMES TO DECODER AND THE FOLLOWING PROCESS IS NOT REQUIRED IN NVR. - auto frame = frame_sp(new EmptyFrame()); - mDetail->compute(frame->data(), frame->size(), frame->timestamp); - LOG_ERROR << "processes sos " ; - mShouldTriggerSOS = true; + // auto frame = frame_sp(new EmptyFrame()); + // mDetail->compute(frame->data(), frame->size(), frame->timestamp); + // LOG_ERROR << "processes sos " ; + // mShouldTriggerSOS = true; return true; } From dbbf63712db7ecb3b615f112ddf0bd16ff9d4a8e Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Thu, 26 Sep 2024 19:36:13 +0530 Subject: [PATCH 10/11] update h264 nvcodec decoder to destroy context --- base/src/H264DecoderNvCodecHelper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/src/H264DecoderNvCodecHelper.cpp b/base/src/H264DecoderNvCodecHelper.cpp index 5f520aadc..6a07b5887 100644 --- a/base/src/H264DecoderNvCodecHelper.cpp +++ b/base/src/H264DecoderNvCodecHelper.cpp @@ -562,6 +562,14 @@ NvDecoder::~NvDecoder() { delete[] pFrame; } } + + if(m_cuContext) + { + if (m_pMutex) m_pMutex->lock(); + cuCtxDestroy(m_cuContext); + if (m_pMutex) m_pMutex->unlock(); + } + STOP_TIMER("Session Deinitialization Time: "); } From af79ad04811777c6269395778c4c5dcc7ac1828b Mon Sep 17 00:00:00 2001 From: Kushal Jain Date: Tue, 1 Oct 2024 12:38:19 +0530 Subject: [PATCH 11/11] revert changes specific to NVR --- base/src/H264Decoder.cpp | 10 ++++------ base/src/NvTransform.cpp | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/base/src/H264Decoder.cpp b/base/src/H264Decoder.cpp index c83570269..90055057e 100644 --- a/base/src/H264Decoder.cpp +++ b/base/src/H264Decoder.cpp @@ -733,12 +733,10 @@ bool H264Decoder::shouldTriggerSOS() bool H264Decoder::processEOS(string& pinId) { - //THIS HAS BEEN COMMENTED IN NVR - BECAUSE EOS IS SENT FROM MP4READER WHICH COMES TO DECODER AND THE FOLLOWING PROCESS IS NOT REQUIRED IN NVR. - - // auto frame = frame_sp(new EmptyFrame()); - // mDetail->compute(frame->data(), frame->size(), frame->timestamp); - // LOG_ERROR << "processes sos " ; - // mShouldTriggerSOS = true; + auto frame = frame_sp(new EmptyFrame()); + mDetail->compute(frame->data(), frame->size(), frame->timestamp); + LOG_ERROR << "processes sos " ; + mShouldTriggerSOS = true; return true; } diff --git a/base/src/NvTransform.cpp b/base/src/NvTransform.cpp index 299d809a8..96773627b 100644 --- a/base/src/NvTransform.cpp +++ b/base/src/NvTransform.cpp @@ -259,7 +259,6 @@ void NvTransform::setMetadata(framemetadata_sp &metadata) bool NvTransform::processEOS(string &pinId) { - //THE FOLLOWING LINE IS COMMENTED FOR SPECIFIC USE IN NVR - MP4READER PASSING EOS WAS COMING HERE AND CAUSING EOS WHICH IS NOT REQUIRED FOR NVR mDetail->outputMetadata.reset(); return true; } \ No newline at end of file