diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index a52c2a762..938d3e688 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 @@ -519,8 +515,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/src/H264Decoder.cpp b/base/src/H264Decoder.cpp index 44c434a7b..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/H264DecoderNvCodecHelper.cpp b/base/src/H264DecoderNvCodecHelper.cpp index 562d6326b..6a07b5887 100644 --- a/base/src/H264DecoderNvCodecHelper.cpp +++ b/base/src/H264DecoderNvCodecHelper.cpp @@ -1,4 +1,3 @@ -#pragma once #include #include #include @@ -563,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: "); } 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 +} 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/NvTransform.cpp b/base/src/NvTransform.cpp index 9e194e080..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(); + mDetail->outputMetadata.reset(); return true; } \ No newline at end of file diff --git a/base/src/PipeLine.cpp b/base/src/PipeLine.cpp index 83998c154..51b750f23 100755 --- a/base/src/PipeLine.cpp +++ b/base/src/PipeLine.cpp @@ -256,6 +256,12 @@ void PipeLine::wait_for_all(bool ignoreStatus) return; } + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } + for (auto i = modules.begin(); i != modules.end(); i++) { Module& m = *(i->get()); @@ -277,12 +283,24 @@ void PipeLine::interrupt_wait_for_all() return; } + 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.interrupt(); } + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } + for (auto i = modules.begin(); i != modules.end(); i++) { Module& m = *(i->get()); 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" } diff --git a/knowledge_docs/H264_Decoder_Fixes.md b/knowledge_docs/H264_Decoder_Fixes.md new file mode 100644 index 000000000..ae022a6ce --- /dev/null +++ b/knowledge_docs/H264_Decoder_Fixes.md @@ -0,0 +1,143 @@ +# Changes from Main Branch + +This document summarizes the actual changes made in the current branch compared to the main branch. + +## Modified Files + +### 1. base/CMakeLists.txt +- Removed dependencies: + ```cmake + # Removed libre and baresip libraries + - find_library(LIBRE_LIB NAMES libre.so libre.a REQUIRED) + - find_library(BARESIP_LIB NAMES libbaresip.so REQUIRED) + ``` +- Removed include directories: + ```cmake + target_include_directories ( aprapipes PRIVATE + # Removed baresip and libre includes + - ${BARESIP_INC_DIR} + - ${LIBRE_INC_DIR} + ) + ``` + +### 2. base/src/H264Decoder.cpp +- Uncommented EOS processing code: + ```cpp + bool H264Decoder::processEOS(string& pinId) + { + auto frame = frame_sp(new EmptyFrame()); + mDetail->compute(frame->data(), frame->size(), frame->timestamp); + LOG_ERROR << "processes sos " ; + mShouldTriggerSOS = true; + return true; + } + ``` + +### 3. base/src/H264DecoderNvCodecHelper.cpp +- Added CUDA context cleanup in destructor: + ```cpp + NvDecoder::~NvDecoder() { + // Added CUDA context cleanup + if(m_cuContext) + { + if (m_pMutex) m_pMutex->lock(); + cuCtxDestroy(m_cuContext); + if (m_pMutex) m_pMutex->unlock(); + } + } + ``` + +### 4. base/src/H264EncoderNVCodecHelper.cpp +- Modified output bitstream handling: + ```cpp + // Changed condition for waiting on free output bitstreams + - else + + else if(!m_nvcodecResources->m_nFreeOutputBitstreams) + { + LOG_INFO << "waiting for free outputbitstream<> busy streams<" << m_nvcodecResources->m_nBusyOutputBitstreams << ">"; + } + ``` + +### 5. base/src/H264Utils.cpp +- Added return value for getNalTypeAfterSpsPps: + ```cpp + H264Utils::H264_NAL_TYPE H264Utils::getNalTypeAfterSpsPps(void* frameData, size_t frameSize) + { + // Added missing return statement + return typeFound; + } + ``` + +### 6. base/src/NvTransform.cpp +- Uncommented metadata reset in processEOS: + ```cpp + bool NvTransform::processEOS(string &pinId) + { + mDetail->outputMetadata.reset(); + return true; + } + ``` + +### 7. base/src/PipeLine.cpp +- Added control module thread handling: + ```cpp + void PipeLine::wait_for_all(bool ignoreStatus) + { + // Added control module thread join + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } + } + + void PipeLine::interrupt_wait_for_all() + { + // Added control module thread interrupt and join + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.interrupt(); + } + // ... existing code ... + if ((modules[0]->controlModule) != nullptr) + { + Module& m = *(modules[0]->controlModule); + m.myThread.join(); + } + } + ``` + +### 8. base/vcpkg.json +- Removed platform-specific dependencies: + ```json + // Removed re and baresip dependencies + - { + - "name": "re", + - "platform": "!windows" + - }, + - { + - "name": "baresip", + - "platform": "!windows" + - } + ``` + +## Summary of Changes + +1. **Dependency Updates** + - Removed libre and baresip libraries and includes + - Removed platform-specific dependencies from vcpkg.json + +2. **Code Improvements** + - Added proper CUDA context cleanup in NVIDIA decoder + - Fixed missing return value in H264Utils + - Improved output bitstream handling in encoder + - Enhanced thread management for control module + - Uncommented and enabled EOS processing in decoder and transform + +3. **Application-Specific Changes** + - Removed Application-specific comments and restrictions + - Enabled EOS processing that was previously disabled for Application + - Enabled metadata reset in transform that was previously disabled for Application + +These changes focus on cleaning up dependencies, improving resource management, and removing Application-specific restrictions while maintaining proper cleanup and error handling. \ No newline at end of file