diff --git a/src/hwenc_jetson/jetson_buffer.cpp b/src/hwenc_jetson/jetson_buffer.cpp index 6cd5b9ae..3fdd31aa 100644 --- a/src/hwenc_jetson/jetson_buffer.cpp +++ b/src/hwenc_jetson/jetson_buffer.cpp @@ -71,17 +71,16 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { input_params.params.memType = NVBUF_MEM_SURFACE_ARRAY; input_params.memtag = NvBufSurfaceTag_NONE; - NvBufSurface* dst_surface = 0; + NvBufSurface* dst_surf = 0; - if (-1 == - NvBufSurfaceAllocate( - &dst_surface, - 1, /* NvUtils では複数のバッファーを同時に初期化できるようになったため、バッファーの数を指定する */ - &input_params)) { + if (NvBufSurfaceAllocate( + &dst_surf, + 1, /* NvUtils では複数のバッファーを同時に初期化できるため、バッファーの数を指定する */ + &input_params) == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufSurfaceAllocate"; return scaled_buffer; } - NvBufSurfaceParams params = dst_surface->surfaceList[0]; + NvBufSurfaceParams params = dst_surf->surfaceList[0]; NvBufSurfTransformRect src_rect, dest_rect; src_rect.top = 0; @@ -101,15 +100,13 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { trans_params.src_rect = &src_rect; trans_params.dst_rect = &dest_rect; - // 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 - NvBufSurface* src_surface = NULL; - if (-1 == NvBufSurfaceFromFd(fd_, (void**)(&src_surface))) { - RTC_LOG(LS_ERROR) << __FUNCTION__ << "Failed to get NvBufSurface from FD"; + NvBufSurface* src_surf = 0; + if (NvBufSurfaceFromFd(fd_, (void**)(&src_surf)) == -1) { + RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufSurfaceFromFd"; return scaled_buffer; } - if (NvBufSurfTransform(src_surface, dst_surface, &trans_params) != + if (NvBufSurfTransform(src_surf, dst_surf, &trans_params) != NvBufSurfTransformError_Success) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufSurfTransform"; return scaled_buffer; @@ -118,13 +115,13 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { int ret; void* data_addr; uint8_t* dest_addr; - int num_planes = dst_surface->surfaceList->planeParams.num_planes; + int num_planes = dst_surf->surfaceList->planeParams.num_planes; int index = 0; for (int plane = 0; plane < num_planes; plane++) { - ret = NvBufSurfaceMap(dst_surface, index, plane, NVBUF_MAP_READ); + ret = NvBufSurfaceMap(dst_surf, index, plane, NVBUF_MAP_READ); if (ret == 0) { - NvBufSurfaceSyncForCpu(dst_surface, index, plane); - data_addr = dst_surface->surfaceList->mappedAddr.addr[plane]; + NvBufSurfaceSyncForCpu(dst_surf, index, plane); + data_addr = dst_surf->surfaceList->mappedAddr.addr[plane]; int height, width; if (plane == 0) { dest_addr = scaled_buffer.get()->MutableDataY(); @@ -142,19 +139,19 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { for (int i = 0; i < height; i++) { memcpy(dest_addr + width * i, (uint8_t*)data_addr + - dst_surface->surfaceList->planeParams.pitch[i] * i, + dst_surf->surfaceList->planeParams.pitch[i] * i, width); } } - NvBufSurfaceUnMap(dst_surface, index, plane); + NvBufSurfaceUnMap(dst_surf, index, plane); if (ret == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ - << " Failed to NvBufSurfaceMap plane=" << plane; + << " Failed to NvBufSurfaceUnMap plane=" << plane; return scaled_buffer; } } - NvBufSurfaceDestroy(dst_surface); + NvBufSurfaceDestroy(dst_surf); return scaled_buffer; } else { diff --git a/src/hwenc_jetson/jetson_video_decoder.cpp b/src/hwenc_jetson/jetson_video_decoder.cpp index 166b2a55..9856cb8b 100644 --- a/src/hwenc_jetson/jetson_video_decoder.cpp +++ b/src/hwenc_jetson/jetson_video_decoder.cpp @@ -368,23 +368,22 @@ void JetsonVideoDecoder::CaptureLoop() { break; } - NvBufSurface* dst_surface = 0; - if (-1 == NvBufSurfaceFromFd(dst_dma_fd_, (void**)(&dst_surface))) { + NvBufSurface* dst_surf = 0; + if (NvBufSurfaceFromFd(dst_dma_fd_, (void**)(&dst_surf)) == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << "Failed to NvBufSurfaceFromFd"; break; } - ret = NvBufSurfaceMap(dst_surface, 0, i, NVBUF_MAP_READ); - NvBufSurfaceSyncForCpu(dst_surface, 0, i); - src_data = dst_surface->surfaceList[0].mappedAddr.addr[i]; + ret = NvBufSurfaceMap(dst_surf, 0, i, NVBUF_MAP_READ); + NvBufSurfaceSyncForCpu(dst_surf, 0, i); + src_data = dst_surf->surfaceList[0].mappedAddr.addr[i]; - NvBufSurfacePlaneParams params = - dst_surface->surfaceList[0].planeParams; + NvBufSurfacePlaneParams params = dst_surf->surfaceList[0].planeParams; for (uint32_t j = 0; j < params.height[i]; j++) { memcpy(dst_data + j * dst_stride, (char*)src_data + j * params.pitch[i], params.width[i]); } - NvBufSurfaceUnMap(dst_surface, 0, i); + NvBufSurfaceUnMap(dst_surf, 0, i); } webrtc::VideoFrame decoded_image = diff --git a/src/hwenc_jetson/jetson_video_encoder.cpp b/src/hwenc_jetson/jetson_video_encoder.cpp index 4dbc99c2..7ea1f1e3 100644 --- a/src/hwenc_jetson/jetson_video_encoder.cpp +++ b/src/hwenc_jetson/jetson_video_encoder.cpp @@ -748,20 +748,20 @@ int32_t JetsonVideoEncoder::Encode( input_frame.timestamp_us() % rtc::kNumMicrosecsPerSec; for (int i = 0; i < MAX_PLANES; i++) { - NvBufSurface* surface = 0; - if (-1 == NvBufSurfaceFromFd(buffer->planes[i].fd, (void**)(&surface))) { + NvBufSurface* surf = 0; + if (NvBufSurfaceFromFd(buffer->planes[i].fd, (void**)(&surf)) == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << "Failed to NvBufSurfaceFromFd"; return WEBRTC_VIDEO_CODEC_ERROR; } - if (NvBufSurfaceSyncForDevice(surface, 0, i) < 0) { + if (NvBufSurfaceSyncForDevice(surf, 0, i) == -1) { RTC_LOG(LS_ERROR) << "Failed to NvBufSurfaceSyncForDevice"; return WEBRTC_VIDEO_CODEC_ERROR; } // ここで NvBufSurfaceDestroy が必要かなと思ったが、以下のサンプル・コードを確認したところ不要そうだった // 参照: jetson_multimedia_api/samples/01_video_encode/video_encode_main.cpp - // NvBufSurfaceDestroy(surface); + // NvBufSurfaceDestroy(surf); } if (encoder_->output_plane.qBuffer(v4l2_buf, nullptr) < 0) {