From 92e03b0011aa7da7e418088f7e0e22147baa7856 Mon Sep 17 00:00:00 2001 From: enm10k Date: Fri, 12 Jan 2024 17:21:38 +0900 Subject: [PATCH] =?UTF-8?q?Jetson=20AGX=20Orin=20=E3=81=AE=20momo=5Fsample?= =?UTF-8?q?=20=E3=81=8B=E3=82=89=E9=80=81=E4=BF=A1=E3=81=97=E3=81=9F=20H.2?= =?UTF-8?q?65=20=E3=82=92=20Safari=20TP=20=E3=81=A7=E5=8F=97=E4=BF=A1?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hwenc_jetson/jetson_video_encoder.cpp | 20 ++++++++++++++++ src/sora_video_encoder_factory.cpp | 28 +++++++++++++++-------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/hwenc_jetson/jetson_video_encoder.cpp b/src/hwenc_jetson/jetson_video_encoder.cpp index 2118d746..c68c74b2 100644 --- a/src/hwenc_jetson/jetson_video_encoder.cpp +++ b/src/hwenc_jetson/jetson_video_encoder.cpp @@ -126,6 +126,8 @@ int32_t JetsonVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, target_bitrate_bps_ = codec_settings->startBitrate * 1000; if (codec_settings->codecType == webrtc::kVideoCodecH264) { key_frame_interval_ = codec_settings->H264().keyFrameInterval; + } else if (codec_settings->codecType == webrtc::kVideoCodecH265) { + key_frame_interval_ = codec_settings->H265().keyFrameInterval; } else if (codec_settings->codecType == webrtc::kVideoCodecVP8) { key_frame_interval_ = codec_settings->VP8().keyFrameInterval; } else if (codec_settings->codecType == webrtc::kVideoCodecVP9) { @@ -190,6 +192,9 @@ int32_t JetsonVideoEncoder::JetsonConfigure() { if (codec_.codecType == webrtc::kVideoCodecH264) { ret = encoder_->setCapturePlaneFormat(V4L2_PIX_FMT_H264, width_, height_, 2 * 1024 * 1024); + } else if (codec_.codecType == webrtc::kVideoCodecH265) { + ret = encoder_->setCapturePlaneFormat(V4L2_PIX_FMT_H265, width_, height_, + 2 * 1024 * 1024); } else if (codec_.codecType == webrtc::kVideoCodecVP8) { ret = encoder_->setCapturePlaneFormat(V4L2_PIX_FMT_VP8, width_, height_, 2 * 1024 * 1024); @@ -226,6 +231,11 @@ int32_t JetsonVideoEncoder::JetsonConfigure() { // NX は V4L2_ENC_HW_PRESET_FAST でないとフレームレートがでない ret = encoder_->setHWPresetType(V4L2_ENC_HW_PRESET_FAST); INIT_ERROR(ret < 0, "Failed to setHWPresetType"); + } else if (codec_.codecType == webrtc::kVideoCodecH265) { + // https://docs.nvidia.com/jetson/l4t-multimedia/group__V4L2Enc.html + // V4L2_MPEG_VIDEO_H265_PROFILE_MAIN or V4L2_MPEG_VIDEO_H265_PROFILE_MAIN10 + ret = encoder_->setProfile(V4L2_MPEG_VIDEO_H265_PROFILE_MAIN); + INIT_ERROR(ret < 0, "Failed to setProfile"); } else if (codec_.codecType == webrtc::kVideoCodecVP8) { uint32_t qp_min = codec_.mode == webrtc::VideoCodecMode::kScreensharing ? 12 : 2; @@ -515,6 +525,12 @@ webrtc::VideoEncoder::EncoderInfo JetsonVideoEncoder::GetEncoderInfo() const { static const int kHighH264QpThreshold = 40; info.scaling_settings = VideoEncoder::ScalingSettings(kLowH264QpThreshold, kHighH264QpThreshold); + } else if (codec_.codecType == webrtc::kVideoCodecH265) { + // TODO(enm10k): 要調整 + static const int kLowH265QpThreshold = 34; + static const int kHighH265QpThreshold = 40; + info.scaling_settings = VideoEncoder::ScalingSettings(kLowH265QpThreshold, + kHighH265QpThreshold); } else if (codec_.codecType == webrtc::kVideoCodecVP8) { static const int kLowVp8QpThreshold = 29; static const int kHighVp8QpThreshold = 95; @@ -808,6 +824,10 @@ int32_t JetsonVideoEncoder::SendFrame( codec_specific.codecSpecific.H264.packetization_mode = webrtc::H264PacketizationMode::NonInterleaved; + } else if (codec_.codecType == webrtc::kVideoCodecH265) { + auto encoded_image_buffer = + webrtc::EncodedImageBuffer::Create(buffer, size); + encoded_image_.SetEncodedData(encoded_image_buffer); } else if (codec_.codecType == webrtc::kVideoCodecAV1 || codec_.codecType == webrtc::kVideoCodecVP9 || codec_.codecType == webrtc::kVideoCodecVP8) { diff --git a/src/sora_video_encoder_factory.cpp b/src/sora_video_encoder_factory.cpp index 7e5b21f5..b076b499 100644 --- a/src/sora_video_encoder_factory.cpp +++ b/src/sora_video_encoder_factory.cpp @@ -175,15 +175,16 @@ SoraVideoEncoderFactoryConfig GetDefaultVideoEncoderFactoryConfig( #if USE_NVCODEC_ENCODER if (NvCodecH264Encoder::IsSupported(cuda_context)) { - config.encoders.insert(config.encoders.begin(), - VideoEncoderConfig( - webrtc::kVideoCodecH264, - [cuda_context = cuda_context](auto format) - -> std::unique_ptr { - return NvCodecH264Encoder::Create( - cricket::CreateVideoCodec(format), cuda_context); - }, - 16)); + config.encoders.insert( + config.encoders.begin(), + VideoEncoderConfig( + webrtc::kVideoCodecH264, + [cuda_context = cuda_context]( + auto format) -> std::unique_ptr { + return NvCodecH264Encoder::Create( + cricket::CreateVideoCodec(format), cuda_context); + }, + 16)); } #endif @@ -278,6 +279,15 @@ SoraVideoEncoderFactoryConfig GetDefaultVideoEncoderFactoryConfig( cricket::CreateVideoCodec(format))); }, 16)); + config.encoders.insert(config.encoders.begin(), + VideoEncoderConfig( + webrtc::kVideoCodecH265, + [](auto format) { + return std::unique_ptr( + absl::make_unique( + cricket::CreateVideoCodec(format))); + }, + 16)); #endif return config;