Code Examples
Following is example code that illustrates NvSciSync
operations for the 2D
component. It can also be used as a model for NvSciSync operations in the other imaging
components.
/***** Init Time *****/
NvSciSyncModule nvscisyncModule;
NvSciError nverr;
NvSciSyncAttrList nvscisyncattr_w;
NvSciSyncAttrList nvscisyncattr_s;
NvSciSyncAttrList nvscisyncattr_unreconciled_h[2];
NvSciSyncAttrList nvscisyncattr_reconciled;
NvSciSyncAttrList ConflictAttrList;
NvSciSyncFence eofnvscisyncfence = NV_SCI_SYNC_FENCE_INITIALIZER;
NvSciSyncObj nvscisyncEOF, nvscisyncpre;
NvMediaStatus nvmstatus;
NvMedia2D *nvm2dhdl = NULL;
nvmstatus = NvMedia2DCreate(&nvm2dhdl, NULL);
nverr = NvSciSyncModuleOpen(&nvscisyncModule);
/***** NvMedia 2D as a signaler *****/
nverr = NvSciSyncAttrListCreate(nvscisyncModule, &nvscisyncattr_s);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvm2dhdl, &nvscisyncattr_s, NVMEDIA_SIGNALER);
nvscisyncattr_unreconciled_h[0] = nvscisyncattr_s;
nvscisyncattr_unreconciled_h[1] = get attribute list from the appropriate waiter;
nverr = NvSciSyncAttrListReconcile(nvscisyncattr_unreconciled_h[],
2 , &nvscisyncattr_reconciled, &ConflictAttrList);
nverr = NvSciSyncObjAlloc(nvscisyncattr_reconciled, &nvscisyncEOF);
/***** NvMedia 2D as a waiter *****/
nverr = NvSciSyncAttrListCreate(&nvscisyncattr_w);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvm2dhdl, &nvscisyncattr_w, NVMEDIA_WAITER);
/*If the signaler is also in the same process as the 2D Waiter, then
NvSciSyncAttrListReconcileAndObjAlloc or NvSciSyncAttrListReconcile and
NvSciSyncObjAlloc API pair has/have to be used to allocate nvscisyncpre NvSciScynObject.
If the signaler is in a different process/VM than the 2D Waiter, then
NvSciSyncAttrList export/import APIs and NvSciSyncObjIpc Export/Import APIs
have to be used allocate a NvSciSyncObject on signaler and waiter sides.
nvscisyncpre is the imported NvSciSyncObject on the waiter side */
/*All the NvSciSyncObjects(NvSciSyncObjects associated with PreFences, EOFFence
) which will be used by NvMedia2D must be registered upfront. */
/***** Start of registration of NvSciSync objects *****/
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl, NVMEDIA_EOFSYNCOBJ, nvscisyncEOF);
/* Register all the NvSciSync objects which will be used to generate prefences for
NvMedia2DBlit operation. nvscisyncpre is one such Pre NvSciSync object */
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl, NVMEDIA_PRESYNCOBJ, nvscisyncpre);
/***** End of Registration of NvSciSync Objects *****.
/*Allocate a NvSciBufObj for inputs, say inputimg[N] */
/*Allocate a NvSciBufObj for output, say outputimg */
/*Register the inputimgs and outputimg */
nvmstatus = NvMedia2DRegisterNvSciBufObj(nvm2dhdl, inputimg[i]);
nvmstatus = NvMedia2DRegisterNvSciBufObj(nvm2dhdl, outputimg);
/***** End of init-time and start of run-time *****/
/* Acquire an empty NvMedia 2D parameters object */
NvMedia2DComposeParameters params;
nvmstatus = NvMedia2DGetComposeParameters(nvm2dhdl, ¶ms);
nvmstatus = NvMedia2DSetNvSciSyncObjforEOF(nvm2dhdl, nvscisyncEOF);
/*Get a nvscisyncfence from somewhere(maybe a eofnvscisyncfence of
some other engine operation) which neeeds to be inserted as prefence
for 2DBlit operation. prenvscisyncfence is one such NvSciSyncFence. */
nvmstatus = NvMedia2DInsertPreNvSciSyncFence(nvm2dhdl, prenvscisyncfence);
/* Set the source layer parameters */
nvmstatus = NvMedia2DSetSrcNvSciBufObj(nvm2dhdl, params, i, inputimg[i]);
nvmstatus = NvMedia2DSetSrcGeometry(nvm2dhdl,params,i,NULL,NULL,NVMEDIA_2D_TRANSFORM_NONE);
nvmstatus = NvMedia2DSetSrcFilter(nvm2dhdl, params, i, NVMEDIA_2D_FILTER_OFF);
nvmstatus = NvMedia2DSetSrcBlendMode(nvm2dhdl, params, i, NVMEDIA_2D_BLEND_MODE_CONSTANT_ALPHA, 0.5);
/* Set destination surface */
nvmstatus = NvMedia2DSetDstNvSciBufObj(nvm2dhdl, params, outputimg);
/* Submit the compose operation */
NvMedia2DComposeResult composeResult;
nvmstatus = NvMedia2DCompose(nvm2dhdl, params, &composeResult);
nvmstatus = NvMedia2DGetEOFNvSciSyncFence(nvm2dhdl, &composeResult, &eofnvscisyncfence);
/*eofnvscisyncfence may be used as prefence for some other engine operation
or application can decide to wait on CPU till their expiry using NvSciSyncWait API. */
/***** End of Run time *****/
/*Unregister the inputimgs and outputimg */
nvmstatus = NvMedia2DUnregisterNvSciBufObj(handle, inputimg[i]);
nvmstatus = NvMedia2DUnregisterNvSciBufObj(handle, outputimg);
/***** Unregister registered NvSciSync objects *****/
nvmstatus = NvMedia2DUnRegisterNvSciSyncObj(nvm2dhdl, nvscisyncEOF);
nvmstatus = NvMedia2DUnRegisterNvSciSyncObj(nvm2dhdl, nvscisyncpre);
NvSciSyncAttrListFree(nvscisyncattr_w);
NvSciSyncAttrListFree(nvscisyncattr_s);
NvSciSyncAttrListFree(nvscisyncattr_reconciled);
NvSciSyncObjFree(nvscisyncEOF);
NvSciSyncObjFree(nvscisyncpre);
NvSciSyncModuleClose(nvscisyncModule);