Skip to content

Commit

Permalink
Merge pull request #339 from shiguredo/feature/nvcodec-h265
Browse files Browse the repository at this point in the history
NVIDIA Video Codec SDK を H.265 に対応する
  • Loading branch information
melpon authored Jun 13, 2024
2 parents 26ff622 + 428adb5 commit 8dde3ad
Show file tree
Hide file tree
Showing 66 changed files with 1,313 additions and 1,048 deletions.
10 changes: 6 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Windows",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/src/hwenc/include",
"${workspaceFolder}/src/sora-cpp-sdk/include",
"${workspaceFolder}/third_party/NvCodec/include",
"${workspaceFolder}/third_party/NvCodec/NvCodec",
"${workspaceFolder}/_install/windows_x86_64/release/webrtc/include",
Expand All @@ -16,15 +16,17 @@
"${workspaceFolder}/_install/windows_x86_64/release/cli11/include",
"${workspaceFolder}/_install/windows_x86_64/release/sdl2/include/SDL2",
"${workspaceFolder}/_install/windows_x86_64/release/vpl/include",
"${workspaceFolder}/_install/windows_x86_64/release/cuda/include",
"${workspaceFolder}/_build/windows_x86_64/release/momo"
],
"defines": [
"WIN32_LEAN_AND_MEAN",
"NOMINMAX",
"WEBRTC_WINDOWS",
"WEBRTC_WIN",
"USE_NVCODEC_ENCODER",
"USE_VPL_ENCODER",
"USE_SCREEN_CAPTURER"
"USE_SCREEN_CAPTURER",
"RTC_ENABLE_H265"
],
"cStandard": "c11",
"cppStandard": "c++17",
Expand All @@ -34,7 +36,7 @@
"name": "Ubuntu 22.04 x86_64",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/src/hwenc/include",
"${workspaceFolder}/src/sora-cpp-sdk/include",
"${workspaceFolder}/third_party/NvCodec/include",
"${workspaceFolder}/third_party/NvCodec/NvCodec",
"${workspaceFolder}/_install/ubuntu-22.04_x86_64/release/webrtc/include",
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
- @torikizi
- [ADD] ubuntu-22.04_armv8_jetson のパッケージを追加
- @melpon
- [ADD] Intel VPL の H.265 ハードウェアエンコーダ/デコーダに対応する
- @melpon
- [ADD] NVIDIA Video Codec SDK の H.265 ハードウェアエンコーダ/デコーダに対応する
- @melpon

## 2023.1.0

