avilib.h
Go to the documentation of this file.
1 /*
2  * avilib.h
3  *
4  * Copyright (C) Thomas Östreich - June 2001
5  * multiple audio track support Copyright (C) 2002 Thomas Östreich
6  *
7  * Original code:
8  * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
9  *
10  * This file is part of transcode, a linux video stream processing tool
11  *
12  * transcode is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2, or (at your option)
15  * any later version.
16  *
17  * transcode is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with GNU Make; see the file COPYING. If not, write to
24  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25  *
26  */
27 
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 
33 //SLM
34 #ifdef __CYGWIN__
35 #include <sys/types.h>
36 #elif defined WIN32
37 #if defined __GNUWIN32__
38 #include <stdint.h>
39 #else
40 #define uint32_t unsigned __int32
41 #define uint8_t unsigned __int8
42 #define uint16_t unsigned __int16
43 #define uint64_t unsigned __int64
44 #endif
45 #else
46 #include <unistd.h>
47 #include <inttypes.h>
48 #endif
49 
50 
51 #include <limits.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <errno.h>
55 
56 #ifndef AVILIB_H
57 #define AVILIB_H
58 
59 #define AVI_MAX_TRACKS 8
60 
61 typedef struct
62 {
63  off_t key;
64  off_t pos;
65  off_t len;
67 
68 typedef struct
69 {
70  off_t pos;
71  off_t len;
72  off_t tot;
74 
75 typedef struct track_s
76 {
77 
78  long a_fmt; /* Audio format, see #defines below */
79  long a_chans; /* Audio channels, 0 for no audio */
80  long a_rate; /* Rate in Hz */
81  long a_bits; /* bits per audio sample */
82  long mp3rate; /* mp3 bitrate kbs*/
83 
84  long audio_strn; /* Audio stream number */
85  off_t audio_bytes; /* Total number of bytes of audio data */
86  long audio_chunks; /* Chunks of audio data in the file */
87 
88  char audio_tag[4]; /* Tag of audio data */
89  long audio_posc; /* Audio position: chunk */
90  long audio_posb; /* Audio position: byte within chunk */
91 
92  off_t a_codech_off; /* absolut offset of audio codec information */
93  off_t a_codecf_off; /* absolut offset of audio codec information */
94 
96 
97 } track_t;
98 
99 typedef struct
100 {
101  uint32_t bi_size;
102  uint32_t bi_width;
103  uint32_t bi_height;
104  uint16_t bi_planes;
105  uint16_t bi_bit_count;
106  uint32_t bi_compression;
107  uint32_t bi_size_image;
110  uint32_t bi_clr_used;
113 
114 typedef struct
115 {
116  uint16_t w_format_tag;
117  uint16_t n_channels;
120  uint16_t n_block_align;
122  uint16_t cb_size;
124 
125 typedef struct
126 {
127  uint32_t fcc_type;
128  uint32_t fcc_handler;
129  uint32_t dw_flags;
130  uint32_t dw_caps;
131  uint16_t w_priority;
132  uint16_t w_language;
133  uint32_t dw_scale;
134  uint32_t dw_rate;
135  uint32_t dw_start;
136  uint32_t dw_length;
139  uint32_t dw_quality;
140  uint32_t dw_sample_size;
141  uint32_t dw_left;
142  uint32_t dw_top;
143  uint32_t dw_right;
144  uint32_t dw_bottom;
145  uint32_t dw_edit_count;
147  char sz_name[64];
148 } AVISTREAMINFO;
149 
150 typedef struct
151 {
152 
153  long fdes; /* File descriptor of AVI file */
154  long mode; /* 0 for reading, 1 for writing */
155 
156  long width; /* Width of a video frame */
157  long height; /* Height of a video frame */
158  double fps; /* Frames per second */
159  char compressor[8]; /* Type of compressor, 4 bytes + padding for 0 byte */
160  char compressor2[8]; /* Type of compressor, 4 bytes + padding for 0 byte */
161  long video_strn; /* Video stream number */
162  long video_frames; /* Number of video frames */
163  char video_tag[4]; /* Tag of video data */
164  long video_pos; /* Number of next frame to be read
165  (if index present) */
166 
167  unsigned long max_len; /* maximum video chunk present */
168 
169  track_t track[AVI_MAX_TRACKS]; // up to AVI_MAX_TRACKS audio tracks supported
170 
171  off_t pos; /* position in file */
172  long n_idx; /* number of index entries actually filled */
173  long max_idx; /* number of index entries actually allocated */
174 
175  off_t v_codech_off; /* absolut offset of video codec (strh) info */
176  off_t v_codecf_off; /* absolut offset of video codec (strf) info */
177 
178  unsigned char (*idx)[16]; /* index entries (AVI idx1 tag) */
180 
181  off_t last_pos; /* Position of last frame written */
182  unsigned long last_len; /* Length of last frame written */
183  int must_use_index; /* Flag if frames are duplicated */
184  off_t movi_start;
185 
186  int anum; // total number of audio tracks
187  int aptr; // current audio working track
188 
191 } avi_t;
192 
193 #define AVI_MODE_WRITE 0
194 #define AVI_MODE_READ 1
195 
196 /* The error codes delivered by avi_open_input_file */
197 
198 #define AVI_ERR_SIZELIM 1 /* The write of the data would exceed
199  the maximum size of the AVI file.
200  This is more a warning than an error
201  since the file may be closed safely */
202 
203 #define AVI_ERR_OPEN 2 /* Error opening the AVI file - wrong path
204  name or file nor readable/writable */
205 
206 #define AVI_ERR_READ 3 /* Error reading from AVI File */
207 
208 #define AVI_ERR_WRITE 4 /* Error writing to AVI File,
209  disk full ??? */
210 
211 #define AVI_ERR_WRITE_INDEX 5 /* Could not write index to AVI file
212  during close, file may still be
213  usable */
214 
215 #define AVI_ERR_CLOSE 6 /* Could not write header to AVI file
216  or not truncate the file during close,
217  file is most probably corrupted */
218 
219 #define AVI_ERR_NOT_PERM 7 /* Operation not permitted:
220  trying to read from a file open
221  for writing or vice versa */
222 
223 #define AVI_ERR_NO_MEM 8 /* malloc failed */
224 
225 #define AVI_ERR_NO_AVI 9 /* Not an AVI file */
226 
227 #define AVI_ERR_NO_HDRL 10 /* AVI file has no has no header list,
228  corrupted ??? */
229 
230 #define AVI_ERR_NO_MOVI 11 /* AVI file has no has no MOVI list,
231  corrupted ??? */
232 
233 #define AVI_ERR_NO_VIDS 12 /* AVI file contains no video data */
234 
235 #define AVI_ERR_NO_IDX 13 /* The file has been opened with
236  getIndex==0, but an operation has been
237  performed that needs an index */
238 
239 /* Possible Audio formats */
240 
241 #ifndef WAVE_FORMAT_PCM
242 #define WAVE_FORMAT_UNKNOWN (0x0000)
243 #define WAVE_FORMAT_PCM (0x0001)
244 #define WAVE_FORMAT_ADPCM (0x0002)
245 #define WAVE_FORMAT_IBM_CVSD (0x0005)
246 #define WAVE_FORMAT_ALAW (0x0006)
247 #define WAVE_FORMAT_MULAW (0x0007)
248 #define WAVE_FORMAT_OKI_ADPCM (0x0010)
249 #define WAVE_FORMAT_DVI_ADPCM (0x0011)
250 #define WAVE_FORMAT_DIGISTD (0x0015)
251 #define WAVE_FORMAT_DIGIFIX (0x0016)
252 #define WAVE_FORMAT_YAMAHA_ADPCM (0x0020)
253 #define WAVE_FORMAT_DSP_TRUESPEECH (0x0022)
254 #define WAVE_FORMAT_GSM610 (0x0031)
255 #define IBM_FORMAT_MULAW (0x0101)
256 #define IBM_FORMAT_ALAW (0x0102)
257 #define IBM_FORMAT_ADPCM (0x0103)
258 #endif
259 
260 avi_t* AVI_open_output_file(char * filename);
261 void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);
262 void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);
263 int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);
264 int AVI_dup_frame(avi_t *AVI);
265 int AVI_write_audio(avi_t *AVI, char *data, long bytes);
266 int AVI_append_audio(avi_t *AVI, char *data, long bytes);
267 long AVI_bytes_remain(avi_t *AVI);
268 int AVI_close(avi_t *AVI);
269 long AVI_bytes_written(avi_t *AVI);
270 
271 avi_t *AVI_open_input_file(const char *filename, int getIndex);
272 avi_t *AVI_open_fd(int fd, int getIndex);
273 int avi_parse_input_file(avi_t *AVI, int getIndex);
274 long AVI_audio_mp3rate(avi_t *AVI);
275 long AVI_video_frames(avi_t *AVI);
276 int AVI_video_width(avi_t *AVI);
277 int AVI_video_height(avi_t *AVI);
278 double AVI_frame_rate(avi_t *AVI);
279 char* AVI_video_compressor(avi_t *AVI);
280 
281 int AVI_audio_channels(avi_t *AVI);
282 int AVI_audio_bits(avi_t *AVI);
283 int AVI_audio_format(avi_t *AVI);
284 long AVI_audio_rate(avi_t *AVI);
285 long AVI_audio_bytes(avi_t *AVI);
286 long AVI_audio_chunks(avi_t *AVI);
287 
288 long AVI_max_video_chunk(avi_t *AVI);
289 
290 long AVI_frame_size(avi_t *AVI, long frame);
291 long AVI_audio_size(avi_t *AVI, long frame);
292 int AVI_seek_start(avi_t *AVI);
293 int AVI_set_video_position(avi_t *AVI, long frame);
294 long AVI_get_video_position(avi_t *AVI, long frame);
295 long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);
296 
297 int AVI_set_audio_position(avi_t *AVI, long byte);
298 int AVI_set_audio_bitrate(avi_t *AVI, long bitrate);
299 
300 long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes);
301 long AVI_read_audio_chunk(avi_t *AVI, char *audbuf);
302 
303 long AVI_audio_codech_offset(avi_t *AVI);
304 long AVI_audio_codecf_offset(avi_t *AVI);
305 long AVI_video_codech_offset(avi_t *AVI);
306 long AVI_video_codecf_offset(avi_t *AVI);
307 
308 int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
309  char *audbuf, long max_audbuf,
310  long *len);
311 
312 void AVI_print_error(char *str);
313 char *AVI_strerror(void);
314 char *AVI_syserror(void);
315 
316 int AVI_scan(char *name);
317 int AVI_dump(char *name, int mode);
318 
319 char *AVI_codec2str(short cc);
320 int AVI_file_check(char *import_file);
321 
322 void AVI_info(avi_t *avifile);
323 uint64_t AVI_max_size(void);
324 int avi_update_header(avi_t *AVI);
325 
326 int AVI_set_audio_track(avi_t *AVI, int track);
327 int AVI_get_audio_track(avi_t *AVI);
328 int AVI_audio_tracks(avi_t *AVI);
329 
330 
331 struct riff_struct
332 {
333  unsigned char id[4]; /* RIFF */
334  uint32_t len;
335  unsigned char wave_id[4]; /* WAVE */
336 };
337 
338 
340 {
341  unsigned char id[4];
342  uint32_t len;
343 };
344 
346 {
347  uint16_t wFormatTag;
348  uint16_t wChannels;
349  uint32_t dwSamplesPerSec;
351  uint16_t wBlockAlign;
352  uint16_t wBitsPerSample; /* Only for PCM */
353 };
354 
355 struct wave_header
356 {
357  struct riff_struct riff;
358  struct chunk_struct format;
359  struct common_struct common;
360  struct chunk_struct data;
361 };
362 
363 
364 
366  long fccType;
368  long dwFlags;
371  long dwScale;
372  long dwRate;
373  long dwStart;
374  long dwLength;
376  long dwQuality;
378 };
379 
380 #endif
uint16_t w_priority
Definition: avilib.h:131
uint32_t dw_scale
Definition: avilib.h:133
int AVI_set_audio_position(avi_t *AVI, long byte)
uint32_t dw_left
Definition: avilib.h:141
off_t v_codecf_off
Definition: avilib.h:176
long dwFlags
Definition: avilib.h:368
int AVI_audio_channels(avi_t *AVI)
int AVI_video_height(avi_t *AVI)
int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf, char *audbuf, long max_audbuf, long *len)
int AVI_audio_tracks(avi_t *AVI)
double AVI_frame_rate(avi_t *AVI)
uint32_t n_samples_per_sec
Definition: avilib.h:118
int anum
Definition: avilib.h:186
long AVI_video_codech_offset(avi_t *AVI)
unsigned long max_len
Definition: avilib.h:167
long AVI_audio_codech_offset(avi_t *AVI)
off_t a_codech_off
Definition: avilib.h:92
uint32_t dw_edit_count
Definition: avilib.h:145
off_t pos
Definition: avilib.h:171
off_t movi_start
Definition: avilib.h:184
video_index_entry * video_index
Definition: avilib.h:179
char audio_tag[4]
Definition: avilib.h:88
long AVI_audio_bytes(avi_t *AVI)
long a_chans
Definition: avilib.h:79
long AVI_read_audio_chunk(avi_t *AVI, char *audbuf)
int AVI_dup_frame(avi_t *AVI)
long fccHandler
Definition: avilib.h:367
long video_pos
Definition: avilib.h:164
uint32_t dw_bottom
Definition: avilib.h:144
avi_t * AVI_open_fd(int fd, int getIndex)
uint16_t wFormatTag
Definition: avilib.h:347
long dwSuggestedBufferSize
Definition: avilib.h:375
long AVI_get_video_position(avi_t *AVI, long frame)
long dwStart
Definition: avilib.h:373
long dwScale
Definition: avilib.h:371
off_t key
Definition: avilib.h:63
uint32_t bi_y_pels_per_meter
Definition: avilib.h:109
int AVI_set_audio_track(avi_t *AVI, int track)
void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor)
long width
Definition: avilib.h:156
uint32_t dwAvgBytesPerSec
Definition: avilib.h:350
int AVI_audio_bits(avi_t *AVI)
Definition: avilib.h:75
char * AVI_codec2str(short cc)
void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate)
uint32_t bi_size_image
Definition: avilib.h:107
uint32_t dw_sample_size
Definition: avilib.h:140
int AVI_set_video_position(avi_t *AVI, long frame)
long height
Definition: avilib.h:157
double fps
Definition: avilib.h:158
uint16_t wBlockAlign
Definition: avilib.h:351
int AVI_video_width(avi_t *AVI)
long max_idx
Definition: avilib.h:173
off_t last_pos
Definition: avilib.h:181
uint64_t AVI_max_size(void)
int AVI_file_check(char *import_file)
void AVI_info(avi_t *avifile)
uint32_t dw_quality
Definition: avilib.h:139
uint32_t dw_suggested_buffer_size
Definition: avilib.h:138
struct track_s track_t
uint32_t dw_top
Definition: avilib.h:142
off_t pos
Definition: avilib.h:64
long AVI_audio_chunks(avi_t *AVI)
audio_index_entry * audio_index
Definition: avilib.h:95
long dwLength
Definition: avilib.h:374
#define AVI_MAX_TRACKS
Definition: avilib.h:59
long dwSampleSize
Definition: avilib.h:377
long mode
Definition: avilib.h:154
long a_fmt
Definition: avilib.h:78
int AVI_set_audio_bitrate(avi_t *AVI, long bitrate)
uint32_t dw_caps
Definition: avilib.h:130
uint32_t dw_rate
Definition: avilib.h:134
uint32_t bi_x_pels_per_meter
Definition: avilib.h:108
long AVI_audio_codecf_offset(avi_t *AVI)
uint16_t cb_size
Definition: avilib.h:122
uint16_t wBitsPerSample
Definition: avilib.h:352
uint16_t w_bits_per_sample
Definition: avilib.h:121
Definition: avilib.h:68
uint32_t dw_length
Definition: avilib.h:136
uint32_t bi_clr_used
Definition: avilib.h:110
uint32_t dw_start
Definition: avilib.h:135
long audio_posb
Definition: avilib.h:90
off_t a_codecf_off
Definition: avilib.h:93
long AVI_frame_size(avi_t *AVI, long frame)
long dwQuality
Definition: avilib.h:376
uint16_t wChannels
Definition: avilib.h:348
int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe)
long AVI_audio_mp3rate(avi_t *AVI)
long dwInitialFrames
Definition: avilib.h:370
long dwPriority
Definition: avilib.h:369
avi_t * AVI_open_input_file(const char *filename, int getIndex)
Definition: avilib.h:61
uint32_t n_avg_bytes_per_sec
Definition: avilib.h:119
uint32_t fcc_type
Definition: avilib.h:127
long AVI_audio_rate(avi_t *AVI)
long mp3rate
Definition: avilib.h:82
long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes)
void AVI_print_error(char *str)
int aptr
Definition: avilib.h:187
int avi_parse_input_file(avi_t *AVI, int getIndex)
char * AVI_video_compressor(avi_t *AVI)
uint16_t w_language
Definition: avilib.h:132
uint32_t dw_format_change_count
Definition: avilib.h:146
int AVI_write_audio(avi_t *AVI, char *data, long bytes)
uint32_t len
Definition: avilib.h:334
Definition: avilib.h:150
long audio_chunks
Definition: avilib.h:86
uint32_t bi_clr_important
Definition: avilib.h:111
int AVI_close(avi_t *AVI)
long AVI_bytes_written(avi_t *AVI)
int avi_update_header(avi_t *AVI)
long AVI_audio_size(avi_t *AVI, long frame)
long video_frames
Definition: avilib.h:162
uint32_t dw_initial_frames
Definition: avilib.h:137
uint16_t bi_bit_count
Definition: avilib.h:105
off_t tot
Definition: avilib.h:72
long video_strn
Definition: avilib.h:161
off_t len
Definition: avilib.h:65
long n_idx
Definition: avilib.h:172
long AVI_max_video_chunk(avi_t *AVI)
uint16_t w_format_tag
Definition: avilib.h:116
uint16_t n_channels
Definition: avilib.h:117
uint32_t bi_compression
Definition: avilib.h:106
avi_t * AVI_open_output_file(char *filename)
int AVI_audio_format(avi_t *AVI)
uint32_t dw_right
Definition: avilib.h:143
long a_rate
Definition: avilib.h:80
off_t len
Definition: avilib.h:71
char * AVI_strerror(void)
int AVI_append_audio(avi_t *AVI, char *data, long bytes)
uint16_t n_block_align
Definition: avilib.h:120
off_t pos
Definition: avilib.h:70
long AVI_video_frames(avi_t *AVI)
long a_bits
Definition: avilib.h:81
int must_use_index
Definition: avilib.h:183
uint32_t dw_flags
Definition: avilib.h:129
long AVI_video_codecf_offset(avi_t *AVI)
uint32_t len
Definition: avilib.h:342
long fccType
Definition: avilib.h:366
int AVI_dump(char *name, int mode)
long audio_posc
Definition: avilib.h:89
int AVI_seek_start(avi_t *AVI)
long fdes
Definition: avilib.h:153
off_t v_codech_off
Definition: avilib.h:175
BITMAPINFOHEADER_avilib * bitmap_info_header
Definition: avilib.h:189
unsigned long last_len
Definition: avilib.h:182
char * AVI_syserror(void)
uint32_t fcc_handler
Definition: avilib.h:128
long audio_strn
Definition: avilib.h:84
off_t audio_bytes
Definition: avilib.h:85
long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe)
uint32_t dwSamplesPerSec
Definition: avilib.h:349
long AVI_bytes_remain(avi_t *AVI)
int AVI_scan(char *name)
int AVI_get_audio_track(avi_t *AVI)


tuw_uvc
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:39:24