00001
00002
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
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;
00025 int val;
00026 }XVParser;
00027
00037 template <class PIXTYPE>
00038 class XVVideo {
00039
00040 protected:
00041
00042 const char *name;
00043 XVSize size;
00044
00045
00046
00047
00048
00049 XVImageBase<PIXTYPE> * image_buffers;
00050
00051 int n_buffers;
00052 int current_buffer;
00053
00054
00055
00056 int frame_count;
00057 XVCapture_Mode capture_mode;
00058
00059
00060
00061 XVImageBase<PIXTYPE> *init_map(XVSize s, int n_buffers);
00062
00063
00064
00065 virtual int next_buffer() {
00066 return (current_buffer = (++current_buffer%=n_buffers));};
00067
00068
00069
00070
00071
00072
00073 int parse_param(char * ¶mstring,XVParser &result);
00074
00075 XVImageBase<PIXTYPE> *frame_addr(int i) const
00076 {
00077 assert(i<buffer_count());
00078 return image_buffers+i;
00079 }
00080
00081 int own_buffers;
00082
00083 public:
00084
00085 00086 00087 00088 00089
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> ¤t_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) {
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
00164
00165
00166
00167
00168
00169
00170
00171 virtual int set_params(char *paramstring)=0;
00172
00173
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