00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FORMATMANAGER_H_
00025 #define FORMATMANAGER_H_
00026
00027 #include <list>
00028 #include <string>
00029
00030 #if !defined(_MSC_VER) && !defined(USE_PREBUILD_LIBS)
00031 # include <stdint.h>
00032 # include "avcap-config.h"
00033 #endif
00034
00035 #include "Manager.h"
00036 #include "avcap-export.h"
00037
00038 #ifdef AVCAP_LINUX
00039 # include <linux/types.h>
00040 # include <linux/videodev.h>
00041 #endif // AVCAP_LINUX
00042
00043 #ifdef _WIN32
00044 typedef unsigned int uint32_t;
00045 #endif
00046
00047
00048
00049 #define FOURCC(a,b,c,d)\
00050 (((uint32_t)(a)<<0)|((uint32_t)(b)<<8)|((uint32_t)(c)<<16)|((uint32_t)(d)<<24))
00051
00052 #define PIX_FMT_RGB332 FOURCC('R','G','B','1')
00053 #define PIX_FMT_RGB555 FOURCC('R','G','B','O')
00054 #define PIX_FMT_RGB565 FOURCC('R','G','B','P')
00055 #define PIX_FMT_RGB555X FOURCC('R','G','B','Q')
00056 #define PIX_FMT_RGB565X FOURCC('R','G','B','R')
00057 #define PIX_FMT_BGR24 FOURCC('B','G','R','3')
00058 #define PIX_FMT_RGB24 FOURCC('R','G','B','3')
00059 #define PIX_FMT_BGR32 FOURCC('B','G','R','4')
00060 #define PIX_FMT_RGB32 FOURCC('R','G','B','4')
00061 #define PIX_FMT_GREY FOURCC('G','R','E','Y')
00062 #define PIX_FMT_YVU410 FOURCC('Y','V','U','9')
00063 #define PIX_FMT_YVU420 FOURCC('Y','V','1','2')
00064 #define PIX_FMT_YUYV FOURCC('Y','U','Y','V')
00065 #define PIX_FMT_UYVY FOURCC('U','Y','V','Y')
00066 #define PIX_FMT_YUV422P FOURCC('4','2','2','P')
00067 #define PIX_FMT_YUV411P FOURCC('4','1','1','P')
00068 #define PIX_FMT_Y41P FOURCC('Y','4','1','P')
00069
00070
00071 #define PIX_FMT_NV12 FOURCC('N','V','1','2')
00072 #define PIX_FMT_NV21 FOURCC('N','V','2','1')
00073
00074
00075 #define PIX_FMT_YUV410 FOURCC('Y','U','V','9')
00076 #define PIX_FMT_YUV420 FOURCC('Y','U','1','2')
00077 #define PIX_FMT_I420 FOURCC('I','4','2','0')
00078 #define PIX_FMT_YYUV FOURCC('Y','Y','U','V')
00079 #define PIX_FMT_HI240 FOURCC('H','I','2','4')
00080 #define PIX_FMT_HM12 FOURCC('H','M','1','2')
00081
00082
00083 #define PIX_FMT_SBGGR8 FOURCC('B','A','8','1')
00084
00085
00086 #define PIX_FMT_MJPEG FOURCC('M','J','P','G')
00087 #define PIX_FMT_JPEG FOURCC('J','P','E','G')
00088 #define PIX_FMT_DV FOURCC('d','v','s','d')
00089 #define PIX_FMT_MPEG FOURCC('M','P','E','G')
00090
00091
00092 #define PIX_FMT_WNVA FOURCC('W','N','V','A')
00093 #define PIX_FMT_SN9C10X FOURCC('S','9','1','0')
00094 #define PIX_FMT_PWC1 FOURCC('P','W','C','1')
00095 #define PIX_FMT_PWC2 FOURCC('P','W','C','2')
00096 #define PIX_FMT_ET61X251 FOURCC('E','6','2','5')
00097
00098 namespace avcap
00099 {
00100 class DeviceDescriptor;
00101
00103 struct AVCAP_Export VideoStandard
00104 {
00105 #ifdef AVCAP_LINUX
00106 typedef v4l2_std_id STANDARD_ID_T;
00107 enum {
00108 PAL = V4L2_STD_PAL_B,
00109 NTSC = V4L2_STD_NTSC_M,
00110 SECAM = V4L2_STD_SECAM_B
00111 };
00112 #endif
00113
00114 #if defined (_WIN32) || defined (AVCAP_OSX)
00115 typedef unsigned int STANDARD_ID_T;
00116 #endif
00117
00118
00119 std::string name;
00120 STANDARD_ID_T id;
00121
00123 VideoStandard(const std::string& n, STANDARD_ID_T i):
00124 name(n),
00125 id(i)
00126 {};
00127 };
00128
00130 struct AVCAP_Export Resolution {
00131 int width, height;
00132
00133 Resolution(int w, int h):
00134 width(w),
00135 height(h)
00136 {}
00137 };
00138
00140 class AVCAP_Export Format
00141 {
00142 public:
00143 typedef std::list<Resolution*> ResolutionList_t;
00144 private:
00145 std::string mName;
00146 uint32_t mFourcc;
00147 ResolutionList_t mResList;
00148
00149 #ifdef _WIN32
00150 void *mediatype;
00151
00152
00153 #endif
00154
00155 public:
00157 inline Format(const std::string& n, uint32_t f):
00158 mName(n), mFourcc(f)
00159 {}
00160
00162 virtual ~Format();
00163
00165
00166 inline const std::string& getName() const
00167 { return mName; }
00168
00170
00171 inline uint32_t getFourcc() const
00172 { return mFourcc; }
00173
00175
00176 inline const ResolutionList_t& getResolutionList() const
00177 { return mResList; }
00178
00179 void addResolution(int w, int h);
00180
00181 #ifdef _WIN32
00182 void* getMediaType() { return mediatype; }
00183
00184 void setMediaType(void* mt) { mediatype = mt; }
00185 #endif
00186 };
00187
00189
00200 class AVCAP_Export FormatManager: public Manager<Format>
00201 {
00202 public:
00203 typedef std::list<VideoStandard*> VideoStandardList;
00204
00205 protected:
00206 ListType mFormats;
00207 int mWidth;
00208 int mHeight;
00209 int mBytesPerLine;
00210 #if defined(AVCAP_LINUX) || defined (AVCAP_OSX)
00211 unsigned int mCurrentFormat;
00212 #endif
00213 #ifdef _WIN32
00214 void *mCurrentFormat;
00215 #endif
00216 unsigned long mImageSize;
00217 bool mModified;
00218 VideoStandardList mStandards;
00219
00220 public:
00222 FormatManager(DeviceDescriptor *dd);
00223
00225 virtual ~FormatManager();
00226
00228
00229 virtual inline const ListType& getFormatList() const
00230 { return (const ListType&) mFormats; }
00231
00233
00235 virtual int setFormat(Format *fmt);
00236
00238
00240 virtual int setFormat(uint32_t fourcc);
00241
00243
00244 virtual Format* getFormat();
00245
00247
00250 virtual int setResolution(int w, int h);
00251
00253
00255 virtual int setBytesPerLine(int bpl);
00256
00258
00259 virtual int getWidth();
00260
00262
00263 virtual int getHeight();
00264
00266
00267 virtual int getBytesPerLine();
00268
00270
00271 virtual int flush();
00272
00274
00275 virtual size_t getImageSize();
00276
00278
00281 virtual int setFramerate(int fps);
00282
00284
00286
00289
00290
00294
00296
00299
00303