Skip to content

Commit

Permalink
Merge branch 'main' into yash/CallbackImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
mraduldubey authored Jul 30, 2024
2 parents 0450430 + 7b852c8 commit 4fef791
Show file tree
Hide file tree
Showing 19 changed files with 362 additions and 110 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI-Linux-ARM64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
NOTE_TO_SELF: "environments can not be passed from here to reused workflows!"
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
jetson-build-test:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/CI-Linux-CUDA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
NOTE_TO_SELF: "environments can not be passed from here to reused workflows!"
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
linux-cuda-build-test:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-lin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
env:
TEST_EXE: build/aprapipesut
CMAKE_TC_FILE: '../vcpkg/scripts/buildsystems/vcpkg.cmake' # Note: naming this variable as CMAKE_TOOLCHAIN_FILE can cause havoc!!!
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
runs-on: ${{ inputs.runner }}
steps:
- name: Prepare builder
Expand Down
64 changes: 38 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A pipeline framework for developing video and image processing applications. Sup
Learn more about ApraPipes here https://apra-labs.github.io/ApraPipes.

## Build status
Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson Boards (Jetpack 4.4) and Windows (11) x64 Visual Studio 2017 Community.
Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson Boards (Jetpack 4.4) and Windows (11) x64 Visual Studio 2019 Community.
|OS|Version|With Cuda|Tests|Status|
|--|-------|---------|------|------|
|Windows|2019|No|[![Test Results](https://gist.githubusercontent.com/kumaakh/f80af234a4aabedc69af3ee197f66944/raw/badge_Windows.svg)](https://gist.githubusercontent.com/kumaakh/f80af234a4aabedc69af3ee197f66944/raw/badge_Windows.svg)|[![CI-Win-NoCUDA](https://github.com/Apra-Labs/ApraPipes/actions/workflows/CI-Win-NoCUDA.yml/badge.svg)](https://github.com/Apra-Labs/ApraPipes/actions/workflows/CI-Win-NoCUDA.yml)|
Expand Down Expand Up @@ -40,22 +40,24 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
<details>
<summary>Requirements</summary>

### Prerequisites

### Visual Studio
* Install Visual Studio 2019 Community
* Install Desktop development C++
* .NET Desktop development
* Universal Windows Development Platform

### Cuda
* Create an account on developer.nvidia.com if you're not already a member. Note : Otherwise the next step will show HTTP 404/403 error.
* Windows 10/11 : [Cuda Toolkit 10.2](https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal) or [CUDA Toolkit 11.8](https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Windows).

### Cudnn
* Download [Cudnn](https://developer.nvidia.com/rdp/cudnn-archive#a-collapse765-102) and extract files where cuda is installed. Note: Please be aware that this process requires some effort. Here are the necessary steps:
* Download the correct zip file matching your cuda version. _Do not download the exe/installer/deb package._
* Windows:
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-windows-x86_64-8.3.2.44_cuda10.2-archive.zip).

### Prerequisites
* Install Visual Studio 2019 Community
* Install Desktop development C++
* .NET Desktop development
* Universal Windows Development Platform

* Download the correct zip file matching your cuda version. _Do not download the exe/installer/deb package._
* Windows:
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-windows-x86_64-8.3.2.44_cuda10.2-archive.zip).

* Clone with submodules and LFS.
```
git clone --recursive https://github.com/Apra-Labs/ApraPipes.git
Expand All @@ -66,9 +68,9 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
<details>
<summary>Build</summary>

### Build Without Cuda
Open PowerShell as an administrator and execute the following commands

### Build Without Cuda
If your windows system does not have an NVIDIA GPU use this script
```
build_windows_no_cuda.bat
Expand All @@ -77,7 +79,10 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
```
build_windows_cuda.bat
```

### To Build With Documentation
```
build_windows_cuda.bat --build-doc
```
</details>

<details>
Expand Down Expand Up @@ -114,6 +119,8 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
<details>
<summary>Requirements</summary>

### Prerequisites

### Cuda
* Create an account on developer.nvidia.com if you're not already a member. Note : Otherwise the next step will show HTTP 404/403 error.
* Ubuntu 18.04/20.04:
Expand All @@ -125,7 +132,8 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
* Linux:
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-linux-x86_64-8.3.2.44_cuda10.2-archive.tar.xz)

### Prerequisites
* Clone with submodules and LFS.
```
git clone --recursive https://github.com/Apra-Labs/ApraPipes.git
```

Expand All @@ -141,11 +149,15 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
### Build Without Cuda
If your windows system does not have an NVIDIA GPU use this script
```
sudo ./build_linux_no_cuda.sh
./build_linux_no_cuda.sh
```
### Build With Cuda
```
sudo ./build_linux_cuda.sh
./build_linux_cuda.sh
```
### To Build With Documentation
```
./build_linux_cuda.sh --build-doc
```

