From 7afddd05d5a59206a03bbb082ccc48e3dc04d7d8 Mon Sep 17 00:00:00 2001 From: venkat0907 <98999942+venkat0907@users.noreply.github.com> Date: Thu, 10 Aug 2023 18:41:10 +0530 Subject: [PATCH] EnhancedDMAFDWrapper (#279) * changed Read to Read_Write * added test * added assertion * removed for loop one check was enough --- base/src/DMAFDWrapper.cpp | 6 +++--- base/test/frame_factory_test_dma.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/base/src/DMAFDWrapper.cpp b/base/src/DMAFDWrapper.cpp index 4d99bbc6e..b5bf25cff 100644 --- a/base/src/DMAFDWrapper.cpp +++ b/base/src/DMAFDWrapper.cpp @@ -33,7 +33,7 @@ DMAFDWrapper *DMAFDWrapper::create(int index, int width, int height, } // Use NvBufferMemMapEx - auto res = NvBufferMemMap(buffer->m_fd, 0, NvBufferMem_Read, &(buffer->hostPtr)); + auto res = NvBufferMemMap(buffer->m_fd, 0,NvBufferMem_Read_Write, &(buffer->hostPtr)); if (res) { LOG_ERROR << "NvBufferMemMap Error<>" << res; @@ -44,7 +44,7 @@ DMAFDWrapper *DMAFDWrapper::create(int index, int width, int height, if (colorFormat == NvBufferColorFormat_NV12 || colorFormat == NvBufferColorFormat_YUV420) { - res = NvBufferMemMap(buffer->m_fd, 1, NvBufferMem_Read, &(buffer->hostPtrU)); + res = NvBufferMemMap(buffer->m_fd, 1,NvBufferMem_Read_Write, &(buffer->hostPtrU)); if (res) { LOG_ERROR << "NvBufferMemMap Error<>" << res; @@ -55,7 +55,7 @@ DMAFDWrapper *DMAFDWrapper::create(int index, int width, int height, if (colorFormat == NvBufferColorFormat_YUV420) { - res = NvBufferMemMap(buffer->m_fd, 2, NvBufferMem_Read, &(buffer->hostPtrV)); + res = NvBufferMemMap(buffer->m_fd, 2, NvBufferMem_Read_Write, &(buffer->hostPtrV)); if (res) { LOG_ERROR << "NvBufferMemMap Error<>" << res; diff --git a/base/test/frame_factory_test_dma.cpp b/base/test/frame_factory_test_dma.cpp index e2794b3db..56df0143c 100755 --- a/base/test/frame_factory_test_dma.cpp +++ b/base/test/frame_factory_test_dma.cpp @@ -237,4 +237,19 @@ BOOST_AUTO_TEST_CASE(setMetadata_rawplanarimage) } } +BOOST_AUTO_TEST_CASE(memcopy_read_write) +{ + uint32_t width = 1280; + uint32_t height = 720; + size_t size = width * height * 4; + + auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::ImageType::RGBA, CV_8UC4, size_t(0), CV_8U, FrameMetadata::MemType::DMABUF, true)); + auto frameFactory = framefactory_sp(new FrameFactory(metadata, 10)); + auto frame = frameFactory->create(size, frameFactory); + void *iptr = (static_cast(frame->data()))->getHostPtr(); + memset(iptr,200,size); + unsigned char *bytePtr = static_cast(iptr); + BOOST_TEST(bytePtr[0] == 200); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file