How to share the buffer in process context?

I want to use nvmap api to get and share the buffer in different process.
use NvBufferCreate to create a buf and than to use ExtractFdFromNvBuffer to get out the fd.but failed in different process.
example:
process A → NvBufferCreate ,and show the phy addr in the NvBufferParams.
process B-> ExtractFdFromNvBuffer (phyaddr_from_A,dmabuf_fd);

this cause the Segment Fault.

Does the V4L2 export the dmabuf_fd can be used in different process?like mmap.

Hi,
There is new NvBuffer APIs on Jetpack 4.6(r32.6.1) for this use-case. Please upgrade to JP4.6 and check nvbuf_utils.h:

/**
 * Gets buffer extended parameters.
 * @param[in] dmabuf_fd `DMABUF FD` of buffer.
 * @param[out] exparams A pointer to the structure to fill with extended parameters.
 *
 * @returns 0 for success, -1 for failure.
 */
int NvBufferGetParamsEx (int dmabuf_fd, NvBufferParamsEx *exparams);
/**
 * Transforms one DMA buffer to another DMA buffer, API to be used for another process.
 * This function can support transforms for copying, scaling, fliping, rotating, and cropping.
 * @param[in] src_dmabuf_fd DMABUF FD of source buffer
 * @param[in] input_params extended input parameters for a hardware buffer.
 * @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
 * @param[in] output_params extended output parameters for a hardware buffer.
 * @param[in] transform_params transform parameters
 *
 * @return 0 for sucess, -1 for failure.
 */
int NvBufferTransformEx (int src_dmabuf_fd, NvBufferParamsEx *input_params, int dst_dmabuf_fd, NvBufferParamsEx *output_params, NvBufferTransformParams *transform_params);

With the API you can send fd through unix domain socket and get the buffer in another process.

1 Like

Thanks DaneLLL:
Would it be so kind for you to show me the sample?
the thing is I can handle the Unix message to send and recv the message,but still not knowing how to use NvBuffer APIs within different process to get the dmabuf_fd.
Process : A send msg
Process : B recv msg
NvBufferGetParamsEx();
PS: in the version from 32.6.1in nvbuffer_utils.h I did not find the API as NvBufferTransformEx instead of NvBufferTransform.

Thanks