Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Oct 3, 2023
1 parent 00b82da commit 6a1ea0b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
66 changes: 40 additions & 26 deletions src/hwenc_jetson/jetson_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <third_party/libyuv/include/libyuv.h>

// Jetson Linux Multimedia API
#include <nvbuf_utils.h>
#include <nvbufsurface.h>
#include <nvbufsurftransform.h>

namespace sora {

Expand Down Expand Up @@ -62,45 +63,58 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> 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_, &params) == -1) {
RTC_LOG(LS_ERROR) << __FUNCTION__ << " Failed to NvBufferGetParams";
return scaled_buffer;
}
// NvBufferParams params = {0};
// if (NvBufferGetParams(fd_, &params) == -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hwenc_jetson/jetson_video_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <third_party/libyuv/include/libyuv/convert.h>

// L4T Multimedia API
#include <nvbuf_utils.h>
#include <nvbufsurface.h>

// Jetson Linux Multimedia API
#include <NvVideoDecoder.h>
Expand Down
2 changes: 1 addition & 1 deletion src/hwenc_jetson/jetson_video_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// L4T Multimedia API
#include <NvBufSurface.h>
#include <NvVideoEncoder.h>
#include <nvbuf_utils.h>
#include <nvbufsurface.h>

#include "sora/hwenc_jetson/jetson_buffer.h"

Expand Down

0 comments on commit 6a1ea0b

Please sign in to comment.