bool FirewireVideo::GrabNewest( unsigned char* image, bool wait ) { dc1394video_frame_t *f; err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &f); if( err != DC1394_SUCCESS) throw VideoException("Could not capture frame", dc1394_error_get_string(err) ); if( f ) { while( true ) { dc1394video_frame_t *nf; err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &nf); if( err != DC1394_SUCCESS) throw VideoException("Could not capture frame", dc1394_error_get_string(err) ); if( nf ) { err=dc1394_capture_enqueue(camera,f); f = nf; }else{ break; } } memcpy(image,f->image,f->image_bytes); err=dc1394_capture_enqueue(camera,f); return true; }else if(wait){ return GrabNext(image,true); } return false; }
FirewireFrame FirewireVideo::GetNewest(bool wait) { dc1394video_frame_t *f; err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &f); if( err != DC1394_SUCCESS) throw VideoException("Could not capture frame", dc1394_error_get_string(err) ); if( f ) { while( true ) { dc1394video_frame_t *nf; err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &nf); if( err != DC1394_SUCCESS) throw VideoException("Could not capture frame", dc1394_error_get_string(err) ); if( nf ) { err=dc1394_capture_enqueue(camera,f); f = nf; }else{ break; } } return FirewireFrame(f); }else if(wait){ return GetNext(true); } return FirewireFrame(0); }
void* thread_acq_image(void*) { timespec time_save0, time_save1, t_sleep, t_rem; t_sleep.tv_sec = 0; t_sleep.tv_nsec = 10; dc1394video_frame_t *frame; for (;;) { /* wait for image */ pthread_mutex_lock( &camera_mutex ); int ret = gCamera.wait_for_image(1); pthread_mutex_unlock( &camera_mutex ); if (ret) { pthread_mutex_lock( &camera_mutex ); dc1394error_t err = dc1394_capture_dequeue(gCamera.cam(), DC1394_CAPTURE_POLICY_POLL, &frame); /* frame->timestamp appears to be broken, so we have to resort to clock_gettime */ timespec fts; clock_gettime( CLOCK_REALTIME, &fts ); double ft = t2d(fts); pthread_mutex_unlock( &camera_mutex ); if (err) { cleanup_and_exit(gCamera); std::cerr << dc1394_error_get_string(err) << "\nCould not capture frame" << std::endl; } // return frame to ring buffer: // if (frame->image) { pthread_mutex_lock( &camera_mutex ); err = dc1394_capture_enqueue(gCamera.cam(), frame); pthread_mutex_unlock( &camera_mutex ); if (err) { std::cerr << dc1394_error_get_string(err) << "\nCould not return frame to ring buffer" << std::endl; cleanup_and_exit(gCamera); } // } int width = frame->size[0]; int height = frame->size[1]; pthread_mutex_lock( &acq_buffer_mutex ); acq_frame_buffer.push(saveframe(std::vector<unsigned char>(&(frame->image)[0], &(frame->image)[width*height]), width, height, ft)); // (double)frame->timestamp)); pthread_mutex_unlock( &acq_buffer_mutex ); } else { nanosleep(&t_sleep, &t_rem); } } }
bool FirewireVideo::GrabNext( unsigned char* image, bool wait ) { const dc1394capture_policy_t policy = wait ? DC1394_CAPTURE_POLICY_WAIT : DC1394_CAPTURE_POLICY_POLL; dc1394video_frame_t *frame; err = dc1394_capture_dequeue(camera, policy, &frame); if( err != DC1394_SUCCESS) throw VideoException("Could not capture frame", dc1394_error_get_string(err) ); if( frame ) { memcpy(image,frame->image,frame->image_bytes); dc1394_capture_enqueue(camera,frame); return true; } return false; }