Buffers for JPEG encoding with NvMedia

What type of buffer is needed for the JPEG compression with NvMedia?
The type is void* and the API gives no details.

This is my code (error checks removed):

uint8_t* image_compressed = NULL; // ???
NvMediaStatus nvStatus = NvMediaIJPEFeedFrame(jpegEncoder, imageYUV, 75);
uint32_t image_compressed_size = 0;
nvStatus = NvMediaIJPEBitsAvailable(jpegEncoder, &image_compressed_size, NVMEDIA_ENCODE_BLOCKING_TYPE_IF_PENDING, 10000);
nvStatus = NvMediaIJPEGetBits(jpegEncoder, &image_compressed_size, &image_compressed, NVMEDIA_JPEG_ENC_FLAG_NONE);

NvMediaIJPEGetBits returns NVMEDIA_STATUS_INSUFFICIENT_BUFFERING, a status that according to the API shouldn’t ever be returned by this function.

Dear nbussas,
Thank you for brining it to our notice. We make a note of it and will be fixed in next release.
The buffer should be large enough to hold the compressed bitstream. It seems you are using a NULL pointer. Can you please look at nvmimg_jpgenc sample in detail.

Here is more guidance on allocating the buffer:

  1. Call NvMediaIJPEBitsAvailable() to determine the number of bytes available for the next frame.
  2. Allocate a buffer with size >= available bytes
  3. Call NvMediaIJPEGetBits()

Thanks for the help, I indeed needed to allocate the buffer. Another error I made in the code above is to add one ampersand to much in the code above in line 5. Here is the fixed version:

NvMediaStatus nvStatus = NvMediaIJPEFeedFrame(jpegEncoder, imageYUV, 75);
uint32_t image_compressed_size = 0;
nvStatus = NvMediaIJPEBitsAvailable(jpegEncoder, &image_compressed_size, NVMEDIA_ENCODE_BLOCKING_TYPE_IF_PENDING, 10000);
uint8_t* image_compressed = (uint8_t*)malloc(image_compressed_size);
nvStatus = NvMediaIJPEGetBits(jpegEncoder, &image_compressed_size, image_compressed, 0);