Could anyone explain this part of nvstream unicast sample code to me?

Please provide the following info (check/uncheck the boxes after creating this topic):
Software Version
DRIVE OS Linux 5.2.6
DRIVE OS Linux 5.2.6 and DriveWorks 4.0
DRIVE OS Linux 5.2.0
DRIVE OS Linux 5.2.0 and DriveWorks 3.5
NVIDIA DRIVE™ Software 10.0 (Linux)
NVIDIA DRIVE™ Software 9.0 (Linux)
other DRIVE OS version
other

Target Operating System
Linux
QNX
other

Hardware Platform
NVIDIA DRIVE™ AGX Xavier DevKit (E3550)
NVIDIA DRIVE™ AGX Pegasus DevKit (E3550)
other

SDK Manager Version
1.7.1.8928
other

Host Machine Version
native Ubuntu 18.04
other

Dear Nvidia,

I am reading the nvstream unicast sample code, and could not understand the below code, 1. first question is : why mapped_ptr only add pitch size? the pitch size seems even smaller than the loop length (inp_surfaceMap.width * nWidth), so there are overlap and will be re-written in the next loop.
2. second question is: does here the pitch*surfaceMap.height determinate the IPC shared buffer size? or is it the same with consumer side received buffer size?

Thanks!

CHECK_NVMEDIAERR(NvMediaImageLock(nvmimg_in[i],
                                              NVMEDIA_IMAGE_ACCESS_WRITE,
                                              &inp_surfaceMap));

            // Fill predefined data
            uint32_t nWidth = 4U;
            // This code assumes YUV 422 PL images with cpu mapping pointers
            mapped_ptr = (uint8_t*)inp_surfaceMap.surface[0].mapping;
            for (uint32_t y = 0U; y < inp_surfaceMap.height; y++) {
                for (uint32_t x = 0U; x < inp_surfaceMap.width * nWidth; x++) {
                    mapped_ptr[x] = (i + ((x % 32)+ (y % 32) )) % (1 << 8);
                }
                mapped_ptr += **inp_surfaceMap.surface[0].pitch**;
            }
            NvMediaImageUnlock(nvmimg_in[i]);

Dear @shoujiang.ma,
why mapped_ptr only add pitch size? the pitch size seems even smaller than the loop length (inp_surfaceMap.width * nWidth)

mapped_ptr is a unit8 buffer array. The buffer size is height * pitch where pitch is represented in bytes value. So the pointer has to be increased in bytes to go next line in the image buffer.

I hope this clarifies the doubt

Thanks for your reply, so I think the loop is not correctly if just want to fill the memory of (inp_surfaceMap.surface[0].pitch * inp_surfaceMap.height), it should be:

            for (uint32_t y = 0U; y < inp_surfaceMap.height; y++) {
                for (uint32_t x = 0U; x < inp_surfaceMap.surface[0].pitch; x++) {
                    mapped_ptr[x] = (i + ((x % 32)+ (y % 32) )) % (1 << 8);
                }
                mapped_ptr += **inp_surfaceMap.surface[0].pitch**;
            }

From my print log, the inp_surfaceMap.surface[0].pitch < inp_surfaceMap.width * nWidth
Thanks again, we could close this channel.

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