#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include "config.h"

#include <XVImageBase.h>
#include <XVColorImage.h>
#include <XVWindowX.h>
#include <XVVideo.h>
#ifdef HAVE_BTTV
#include <XVBt8x8.h>
#endif



int main (int argc, char **argv)
{
  int num_buffers;  /* number of buffers held by video device */
  XVImageRGB<XV_RGB> im;
  XVWindowX <XV_RGB> *win;
  XVVideo <XVImageRGB<XV_RGB> > *vid;

  vid = new XVBt8x8 <XVImageRGB<XV_RGB> > ("/dev/video0");
  vid->set_params("B2I1N0");
  num_buffers = vid->buffer_count();

  win = new XVWindowX <XV_RGB> (vid->frame(0));
  win->map();

  while(1) {
    im = vid->next_frame_continuous();
    
    win->CopySubImage(im);

    win->swap_buffers();
    win->flush();
  }
 
  return 0;
}