Skip to content

Commit

Permalink
Jetson AGX Orin の momo_sample から送信した H.265 を Safari TP で受信できた
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Jan 12, 2024
1 parent d876bbc commit 92e03b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/hwenc_jetson/jetson_video_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 19 additions & 9 deletions src/sora_video_encoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<webrtc::VideoEncoder> {
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<webrtc::VideoEncoder> {
return NvCodecH264Encoder::Create(
cricket::CreateVideoCodec(format), cuda_context);
},
16));
}
#endif

Expand Down Expand Up @@ -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<webrtc::VideoEncoder>(
absl::make_unique<JetsonVideoEncoder>(
cricket::CreateVideoCodec(format)));
},
16));
#endif

return config;
Expand Down

0 comments on commit 92e03b0

Please sign in to comment.