NvBufSurf API upgrade - transform failed, Error -2

Hello, I am migrating from nvbuf_utils to nvbufsurface. I am following this guide https://developer.nvidia.com/sites/default/files/akamai/embedded/nvbuf_utils_to_nvutils_migration_guide.pdf for the migration, and referencing the examples in the mmapi.

Now, I find that the NvBufSurfTransform() function no longer works, it returns -2, NvBufSurfTransformError_Execution_Error.

Version is

$uname -r 
5.10.104-l4t-r35.1+gc7f946aacc63

What might I be missing?

int MakeBuffer(const std::uint32_t width, const std::uint32_t height, const ColorFormat format)
{

    // This is pulled from the example code in the Jetson_Multimedia_API_R35.1.0
    NvBufSurface *nvbuf_surf = nullptr;

    {
        NvBufSurfaceAllocateParams input_params = {{0}};

        input_params.params.width = width;
        input_params.params.height = height;
        input_params.params.memType = NVBUF_MEM_SURFACE_ARRAY;
        input_params.params.layout = NVBUF_LAYOUT_PITCH;
        input_params.params.colorFormat = AsNvidiaFormat(format);
        input_params.memtag = NvBufSurfaceTag_VIDEO_CONVERT;

        if (NvBufSurfaceAllocate(&nvbuf_surf, 1, &input_params))
        {
            fprintf(stderr, "Failed to create image buffer!\n");
            std::abort();
        }
    }
    nvbuf_surf->numFilled = 1;

    if (NvBufSurfaceMap(nvbuf_surf, -1, -1, NVBUF_MAP_READ_WRITE))
    {
        fprintf(stderr, "Failed to map image buffer!\n");
        std::abort();
    }

    if (static_cast<uint32_t>(buffer.width) != nvbuf_surf->surfaceList[0].width ||
        static_cast<uint32_t>(buffer.height) != nvbuf_surf->surfaceList[0].height)
    {
        fprintf(stderr, "Image buffer dimensions don't match expectations!\n");
        std::abort();
    }

    return nvbuf_surf->surfaceList[0].bufferDesc;;
}

void Convert(const std::int32_t src_fd, const std::int32_t dst_fd, const Crop &src_crop, const Crop &dst_crop)
{
    NvBufSurfTransformParams transform_params{};
    NvBufSurfTransformRect src_rect{0};
    NvBufSurfTransformRect dst_rect{0};
    NvBufSurface *src_buf = nullptr;
    NvBufSurface *dst_buf = nullptr;

    NvBufSurfTransformConfigParams config_params = {};
    config_params.compute_mode = NvBufSurfTransformCompute_VIC;
    NvBufSurfTransformSetSessionParams(&config_params);

   src_rect.top = src_crop.top;
   src_rect.left = src_crop.left;
   src_rect.width = src_crop.width;
   src_rect.height = src_crop.height;

   dst_rect.top = dst_crop.top;
   dst_rect.left = dst_crop.left;
   dst_rect.width = dst_crop.width;
   dst_rect.height = dst_crop.height;

    memset(&transform_params, 0, sizeof(transform_params));

    transform_params.transform_flag = NVBUFSURF_TRANSFORM_FILTER;
    transform_params.transform_filter = NvBufSurfTransformInter_Nearest;

    transform_params.src_rect = &src_rect;
    transform_params.dst_rect = &dst_rect;

    if (NvBufSurfaceFromFd(src_fd, (void **)(&src_buf)))
    {
        fprintf(stderr, "Failed to get image buffer from src fd!\n");
        std::abort();
    }

    if (NvBufSurfaceFromFd(dst_fd, (void **)(&dst_buf)))
    {
        fprintf(stderr, "Failed to get image buffer from dst fd!\n");
        std::abort();
    };

    if (src_crop.width != src_buf->surfaceList[0].width || src_crop.height != src_buf->surfaceList[0].height)
    {
        transform_params.transform_flag |= NVBUFSURF_TRANSFORM_CROP_SRC;
    }
    if (dst_crop.width != dst_buf->surfaceList[0].width || dst_crop.height != dst_buf->surfaceList[0].height)
    {
        transform_params.transform_flag |= NVBUFSURF_TRANSFORM_CROP_DST;
    }

    NvBufSurfTransform_Error result = NvBufSurfTransform(src_buf, dst_buf, &transform_params);

    if (result)
    {
        fprintf(stderr, "Failed to convert image buffer! Error code is %d\n", result);
        std::abort();
    }
}

Hi,
You can try NvBufSurf::NvTransform() in

/usr/src/jetson_multimedia_api/samples/common/classes/NvBufSurface.cpp

And see if it works. We use the function in jetson_multimedia_api samples and it is supposed to work fine. Please give it a try.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.