00001 #ifndef VIDEO_MANAGER_H 00002 #define VIDEO_MANAGER_H 00003 00004 #include "../libSock/Socket.h" 00005 #include "JpegReader.h" 00006 #include "JpegStreamSaver.h" 00007 #include "Videogram.h" 00008 00009 class VideoManager 00010 { 00011 public : 00012 typedef void (*SignalF)(void*,const JpegReader *,unsigned int); 00013 protected : 00014 VideoGram reception; 00015 double lastFrameTimeStamp; 00016 double interImageDelay; 00017 double observedFrameRate; 00018 bool paused; 00019 bool readyToRequest; 00020 unsigned char * destination; 00021 00022 unsigned int verbose; 00023 bool terminate; 00024 00025 unsigned int frame; 00026 SignalF signal; 00027 void * signalarg; 00028 pthread_t rec_thr_id; 00029 pthread_t req_thr_id; 00030 pthread_mutex_t sockMtx; 00031 pthread_mutex_t initMtx; 00032 pthread_mutex_t reqMtx; 00033 pthread_cond_t reqCond; 00034 00035 unsigned int width, height; 00036 JpegReader *jpeg; 00037 JpegStreamSaver ssaver; 00038 bool savestream; 00039 00040 bool decodeImage(); 00041 bool receiveOneFrame(); 00042 bool requestNextImage(); 00043 bool requestNextImageIfNecessary(); 00044 bool checkSocketState(); 00045 bool sendInitSeq(); 00046 00047 Socket * videosock; 00048 00049 friend void * video_reception_thread(void * thrarg); 00050 friend void * video_request_thread(void * thrarg); 00051 bool reconnect(); 00052 00053 public : 00054 VideoManager(); 00055 ~VideoManager(); 00056 00057 bool open(const char * hostname, unsigned int port); 00058 bool close(); 00059 00060 bool isPaused() const {return paused;} 00061 bool pause(); 00062 bool resume(); 00063 00064 bool isRecording() const {return savestream;} 00065 void startRecording() {savestream = true;} 00066 void stopRecording() {savestream = false;} 00067 void setRecordingDestination(const char * dirname); 00068 void setRecordingBasename(const char * bname); 00069 00071 // TODO : test other modes 00072 bool setImageSize(unsigned int width, unsigned int height); 00073 bool getImageSize(unsigned int *width, unsigned int *height); 00074 00075 00076 void setDestination(unsigned char * dst) {destination = dst;} 00077 void setSignalFunction(SignalF f, void * arg) { 00078 signal = f; signalarg = arg; 00079 } 00080 00081 void setVerboseLevel(unsigned int v); 00082 00083 void setMaxFrameRate(); 00084 void setFrameRate(double fps); 00085 double getRequiredFrameRate(); 00086 double getObservedFrameRate(); 00087 void setVideoOutputColorSpace(JpegReader::ColorSpace cspace); 00088 }; 00089 00090 00091 00092 00093 #endif // VIDEO_MANAGER_H