Expand Down
53 changes: 27 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ string(SUBSTRING "${MOMO_COMMIT}" 0 8 MOMO_COMMIT_SHORT)
string(SUBSTRING "${WEBRTC_COMMIT}" 0 8 WEBRTC_COMMIT_SHORT)
configure_file(src/momo_version.gen.h.template ${CMAKE_CURRENT_BINARY_DIR}/momo_version.gen.h)
target_include_directories(momo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(momo PRIVATE src/hwenc/include)
target_include_directories(momo PRIVATE src/sora-cpp-sdk/include)

target_sources(momo
PRIVATE
Expand All @@ -117,9 +117,9 @@ target_sources(momo
src/rtc/rtc_connection.cpp
src/rtc/rtc_manager.cpp
src/rtc/rtc_ssl_verifier.cpp
src/rtc/scalable_track_source.cpp
src/serial_data_channel/serial_data_channel.cpp
src/serial_data_channel/serial_data_manager.cpp
src/sora-cpp-sdk/src/scalable_track_source.cpp
src/sora/sora_client.cpp
src/sora/sora_server.cpp
src/sora/sora_session.cpp
Expand Down Expand Up @@ -281,10 +281,10 @@ if ("${TARGET_OS}" STREQUAL "windows")
if (USE_NVCODEC_ENCODER)
target_sources(momo
PRIVATE
src/hwenc_nvcodec/nvcodec_h264_encoder.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_encoder.cpp
third_party/NvCodec/NvCodec/NvEncoder/NvEncoder.cpp
third_party/NvCodec/NvCodec/NvEncoder/NvEncoderD3D11.cpp
src/hwenc_nvcodec/nvcodec_video_decoder.cpp)
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_decoder.cpp)
target_include_directories(momo
PRIVATE
third_party/NvCodec/include
Expand All @@ -303,16 +303,16 @@ if ("${TARGET_OS}" STREQUAL "windows")
find_package(CUDA REQUIRED)

set_source_files_properties(
src/cuda/cuda_context_cuda.cpp
src/sora-cpp-sdk/src/cuda_context_cuda.cpp
third_party/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT OBJ
)
cuda_compile(CUDA_FILES
src/cuda/cuda_context_cuda.cpp
src/sora-cpp-sdk/src/cuda_context_cuda.cpp
third_party/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
OPTIONS
# VS 2022 の 17.10.x 以上に上げると、ツールセットのバージョンが 14.40 以上になってしまい、以下のエラーが出るため -allow-unsupported-compiler を指定する
#
Expand All @@ -335,6 +335,7 @@ if ("${TARGET_OS}" STREQUAL "windows")
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/third_party/NvCodec/include
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/third_party/NvCodec/NvCodec
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/src
-Xcompiler /I${CMAKE_CURRENT_SOURCE_DIR}/src/sora-cpp-sdk/include
-Xcompiler "/MT$<$<CONFIG:Debug>:d>"
-Xcompiler /D_HAS_ITERATOR_DEBUGGING=0
-Xcompiler /DUSE_NVCODEC_ENCODER
Expand All @@ -352,9 +353,9 @@ if ("${TARGET_OS}" STREQUAL "windows")
if (USE_VPL_ENCODER)
target_sources(momo
PRIVATE
src/hwenc/src/hwenc_vpl/vpl_session_impl.cpp
src/hwenc/src/hwenc_vpl/vpl_video_decoder.cpp
src/hwenc/src/hwenc_vpl/vpl_video_encoder.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_session_impl.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_video_decoder.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_video_encoder.cpp
)
target_include_directories(momo PRIVATE ${VPL_ROOT_DIR}/include)
target_link_libraries(momo
Expand Down Expand Up @@ -407,7 +408,7 @@ elseif (TARGET_OS STREQUAL "linux")

target_sources(momo
PRIVATE
src/v4l2_video_capturer/v4l2_video_capturer.cpp
src/sora-cpp-sdk/src/v4l2/v4l2_video_capturer.cpp
)
target_compile_definitions(momo
PRIVATE
Expand Down Expand Up @@ -449,12 +450,12 @@ elseif (TARGET_OS STREQUAL "linux")
third_party/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
third_party/NvCodec/NvCodec/NvEncoder/NvEncoder.cpp
third_party/NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp
src/cuda/cuda_context_cuda.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_v4l2_capturer.cpp
src/hwenc_nvcodec/nvcodec_video_decoder.cpp)
src/sora-cpp-sdk/src/cuda_context_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_encoder.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_encoder_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_v4l2_capturer.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_decoder.cpp)
target_include_directories(momo
PRIVATE
third_party/NvCodec/include
Expand All @@ -463,9 +464,9 @@ elseif (TARGET_OS STREQUAL "linux")

# これらのソースは CUDA としてコンパイルする
set_source_files_properties(
src/cuda/cuda_context_cuda.cpp
src/hwenc_nvcodec/nvcodec_h264_encoder_cuda.cpp
src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
src/sora-cpp-sdk/src/cuda_context_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_video_encoder_cuda.cpp
src/sora-cpp-sdk/src/hwenc_nvcodec/nvcodec_decoder_cuda.cpp
third_party/NvCodec/NvCodec/NvDecoder/NvDecoder.cpp
third_party/NvCodec/NvCodec/NvEncoder/NvEncoderCuda.cpp
PROPERTIES
Expand All @@ -483,11 +484,11 @@ elseif (TARGET_OS STREQUAL "linux")
find_package(VPL REQUIRED)
target_sources(momo
PRIVATE
src/hwenc/src/hwenc_vpl/vpl_session_impl.cpp
src/hwenc/src/hwenc_vpl/vpl_video_decoder.cpp
src/hwenc/src/hwenc_vpl/vpl_video_encoder.cpp
src/hwenc/src/hwenc_vpl/vaapi_utils_drm.cpp
src/hwenc/src/hwenc_vpl/vaapi_utils.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_session_impl.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_video_decoder.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vpl_video_encoder.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vaapi_utils_drm.cpp
src/sora-cpp-sdk/src/hwenc_vpl/vaapi_utils.cpp
)
target_link_libraries(momo
PRIVATE
Expand Down
54 changes: 0 additions & 54 deletions src/cuda/cuda_context_cuda.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions src/cuda/cuda_context_cuda.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/hwenc/README.md

This file was deleted.

8 changes: 4 additions & 4 deletions src/hwenc_jetson/jetson_v4l2_capturer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define MJPEG_EOS_SEARCH_SIZE 4096

rtc::scoped_refptr<JetsonV4L2Capturer> JetsonV4L2Capturer::Create(
const V4L2VideoCapturerConfig& config) {
const sora::V4L2VideoCapturerConfig& config) {
rtc::scoped_refptr<JetsonV4L2Capturer> capturer;
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> device_info(
webrtc::VideoCaptureFactory::CreateDeviceInfo());
Expand Down Expand Up @@ -77,7 +77,7 @@ void JetsonV4L2Capturer::LogDeviceList(

rtc::scoped_refptr<JetsonV4L2Capturer> JetsonV4L2Capturer::Create(
webrtc::VideoCaptureModule::DeviceInfo* device_info,
const V4L2VideoCapturerConfig& config,
const sora::V4L2VideoCapturerConfig& config,
size_t capture_device_index) {
char device_name[256];
char unique_name[256];
Expand All @@ -103,7 +103,7 @@ rtc::scoped_refptr<JetsonV4L2Capturer> JetsonV4L2Capturer::Create(
return v4l2_capturer;
}

JetsonV4L2Capturer::JetsonV4L2Capturer(const V4L2VideoCapturerConfig& config)
JetsonV4L2Capturer::JetsonV4L2Capturer(const sora::V4L2VideoCapturerConfig& config)
: ScalableVideoTrackSource(config),
_deviceFd(-1),
_buffersAllocatedByDevice(-1),
Expand Down Expand Up @@ -176,7 +176,7 @@ JetsonV4L2Capturer::~JetsonV4L2Capturer() {
}

int32_t JetsonV4L2Capturer::StartCapture(
const V4L2VideoCapturerConfig& config) {
const sora::V4L2VideoCapturerConfig& config) {
if (_captureStarted) {
if (config.width == _currentWidth && config.height == _currentHeight) {
return 0;
Expand Down
14 changes: 7 additions & 7 deletions src/hwenc_jetson/jetson_v4l2_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#include <rtc_base/synchronization/mutex.h>

#include "jetson_jpeg_decoder_pool.h"
#include "rtc/scalable_track_source.h"
#include "v4l2_video_capturer/v4l2_video_capturer.h"
#include "sora/scalable_track_source.h"
#include "sora/v4l2/v4l2_video_capturer.h"

class JetsonV4L2Capturer : public ScalableVideoTrackSource {
class JetsonV4L2Capturer : public sora::ScalableVideoTrackSource {
public:
static rtc::scoped_refptr<JetsonV4L2Capturer> Create(
const V4L2VideoCapturerConfig& config);
JetsonV4L2Capturer(const V4L2VideoCapturerConfig& config);
const sora::V4L2VideoCapturerConfig& config);
JetsonV4L2Capturer(const sora::V4L2VideoCapturerConfig& config);
~JetsonV4L2Capturer();

private:
Expand All @@ -32,7 +32,7 @@ class JetsonV4L2Capturer : public ScalableVideoTrackSource {

int32_t Init(const char* deviceUniqueId,
const std::string& specifiedVideoDevice);
int32_t StartCapture(const V4L2VideoCapturerConfig& config);
int32_t StartCapture(const sora::V4L2VideoCapturerConfig& config);

int32_t StopCapture();
bool AllocateVideoBuffers();
Expand All @@ -55,7 +55,7 @@ class JetsonV4L2Capturer : public ScalableVideoTrackSource {
private:
static rtc::scoped_refptr<JetsonV4L2Capturer> Create(
webrtc::VideoCaptureModule::DeviceInfo* device_info,
const V4L2VideoCapturerConfig& config,
const sora::V4L2VideoCapturerConfig& config,
size_t capture_device_index);
bool FindDevice(const char* deviceUniqueIdUTF8, const std::string& device);

Expand Down
Loading

0 comments on commit 8dde3ad

Please sign in to comment.