include/avcap/FormatManager.h

Go to the documentation of this file.
00001 /*
00002  * (c) 2005, 2008 Nico Pranke <Nico.Pranke@googlemail.com>, Robin Luedtke <RobinLu@gmx.de>
00003  *
00004  * This file is part of avcap.
00005  *
00006  * avcap is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * avcap is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with avcap.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 /* avcap is free for non-commercial use.
00021  * To use it in commercial endeavors, please contact Nico Pranke <Nico.Pranke@googlemail.com>
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 /* taken from linux/videodev2.h but all FormatManagers use these fourcc-codes*/
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') /*  8  RGB-3-3-2     */
00053 #define PIX_FMT_RGB555  FOURCC('R','G','B','O') /* 16  RGB-5-5-5     */
00054 #define PIX_FMT_RGB565  FOURCC('R','G','B','P') /* 16  RGB-5-6-5     */
00055 #define PIX_FMT_RGB555X FOURCC('R','G','B','Q') /* 16  RGB-5-5-5 BE  */
00056 #define PIX_FMT_RGB565X FOURCC('R','G','B','R') /* 16  RGB-5-6-5 BE  */
00057 #define PIX_FMT_BGR24   FOURCC('B','G','R','3') /* 24  BGR-8-8-8     */
00058 #define PIX_FMT_RGB24   FOURCC('R','G','B','3') /* 24  RGB-8-8-8     */
00059 #define PIX_FMT_BGR32   FOURCC('B','G','R','4') /* 32  BGR-8-8-8-8   */
00060 #define PIX_FMT_RGB32   FOURCC('R','G','B','4') /* 32  RGB-8-8-8-8   */
00061 #define PIX_FMT_GREY    FOURCC('G','R','E','Y') /*  8  Greyscale     */
00062 #define PIX_FMT_YVU410  FOURCC('Y','V','U','9') /*  9  YVU 4:1:0     */
00063 #define PIX_FMT_YVU420  FOURCC('Y','V','1','2') /* 12  YVU 4:2:0     */
00064 #define PIX_FMT_YUYV    FOURCC('Y','U','Y','V') /* 16  YUV 4:2:2     */
00065 #define PIX_FMT_UYVY    FOURCC('U','Y','V','Y') /* 16  YUV 4:2:2     */
00066 #define PIX_FMT_YUV422P FOURCC('4','2','2','P') /* 16  YVU422 planar */
00067 #define PIX_FMT_YUV411P FOURCC('4','1','1','P') /* 16  YVU411 planar */
00068 #define PIX_FMT_Y41P    FOURCC('Y','4','1','P') /* 12  YUV 4:1:1     */
00069 
00070 /* two planes -- one Y, one Cr + Cb interleaved  */
00071 #define PIX_FMT_NV12    FOURCC('N','V','1','2') /* 12  Y/CbCr 4:2:0  */
00072 #define PIX_FMT_NV21    FOURCC('N','V','2','1') /* 12  Y/CrCb 4:2:0  */
00073 
00074 /*  The following formats are not defined in the V4L2 specification */
00075 #define PIX_FMT_YUV410  FOURCC('Y','U','V','9') /*  9  YUV 4:1:0     */
00076 #define PIX_FMT_YUV420  FOURCC('Y','U','1','2') /* 12  YUV 4:2:0     */
00077 #define PIX_FMT_I420    FOURCC('I','4','2','0') /* 12  identical to YU12 */
00078 #define PIX_FMT_YYUV    FOURCC('Y','Y','U','V') /* 16  YUV 4:2:2     */
00079 #define PIX_FMT_HI240   FOURCC('H','I','2','4') /*  8  8-bit color   */
00080 #define PIX_FMT_HM12    FOURCC('H','M','1','2') /*  8  YUV 4:1:1 16x16 macroblocks */
00081 
00082 /* see http://www.siliconimaging.com/RGB%20Bayer.htm */
00083 #define PIX_FMT_SBGGR8  FOURCC('B','A','8','1') /*  8  BGBG.. GRGR.. */
00084 
00085 /* compressed formats */
00086 #define PIX_FMT_MJPEG    FOURCC('M','J','P','G') /* Motion-JPEG   */
00087 #define PIX_FMT_JPEG     FOURCC('J','P','E','G') /* JFIF JPEG     */
00088 #define PIX_FMT_DV       FOURCC('d','v','s','d') /* 1394          */
00089 #define PIX_FMT_MPEG     FOURCC('M','P','E','G') /* MPEG-1/2/4    */
00090 
00091 /*  Vendor-specific formats   */
00092 #define PIX_FMT_WNVA     FOURCC('W','N','V','A') /* Winnov hw compress */
00093 #define PIX_FMT_SN9C10X  FOURCC('S','9','1','0') /* SN9C10x compression */
00094 #define PIX_FMT_PWC1     FOURCC('P','W','C','1') /* pwc older webcam */
00095 #define PIX_FMT_PWC2     FOURCC('P','W','C','2') /* pwc newer webcam */
00096 #define PIX_FMT_ET61X251 FOURCC('E','6','2','5') /* ET61X251 compression */
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;              // A textual description.
00146                 uint32_t mFourcc;               // The Four Character Code of the format.
00147                 ResolutionList_t        mResList;
00148 
00149 #ifdef _WIN32
00150                 void *mediatype;                /* stores DirectShow-specific format description (only used internaly).
00151                                                                  *< It is always casted to a AM_MEDIA_TYPE
00152                                                                  * DirectShow structure; see DirectShow documentation */
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;                // Always casted to a AM_MEDIA_TYPE DirectShow structure
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 

Generated on Mon Nov 30 11:10:30 2009 for avcap-0.1 by  doxygen 1.5.1