Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

v4l2capture.h

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  */
00017 //========================================================================
00018 //
00019 // Desc: Own helper functions for capturing from v4l2 device
00020 // Author: Marcin Rudowski
00021 // Email: mar_rud@poczta.onet.pl
00022 // Date: 19 Jun 2006
00023 //
00024 //
00025 // NOTE: this was based on similar library for v4l:
00026 //  Project:        libfg - Frame Grabber interface for Linux
00027 //  Author:         Gavin Baker <gavinb@antonym.org>
00028 //  Homepage:       http://www.antonym.org/libfg
00029 //--------------------------------------------------------------------------
00030 
00031 //========================================================================
00051 #ifndef __V4L2CAPTURE__H_
00052 #define __V4L2CAPTURE__H_
00053 
00054 
00055 #ifdef __cplusplus
00056 extern "C"
00057 {
00058 #endif
00059 
00060 
00061 #include <stdio.h>
00062 #include <fcntl.h>
00063 #include <stdlib.h>
00064 #include <unistd.h>
00065 
00066 #include <sys/mman.h>
00067 #include <sys/ioctl.h>
00068 
00069 #include <linux/fs.h>
00070 #include <linux/kernel.h>
00071 #include <asm/types.h>          /* for videodev2.h */
00072 #include <linux/videodev.h>
00073 
00074 
00075 //==========================================================================
00076 //  Definitions
00077 //==========================================================================
00078 
00079 // Standard device for fg2_open()
00080 #define FG_DEFAULT_DEVICE       "/dev/video0"
00081 
00082 // Normal capture size
00083 #define FG_DEFAULT_WIDTH        640
00084 #define FG_DEFAULT_HEIGHT       480
00085 
00086 // Default input sources
00087 #define FG_SOURCE_TV            0
00088 #define FG_SOURCE_COMPOSITE     1
00089 #define FG_SOURCE_SVIDEO        2
00090 
00091 
00096 struct my_buffer
00097 {
00098     int id;
00099     void * start;
00100     size_t length;
00101     struct v4l2_buffer *buf;
00102 };
00103 
00104 
00108 typedef struct
00109 {
00110     char*                       device;     // Device name, eg. "/dev/video"
00111     int                         fd;         // File handle for open device
00112     struct v4l2_capability      caps;       // Capabilities
00113     unsigned int                numOfIn;    // Number of Inputa
00114     struct v4l2_input*          sources;    // Input sources (eg. TV, SVideo)
00115     int                         source;     // Currently selected source
00116     struct v4l2_format          frmt;       // pixel format
00117     struct my_buffer            *buffers;   // memory mapped buffer
00118     unsigned int                n_buffers;
00119 
00120     struct v4l2_queryctrl       *controls;   // various countrols like brighteness etc
00121     unsigned int                numOfCtls;  // size of controls tab
00122 
00123     int                         isCapturing;
00124     unsigned int                pix_fmt;
00125     unsigned int                width;
00126     unsigned int                height;
00127     enum v4l2_field             field;
00128     int                         depth;
00129     enum v4l2_field             altField; // current field type in alternate mode
00130 
00131 
00132 
00133 
00134     struct v4l2_tuner          tuner;      // TV or Radio tuner
00135     int                         cur_frame;  // Currently capuring frame no.
00136 
00137 } FRAMEGRABBER2;
00138 
00139 
00140 
00141 
00142 //==========================================================================
00143 //                  General access functions
00144 //==========================================================================
00145 
00146 
00151 FRAMEGRABBER2* fg2_createFrameGrabber();
00152 
00153 
00158 void fg2_delete(FRAMEGRABBER2** fg);
00159 
00160 
00168 int fg2_open( FRAMEGRABBER2* fg, const char *dev);
00169 
00170 //==========================================================================
00171 //                  Capturing
00172 //==========================================================================
00173 
00174 
00180 int fg2_startCapture(FRAMEGRABBER2* fg);
00181 
00188 int fg2_stopCapture(FRAMEGRABBER2* fg);
00189 
00190 
00191 
00198 struct my_buffer *getFrameBuffer( FRAMEGRABBER2* fg );
00199 
00200 
00206 void giveBackFrameBuffer( FRAMEGRABBER2* fg, struct my_buffer *mBuff);
00207 
00208 
00209 //==========================================================================
00210 //                  Source selection
00211 //==========================================================================
00212 
00216 int fg2_get_source_count( FRAMEGRABBER2* fg );
00217 
00221 int fg2_get_source_id( FRAMEGRABBER2* fg);
00222 
00226 const char* fg2_get_source_name( FRAMEGRABBER2* fg);
00227 
00231 const char* fg2_get_id_source_name( FRAMEGRABBER2* fg, int src );
00232 
00236 const char * fg2_get_device_name( FRAMEGRABBER2* fg );
00237 
00243 int fg2_set_source( FRAMEGRABBER2* fg, int src, const char *strSrc );
00244 
00245 
00246 //==========================================================================
00247 //                  Changing settings by controls
00248 //==========================================================================
00249 
00253 int fg2_countControls( FRAMEGRABBER2* fg);
00254 
00259 int fg2_setControlValueI( FRAMEGRABBER2* fg, int id, double val);
00264 int fg2_setControlValue( FRAMEGRABBER2* fg, const char *id, double val);
00265 
00270 double fg2_getControlValueI( FRAMEGRABBER2* fg, int id);
00275 double fg2_getControlValue( FRAMEGRABBER2* fg, const char *id);
00276 
00277 
00278 const char *fg2_getControlName( FRAMEGRABBER2* fg, int id);
00279 
00280 //==========================================================================
00281 //                  Other settings
00282 //==========================================================================
00283 
00284 
00288 int fg2_set_source_norm( FRAMEGRABBER2* fg, v4l2_std_id norm );
00289 
00290 
00294 int fg2_setPixelSettings( FRAMEGRABBER2* fg, int width, int height,
00295                           unsigned int fmt, enum v4l2_field fld, int depth );
00296 
00297 
00298 
00299 #ifdef __cplusplus
00300 }
00301 #endif
00302 
00303 #endif /* __CAPTURE__H_ */

Generated on Thu Jun 29 22:04:43 2006 for Camerav4l2 by  doxygen 1.4.4