Changeset 351 in flair-src for trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
- Timestamp:
- Feb 19, 2020, 3:10:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
r350 r351 24 24 #include <FrameworkManager.h> 25 25 #include <fcntl.h> 26 #include <linux/videodev2.h>26 //#include <linux/videodev2.h> 27 27 #include <sys/ioctl.h> 28 28 #include <unistd.h> … … 40 40 V4LCamera::V4LCamera(string name,uint8_t camera_index, uint16_t width, uint16_t height, 41 41 Image::Type::Format format, uint8_t priority) 42 : Thread(getFrameworkManager(), name, priority ,1024*1024),42 : Thread(getFrameworkManager(), name, priority), 43 43 Camera(name, width, height, format) { 44 44 … … 63 63 } 64 64 65 dQueuedBuffer.index=-1;//mark current buffer not valid for initialisation 65 //todo: better handling of detection, only neeeded for omap/dm 66 //also in run, copy from v4l to cmem is not necessary if not using cmem... 67 #ifdef ARMV7A 68 useMemoryUsrPtr=true; 69 #else 66 70 useMemoryUsrPtr=false; 71 #endif 67 72 if(useMemoryUsrPtr) { 68 73 AllocUserBuffers(); … … 153 158 } 154 159 155 /*156 void V4LCamera::Run(void) {157 Time cam_time, new_time, fpsNow, fpsPrev;158 int fpsCounter = 0;159 160 // init image old161 GrabFrame();162 cam_time = GetTime();163 fpsPrev = cam_time;164 165 while (!ToBeStopped()) {166 //check for ps3eye deconnection in hds uav167 if(hasProblems==false) {168 struct v4l2_format form;169 form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;170 xioctl(device, VIDIOC_G_FMT,&form);171 if(xioctl (device, VIDIOC_G_FMT,&form)<0) {172 Thread::Warn("camera disconnected\n");173 hasProblems=true;174 }175 }176 177 // fps counter178 fpsCounter++;179 if (GetTime() > (fpsPrev + 5 * (Time)1000000000)) {180 // every 5 secondes181 fpsNow = GetTime();182 fps->SetText("fps: %.1f",183 fpsCounter / ((float)(fpsNow - fpsPrev) / 1000000000.));184 fpsCounter = 0;185 fpsPrev = fpsNow;186 }187 188 // cam properties189 if (gain->ValueChanged() == true && autogain->Value() == false)190 SetGain(gain->Value());191 if (exposure->ValueChanged() == true && autoexposure->Value() == false)192 SetExposure(exposure->Value());193 if (bright->ValueChanged() == true)194 SetBrightness(bright->Value());195 if (sat->ValueChanged() == true)196 SetSaturation(sat->Value());197 if (contrast->ValueChanged() == true)198 SetContrast(contrast->Value());199 if (hue->ValueChanged() == true)200 SetHue(hue->Value());201 if (sharpness->ValueChanged() == true)202 SetProperty(V4L2_CID_SHARPNESS, sharpness->Value());203 if (autogain->ValueChanged() == true) {204 if (autogain->Value() == true) {205 gain->setEnabled(false);206 } else {207 gain->setEnabled(true);208 SetGain(gain->Value());209 }210 SetAutoGain(autogain->Value());211 }212 if (autoexposure->ValueChanged() == true) {213 if (autoexposure->Value() == true) {214 exposure->setEnabled(false);215 } else {216 exposure->setEnabled(true);217 SetExposure(exposure->Value());218 }219 SetAutoExposure(autoexposure->Value());220 }221 if (awb->ValueChanged() == true)222 SetProperty(V4L2_CID_AUTO_WHITE_BALANCE, awb->Value());223 224 // get picture225 GrabFrame();226 new_time = GetTime();227 228 //check for ps3eye deconnection in hds uav229 if(new_time-cam_time>100*1000*1000) {230 Thread::Warn("delta trop grand\n");231 hasProblems=true;232 }233 234 output->GetMutex();235 output->buffer=(char*)buffers[bufferIndex].start;236 output->ReleaseMutex();237 238 output->SetDataTime(cam_time);239 ProcessUpdate(output);240 241 cam_time = new_time;242 }243 244 close(device);245 }246 */247 160 int V4LCamera::AllocV4LBuffers() { 248 161 struct v4l2_requestbuffers req; … … 304 217 //allocate output data 305 218 imageData = AllocFunction(output->GetDataType().GetSize()); 306 Printf("cmem allocated %i at %x\n",output->GetDataType().GetSize(),imageData);219 //Printf("cmem allocated %i at %x\n",output->GetDataType().GetSize(),imageData); 307 220 308 221 return 1; … … 333 246 return 1; 334 247 }; 335 /* 248 336 249 int V4LCamera::GrabFrame(void) { 337 //queue previous buffer338 if(QueueBuffer(bufferIndex)<0) return -1;339 340 fd_set fds;341 struct timeval tv;342 FD_ZERO (&fds);343 FD_SET (device, &fds);344 345 tv.tv_sec = 0;346 tv.tv_usec = 100000;347 348 int r = select (device+1, &fds, NULL, NULL, &tv);349 350 if (-1 == r) {351 char errorMsg[256];352 Thread::Err("select (%s)\n", strerror_r(-r, errorMsg, sizeof(errorMsg)));353 return -1;354 }355 356 if (0 == r) {357 Thread::Err("select timeout\n");358 return -1;359 }360 361 struct v4l2_buffer buf;362 memset(&buf, 0, sizeof (v4l2_buffer));363 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;364 buf.memory = V4L2_MEMORY_USERPTR;//V4L2_MEMORY_MMAP;365 366 //get last captured image367 int prevDQbuf=-1;368 for(int i=0;i<nbBuffers;i++) {369 if (xioctl (device, VIDIOC_DQBUF, &buf)==-1) {370 if (errno==EAGAIN) {371 break;372 } else {373 Thread::Err("VIDIOC_DQBUF xioctl\n");374 return -1;375 }376 } else {377 if(prevDQbuf!=-1) {378 QueueBuffer(prevDQbuf);379 }380 for (int i=0; i<nbBuffers; i++) {381 if((void*)(buf.m.userptr)==buffers[i]) {382 prevDQbuf=i;383 bufferIndex=i;384 break;385 }386 }387 }388 }389 390 return 1;391 }392 */393 int V4LCamera::cvGrabFrame(void) {394 if(QueueBuffer(&dQueuedBuffer)<0) return -1;395 396 250 fd_set fds; 397 251 struct timeval tv; … … 424 278 } 425 279 426 //get last captured image280 //get last captured buffer 427 281 dQueuedBuffer.index=-1; 428 282 for(int i=0;i<nbBuffers;i++) { … … 505 359 506 360 // cam pictures 507 if (! cvGrabFrame()) {361 if (!GrabFrame()) { 508 362 Printf("Could not grab a frame\n"); 509 }510 511 //copy to CMEM allocated buffer if necessary512 if(!useMemoryUsrPtr) {513 memcpy(imageData,(char *)buffers[dQueuedBuffer.index],output->GetDataType().GetSize());514 363 } 515 364 … … 530 379 }*/ 531 380 381 //select buffer 382 if(useMemoryUsrPtr) {//buffers are already in CMEM 383 imageData=(char*)buffers[dQueuedBuffer.index]; 384 //dequeue it latter (buffer used by ProcessUpdate) 385 } else {//copy to CMEM allocated buffer 386 memcpy(imageData,(char *)buffers[dQueuedBuffer.index],output->GetDataType().GetSize()); 387 QueueBuffer(&dQueuedBuffer);//we can do it right now 388 } 389 532 390 output->GetMutex(); 533 391 output->buffer=imageData; … … 537 395 ProcessUpdate(output); 538 396 cam_time = new_time; 397 398 if(useMemoryUsrPtr) { 399 QueueBuffer(&dQueuedBuffer);//now it is possible to dequeue 400 } 539 401 } 540 402 }
Note:
See TracChangeset
for help on using the changeset viewer.