# Understanding nvjpeg dma buffer

**URL:** <https://forums.developer.nvidia.com/t/understanding-nvjpeg-dma-buffer/192929>\
**Category:** Jetson AGX Xavier\
**Tags:** gstreamer, mmapi\
**Created:** [October 25, 2021, 8:09am UTC](https://forums.developer.nvidia.com/t/understanding-nvjpeg-dma-buffer/192929 "2021-10-25T08:09:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannes09](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@hannes09](https://forums.developer.nvidia.com/u/hannes09)\
**Post date:** [October 25, 2021, 8:09am UTC](https://forums.developer.nvidia.com/t/understanding-nvjpeg-dma-buffer/192929/1 "2021-10-25T08:09:06Z")

</div>

I am working on a custom jpeg decoder that uses nvjpeg.  
When I use something similar to `decodeToFd` I get a file handle to the dma buffer.

When does this buffer get allocated and when does the dma buffer get freed?  
For example if I push all dma fds into a vector, would that be a memory leak?

Currently I use this code to get the dma buffer after the jpeg decoding:

```auto
dma_fd = cinfo.fd;

```

From gst-nvjpeg sources I also know that there is:

```auto
 cinfo.pVendor_buf = info.data;

```

Can I use `cinfo.pVendor_buf` to pass a preallocated dma buffer to the decoder?

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [October 26, 2021, 1:57am UTC](https://forums.developer.nvidia.com/t/understanding-nvjpeg-dma-buffer/192929/3 "2021-10-26T01:57:59Z")

</div>

Hi,  
The buffer is allocated in first _decodeToFd()_ call and destroyed in

```auto
delete ctx->jpegdec;

```

We would suggest keep it for putting decoded YUV and copy data to another NvBuffer through _NvBufferTransform()_. Please refer to how MJPG decoding is done in

```auto
/usr/src/jetson_multimedia_api/samples/12_camera_v4l2_cuda

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [November 17, 2021, 3:39am UTC](https://forums.developer.nvidia.com/t/understanding-nvjpeg-dma-buffer/192929/5 "2021-11-17T03:39:47Z")

</div>

Closed on November 17, 2021, 3:39am UTC

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