Logo Search packages:      
Sourcecode: camstream version File versions  Download package

void CVideoDevice::Init (  )  [private]

Gather data from video device, like name, size, etc. Also initializes buffers.

This function must be called after every first open.

Definition at line 155 of file VideoDevice.cc.

References GetSize().

Referenced by Open().

{
   struct video_window vwin;
   int i;

qDebug("CVideoDevice::Init()");
   if (CamFD < 0) {
     qDebug("CVideoDevice::Init: device not openend.");
     return;
   }
   if (Opened > 1) {
     qDebug("CVideoDevice::Init: device already opened.");
     return;
   }
   
   if (ioctl(CamFD, VIDIOCGPICT, &VPic) < 0) {
     qDebug("CVideoDevice::Init: could not get picture parameters. (duh?)");
     return;
   }
   Palette = VPic.palette; // To start with

   HasFramerate = FALSE;
   memset(&vwin, 0, sizeof(struct video_window));
   if (ioctl(CamFD, VIDIOCGWIN, &vwin) == 0) {
#if defined(PWC_FPS_SHIFT)
     if ((vwin.flags & PWC_FPS_FRMASK) >> PWC_FPS_SHIFT) {
       HasFramerate = TRUE;
//qDebug("VideoDevice supports framerate setting [%x].", vwin.flags);
     }
#endif
   }
   CurBuffer = 0;

   GetSize(); // Get current image size

   /* See if device has mmap(); */
   VMBuf.size = 0;
   VMBuf.frames = 0;
   vid_io_buffer_size = 0;
   if (ioctl(CamFD, VIDIOCGMBUF, &VMBuf) == 0) {
qDebug("Using mmap(), VMBuf.size = %d", VMBuf.size);
     vid_io_buffer_size = VMBuf.size;
     if (Buffers > 0) {
       // User specified a number of buffers; see if we can match that.
       if (VMBuf.frames < Buffers) {
         qWarning("CVideoDevice::Init(): there are more buffers requested than MBUF can provide. Limiting buffers.\n");
         Buffers = VMBuf.frames;
       }
     }
     else // We grab everything we can.
       Buffers = VMBuf.frames;
   }
   else {
     VMBuf.size = 0; // Just to be sure....
     VMBuf.frames = 0;
   }
   
   /* See if we can actually mmap() the memory */
   if (VMBuf.size > 0) {
     vid_io_buffer = (uchar *)mmap(NULL, vid_io_buffer_size, PROT_READ, MAP_SHARED, CamFD, 0);
     if (vid_io_buffer == (uchar *)-1) {
       qWarning("CVideoDevice::Init(): mmap() failed (%d). Falling back to non-mmap()ed mode.", errno);
       VMBuf.size = 0;
       vid_io_buffer = NULL;
     }
     else {
       vid_io_offsets.resize(Buffers);
       for (i = 0; i < Buffers; i++)
          vid_io_offsets[i] = VMBuf.offsets[i];
     }
   }

   if (VMBuf.size == 0) { // No mmap or failed: allocate a buffer
qDebug("Allocating own buffer.");
     if (Buffers < 0)
       Buffers = 4; // In case the user didn't specify a buffer size, we make one.
     vid_io_buffer_size = Buffers * max_w * max_h * 4;
     vid_io_buffer = new uchar[vid_io_buffer_size];
     vid_io_offsets.resize(Buffers);
     for (i = 0; i < Buffers; i++)
        vid_io_offsets[i] = i * max_w * max_h * 4;
   }
   if (vid_io_buffer == NULL) {
     qWarning("CVideoDevice::Init() Failed to mmap/allocate memory!");
   }
}


Generated by  Doxygen 1.6.0   Back to index