Skip to content

Commit

Permalink
EnhancedDMAFDWrapper (#279)
Browse files Browse the repository at this point in the history
* changed Read to Read_Write

* added test

* added assertion

* removed for loop one check was enough
  • Loading branch information
venkat0907 authored Aug 10, 2023
1 parent 388f1c7 commit 7afddd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/src/DMAFDWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions base/test/frame_factory_test_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DMAFDWrapper *>(frame->data()))->getHostPtr();
memset(iptr,200,size);
unsigned char *bytePtr = static_cast<unsigned char *>(iptr);
BOOST_TEST(bytePtr[0] == 200);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 7afddd0

Please sign in to comment.