Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Oct 4, 2023
1 parent a2c1f77 commit 41f47c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
20 changes: 3 additions & 17 deletions src/hwenc_jetson/jetson_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,15 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> 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_, &params) == -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;
Expand All @@ -109,26 +103,18 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> 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;
Expand Down Expand Up @@ -159,7 +145,7 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> 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;
Expand Down
7 changes: 4 additions & 3 deletions src/hwenc_jetson/jetson_video_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down

0 comments on commit 41f47c9

Please sign in to comment.