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

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

00001 // *** BEGIN_XVISION2_COPYRIGHT_NOTICE ***
00002 // *** END_XVISION2_COPYRIGHT_NOTICE ***
00003 
00004 #ifndef _XVVIDEO_H_
00005 #define _XVVIDEO_H_
00006 
00007 #include <stdlib.h>
00008 #include "XVImageRGB.h"
00009 
00010 typedef enum {MODE_CAP_SINGLE = 0, MODE_CAP_CONTINUOUS = 1}       XVCapture_Mode;
00011 typedef enum {NORM_NTSC=0,NORM_PAL,NORM_SECAM, INPUT_DETERMINED}  XV_Video_Norms;
00012 typedef enum {FULL_SIZE, HALF_SIZE, QUARTER_SIZE}                 XV_Resolution;
00013 
00014 // XVSize is defined in XVImageBase.h
00015 
00016 extern XVSize XVSize_AVI_full,
00017   XVSize_NTSC_full,
00018   XVSize_NTSC_half,
00019   XVSize_NTSC_quarter;
00020 
00021 //
00022 typedef struct
00023 {
00024    char   c;             // parameter specification e.g. B
00025    int  val;             // assigned value
00026 }XVParser;
00027 
00037 template <class PIXTYPE>
00038 class XVVideo {
00039 
00040 protected:
00041 
00042   const char     *name;
00043   XVSize          size;
00044 
00045   // By default, it is assumed that any video device might use multiple
00046   // buffers (e.g. a ring-buffer), so video provides basic support for
00047   // managing them.
00048 
00049   XVImageBase<PIXTYPE>     * image_buffers;
00050 
00051   int               n_buffers;
00052   int             current_buffer;
00053 
00054   // This is the index of the most recently acquired frame. 
00055 
00056   int             frame_count;
00057   XVCapture_Mode  capture_mode;
00058 
00059   // Default creation of buffers to be used in open
00060   
00061   XVImageBase<PIXTYPE> *init_map(XVSize s, int n_buffers);
00062 
00063   // Some local buffer management...by default this is just a ring queue
00064 
00065   virtual int next_buffer() {
00066     return (current_buffer = (++current_buffer%=n_buffers));};
00067 
00068   // parse through the param string, the resulting char * is
00069   // modified by each call
00070   //     return 1     - got parameters
00071   //     return 0     - end of file
00072   //     return -1    - error
00073   int   parse_param(char * &paramstring,XVParser &result);
00074 
00075   XVImageBase<PIXTYPE> *frame_addr(int i) const 
00076   {
00077     assert(i<buffer_count());
00078     return image_buffers+i;
00079   }
00080   // describes if the buffers in XVImageRGB where created by Video
00081   int   own_buffers;
00082 
00083  public:
00084 
00085   /* This is the generic declaration of a video device and is what
00086      the user would normally see when opening it.  The second
00087      parameter is not used, but is here for reference since
00088      most devices will probably want to pass a parameter string in
00089      to get some default device configuration. */
00090 
00091   XVVideo(const char *dev_name="/dev/video",const char *parm_string = NULL);
00092 
00093   virtual ~XVVideo();
00094 
00097   int          buffer_count(void) const {return n_buffers;};
00098 
00100   XVImageBase<PIXTYPE> &frame(int i) const {return *(frame_addr(i));}
00101 
00103   XVImageBase<PIXTYPE> &current_frame() const {return frame(current_buffer);}
00104 
00110   virtual int  initiate_acquire(int buffernum)=0;
00111   virtual int  wait_for_completion(int buffernum)=0;
00112   int          release_buffer(int buffernum){};
00113 
00119   int &request_frame_continuous(int framenum) {
00120     while (frame_count < framenum)
00121       next_frame_continuous();
00122 
00123     return frame_count;
00124   }
00125 
00126   XVImageBase<PIXTYPE> &next_frame_continuous() {
00127     if (capture_mode != MODE_CAP_CONTINUOUS) {// Start the cycle
00128       capture_mode = MODE_CAP_CONTINUOUS;
00129       initiate_acquire(current_buffer);
00130     }
00131     int temp = current_buffer;
00132     initiate_acquire(next_buffer());
00133     wait_for_completion(temp);
00134     frame_count++;
00135     return frame(temp);
00136   }
00137 
00141   int request_frame_poll(int framenum) {
00142     int next;
00143 
00144     if (capture_mode != MODE_CAP_SINGLE) {
00145       wait_for_completion(current_buffer);
00146       capture_mode = MODE_CAP_SINGLE;
00147       frame_count++;
00148     }
00149     while (framenum > frame_count) {
00150       initiate_acquire(next=next_buffer());
00151       wait_for_completion(next);
00152       frame_count++;
00153     }
00154     return (current_buffer);
00155   };
00156 
00157   const XVImageBase<PIXTYPE> &next_frame_poll(void)
00158   {
00159     if (request_frame_poll(frame_count++))
00160       return current_frame();
00161   }
00162 
00163   //*** hardware device functions that need to be implemented for
00164   //*** any device
00165 
00166   // paramstring content
00167   // Bxx     - xx number of available buffers
00168   // I[0-2]  - input number
00169   // N[0-..] - norm XV_Video_Norms
00170   // S[1-2]  - full size, half size...
00171   virtual int  set_params(char *paramstring)=0;
00172   // This allow remapping of video buffers --- for example the
00173   // buffering class manages it's own; many framegrabber remap memory, etc.
00174 
00175   XVImageBase<PIXTYPE> *remap(PIXTYPE *mm_buf[],int n_buffers);
00176 
00177   virtual XVImageBase<PIXTYPE> * createImages(int, int, int) = 0;
00178 
00179 };
00180 #endif
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 

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