00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _KINO_V4L_H
00022 #define _KINO_V4L_H
00023
00024 #include <vector>
00025 #include <deque>
00026 using std::vector;
00027 using std::deque;
00028
00029 #include <string>
00030
00031 #include <fcntl.h>
00032 #include <unistd.h>
00033 #include <sys/mman.h>
00034 #include <sys/types.h>
00035 #include <sys/stat.h>
00036 #include <sys/ioctl.h>
00037
00038 #include <time.h>
00039 #include <sys/time.h>
00040
00041 #define _DEVICE_H_
00042 #define _LINUX_TIME_H
00043 #include <linux/videodev.h>
00044
00045 #include "displayer.h"
00046
00050 class V4LStruct
00051 {
00052 public:
00053 virtual ~V4LStruct() {}
00054 virtual void *getStruct() = 0;
00055 };
00056
00060 class V4LDevice
00061 {
00062 public:
00063 virtual ~V4LDevice() {}
00064 virtual int getHandle() = 0;
00065 bool request( int req, V4LStruct *v4l );
00066 bool request( int req, void *addr );
00067 };
00068
00072 class V4LCapability : public V4LStruct
00073 {
00074 private:
00075 struct video_capability capability;
00076
00077 public:
00078 V4LCapability( V4LDevice *device );
00079 virtual ~V4LCapability();
00080 void *getStruct();
00081 char *getName();
00082 int getNumberOfChannels();
00083 int getNumberOfAudioDevices();
00084 int getMinWidth();
00085 int getMinHeight();
00086 int getMaxWidth();
00087 int getMaxHeight();
00088 bool canCapture();
00089 bool hasTuner();
00090 bool hasChromakey();
00091 bool hasClipping();
00092 bool hasOverwrite();
00093 bool hasScaling();
00094 bool isMonochrome();
00095 bool canSubCapture();
00096 void report();
00097 };
00098
00099 class V4LTuner : public V4LStruct
00100 {
00101 private:
00102 V4LDevice *device;
00103 struct video_tuner tuner;
00104
00105 public:
00106 V4LTuner( V4LDevice *device, int index );
00107 void *getStruct();
00108 void report();
00109 int getRangeLow();
00110 void setRangeLow( int low );
00111 int getRangeHigh();
00112 void setRangeHigh( int high );
00113 int getFlags();
00114 void setFlags( int flags );
00115 int getMode();
00116 void setMode( int mode );
00117 int getSignal();
00118 };
00119
00120 class V4LChannel : public V4LStruct
00121 {
00122 private:
00123 V4LDevice *device;
00124 struct video_channel channel;
00125 vector <V4LTuner *> tuners;
00126 V4LTuner *current;
00127
00128 public:
00129 V4LChannel( V4LDevice *device, int index );
00130 virtual ~V4LChannel();
00131 void *getStruct();
00132 char *getName();
00133 bool setTuner( unsigned int index );
00134 unsigned int getNumberOfTuners();
00135 V4LTuner *getTuner( unsigned int index );
00136 int getSignal();
00137 void report();
00138 };
00139
00140 class V4LFrame : public V4LStruct
00141 {};
00142
00143 class V4L : public V4LDevice
00144 {
00145 private:
00146 int fd;
00147 vector <V4LChannel *> channels;
00148 V4LChannel *current;
00149 int width;
00150 int height;
00151 void *map;
00152 struct video_mmap frame[ 32 ];
00153 int frame_maps;
00154 int frame_next;
00155 int size;
00156 int frames;
00157 long long starttime;
00158 char *device;
00159 char *input;
00160 int sample;
00161 int fps;
00162 public:
00163 char *audio;
00164 V4LCapability *capability;
00165 V4L();
00166 virtual ~V4L();
00167 void setInfo( char *device, char *input, char *audio, int sample );
00168 bool openDevice();
00169 bool deviceAvailable();
00170 int getHandle();
00171 unsigned int getNumberOfChannels();
00172 V4LChannel *getChannel( unsigned int );
00173 bool setChannel( unsigned int channel );
00174 unsigned int getNumberOfTuners();
00175 V4LTuner *getTuner( unsigned int );
00176 bool setTuner( unsigned int tuner );
00177 bool setCaptureResolution( int width, int height );
00178 int getWidth();
00179 int getHeight();
00180 void startAudio();
00181 void stopAudio();
00182 bool initialiseCapture( int format );
00183 void *getNextFrame();
00184 void stopCapture();
00185 int getFrequency();
00186 bool setFrequency( int frequency );
00187 int getSignal();
00188 void report();
00189 int mappedMemorySize( bool init = false );
00190 int frameSample;
00191 };
00192
00193 class EncoderFrame
00194 {
00195 public:
00196 uint8_t *image;
00197 int width;
00198 int height;
00199
00200 unsigned char audio[ 10240 ];
00201 int length;
00202
00203 EncoderFrame();
00204 ~EncoderFrame();
00205 void setVideo( void *, int, int );
00206 void setAudio( void *, int );
00207 };
00208
00209 class DvEncoder
00210 {
00211 private:
00212 unsigned char data[ 144000 ];
00213 dv_encoder_t *encoder;
00214 FILE *p;
00215 static deque < EncoderFrame * > used;
00216 static deque < EncoderFrame * > available;
00217 bool active;
00218 pthread_t thread;
00219 pthread_mutex_t mutex;
00220 char *filename;
00221 int width;
00222 int height;
00223 public:
00224 char *audio;
00225 DvEncoder( char *, int, int );
00226 ~DvEncoder();
00227 EncoderFrame *getFrame();
00228 void doneWithFrame( EncoderFrame * );
00229 static void *startThread( void * );
00230 void writeThread();
00231 };
00232
00239 class GDKV4L : public V4L
00240 {
00241 private:
00242
00243 Displayer *displayer;
00244 DisplayerInput input;
00245
00246 public:
00247 GtkWidget *widget;
00248 GDKV4L( GtkWidget *widget );
00249 virtual ~GDKV4L();
00250 void startVideo();
00251 void startCapturing();
00252 void stopVideo();
00253 void stopCapturing();
00254 void draw();
00255 void capture( DvEncoder * );
00256 bool active;
00257 bool capturing;
00258 };
00259
00260 #endif