NvMedia2D NvSciSync API Usage#

/********** Init-time **********/
NvSciSyncModule   nvscisyncModule;
NvSciError        nverr;
NvSciSyncAttrList nvscisyncattr_w;
NvSciSyncAttrList nvscisyncattr_s;
NvSciSyncAttrList nvscisyncattr_unreconciled_h[2];
NvSciSyncAttrList nvscisyncattr_reconciled;
NvSciSyncAttrList nvscisyncattr_conflict;
NvSciSyncFence eofnvscisyncfence = NV_SCI_SYNC_FENCE_INITIALIZER;
NvSciSyncObj nvscisyncEOF, nvscisyncpre;
nvmstatus = NvMedia2DCreate(&nvm2dhdl, &nvm2dattr);
nverr = NvSciSyncModuleOpen(&nvscisyncModule);

/* NvMedia 2D as signaler */
nverr =  NvSciSyncAttrListCreate(nvscisyncModule, &nvscisyncattr_s);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvm2dhdl,
                                           nvscisyncattr_s,
                                           NVMEDIA_SIGNALER);
nvscisyncattr_unreconciled_h[0] = nvscisyncattr_s;
nvscisyncattr_unreconciled_h[1] = get attr list from the appropriate waiter;
nverr =  NvSciSyncAttrListReconcile(nvscisyncattr_unreconciled_h,
                                    2,
                                    &nvscisyncattr_reconciled,
                                    &nvscisyncattr_conflict);
nverr =  NvSciSyncObjAlloc(nvscisyncattr_reconciled, &nvscisyncEOF);

/* NvMedia 2D as waiter */
nverr =  NvSciSyncAttrListCreate(&nvscisyncattr_w);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvm2dhdl,
                                           nvscisyncattr_w,
                                           NVMEDIA_WAITER);
/*
 * If the signaler is also in the same process as the NvMedia 2D waiter, then
 * NvSciSyncAttrListReconcileAndObjAlloc or NvSciSyncAttrListReconcile and
 * NvSciSyncObjAlloc API pair has/have to be used to allocate the "nvscisyncpre"
 * NvSciSyncObject.
 *
 * If the signaler is in a different process/VM than the NvMedia 2D Waiter, then
 * NvSciSyncAttrList export/import APIs and NvSciSyncObjIpc Export/Import APIs
 * have to be used to allocate a NvSciSyncObject on signaler and waiter sides.
 * The "nvscisyncpre" NvSciSyncObject 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.
 */

/* Registration of NvSciSync Objects */
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl,
                                          NVMEDIA_EOFSYNCOBJ,
                                          nvscisyncEOF);
/*
 * Register all the NvSciSync objects which will be used to generate prefences
 * for NvMedia2DCompose operation. "nvscisyncpre" is one such Pre NvSciSync
 * object in this example.
 */
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl,
                                          NVMEDIA_PRESYNCOBJ,
                                          nvscisyncpre);

/********** Run-time **********/
nvmstatus = NvMedia2DSetNvSciSyncObjforEOF(nvm2dhdl, nvm2dparams, nvscisyncEOF);
/*
 * Get an NvSciSyncFence from somewhere (maybe a eofnvscisyncfence of some other
 * engine operation) which neeeds to be inserted as prefence for the
 * NvMedia2DCompose operation. "prenvscisyncfence" is one such NvSciSyncFence in
 * this example.
 */
nvmstatus = NvMedia2DInsertPreNvSciSyncFence(nvm2dhdl,
                                             nvm2dparams,
                                             prenvscisyncfence);
/*
 * Set other parameters required for the NvMedia2DCompose operation to
 * "nvm2dparams" before submitting the operation.
 */
nvmstatus = NvMedia2DCompose(nvm2dhdl, nvm2dparams, &nvm2dresult);
nvmstatus = NvMedia2DGetEOFNvSciSyncFence(nvm2dhdl,
                                          nvm2dresult,
                                          &eofnvscisyncfence);
/*
 * "eofnvscisyncfence" may be used as prefence for some other engine operation
 * or application can decide to wait on CPU until its expiry using
 * NvSciSyncFenceWait API.
 */

/********** Deinit-time **********/
nvmstatus = NvMedia2DUnregisterNvSciSyncObj(nvm2dhdl, nvscisyncEOF);
nvmstatus = NvMedia2DUnregisterNvSciSyncObj(nvm2dhdl, nvscisyncpre);
NvSciSyncAttrListFree(nvscisyncattr_w);
NvSciSyncAttrListFree(nvscisyncattr_s);
NvSciSyncAttrListFree(nvscisyncattr_reconciled);
NvSciSyncObjFree(nvscisyncEOF);
NvSciSyncObjFree(nvscisyncpre);
NvSciSyncModuleClose(nvscisyncModule);