From 6a1ea0b08ff718111415949c346c074b90f042e6 Mon Sep 17 00:00:00 2001 From: enm10k Date: Tue, 3 Oct 2023 17:23:11 +0900 Subject: [PATCH] wip --- src/hwenc_jetson/jetson_buffer.cpp | 66 ++++++++++++++--------- src/hwenc_jetson/jetson_video_decoder.cpp | 2 +- src/hwenc_jetson/jetson_video_encoder.cpp | 2 +- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/hwenc_jetson/jetson_buffer.cpp b/src/hwenc_jetson/jetson_buffer.cpp index a475ab1a..066e573d 100644 --- a/src/hwenc_jetson/jetson_buffer.cpp +++ b/src/hwenc_jetson/jetson_buffer.cpp @@ -9,7 +9,8 @@ #include // Jetson Linux Multimedia API -#include +#include +#include namespace sora { @@ -62,45 +63,58 @@ rtc::scoped_refptr JetsonBuffer::ToI420() { int32_t buffer_width = ((scaled_width_ + 15) / 16) * 16; int32_t buffer_height = ((scaled_height_ + 15) / 16) * 16; - NvBufferCreateParams input_params = {0}; - input_params.payloadType = NvBufferPayload_SurfArray; - input_params.width = buffer_width; - input_params.height = buffer_height; - input_params.layout = NvBufferLayout_Pitch; - input_params.colorFormat = NvBufferColorFormat_YUV420; - input_params.nvbuf_tag = NvBufferTag_NONE; + NvBufSurfaceAllocateParams input_params = {0}; + input_params.params.width = buffer_width; + input_params.params.height = buffer_height; + input_params.params.layout = NVBUF_LAYOUT_PITCH; + input_params.params.colorFormat = NVBUF_COLOR_FORMAT_YUV420; + input_params.memtag = NvBufSurfaceTag_NONE; - int dmabuf_fd; - if (NvBufferCreateEx(&dmabuf_fd, &input_params) == -1) { + NvBufSurface* surface = new NvBufSurface; + surface->memType = NVBUF_MEM_SURFACE_ARRAY; + + // int batch_size = 1; + // NvBufSurface* surfaces[batch_size]; + //surfaces[0] = surface; + NvBufSurface* surfaces[] = {surface}; + int batch_size = sizeof(surfaces) / sizeof(surfaces[0]); + + // int dmabuf_fd; + if (NvBufSurfaceAllocate(surfaces, batch_size, &input_params) == -1) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferCreateEx"; return scaled_buffer; } + int dmabuf_fd = surface->gpuId; + NvBufSurfaceParams params = surfaces[0]->surfaceList[0]; - NvBufferParams params = {0}; - if (NvBufferGetParams(fd_, ¶ms) == -1) { - RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferGetParams"; - return scaled_buffer; - } + // NvBufferParams params = {0}; + // if (NvBufferGetParams(fd_, ¶ms) == -1) { + // RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferGetParams"; + // return scaled_buffer; + // } - NvBufferRect src_rect, dest_rect; + NvBufSurfTransformRect src_rect, dest_rect; src_rect.top = 0; src_rect.left = 0; - src_rect.width = params.width[0]; - src_rect.height = params.height[0]; + src_rect.width = params.width; + src_rect.height = params.height; dest_rect.top = 0; dest_rect.left = 0; dest_rect.width = buffer_width; dest_rect.height = buffer_height; - NvBufferTransformParams trans_params; + NvBufSurfTransformParams trans_params; memset(&trans_params, 0, sizeof(trans_params)); - trans_params.transform_flag = NVBUFFER_TRANSFORM_FILTER; - trans_params.transform_flip = NvBufferTransform_None; - trans_params.transform_filter = NvBufferTransform_Filter_Smart; - trans_params.src_rect = src_rect; - trans_params.dst_rect = dest_rect; - - if (NvBufferTransform(fd_, dmabuf_fd, &trans_params) == -1) { + trans_params.transform_flag = NVBUFSURF_TRANSFORM_FILTER; + trans_params.transform_flip = NvBufSurfTransform_None; + trans_params.transform_filter = NvBufSurfTransformInter_Algo3; + trans_params.src_rect = &src_rect; + trans_params.dst_rect = &dest_rect; + + // TODO: fd_ の型を NvBufSurface に変える + NvBufSurfTransform_Error error; + if (NvBufSurfTransform(fd_, dmabuf_fd, &trans_params) != + NvBufSurfTransformError_Success) { RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferTransform"; return scaled_buffer; } diff --git a/src/hwenc_jetson/jetson_video_decoder.cpp b/src/hwenc_jetson/jetson_video_decoder.cpp index e37c95f8..0b495e75 100644 --- a/src/hwenc_jetson/jetson_video_decoder.cpp +++ b/src/hwenc_jetson/jetson_video_decoder.cpp @@ -22,7 +22,7 @@ #include // L4T Multimedia API -#include +#include // Jetson Linux Multimedia API #include diff --git a/src/hwenc_jetson/jetson_video_encoder.cpp b/src/hwenc_jetson/jetson_video_encoder.cpp index 4d27e23a..98332cb7 100644 --- a/src/hwenc_jetson/jetson_video_encoder.cpp +++ b/src/hwenc_jetson/jetson_video_encoder.cpp @@ -28,7 +28,7 @@ // L4T Multimedia API #include #include -#include +#include #include "sora/hwenc_jetson/jetson_buffer.h"