avilib.h
Go to the documentation of this file.
00001 /*******************************************************************************#
00002 #           guvcview              http://guvcview.berlios.de                    #
00003 #                                                                               #
00004 #           Paulo Assis <pj.assis@gmail.com>                                    #
00005 #                                                                               #
00006 # This program 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 2 of the License, or             #
00009 # (at your option) any later version.                                           #
00010 #                                                                               #
00011 # This program 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 this program; if not, write to the Free Software                   #
00018 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     #
00019 #                                                                               #
00020 ********************************************************************************/
00021 /*******************************************************************************#
00022 #   Some utilities for writing and reading AVI files.                           # 
00023 #   These are not intended to serve for a full blown                            #
00024 #   AVI handling software (this would be much too complex)                      #
00025 #   The only intention is to write out MJPEG encoded                            #
00026 #   AVIs with sound and to be able to read them back again.                     #
00027 #   These utilities should work with other types of codecs too, however.        #
00028 #                                                                               #
00029 #   Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>                       #
00030 ********************************************************************************/
00031 
00032 
00033 #ifndef AVILIB_H
00034 #define AVILIB_H
00035 
00036 #include "defs.h"
00037 #include <inttypes.h>
00038 #include <sys/types.h>
00039 //#include <glib.h>
00040 
00041 #define AVI_MAX_TRACKS 8
00042 #define FRAME_RATE_SCALE 1000000
00043 
00044 typedef struct _video_index_entry
00045 {
00046         off_t key;
00047         off_t pos;
00048         off_t len;
00049 } video_index_entry;
00050 
00051 typedef struct _audio_index_entry
00052 {
00053         off_t pos;
00054         off_t len;
00055         off_t tot;
00056 } audio_index_entry;
00057 
00058 
00059 typedef struct track_s
00060 {
00061 
00062         long   a_fmt;             /* Audio format, see #defines below */
00063         long   a_chans;           /* Audio channels, 0 for no audio */
00064         long   a_rate;            /* Rate in Hz */
00065         long   a_bits;            /* bits per audio sample */
00066         long   mpgrate;           /* mpg bitrate kbs*/
00067         long   a_vbr;             /* 0 == no Variable BitRate */
00068         long   padrate;       /* byte rate used for zero padding */
00069 
00070         long   audio_strn;        /* Audio stream number */
00071         off_t  audio_bytes;       /* Total number of bytes of audio data */
00072         long   audio_chunks;      /* Chunks of audio data in the file */
00073 
00074         char   audio_tag[4];      /* Tag of audio data */
00075         long   audio_posc;        /* Audio position: chunk */
00076         long   audio_posb;        /* Audio position: byte within chunk */
00077  
00078         off_t  a_codech_off;       /* absolut offset of audio codec information */ 
00079         off_t  a_codecf_off;       /* absolut offset of audio codec information */ 
00080 
00081         audio_index_entry *audio_index;
00082 
00083 } __attribute__ ((packed)) track_t;
00084 
00085 /*
00086 typedef struct
00087 {
00088   DWORD  bi_size;
00089   DWORD  bi_width;
00090   DWORD  bi_height;
00091   DWORD  bi_planes;
00092   DWORD  bi_bit_count;
00093   DWORD  bi_compression;
00094   DWORD  bi_size_image;
00095   DWORD  bi_x_pels_per_meter;
00096   DWORD  bi_y_pels_per_meter;
00097   DWORD  bi_clr_used;
00098   DWORD  bi_clr_important;
00099 } __attribute__ ((packed)) alBITMAPINFOHEADER;
00100 
00101 typedef struct
00102 {
00103   WORD  w_format_tag;
00104   WORD  n_channels;
00105   DWORD  n_samples_per_sec;
00106   DWORD  n_avg_bytes_per_sec;
00107   WORD  n_block_align;
00108   WORD  w_bits_per_sample;
00109   WORD  cb_size;
00110 } __attribute__ ((packed)) alWAVEFORMATEX;
00111 
00112 typedef struct
00113 {
00114   DWORD fcc_type; 
00115   DWORD fcc_handler; 
00116   DWORD dw_flags; 
00117   DWORD dw_caps; 
00118   WORD w_priority;
00119   WORD w_language;
00120   DWORD dw_scale;
00121   DWORD dw_rate;
00122   DWORD dw_start;
00123   DWORD dw_length;
00124   DWORD dw_initial_frames;
00125   DWORD dw_suggested_buffer_size;
00126   DWORD dw_quality;
00127   DWORD dw_sample_size;
00128   DWORD dw_left;
00129   DWORD dw_top;
00130   DWORD dw_right;
00131   DWORD dw_bottom;
00132   DWORD dw_edit_count;
00133   DWORD dw_format_change_count;
00134   char     sz_name[64];
00135 } __attribute__ ((packed)) alAVISTREAMINFO;
00136 
00137 */
00138 
00139 struct avi_t
00140 {
00141         long   fdes;              /* File descriptor of AVI file */
00142         long   mode;              /* 0 for reading, 1 for writing */
00143                                   /* let's make it thead safe                        */
00144   
00145         long   width;             /* Width  of a video frame */
00146         long   height;            /* Height of a video frame */
00147         double fps;               /* Frames per second */
00148         char   compressor[8];     /* Type of compressor, 4 bytes + padding for 0 byte */
00149         char   compressor2[8];     /* Type of compressor, 4 bytes + padding for 0 byte */
00150         long   video_strn;        /* Video stream number */
00151         long   video_frames;      /* Number of video frames */
00152         char   video_tag[4];      /* Tag of video data */
00153         long   video_pos;         /* Number of next frame to be read
00154                                      (if index present) */
00155     
00156         DWORD max_len;    /* maximum video chunk present */
00157   
00158         track_t track[AVI_MAX_TRACKS];  // up to AVI_MAX_TRACKS audio tracks supported
00159   
00160         off_t  pos;               /* position in file */
00161         long   n_idx;             /* number of index entries actually filled */
00162         long   max_idx;           /* number of index entries actually allocated */
00163   
00164         off_t  v_codech_off;      /* absolut offset of video codec (strh) info */ 
00165         off_t  v_codecf_off;      /* absolut offset of video codec (strf) info */ 
00166   
00167         BYTE (*idx)[16]; /* index entries (AVI idx1 tag) */
00168 
00169         video_index_entry *video_index;
00170     
00171         //int is_opendml;           /* set to 1 if this is an odml file with multiple index chunks */
00172   
00173         off_t  last_pos;          /* Position of last frame written */
00174         DWORD last_len;   /* Length of last frame written */
00175         int must_use_index;       /* Flag if frames are duplicated */
00176         off_t  movi_start;
00177         int total_frames;         /* total number of frames if dmlh is present */
00178     
00179         int anum;            // total number of audio tracks 
00180         int aptr;            // current audio working track 
00181         // int comment_fd;      // Read avi header comments from this fd
00182         // char *index_file;    // read the avi index from this file
00183   
00184         //alBITMAPINFOHEADER *bitmap_info_header;
00185         //alWAVEFORMATEX *wave_format_ex[AVI_MAX_TRACKS];
00186 
00187         void*   extradata;
00188         ULONG   extradata_size;
00189         int closed; /* 0 - AVI is opened(recordind) 1 -AVI is closed (not recording)*/ 
00190 
00191 } __attribute__ ((packed));
00192 
00193 #define AVI_MODE_WRITE  0
00194 #define AVI_MODE_READ   1
00195 
00196 /* The error codes delivered by avi_open_input_file */
00197 
00198 #define AVI_ERR_SIZELIM      1     /* The write of the data would exceed
00199                                       the maximum size of the AVI file.
00200                                       This is more a warning than an error
00201                                       since the file may be closed safely */
00202 
00203 #define AVI_ERR_OPEN         2     /* Error opening the AVI file - wrong path
00204                                       name or file nor readable/writable */
00205 
00206 #define AVI_ERR_READ         3     /* Error reading from AVI File */
00207 
00208 #define AVI_ERR_WRITE        4     /* Error writing to AVI File,
00209                                       disk full ??? */
00210 
00211 #define AVI_ERR_WRITE_INDEX  5     /* Could not write index to AVI file
00212                                       during close, file may still be
00213                                       usable */
00214 
00215 #define AVI_ERR_CLOSE        6     /* Could not write header to AVI file
00216                                       or not truncate the file during close,
00217                                       file is most probably corrupted */
00218 
00219 #define AVI_ERR_NOT_PERM     7     /* Operation not permitted:
00220                                       trying to read from a file open
00221                                       for writing or vice versa */
00222 
00223 #define AVI_ERR_NO_MEM       8     /* malloc failed */
00224 
00225 #define AVI_ERR_NO_AVI       9     /* Not an AVI file */
00226 
00227 #define AVI_ERR_NO_HDRL     10     /* AVI file has no has no header list,
00228                                       corrupted ??? */
00229 
00230 #define AVI_ERR_NO_MOVI     11     /* AVI file has no has no MOVI list,
00231                                       corrupted ??? */
00232 
00233 #define AVI_ERR_NO_VIDS     12     /* AVI file contains no video data */
00234 
00235 #define AVI_ERR_NO_IDX      13     /* The file has been opened with
00236                                       getIndex==0, but an operation has been
00237                                       performed that needs an index */
00238 
00239 /* Possible Audio formats */
00240 
00241 #define WAVE_FORMAT_UNKNOWN             (0x0000)
00242 #define WAVE_FORMAT_PCM                 (0x0001)
00243 #define WAVE_FORMAT_ADPCM               (0x0002)
00244 #define WAVE_FORMAT_IBM_CVSD            (0x0005)
00245 #define WAVE_FORMAT_ALAW                (0x0006)
00246 #define WAVE_FORMAT_MULAW               (0x0007)
00247 #define WAVE_FORMAT_OKI_ADPCM           (0x0010)
00248 #define WAVE_FORMAT_DVI_ADPCM           (0x0011)
00249 #define WAVE_FORMAT_DIGISTD             (0x0015)
00250 #define WAVE_FORMAT_DIGIFIX             (0x0016)
00251 #define WAVE_FORMAT_YAMAHA_ADPCM        (0x0020)
00252 #define WAVE_FORMAT_DSP_TRUESPEECH      (0x0022)
00253 #define WAVE_FORMAT_GSM610              (0x0031)
00254 #define IBM_FORMAT_MULAW                (0x0101)
00255 #define IBM_FORMAT_ALAW                 (0x0102)
00256 #define IBM_FORMAT_ADPCM                (0x0103)
00257 /*extra audio formats (codecs)*/
00258 #define DOLBY_FORMAT_AC3                (0x2000)
00259 #define ANTEX_FORMAT_ADPCME             (0x0033)
00260 #define AUDIO_FORMAT_APTX               (0x0025)
00261 #define AUDIOFILE_FORMAT_AF10           (0x0026)
00262 #define AUDIOFILE_FORMAT_AF36           (0x0024) 
00263 #define BROOKTREE_FORMAT_BTVD           (0x0400)
00264 #define CANOPUS_FORMAT_ATRAC            (0x0063)
00265 #define CIRRUS_FORMAT_CIRRUS            (0x0060)
00266 #define CONTROL_FORMAT_CR10             (0x0037)
00267 #define CONTROL_FORMAT_VQLPC            (0x0034)
00268 #define CREATIVE_FORMAT_ADPCM           (0x0200)
00269 #define CREATIVE_FORMAT_FASTSPEECH10    (0x0203)
00270 #define CREATIVE_FORMAT_FASTSPEECH8     (0x0202)
00271 #define IMA_FORMAT_ADPCM                (0x0039)
00272 #define CONSISTENT_FORMAT_CS2           (0x0260)
00273 #define HP_FORMAT_CU                    (0x0019)
00274 #define DEC_FORMAT_G723                 (0x0123)
00275 #define DF_FORMAT_G726                  (0x0085)
00276 #define DSP_FORMAT_ADPCM                (0x0036)
00277 #define DOLBY_FORMAT_AC2                (0x0030)
00278 #define DOLBY_FORMAT_AC3_SPDIF          (0x0092)
00279 #define ESS_FORMAT_ESPCM                (0x0061)
00280 #define IEEE_FORMAT_FLOAT               (0x0003)
00281 #define ISO_FORMAT_MP3                  (0x0055)
00282 #define ISO_FORMAT_MPEG12               (0x0050)
00283 #define MS_FORMAT_MSAUDIO1_DIVX         (0x0160)
00284 #define MS_FORMAT_MSAUDIO2_DIVX         (0x0161)
00285 #define OGG_FORMAT_VORBIS1              (0x674f)
00286 #define OGG_FORMAT_VORBIS1P             (0x676f)
00287 #define OGG_FORMAT_VORBIS2              (0x6750)
00288 #define OGG_FORMAT_VORBIS2P             (0x6770)
00289 #define OGG_FORMAT_VORBIS3              (0x6751)
00290 #define OGG_FORMAT_VORBIS3P             (0x6771)
00291 #define MS_FORMAT_WMA9                  (0x0163)
00292 #define MS_FORMAT_WMA9_PRO              (0x0162)
00293 
00294 int AVI_open_output_file(struct avi_t *AVI, const char * filename);
00295 void AVI_set_video(struct avi_t *AVI, int width, int height, double fps, char *compressor);
00296 void AVI_set_audio(struct avi_t *AVI, int channels, long rate, int mpgrate, int bits, int format);
00297 int  AVI_write_frame(struct avi_t *AVI, BYTE *data, long bytes, int keyframe);
00298 int  AVI_dup_frame(struct avi_t *AVI);
00299 int  AVI_write_audio(struct avi_t *AVI, BYTE *data, long bytes);
00300 int  AVI_append_audio(struct avi_t *AVI, BYTE *data, long bytes);
00301 ULONG AVI_bytes_remain(struct avi_t *AVI);
00302 int  AVI_close(struct avi_t *AVI);
00303 
00304 //int avi_update_header(struct avi_t *AVI);
00305 int AVI_set_audio_track(struct avi_t *AVI, int track);
00306 void AVI_set_audio_vbr(struct avi_t *AVI, long is_vbr);
00307 
00308 
00309 ULONG AVI_set_MAX_LEN(ULONG len);
00310 
00311 int AVI_getErrno();
00312 
00313 void AVI_print_error(char *str);
00314 char *AVI_strerror();
00315 char *AVI_syserror();
00316 
00317 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


uvc_cam2
Author(s): Morgan Quigley, extended and maintained by Juergen Sturm
autogenerated on Wed Dec 26 2012 15:36:00