core/vidl/vidl_v4l2_istream.cxx
Go to the documentation of this file.
00001 // This is core/vidl/vidl_v4l2_istream.cxx
00002 #include "vidl_v4l2_istream.h"
00003 //:
00004 // \file
00005 //
00006 // \author Antonio Garrido
00007 // \verbatim
00008 //  Modifications
00009 //   30 Apr 2008 Created (A. Garrido)
00010 //\endverbatim
00011 
00012 #include "vcl_iostream.h"
00013 #include "vidl_frame.h"
00014 #include "vidl_v4l2_pixel_format.h"
00015 
00016 
00017 void vidl_v4l2_istream::update_frame()
00018 {
00019   frame_number_=0;
00020 #if 0
00021   if (!dev) return;
00022   vcl_cout << "Nbuf: " << dev->get_number_of_buffers() << vcl_endl;
00023   if (dev->get_number_of_buffers()!=1 && dev->is_capturing()){
00024     dev->stop_capturing();
00025     if (!dev->set_number_of_buffers(1)) // right now, only 1
00026       vcl_cout << "No puedo!" << vcl_endl;
00027     dev->start_capturing();
00028   }
00029   else if (!dev->set_number_of_buffers(1)) // right now, only 1
00030     vcl_cout << "No!" << vcl_endl;
00031 #endif // 0
00032   dev.set_number_of_buffers(1);
00033   if (dev.ibuffer(0)) {
00034     cur_frame_ = new vidl_shared_frame(
00035         dev.ibuffer(0), dev.get_width(), dev.get_height(), v4l2_to_vidl(dev.get_v4l2_format()));
00036   }
00037   else {
00038     vcl_cout << "No Buf!" << vcl_endl;
00039     cur_frame_=0;
00040   }
00041 }
00042 
00043 vidl_v4l2_istream::vidl_v4l2_istream(vidl_v4l2_device& device): dev(device)
00044 {
00045   update_frame();
00046 }
00047 
00048 bool vidl_v4l2_istream::advance()
00049 {
00050    if (!dev.is_capturing())
00051     if (!dev.start_capturing())
00052        return false;
00053    if (cur_frame_!=0 && dev.read_frame()) {
00054      frame_number_++;
00055      return true;
00056    }
00057    else return false;
00058 }
00059 
00060 vidl_frame_sptr vidl_v4l2_istream::read_frame()
00061 {
00062   advance();
00063   return cur_frame_;
00064 }
00065