Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Devices/Video.h

00001 #ifndef __xvvideo_h
00002 #define __xvvideo_h
00003 
00004 /*                                                      -*-c++-*-
00005     Copyright (C) 2000 Gregory D. Hager and Darius Burschka (JHU
00006     Lab for Computational Interaction with Physical Systems (CIPS))
00007 
00008 Permission is granted to any individual or institution to use, copy,
00009 modify, and distribute this software, provided that this complete
00010 copyright and permission notice is maintained, intact, in all copies and
00011 supporting documentation.  Authors of papers that describe software
00012 systems using this software package are asked to acknowledge such use by
00013 a brief statement in the paper.
00014 
00015 We provide this software "as is" without express or implied warranty.
00016 */
00017 
00018 #include <stdlib.h>
00019 #include "XVImageRGB.h"
00020 
00021 typedef enum {MODE_CAP_SINGLE = 0, MODE_CAP_CONTINUOUS = 1}       XVCapture_Mode;
00022 typedef enum {NORM_NTSC=0,NORM_PAL,NORM_SECAM, INPUT_DETERMINED}  XV_Video_Norms;
00023 typedef enum {FULL_SIZE, HALF_SIZE, QUARTER_SIZE}                 XV_Resolution;
00024 
00025 // XVSize is defined in XVImageBase.h
00026 
00027 extern XVSize XVSize_AVI_full,
00028   XVSize_NTSC_full,
00029   XVSize_NTSC_half,
00030   XVSize_NTSC_quarter;
00031 
00032 //
00033 typedef struct
00034 {
00035    char   c;             // parameter specification e.g. B
00036    int  val;             // assigned value
00037 }XVParser;
00038 
00048 template <class PIXTYPE>
00049 class Video
00050 {
00051 protected:
00052 
00053   const char     *name;
00054   XVSize          size;
00055 
00056   // By default, it is assumed that any video device might use multiple
00057   // buffers (e.g. a ring-buffer), so video provides basic support for
00058   // managing them.
00059 
00060   XVImageRGB<PIXTYPE>      *image_buffers;
00061   int               n_buffers;
00062   int             current_buffer;
00063 
00064   // This is the index of the most recently acquired frame. 
00065 
00066   int             frame_count;
00067   XVCapture_Mode  capture_mode;
00068 
00069   // Default creation of buffers to be used in open
00070   
00071   XVImageRGB<PIXTYPE> *init_map(XVSize s, int n_buffers);
00072 
00073   // Some local buffer management...by default this is just a ring queue
00074 
00075   virtual int next_buffer() {
00076     return (current_buffer = (++current_buffer%=n_buffers));};
00077 
00078   // parse through the param string, the resulting char * is
00079   // modified by each call
00080   //     return 1     - got parameters
00081   //     return 0     - end of file
00082   //     return -1    - error
00083   int   parse_param(char * &paramstring,XVParser &result);
00084 
00085   XVImageRGB<PIXTYPE> *frame_addr(int i) const 
00086   {
00087     assert(i<buffer_count());
00088     return image_buffers+i;
00089   }
00090   // describes if the buffers in XVImageRGB where created by Video
00091   int   own_buffers;
00092 
00093  public:
00094 
00095   /* This is the generic declaration of a video device and is what
00096      the user would normally see when opening it.  The second
00097      parameter is not used, but is here for reference since
00098      most devices will probably want to pass a parameter string in
00099      to get some default device configuration. */
00100 
00101   Video(const char *dev_name="/dev/video",const char *parm_string = NULL);
00102 
00103   virtual ~Video();
00104 
00107   int          buffer_count(void) const {return n_buffers;};
00108 
00110   XVImageRGB<PIXTYPE> &frame(int i) const {return *(frame_addr(i));}
00111 
00113   XVImageRGB<PIXTYPE> &current_frame() const {return frame(current_buffer);}
00114 
00120   virtual int  initiate_acquire(int buffernum)=0;
00121   virtual int  wait_for_completion(int buffernum)=0;
00122   int          release_buffer(int buffernum){};
00123 
00129   int &request_frame_continuous(int framenum) {
00130     while (frame_count < framenum)
00131       next_frame_continuous();
00132 
00133     return frame_count;
00134   }
00135 
00136   XVImageRGB<PIXTYPE> &next_frame_continuous() {
00137     if (capture_mode != MODE_CAP_CONTINUOUS) {// Start the cycle
00138       capture_mode = MODE_CAP_CONTINUOUS;
00139       initiate_acquire(current_buffer);
00140     }
00141     int temp = current_buffer;
00142     initiate_acquire(next_buffer());
00143     wait_for_completion(temp);
00144     frame_count++;
00145     return frame(temp);
00146   }
00147 
00151   int request_frame_poll(int framenum) {
00152     int next;
00153 
00154     if (capture_mode != MODE_CAP_SINGLE) {
00155       wait_for_completion(current_buffer);
00156       capture_mode = MODE_CAP_SINGLE;
00157       frame_count++;
00158     }
00159     while (framenum > frame_count) {
00160       initiate_acquire(next=next_buffer());
00161       wait_for_completion(next);
00162       frame_count++;
00163     }
00164     return (current_buffer);
00165   };
00166 
00167   const XVImageRGB<PIXTYPE> &next_frame_poll(void)
00168   {
00169     if (request_frame_poll(frame_count++))
00170       return current_frame();
00171   }
00172 
00173   //*** hardware device functions that need to be implemented for
00174   //*** any device
00175 
00176   // paramstring content
00177   // Bxx     - xx number of available buffers
00178   // I[0-2]  - input number
00179   // N[0-..] - norm XV_Video_Norms
00180   // S[1-2]  - full size, half size...
00181   virtual int  set_params(char *paramstring)=0;
00182   // This allow remapping of video buffers --- for example the
00183   // buffering class manages it's own; many framegrabber remap memory, etc.
00184 
00185   XVImageRGB<PIXTYPE> *remap(PIXTYPE *mm_buf[],int n_buffers);
00186 
00187 };
00188 #endif
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000