Skip to content

Commit

Permalink
Merge branch 'main' into MotionVectorExtractorFix
Browse files Browse the repository at this point in the history
  • Loading branch information
mraduldubey authored Aug 23, 2023
2 parents 62afbab + 88864b2 commit ee40723
Show file tree
Hide file tree
Showing 12 changed files with 2,071 additions and 14 deletions.
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ SET(CUDA_CORE_FILES
src/apra_cudamalloc_allocator.cu
src/apra_cudamallochost_allocator.cu
src/CudaMemCopy.cpp
src/MemTypeConversion.cpp
src/CudaStreamSynchronize.cpp
src/CuCtxSynchronize.cpp
src/CudaCommon.cpp
Expand All @@ -323,6 +324,7 @@ SET(CUDA_CORE_FILES
SET(CUDA_CORE_FILES_H
include/CudaStreamSynchronize.h
include/CudaMemCopy.h
include/MemTypeConversion.h
include/apra_cudamallochost_allocator.h
include/apra_cudamalloc_allocator.h
include/CuCtxSynchronize.h
Expand Down Expand Up @@ -486,6 +488,7 @@ IF (ENABLE_CUDA)
test/resizenppi_tests.cpp
test/rotatenppi_tests.cpp
test/ccnppi_tests.cpp
test/memtypeconversion_tests.cpp
)
IF(NOT ENABLE_ARM64) # following tests need CUDA but can not run on ARM ?

Expand Down
102 changes: 88 additions & 14 deletions base/include/DMAFrameUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ImagePlaneData.h"
#include "AIPExceptions.h"
#include "DMAFDWrapper.h"
#include "DMAAllocator.h"
#include <memory>

class DMAFrameUtils
Expand All @@ -22,27 +23,89 @@ class DMAFrameUtils
{
case FrameMetadata::FrameType::RAW_IMAGE:
{
size_t pitch[4] = {0, 0, 0, 0};
auto rawMetadata = FrameMetadataFactory::downcast<RawImageMetadata>(metadata);
imagePlanes.push_back(std::make_shared<ImagePlaneData>(metadata->getDataSize(),
rawMetadata->getStep(),
rawMetadata->getRowSize(),
rawMetadata->getWidth(),
rawMetadata->getHeight()));
auto imageType = rawMetadata->getImageType();
FrameMetadata::MemType inputMemType = metadata->getMemType();
if (inputMemType == FrameMetadata::MemType::DMABUF)
{
int type = CV_8UC4;
switch (imageType)
{
case ImageMetadata::ImageType::RGBA:
case ImageMetadata::ImageType::BGRA:
type = CV_8UC4;
break;
case ImageMetadata::ImageType::UYVY:
case ImageMetadata::ImageType::YUYV:
type = CV_8UC3;
break;
default:
throw AIPException(AIP_FATAL, "Only Image Type accepted are UYVY or ARGB found " + std::to_string(imageType));
}
auto imageType = rawMetadata->getImageType();
auto metadata = framemetadata_sp(new RawImageMetadata(rawMetadata->getWidth(), rawMetadata->getHeight(), imageType, type, size_t(0), CV_8U, FrameMetadata::MemType::DMABUF, true));
DMAAllocator::setMetadata(metadata, rawMetadata->getWidth(), rawMetadata->getHeight(), imageType, pitch);

imagePlanes.push_back(std::make_shared<ImagePlaneData>(metadata->getDataSize(),
pitch[0],
rawMetadata->getRowSize(),
rawMetadata->getWidth(),
rawMetadata->getHeight()));
}

else
{

imagePlanes.push_back(std::make_shared<ImagePlaneData>(metadata->getDataSize(),
rawMetadata->getStep(),
rawMetadata->getRowSize(),
rawMetadata->getWidth(),
rawMetadata->getHeight()));
}

return getDMAFDHostImagePlanes;
}
case FrameMetadata::FrameType::RAW_IMAGE_PLANAR:
{
auto rawMetadata = FrameMetadataFactory::downcast<RawImagePlanarMetadata>(metadata);
auto imageType = rawMetadata->getImageType();

auto channels = rawMetadata->getChannels();
for (auto i = 0; i < channels; i++)
FrameMetadata::MemType inputMemType = metadata->getMemType();
size_t pitch[4] = {0, 0, 0, 0};
size_t offset[4] = {0, 0, 0, 0};
size_t width[4];
size_t height[4];
if (inputMemType == FrameMetadata::MemType::DMABUF)
{
imagePlanes.push_back(std::make_shared<ImagePlaneData>(rawMetadata->getDataSizeByChannel(i),
rawMetadata->getStep(i),
rawMetadata->getRowSize(i),
rawMetadata->getWidth(i),
rawMetadata->getHeight(i)));
for (auto i = 0; i < channels; i++)
{
width[i] = rawMetadata->getWidth(i);
height[i] = rawMetadata->getHeight(i);
}
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(width[0], height[0], imageType, size_t(0), CV_8U, FrameMetadata::MemType::DMABUF));
DMAAllocator::setMetadata(metadata, width[0], height[0], imageType, pitch, offset);

for (auto i = 0; i < channels; i++)
{
imagePlanes.push_back(std::make_shared<ImagePlaneData>(rawMetadata->getDataSizeByChannel(i),
pitch[i],
rawMetadata->getRowSize(i),
width[i],
height[i]));
}
}

else
{
for (auto i = 0; i < channels; i++)
{
imagePlanes.push_back(std::make_shared<ImagePlaneData>(rawMetadata->getDataSizeByChannel(i),
rawMetadata->getStep(i),
rawMetadata->getRowSize(i),
rawMetadata->getWidth(i),
rawMetadata->getHeight(i)));
}
}

switch (imageType)
Expand All @@ -62,8 +125,19 @@ class DMAFrameUtils

static void getDMAFDHostImagePlanes(frame_sp &frame, ImagePlanes &imagePlanes)
{
auto ptr = static_cast<DMAFDWrapper *>(frame->data());
imagePlanes[0]->data = ptr->getHostPtr();
auto inputMetadata = frame->getMetadata();
FrameMetadata::MemType mInputMemType = inputMetadata->getMemType();
if (mInputMemType == FrameMetadata::MemType::DMABUF)
{

auto ptr = static_cast<DMAFDWrapper *>(frame->data());
imagePlanes[0]->data = ptr->getHostPtr();
}
else
{
auto ptr = static_cast<uint8_t *>(frame->data());
imagePlanes[0]->data = ptr;
}
}

static void getDMAFDYUV420HostImagePlanes(frame_sp &frame, ImagePlanes &imagePlanes)
Expand Down
51 changes: 51 additions & 0 deletions base/include/MemTypeConversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include "Module.h"
#include "CudaCommon.h"

class DetailMemory;
class DetailDEVICEtoHOST;
class DetailHOSTtoDEVICE;
class DetailDMAtoHOST;
class DetailHOSTtoDMA;
class DetailDEVICEtoDMA;
class DetailDMAtoDEVICE;

class MemTypeConversionProps : public ModuleProps
{
public:
MemTypeConversionProps(FrameMetadata::MemType _outputMemType) : ModuleProps()
{
outputMemType = _outputMemType;
}

MemTypeConversionProps(FrameMetadata::MemType _outputMemType, cudastream_sp &_stream) : ModuleProps()
{
outputMemType = _outputMemType;
stream_sp = _stream;
stream = _stream->getCudaStream();
}

cudastream_sp stream_sp;
cudaStream_t stream;
FrameMetadata::MemType outputMemType;
};

class MemTypeConversion : public Module
{
public:
MemTypeConversion(MemTypeConversionProps _props);
virtual ~MemTypeConversion();
bool init();
bool term();

protected:
bool process(frame_container &frames);
bool processSOS(frame_sp &frame);
bool validateInputPins();
bool validateOutputPins();
void addInputPin(framemetadata_sp &metadata, string &pinId); // throws exception if validation fails
bool processEOS(string &pinId);
std::shared_ptr<DetailMemory> mDetail;
MemTypeConversionProps mProps;
};
Loading

0 comments on commit ee40723

Please sign in to comment.