Build can take ~2 hours depending on the machine configuration.
Expand Down Expand Up @@ -200,11 +212,14 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
```
chmod +x build_jetson.sh
```
* ApraPipes builds CUDA version on Jerson Boads.
* ApraPipes builds CUDA version on Jetson Boards.
```
sudo ./build_jetson.sh
./build_jetson.sh
```
* To Build With Documentation
```
./build_jetson.sh --build-doc
```
Build can take ~12 hours on Jetson Nano.
Note: Jetson build can also be done using Ubuntu 18.04 x86_64 Laptop via cross compilation.
</details>
Expand Down Expand Up @@ -290,13 +305,10 @@ This build will be fairly fast (~10 mins) as entire vcpkg cache comes down with
git submodule update --init --recursive
```
## Update Documentation
After making changes to the documentation located in the /docs/source folder, it's essential to regenerate the documentation by following the provided steps. Once regenerated, commit the new content to ensure the latest documentation is up-to-date.
To update documentation, refer to Documentation Guidelines in the [Contribution-Guidelines](https://github.com/Apra-Labs/ApraPipes/wiki/Contribution-Guidelines).

### To regenerate documentation
Run,
```
./build_documentation.sh
```
To build docs
apt-install get python-sphinx
pip install sphinx-rtd-theme
cd docs
make html
```
1 change: 1 addition & 0 deletions base/include/AbsControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AbsControlModule : public Module {
boost::container::deque<boost::shared_ptr<Module>> pipelineModules;
std::map<std::string, boost::shared_ptr<Module>> moduleRoles;


protected:
bool process(frame_container& frames);
bool handleCommand(Command::CommandType type, frame_sp& frame);
Expand Down
58 changes: 49 additions & 9 deletions base/include/H264EncoderNVCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,70 @@
#include "Module.h"
#include "CudaCommon.h"

/**
* @brief Properties for the H264 encoder using NVCodec.
*/
class H264EncoderNVCodecProps : public ModuleProps
{
public:
/**
* @enum H264CodecProfile
* @brief Enum representing different H.264 codec profiles.
*/
enum H264CodecProfile
{
BASELINE,
MAIN,
HIGH,
BASELINE, /**< Baseline profile */
MAIN, /**< Main profile */
HIGH, /**< High profile */
};

/**
* @brief Constructor for H264EncoderNVCodecProps with all parameters.
*
* @param _bitRateKbps Bit rate in kilobits per second.
* @param _cuContext CUDA context.
* @param _gopLength Group of Pictures (GOP) length.
* @param _frameRate Frame rate.
* @param _vProfile Video profile from H264CodecProfile enum.
* @param _enableBFrames Enable or disable B-frames.
*/
H264EncoderNVCodecProps(const uint32_t &_bitRateKbps, const apracucontext_sp& _cuContext, const uint32_t &_gopLength,const uint32_t &_frameRate,H264CodecProfile _vProfile,bool _enableBFrames)
: cuContext(_cuContext), gopLength(_gopLength), frameRate(_frameRate), bitRateKbps(_bitRateKbps), vProfile(_vProfile), enableBFrames(_enableBFrames)
{
}

/**
* @brief Constructor for H264EncoderNVCodecProps with default bit rate.
*
* @param _cuContext CUDA context.
*/
H264EncoderNVCodecProps(apracucontext_sp& _cuContext) : bitRateKbps(0), cuContext(_cuContext)
{
}

/**
* @brief Constructor for H264EncoderNVCodecProps with buffer threshold.
*
* @param _bitRateKbps Bit rate in kilobits per second.
* @param _cuContext CUDA context.
* @param _gopLength Group of Pictures (GOP) length.
* @param _frameRate Frame rate.
* @param _vProfile Video profile from H264CodecProfile enum.
* @param _enableBFrames Enable or disable B-frames.
* @param _bufferThres Buffer threshold.
*/
H264EncoderNVCodecProps(const uint32_t &_bitRateKbps, const apracucontext_sp& _cuContext, const uint32_t &_gopLength,const uint32_t &_frameRate,H264CodecProfile _vProfile,bool _enableBFrames, uint32_t &_bufferThres)
: cuContext(_cuContext), gopLength(_gopLength), frameRate(_frameRate), bitRateKbps(_bitRateKbps), vProfile(_vProfile), enableBFrames(_enableBFrames), bufferThres(_bufferThres)
{
}
H264CodecProfile vProfile= H264EncoderNVCodecProps::BASELINE;
bool enableBFrames=false;
uint32_t gopLength = 30;
uint32_t bitRateKbps = 1000;
uint32_t frameRate = 30;
apracucontext_sp cuContext;

H264CodecProfile vProfile = H264EncoderNVCodecProps::BASELINE; /**< Video profile. */
bool enableBFrames = false; /**< Enable or disable B-frames. */
uint32_t gopLength = 30; /**< Group of Pictures (GOP) length. */
uint32_t bitRateKbps = 1000; /**< Bit rate in kilobits per second. */
uint32_t frameRate = 30; /**< Frame rate. */
apracucontext_sp cuContext; /**< CUDA context. */
uint32_t bufferThres = 30; /**< Buffer threshold. */
};

class H264EncoderNVCodec : public Module
Expand Down
69 changes: 69 additions & 0 deletions base/include/H264EncoderNVCodecHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,88 @@
#include "CommonDefs.h"
#include "CudaCommon.h"
#include "H264EncoderNVCodec.h"

/**
* @brief Helper class for H264 encoding using NVCodec.
*/
class H264EncoderNVCodecHelper
{
public:
/**
* @brief Constructor for H264EncoderNVCodecHelper.
*
* @param _bitRateKbps Bit rate in kilobits per second.
* @param _cuContext CUDA context.
* @param _gopLength Group of Pictures (GOP) length.
* @param _frameRate Frame rate.
* @param _profile Video profile from H264EncoderNVCodecProps::H264CodecProfile enum.
* @param enableBFrames Enable or disable B-frames.
*/
H264EncoderNVCodecHelper(uint32_t _bitRateKbps, apracucontext_sp& _cuContext, uint32_t _gopLength, uint32_t _frameRate,H264EncoderNVCodecProps::H264CodecProfile _profile, bool enableBFrames);

/**
* @brief Constructor for H264EncoderNVCodecHelper with buffer threshold.
*
* @param _bitRateKbps Bit rate in kilobits per second.
* @param _cuContext CUDA context.
* @param _gopLength Group of Pictures (GOP) length.
* @param _frameRate Frame rate.
* @param _profile Video profile from H264EncoderNVCodecProps::H264CodecProfile enum.
* @param enableBFrames Enable or disable B-frames.
* @param _bufferThres Buffer threshold.
*/
H264EncoderNVCodecHelper(uint32_t _bitRateKbps, apracucontext_sp& _cuContext, uint32_t _gopLength, uint32_t _frameRate,H264EncoderNVCodecProps::H264CodecProfile _profile, bool enableBFrames, uint32_t _bufferThres);

/**
* @brief Destructor for H264EncoderNVCodecHelper.
*/
~H264EncoderNVCodecHelper();

/**
* @brief Initialize the encoder.
*
* @param width Frame width.
* @param height Frame height.
* @param pitch Frame pitch.
* @param imageType Type of the image from ImageMetadata::ImageType.
* @param makeFrame Function to create a frame.
* @param send Function to send a frame.
* @return True if initialization was successful, false otherwise.
*/
bool init(uint32_t width, uint32_t height, uint32_t pitch, ImageMetadata::ImageType imageType, std::function<frame_sp(size_t)> makeFrame, std::function<void(frame_sp& ,frame_sp&)> send);

/**
* @brief Process a frame.
*
* @param frame Frame to process.
* @return True if the frame was processed successfully, false otherwise.
*/
bool process(frame_sp &frame);

/**
* @brief End encoding.
*/
void endEncode();

/**
* @brief Get SPS and PPS data.
*
* @param buffer Pointer to buffer to store SPS and PPS data.
* @param size Size of the buffer.
* @param width Width of the frame.
* @param height Height of the frame.
* @return True if SPS and PPS data was retrieved successfully, false otherwise.
*/
bool getSPSPPS(void*& buffer, size_t& size, int& width, int& height);

private:
/**
* @brief Internal detail class.
*/
class Detail;

/**
* @brief Shared pointer to the internal detail class.
*/
boost::shared_ptr<Detail> mDetail;
};
3 changes: 2 additions & 1 deletion base/src/AbsControlModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ bool AbsControlModule::enrollModule(std::string role, boost::shared_ptr<Module>
{
if (moduleRoles.find(role) != moduleRoles.end())
{
throw AIPException(CTRL_MODULE_INVALID_STATE, "Role already registered with the control module.");
LOG_ERROR << "Role already registered with the control module."
return false;
}

moduleRoles[role] = module;
Expand Down
11 changes: 10 additions & 1 deletion base/src/H264EncoderNVCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
#include "nvEncodeAPI.h"
#include "Command.h"

#define DEFAULT_BUFFER_THRESHOLD 30

class H264EncoderNVCodec::Detail
{
public:
Detail(H264EncoderNVCodecProps &_props) : mProps(_props)
{
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames));
if(_props.bufferThres == DEFAULT_BUFFER_THRESHOLD)
{
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames));
}
else
{
helper.reset(new H264EncoderNVCodecHelper(_props.bitRateKbps, _props.cuContext,_props.gopLength,_props.frameRate,_props.vProfile,_props.enableBFrames,_props.bufferThres));
}
}

~Detail()
Expand Down
Loading

0 comments on commit 4fef791

Please sign in to comment.