frame_observer.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 #include <avt_vimba_camera/frame_observer.h>
00034 
00035 FrameObserver::FrameObserver(CameraPtr cam_ptr, Callback callback) : IFrameObserver( cam_ptr ), callback_(callback), cam_ptr_(cam_ptr)
00036 {
00037   // Nothing
00038 }
00039 
00040 void FrameObserver::FrameReceived( const FramePtr vimba_frame_ptr )
00041 {
00042   VmbFrameStatusType eReceiveStatus;
00043 
00044   if ( VmbErrorSuccess == vimba_frame_ptr->GetReceiveStatus( eReceiveStatus ))
00045   {
00046     // Lock the frame queue
00047     mutex.lock();
00048     // Add frame to queue
00049     vimba_frames.push( vimba_frame_ptr );
00050     // Call the callback
00051     callback_(vimba_frame_ptr);
00052     // Unlock frame queue
00053     mutex.unlock();
00054   }
00055   else
00056   {
00057     // If any error occurred we queue the frame without notification
00058     cam_ptr_->QueueFrame( vimba_frame_ptr );
00059   }
00060 }
00061 
00062 // Returns the oldest frame that has not been picked up yet
00063 FramePtr FrameObserver::GetFrame()
00064 {
00065   // Lock the frame queue
00066   mutex.lock();
00067   // Pop frame from queue
00068   FramePtr res = vimba_frames.front();
00069   // Unlock frame queue
00070   mutex.unlock();
00071   return res;
00072 }
00073 
00074 void FrameObserver::ClearFrameQueue()
00075 {
00076   // Lock the frame queue
00077   mutex.lock();
00078   // Clear the frame queue and release the memory
00079   std::queue<FramePtr> empty;
00080   std::swap( vimba_frames, empty );
00081   // Unlock the frame queue
00082   mutex.unlock();
00083 }


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Thu Aug 27 2015 12:29:49