Dear SivaRamaKrishna:
I post my code of getting dwImageCPU, is there something wrong with it ?
SensorIONvmedia::SensorIONvmedia(dwContextHandle_t context, Camera *camera, int cameraWidth, int cameraHeight)
: m_numSiblings(camera->numSiblings)
, m_sensor(camera->sensor)
, m_nvm2Cpu(DW_NULL_HANDLE)
, m_frameHandle(camera->numSiblings)
, m_frameNvmYuv(camera->numSiblings)
, m_frameCpuYuv(camera->numSiblings)
{
dwStatus result = DW_FAILURE;
result = dwContext_getNvMediaDevice(&m_nvmedia, context);
if (result != DW_SUCCESS)
throw std::runtime_error(std::string("Error intializing nvmedia: ") + dwGetStatusName(result));
m_sensor = camera->sensor;
dwImageProperties cameraImageProperties;
dwSensorCamera_getImageProperties(&cameraImageProperties, DW_CAMERA_PROCESSED_IMAGE, m_sensor);
dwImageProperties displayImageProperties = cameraImageProperties;
displayImageProperties.type = DW_IMAGE_NVMEDIA;
result = dwImageStreamer_initialize(&m_nvm2Cpu, &displayImageProperties, DW_IMAGE_CPU, context);
if (result != DW_SUCCESS) {
throw std::runtime_error(std::string("Cannot init image streamer nvm-cpu: ") + dwGetStatusName(result));
}
}
SensorIONvmedia::~SensorIONvmedia(){
if (m_nvm2Cpu != DW_NULL_HANDLE)
dwImageStreamer_release(&m_nvm2Cpu);
}
dwStatus SensorIONvmedia::getFrame(uint32_t siblingIdx){
// try different image types
dwStatus result = DW_FAILURE;
result = dwSensorCamera_readFrame(&m_frameHandle[siblingIdx], siblingIdx, 1000000, m_sensor);
if (result != DW_SUCCESS)
{
m_frameHandle[siblingIdx] = nullptr;
return result;
}
result = dwSensorCamera_getImageNvMedia(&m_frameNvmYuv[siblingIdx], DW_CAMERA_PROCESSED_IMAGE, m_frameHandle[siblingIdx]);
if (result != DW_SUCCESS)
{
m_frameNvmYuv[siblingIdx] = nullptr;
return result;
}
// Send the YUV frame
result = dwImageStreamer_postNvMedia(m_frameNvmYuv[siblingIdx], m_nvm2Cpu); /*added*/
if (result != DW_SUCCESS) {
std::cerr << "cannot post NvMedia YUV frame " << dwGetStatusName(result);
}
return DW_SUCCESS;
}
dwImageCPU *SensorIONvmedia::getCpuYuv(uint32_t siblingIdx){
if(!m_frameCpuYuv[siblingIdx])
{
dwStatus result = dwImageStreamer_receiveCPU(&m_frameCpuYuv[siblingIdx],60000,m_nvm2Cpu);
if(result != DW_SUCCESS)
{
std::cerr << "can not received CPU frame: " << dwGetStatusName(result);
m_frameCpuYuv[siblingIdx] = nullptr;
}
}
return m_frameCpuYuv[siblingIdx];
}
void SensorIONvmedia::releaseCpuYuvFrame(uint32_t siblingIdx){
if(m_frameCpuYuv[siblingIdx])
{
dwImageStreamer_returnReceivedCPU(m_frameCpuYuv[siblingIdx],m_nvm2Cpu);
m_frameCpuYuv[siblingIdx] = nullptr;
}
}
void SensorIONvmedia::releaseFrame(uint32_t siblingIdx){
dwTime_t WAIT_TIME = 33000;
// any image returned back, we put back into the pool
{
dwImageNvMedia *retimg = nullptr;
dwStatus result = dwImageStreamer_waitPostedNvMedia(&retimg, WAIT_TIME, m_nvm2Cpu);
if (result == DW_TIME_OUT) {
IERROR << "Warning: waitPosted (nvmedia cpu) timed out\n";
} else if (result != DW_SUCCESS) {
IERROR << " ERROR waitPostedNvMedia GL: " << dwGetStatusName(result);
} else {
//m_rgbaImagePool.push_back(retimg);
}
}
if (m_frameHandle[siblingIdx]){
dwSensorCamera_returnFrame(&m_frameHandle[siblingIdx]);
}
}