3#include "DMAFDWrapper.h"
4#include "nvbuf_utils.h"
5#include "ImageMetadata.h"
6#include "RawImageMetadata.h"
7#include "RawImagePlanarMetadata.h"
8#include "FrameMetadataFactory.h"
9#include "ApraEGLDisplay.h"
26 NvBufferColorFormat colorFormat;
30 colorFormat = NvBufferColorFormat_UYVY;
33 colorFormat = NvBufferColorFormat_YUYV;
36 colorFormat = NvBufferColorFormat_ABGR32;
39 colorFormat = NvBufferColorFormat_ARGB32;
42 colorFormat = NvBufferColorFormat_YUV420;
45 colorFormat = NvBufferColorFormat_NV12;
48 throw AIPException(AIP_FATAL,
"Expected <RGBA/BGRA/UYVY/YUV420/NV12> Actual<" + std::to_string(imageType) +
">");
57 if (!framemetadata->isSet())
66 auto frameType = framemetadata->getFrameType();
72 mWidth = inputRawMetadata->getWidth();
73 mHeight = inputRawMetadata->getHeight();
74 imageType = inputRawMetadata->getImageType();
80 mWidth = inputRawMetadata->getWidth(0);
81 mHeight = inputRawMetadata->getHeight(0);
82 imageType = inputRawMetadata->getImageType();
86 throw AIPException(AIP_FATAL,
"Expected Raw Image or RAW_IMAGE_PLANAR. Actual<" + std::to_string(frameType) +
">");
106 auto dmaFDWrapper =
DMAFDWrapper::create(0, width, height, colorFormat, NvBufferLayout_Pitch, eglDisplay);
109 LOG_ERROR <<
"Failed to allocate dmaFDWrapper";
110 throw AIPException(AIP_FATAL,
"Memory Allocation Failed.");
113 NvBufferParams fdParams;
114 if (NvBufferGetParams(dmaFDWrapper->getFd(), &fdParams))
116 throw AIPException(AIP_FATAL,
"NvBufferGetParams Failed.");
119 LOG_DEBUG <<
"PixelFormat<" << fdParams.pixel_format <<
"> Planes<" << fdParams.num_planes <<
"> NvBufferSize<" << fdParams.nv_buffer_size <<
"> MemSize<" << fdParams.memsize <<
">";
120 for (
auto i = 0; i < fdParams.num_planes; i++)
122 LOG_DEBUG <<
"Width<" << fdParams.width[i] <<
"> Height<" << fdParams.height[i] <<
"> Pitch<" << fdParams.pitch[i] <<
"> Offset<" << fdParams.offset[i] <<
"> PSize<" << fdParams.psize[i] <<
"> Layout<" << fdParams.layout[i] <<
">";
125 auto frameType = metadata->getFrameType();
142 throw AIPException(AIP_FATAL,
"Only Image Type accepted are UYVY or ARGB found " + std::to_string(imageType));
146 inputRawMetadata->setData(rawMetadata);
147 if(pitchValues !=
nullptr)
149 pitchValues[0] = fdParams.pitch[0];
156 size_t step[4] = {0, 0, 0, 0};
157 for (
auto i = 0; i < fdParams.num_planes; i++)
159 step[i] = fdParams.pitch[i];
160 if(pitchValues !=
nullptr)
162 pitchValues[i] = fdParams.pitch[i];
164 if(offsetValues !=
nullptr)
166 offsetValues[i] = fdParams.offset[i];
170 inputRawMetadata->setData(rawMetadata);
174 throw AIPException(AIP_FATAL,
"Expected Raw Image or RAW_IMAGE_PLANAR. Actual<" + std::to_string(frameType) +
">");
188 LOG_ERROR <<
"Failed to allocate dmaFDWrapper";
189 throw AIPException(AIP_FATAL,
"Memory Allocation Failed.");
192 dmaFDWrapper->tempFD = dmaFDWrapper->getFd();
200 return static_cast<void *
>(wrapper);
static EGLDisplay getEGLDisplay()
Definition ApraEGLDisplay.cpp:6
void freeChunks(void *MemPtr, size_t n)
Definition DMAAllocator.h:203
void * allocateChunks(size_t n)
Definition DMAAllocator.h:181
static void setMetadata(framemetadata_sp &metadata, int width, int height, ImageMetadata::ImageType imageType, size_t pitchValues[4]=nullptr, size_t offsetValues[4]=nullptr)
Definition DMAAllocator.h:101
NvBufferColorFormat mColorFormat
Definition DMAAllocator.h:18
int mCount
Definition DMAAllocator.h:22
int mFreeDMACount
Definition DMAAllocator.h:17
EGLDisplay mEglDisplay
Definition DMAAllocator.h:19
DMAAllocator(framemetadata_sp framemetadata)
Definition DMAAllocator.h:55
static NvBufferColorFormat getColorFormat(ImageMetadata::ImageType imageType)
Definition DMAAllocator.h:24
~DMAAllocator()
Definition DMAAllocator.h:93
int mHeight
Definition DMAAllocator.h:20
size_t getChunkSize()
Definition DMAAllocator.h:209
std::vector< DMAFDWrapper * > mDMAFDWrapperArr
Definition DMAAllocator.h:16
int mWidth
Definition DMAAllocator.h:21
Definition DMAFDWrapper.h:8
static DMAFDWrapper * create(int index, int width, int height, NvBufferColorFormat colorFormat, NvBufferLayout layout, EGLDisplay eglDisplay)
Definition DMAFDWrapper.cpp:9
HostAllocator()
Definition Allocators.h:17