00001 #ifndef __xvvideo_h
00002 #define __xvvideo_h
00003
00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 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
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;
00036 int val;
00037 }XVParser;
00038
00048 template <class PIXTYPE>
00049 class Video
00050 {
00051 protected:
00052
00053 const char *name;
00054 XVSize size;
00055
00056
00057
00058
00059
00060 XVImageRGB<PIXTYPE> *image_buffers;
00061 int n_buffers;
00062 int current_buffer;
00063
00064
00065
00066 int frame_count;
00067 XVCapture_Mode capture_mode;
00068
00069
00070
00071 XVImageRGB<PIXTYPE> *init_map(XVSize s, int n_buffers);
00072
00073
00074
00075 virtual int next_buffer() {
00076 return (current_buffer = (++current_buffer%=n_buffers));};
00077
00078
00079
00080
00081
00082
00083 int parse_param(char * ¶mstring,XVParser &result);
00084
00085 XVImageRGB<PIXTYPE> *frame_addr(int i) const
00086 {
00087 assert(i<buffer_count());
00088 return image_buffers+i;
00089 }
00090
00091 int own_buffers;
00092
00093 public:
00094
00095 00096 00097 00098 00099
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> ¤t_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) {
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
00174
00175
00176
00177
00178
00179
00180
00181 virtual int set_params(char *paramstring)=0;
00182
00183
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