QCamV4L.hpp

00001 #ifndef _QCamV4L_hpp_
00002 #define _QCamV4L_hpp_
00003 
00004 #include <qobject.h>
00005 #include <qimage.h>
00006 
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 //#include <linux/types.h>
00011 #include <linux/videodev.h>
00012 
00013 #include "QCam.hpp"
00014 
00015 class QCamSlider;
00016 class QTimer;
00017 class QSocketNotifier;
00018 
00020 class QCamV4L : public QCam {
00021    Q_OBJECT
00022 public:
00023    enum Options {
00024       ioNoBlock=(1<<0),
00025       ioUseSelect=(1<<1),
00026       haveBrightness=(1<<2),
00027       haveContrast=(1<<3),
00028       haveHue=(1<<4),
00029       haveColor=(1<<5),
00030       haveWhiteness=(1<<6),
00031       sendJpegFrames=(1<<7)
00032    };
00033    static const int DefaultOptions;
00034    
00035    static QCam * openBestDevice(const char * devpath = "/dev/video0");
00036    QCamV4L(const char * devpath="/dev/video0",
00037            int preferedPalette = 0 /* auto palette*/,
00038            unsigned long options =  DefaultOptions /* cf QCamV4L::options */);
00039    QCamFrame yuvFrame() const { return yuvBuffer_; }
00040    const QSize & size() const;
00041    void resize(const QSize & s);
00042    ~QCamV4L();
00043    int getBrightness() const;
00044    int getContrast() const;
00045    int getColor() const;
00046    int getHue() const;
00047    int getWhiteness() const;
00048    QWidget * buildGUI(QWidget * parent);
00049 protected:
00050    int device_;
00051    unsigned long options_;
00052    struct video_capability capability_;
00053    struct video_window window_;
00054    struct video_picture picture_;
00056    struct video_mbuf mmap_mbuf_;
00057    uchar * mmap_buffer_;
00058    long mmap_last_sync_buff_;
00059    long mmap_last_capture_buff_;
00060    mutable QSize * sizeTable_;
00061    
00062    void updatePictureSettings();
00063    virtual void refreshPictureSettings();
00064    bool dropFrame();
00068    virtual void checkSize(int & x, int & y) const;
00072    virtual const QSize* getAllowedSize() const;
00076    virtual int getFrameRate() const { return 10;}
00077    
00078 private:
00079    bool setSize(int x, int y);
00080    void init(int preferedPalette);
00081    void allocBuffers();
00082    bool mmapInit();
00083    void mmapCapture();
00084    void mmapSync();
00085    uchar * mmapLastFrame() const;
00086 
00087    QCamFrame yuvBuffer_;
00088    uchar * tmpBuffer_;
00089    // to probe the cam for new frame
00090    QTimer * timer_;
00091    // to probe the cam if it support select
00092    QSocketNotifier * notifier_;
00093    QSize size_;
00094    /* for remote controle */
00095    QCamSlider * remoteCTRLbrightness_;
00096    QCamSlider * remoteCTRLcontrast_;
00097    QCamSlider * remoteCTRLhue_;
00098    QCamSlider * remoteCTRLcolor_;
00099    QCamSlider * remoteCTRLwhiteness_;
00100    
00101    ImageMode mode_;
00102    int frameRate_;
00103    
00104 public slots:
00105    void setContrast(int value);
00106    void setBrightness(int value);
00107    void setColor(int value);
00108    void setHue(int value);
00109    void setWhiteness(int value);
00110    void setMode(ImageMode val);
00111    void setMode(int val) /* proxy to ' void setMode(ImageMode val)' */;
00112 protected slots:
00113    virtual bool updateFrame();
00114 signals:
00115    void contrastChange(int);
00116    void brightnessChange(int);
00117    void colorChange(int value);
00118    void hueChange(int value);
00119    void whitenessChange(int value);
00120 };
00121 
00122 #endif

Generated on Sat Oct 27 09:21:03 2007 for QastroCam by  doxygen 1.5.1