NvMedia Image Surface Allocation with NvSciBuf

This is an example of how to allocate an NvMedia image surface with NvSciBuf:

NvMediaDevice *device;
NvMediaStatus status;
NvSciError  err;
NvSciBufModule module;
NvSciBufAttrList attrlist, conflictlist;
NvSciBufObj bufObj;
NvMediaImage *image;
NvMediaSurfaceType nvmsurfacetype;
NvMediaSurfAllocAttr surfAllocAttrs[8];
NVM_SURF_FMT_DEFINE_ATTR(surfFormatAttrs);

/*NvMedia related initialization. */
device = NvMediaDeviceCreate();
status = NvMediaImageNvSciBufInit();

/*NvSciBuf related initialization. */  
err = NvSciBufModuleOpen(&module);

/*Create NvSciBuf attribute list. */
err = NvSciBufAttrListCreate(module, &attrlist);

/* Initialize surfFormatAttrs and surfAllocAttrs as required. */

/* Define an array of NvMediaSurfFormatAttr */    
NVM_SURF_FMT_DEFINE_ATTR(surfFormatAttrs);

/* Set attributes that uniquely represent a YUV 444 8-bit pitch-linear planar surface */
NVM_SURF_FMT_SET_ATTR_YUV (surfFormatAttrs, YUV, 444, PLANAR, UINT, 8, PL);

/* Get NvMediaSurfaceType for the specified surface format attributes. */
type = NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);

/* Define an array of NvMediaSurfAllocAttr objects. */
NvMediaSurfAllocAttr surfAllocAttrs[NVM_SURF_ALLOC_ATTR_MAX];

/* Set surface allocation attributes. */
surfAllocAttrs[0].type = NVM_SURF_ATTR_WIDTH;
surfAllocAttrs[0].value = 1280;
surfAllocAttrs[1].type = NVM_SURF_ATTR_HEIGHT;
surfAllocAttrs[1].value = 1080;
surfAllocAttrs[2].type = NVM_SURF_ATTR_CPU_ACCESS;
surfAllocAttrs[2].value = NVM_SURF_ATTR_CPU_ACCESS_CACHED;
numSurfAllocAttrs = 3;

/* Ask NvMedia to fill NvSciBufAttrs corresponding to nvmsurfacetype
 and surfAllocAttrs. */
status = NvMediaImageFillNvSciBufAttrs(device, nvmsurfacetype, 
surfAllocAttrs, numsurfallocattrs, 0, attrlist);

/* Reconcile the NvSciBufAttrs and then allocate an NvSciBufObj. */
err = NvSciBufAttrListReconcileAndObjAlloc(&attrlist, 1, bufobj,  &conflictlist);

/* Create NvMediaImage from NvSciBufObj. */
status = NvMediaImageCreateFromNvSciBuf(device, bufobj, &image);

/* Free the NvSciBufAttrList which is no longer required. */
err = NvSciBufAttrListFree(attrlist);

/* Use the image as input or output for any of the NvMedia
 component. */
....
....
/* Free the resources after use. */

/* Destroy NvMediaImage. */
NvMediaImageDestroy(image);

/* NvMedia related Deinit. */
NvMediaImageNvSciBufDeinit();
NvMediaDeviceDestroy(device);

/* NvSciBuf related deinit. */
NvSciBufObjFree(bufobj);
NvSciBufModuleClose(module);