diff --git a/src/hwenc_jetson/jetson_buffer.cpp b/src/hwenc_jetson/jetson_buffer.cpp index 282d1d11..3c3e17cf 100644 --- a/src/hwenc_jetson/jetson_buffer.cpp +++ b/src/hwenc_jetson/jetson_buffer.cpp @@ -74,21 +74,15 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { dst_surface->memType = NVBUF_MEM_SURFACE_ARRAY; NvBufSurface* dst_surfaces[] = {dst_surface}; - int batch_size = sizeof(dst_surfaces) / sizeof(dst_surfaces[0]); - if (NvBufSurfaceAllocate(dst_surfaces, batch_size, &input_params) == -1) { + if (NvBufSurfaceAllocate(dst_surfaces, 1, // batch size + &input_params) == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferCreateEx"; return scaled_buffer; } int dmabuf_fd = dst_surface->gpuId; NvBufSurfaceParams params = dst_surfaces[0]->surfaceList[0]; - // NvBufferParams params = {0}; - // if (NvBufferGetParams(fd_, ¶ms) == -1) { - // RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferGetParams"; - // return scaled_buffer; - // } - NvBufSurfTransformRect src_rect, dest_rect; src_rect.top = 0; src_rect.left = 0; @@ -109,26 +103,18 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { // NvBufSurfaceFromFd で fd_ を NvBufSurface に変換する // 参照:_install/ubuntu-20.04_armv8_jetson/release/rootfs/usr/src/jetson_multimedia_api/samples/12_v4l2_camera_cuda/camera_v4l2_cuda.cpp - // NOTE: NvBufSurfaceFromFd のコストが高い場合、コンストラクタで変換する必要があるかもしれない? NvBufSurface* src_surface = NULL; if (-1 == NvBufSurfaceFromFd(fd_, (void**)(&src_surface))) { RTC_LOG(LS_ERROR) << __FUNCTION__ << "Failed to get NvBufSurface from FD"; return scaled_buffer; } - // TODO: memcpy を使わなくても dst からデータを取得できそうなので調べる if (NvBufSurfTransform(src_surface, dst_surface, &trans_params) != NvBufSurfTransformError_Success) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferTransform"; return scaled_buffer; } - // NvBufferParams dmabuf_params = {0}; - // if (NvBufferGetParams(dmabuf_fd, &dmabuf_params) == -1) { - // RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferGetParams"; - // return scaled_buffer; - // } - int ret; void* data_addr; uint8_t* dest_addr; @@ -159,7 +145,7 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { width); } } - NvBufSurfaceUnMap(dst_surface, 0, plane); + NvBufSurfaceUnMap(dst_surface, index, plane); if (ret == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufSurfaceMap plane=" << plane; diff --git a/src/hwenc_jetson/jetson_video_encoder.cpp b/src/hwenc_jetson/jetson_video_encoder.cpp index be87cba5..5c4ac9c7 100644 --- a/src/hwenc_jetson/jetson_video_encoder.cpp +++ b/src/hwenc_jetson/jetson_video_encoder.cpp @@ -748,10 +748,11 @@ int32_t JetsonVideoEncoder::Encode( input_frame.timestamp_us() % rtc::kNumMicrosecsPerSec; for (int i = 0; i < MAX_PLANES; i++) { + // JetPack 5.2.1 対応で NvBufferMemSyncForDevice を NvBufSurfaceSyncForDevice に置き換える際に、 + // fd から NvBufSurface を作成する必要があった NvBufSurface* surface = NULL; if (-1 == NvBufSurfaceFromFd(buffer->planes[i].fd, (void**)(&surface))) { - RTC_LOG(LS_ERROR) << __FUNCTION__ - << "Failed to get NvBufSurface from FD"; + RTC_LOG(LS_ERROR) << __FUNCTION__ << "Failed to NvBufSurfaceFromFd"; return WEBRTC_VIDEO_CODEC_ERROR; } @@ -760,7 +761,7 @@ int32_t JetsonVideoEncoder::Encode( return WEBRTC_VIDEO_CODEC_ERROR; } - // TODO: NvBufsurface の解放 + NvBufSurfaceDestroy(surface); } if (encoder_->output_plane.qBuffer(v4l2_buf, nullptr) < 0) {