Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

v4lcapture.h

Go to the documentation of this file.
00001 //==========================================================================
00002 //
00003 //  Project:        libfg - Frame Grabber interface for Linux
00004 //
00005 //  Module:         Capture client interface
00006 //
00007 //  Description:    Provides a high-level C interface for controlling frame
00008 //                  grabber and TV tuner cards.  Uses the Video 4 Linux API
00009 //                  (currently v1) and thus supports any V4L supported
00010 //                  device.
00011 //
00012 //  Author:         Gavin Baker <gavinb@antonym.org>
00013 //
00014 //  Homepage:       http://www.antonym.org/libfg
00015 //
00016 //--------------------------------------------------------------------------
00017 //
00018 //  libfg - Frame Grabber interface for Linux
00019 //  Copyright (c) 2002 Gavin Baker
00020 //
00021 //  This library is free software; you can redistribute it and/or
00022 //  modify it under the terms of the GNU Lesser General Public
00023 //  License as published by the Free Software Foundation; either
00024 //  version 2.1 of the License, or (at your option) any later version.
00025 //
00026 //  This library is distributed in the hope that it will be useful,
00027 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00028 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00029 //  Lesser General Public License for more details.
00030 //
00031 //  You should have received a copy of the GNU Lesser General Public
00032 //  License along with this library; if not, write to the Free Software
00033 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00034 //  or obtain a copy from the GNU website at http://www.gnu.org/
00035 //
00036 //==========================================================================
00037 
00038 #ifndef __V4LCAPTURE__H_
00039 #define __V4LCAPTURE__H_
00040 
00041 
00042 #ifdef __cplusplus
00043 extern "C"
00044 {
00045 #endif
00046 
00047 
00048 #include <stdio.h>
00049 #include <fcntl.h>
00050 #include <stdlib.h>
00051 #include <unistd.h>
00052 
00053 #include <sys/mman.h>
00054 #include <sys/ioctl.h>
00055 
00056 #include <linux/fs.h>
00057 #include <linux/kernel.h>
00058 #include <linux/videodev.h>
00059 
00060 #include "v4lframe.h"
00061 
00062 //==========================================================================
00063 //  Definitions
00064 //==========================================================================
00065 
00066 // Standard device for fg_open()
00067 #define FG_DEFAULT_DEVICE       "/dev/video0"
00068 
00069 // Normal capture size
00070 #define FG_DEFAULT_WIDTH        640
00071 #define FG_DEFAULT_HEIGHT       480
00072 
00073 // Percentage of a ushort
00074 #define FG_PERCENT(n)           ((n)*65535/100)
00075 #define FG_50PC                 FG_PERCENT(50)
00076 
00077 // Default input sources
00078 #define FG_SOURCE_TV            0
00079 #define FG_SOURCE_COMPOSITE     1
00080 #define FG_SOURCE_SVIDEO        2
00081 
00082 
00083 //--------------------------------------------------------------------------
00084 //
00085 //  Type:           FRAMEGRABBER
00086 //
00087 //  Description:    Represents all information about a frame grabber
00088 //                  device.  Returned by fg_open(), and used as the first
00089 //                  parameter for all other fg_*() calls.
00090 //
00091 //--------------------------------------------------------------------------
00092 typedef struct
00093 {
00094     char*                       device;     // Device name, eg. "/dev/video"
00095     int                         fd;         // File handle for open device
00096     struct video_capability     caps;       // Capabilities
00097     struct video_channel*       sources;    // Input sources (eg. TV, SVideo)
00098     int                         source;     // Currently selected source
00099     struct video_tuner          tuner;      // TV or Radio tuner
00100     struct video_window         window;     // Capture window
00101     struct video_picture        picture;    // Picture controls (eg. bright)
00102     struct video_mmap           mmap;       // Memory-mapped info
00103     struct video_buffer         fbuffer;    // Frame buffer
00104     struct video_mbuf           mbuf;       // Memory buffer #frames, offsets
00105     void*                       mb_map;     // Memory-mapped buffer
00106     int                         cur_frame;  // Currently capuring frame no.
00107 
00108 } FRAMEGRABBER;
00109 
00110 
00111 
00112 //==========================================================================
00113 //  Prototypes
00114 //==========================================================================
00115 
00116 
00117 //--------------------------------------------------------------------------
00118 //
00119 //  Function:       fg_open
00120 //
00121 //  Description:    Opens and initialises the frame grabber device with
00122 //                  some reasonable default values, and queries for all
00123 //                  capabilities.
00124 //
00125 //  Parameters:     char*   dev     Device name to open, eg. "/dev/video2"
00126 //                                  or NULL for "/dev/video".
00127 //
00128 //  Returns:        FRAMEGRABBER*   The open framegrabber device, or
00129 //                                  NULL in the case of an error.
00130 //
00131 //--------------------------------------------------------------------------
00132 
00133 FRAMEGRABBER* fg_open( const char *dev );
00134 
00135 
00136 //--------------------------------------------------------------------------
00137 //
00138 //  Function:       fg_close
00139 //
00140 //  Description:    Closes an open framegrabber device, and releases all
00141 //                  memory allocated to it.
00142 //
00143 //--------------------------------------------------------------------------
00144 
00145 void fg_close( FRAMEGRABBER* fg );
00146 
00147 
00148 //--------------------------------------------------------------------------
00149 //
00150 //  Function:       fg_grab
00151 //
00152 //  Description:    Reads a frame from the capture device, allocating
00153 //                  a new FRAME instance and returning it.
00154 //                  Note that this is a *blocking* read, and thus will
00155 //                  wait until the next frame is ready.
00156 //                  The caller is responsible for doing a frame_release()
00157 //                  when done with the frame (to free memory).
00158 //
00159 //  Returns:        FRAME*      The most recently captured frame
00160 //                  NULL        On error
00161 //
00162 //  Notes:          This function blocks!
00163 //
00164 //--------------------------------------------------------------------------
00165 
00166 FRAME* fg_grab( FRAMEGRABBER* fg );
00167 
00168 
00169 //--------------------------------------------------------------------------
00170 //
00171 //  Function:       fg_grab_frame
00172 //
00173 //  Description:    Reads a frame from the capture device, using the
00174 //                  existing frame storage as passed in.  Returns the
00175 //                  same instance, with the contents of the last frame.
00176 //                  Note that this is a *blocking* read, and thus will
00177 //                  wait until the next frame is ready.
00178 //
00179 //  Parameters:     FRAME*      An existing frame
00180 //
00181 //  Returns:        FRAME*      The most recently captured frame
00182 //                  NULL        On error
00183 //
00184 //  Notes:          This function blocks!
00185 //                  The size *must* be correct!
00186 //
00187 //--------------------------------------------------------------------------
00188 
00189 FRAME* fg_grab_frame( FRAMEGRABBER* fg, FRAME* fr );
00190 
00191 
00192 //--------------------------------------------------------------------------
00193 //
00194 //  Function:       fg_set_source
00195 //
00196 //  Description:    Specifies the number of the video source to be used
00197 //                  for the input signal.  For example, tuner, composite
00198 //                  or S/Video signal.
00199 //
00200 //  Parameters:     int src     Source id (eg. FG_SOURCE_SVIDEO)
00201 //
00202 //  Returns:        0           On success
00203 //                  -1          Failure
00204 //
00205 //--------------------------------------------------------------------------
00206 
00207 int fg_set_source( FRAMEGRABBER* fg, int src );
00208 
00209 
00210 //--------------------------------------------------------------------------
00211 //
00212 //  Function:       fg_set_source_norm
00213 //
00214 //  Description:    Specifies the video signal norm (eg. PAL, NTSC, SECAM)
00215 //                  for the current input source.
00216 //
00217 //  Parameters:     int norm    Signal norm (eg. VIDEO_MODE_PAL)
00218 //
00219 //  Returns:        0           On success
00220 //                  -1          Failure
00221 //
00222 //--------------------------------------------------------------------------
00223 
00224 int fg_set_source_norm( FRAMEGRABBER* fg, int norm );
00225 
00226 
00227 //--------------------------------------------------------------------------
00228 //
00229 //  Function:       fg_get_source_count
00230 //
00231 //  Description:    Returns the number of input sources available.
00232 //
00233 //  Returns:        >0          Sources (can be used in fg_set_source)
00234 //
00235 //--------------------------------------------------------------------------
00236 
00237 int fg_get_source_count( FRAMEGRABBER* fg );
00238 
00239 
00240 //--------------------------------------------------------------------------
00241 //
00242 //  Function:       fg_get_source_name
00243 //
00244 //  Description:    Returns a user-friendly name corresponding to the
00245 //                  supplied channel number.
00246 //
00247 //  Parameters:     int src     Source id (eg. FG_SOURCE_TV)
00248 //
00249 //  Returns:        char*       Name, like "Television"
00250 //
00251 //--------------------------------------------------------------------------
00252 
00253 char* fg_get_source_name( FRAMEGRABBER* fg, int src );
00254 
00255 
00256 //--------------------------------------------------------------------------
00257 //
00258 //  Function:       fg_set_channel
00259 //
00260 //  Description:    Sets the TV tuner to the specified frequency.
00261 //
00262 //  Parameters:     float freq  Tuner frequency, in MHz
00263 //
00264 //  Returns:        0           Success, tuned in
00265 //                  -1          Failure
00266 //
00267 //--------------------------------------------------------------------------
00268 
00269 int fg_set_channel( FRAMEGRABBER* fg, float freq );
00270 
00271 
00272 //--------------------------------------------------------------------------
00273 //
00274 //  Function:       fg_get_channel
00275 //
00276 //  Description:    Queries the current frequency of the TV tuner.
00277 //
00278 //  Returns:        float       The frequency in MHz
00279 //
00280 //--------------------------------------------------------------------------
00281 
00282 float fg_get_channel( FRAMEGRABBER* fg );
00283 
00284 
00285 //--------------------------------------------------------------------------
00286 //
00287 //  Function:       fg_set_format
00288 //
00289 //  Description:    Specifies the capture format to use.  Must be one of
00290 //                  the VIDEO_PALETTE_* flags.
00291 //
00292 //  Notes:          Currently only RGB32 and RGB24 are properly supported.
00293 //
00294 //  Returns:        0           Success
00295 //
00296 //--------------------------------------------------------------------------
00297 
00298 int fg_set_format( FRAMEGRABBER* fg, int fmt );
00299 
00300 //--------------------------------------------------------------------------
00301 //
00302 //  Function:       fg_set_capture_window
00303 //
00304 //  Description:    Specifies a sub-window of the input source to capture.
00305 //
00306 //  Parameters:     int         x           }
00307 //                  int         y           }  A window that is smaller than
00308 //                  int         width       } or equal to the capture window
00309 //                  int         height      }
00310 //
00311 //  Returns:        0           Success
00312 //                  -1          Failure
00313 //
00314 //--------------------------------------------------------------------------
00315 
00316 int fg_set_capture_window( FRAMEGRABBER* fg,
00317                            int x, int y, int width, int height );
00318 
00319 
00320 //--------------------------------------------------------------------------
00321 //
00322 //  Function:       fg_set_brightness
00323 //
00324 //  Description:    Sets the picture brightness to the specified value.
00325 //
00326 //  Parameters:     int         br          Brightness (in percent)
00327 //
00328 //  Returns:        0           Success
00329 //                  -1          Failure
00330 //
00331 //--------------------------------------------------------------------------
00332 
00333 int fg_set_brightness( FRAMEGRABBER* fg, int br );
00334 
00335 
00336 //--------------------------------------------------------------------------
00337 //
00338 //  Function:       fg_set_contrast
00339 //
00340 //  Description:    Sets the picture contrast to the specified value.
00341 //
00342 //  Parameters:     int         ct          Contrast (in percent)
00343 //
00344 //  Returns:        0           Success
00345 //                  -1          Failure
00346 //
00347 //--------------------------------------------------------------------------
00348 
00349 int fg_set_contrast( FRAMEGRABBER* fg, int ct );
00350 
00351 
00352 //--------------------------------------------------------------------------
00353 //
00354 //  Function:       fg_new_compatible_frame
00355 //
00356 //  Description:    Returns a newly allocated frame that is compatible with
00357 //                  the current frame grabber settings; that is, the window
00358 //                  width and height, and the capture format.  This frame
00359 //                  must be deleted by the caller with frame_release().
00360 //
00361 //  Returns:        FRAME*      A new frame
00362 //
00363 //--------------------------------------------------------------------------
00364 
00365 FRAME* fg_new_compatible_frame( FRAMEGRABBER* fg );
00366 
00367 
00368 //--------------------------------------------------------------------------
00369 //
00370 //  Function:       fg_dump_info
00371 //
00372 //  Description:    Dumps to the console on stdout all the status
00373 //                  information available for the framegrabber.
00374 //
00375 //--------------------------------------------------------------------------
00376 
00377 void fg_dump_info( FRAMEGRABBER* fg );
00378 
00379 
00380 //==========================================================================
00381 
00382 #ifdef __cplusplus
00383 }
00384 #endif
00385 
00386 #endif /* __CAPTURE__H_ */

Generated on Tue May 3 14:15:36 2005 for Player by doxygen 1.3.6