OSDN Git Service

add tstools.
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / internal / avilib.h
1 /*\r
2  *  avilib.h\r
3  *\r
4  *  Copyright (C) Thomas Ã–streich - June 2001\r
5  *  multiple audio track support Copyright (C) 2002 Thomas Ã–streich\r
6  *\r
7  *  Original code:\r
8  *  Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> \r
9  *\r
10  *  This file is part of transcode, a linux video stream processing tool\r
11  *      \r
12  *  transcode is free software; you can redistribute it and/or modify\r
13  *  it under the terms of the GNU Lesser General Public License as published by\r
14  *  the Free Software Foundation; either version 2, or (at your option)\r
15  *  any later version.\r
16  *   \r
17  *  transcode is distributed in the hope that it will be useful,\r
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
20  *  GNU Lesser General Public License for more details.\r
21  *   \r
22  *  You should have received a copy of the GNU Lesser General Public\r
23  *  License along with this library; see the file COPYING.  If not, write to\r
24  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
25  *\r
26  */\r
27 \r
28 #ifndef _GF_AVILIB_H_\r
29 #define _GF_AVILIB_H_\r
30 \r
31 #include <gpac/tools.h>\r
32 \r
33 #define AVI_MAX_TRACKS 8\r
34 \r
35 typedef struct\r
36 {\r
37   u64 key;\r
38   u64 pos;\r
39   u64 len;\r
40 } video_index_entry;\r
41 \r
42 typedef struct\r
43 {\r
44    u64 pos;\r
45    u64 len;\r
46    u64 tot;\r
47 } audio_index_entry;\r
48 \r
49 \r
50 // Index types\r
51 \r
52 \r
53 #define AVI_INDEX_OF_INDEXES 0x00             // when each entry in aIndex\r
54                                               // array points to an index chunk\r
55 #define AVI_INDEX_OF_CHUNKS  0x01             // when each entry in aIndex\r
56                                               // array points to a chunk in the file\r
57 #define AVI_INDEX_IS_DATA    0x80             // when each entry is aIndex is\r
58                                               // really the data\r
59 // bIndexSubtype codes for INDEX_OF_CHUNKS\r
60 //\r
61 #define AVI_INDEX_2FIELD     0x01             // when fields within frames\r
62                                               // are also indexed\r
63 \r
64 \r
65 \r
66 typedef struct _avisuperindex_entry {\r
67     u64 qwOffset;           // absolute file offset\r
68     u32 dwSize;                  // size of index chunk at this offset\r
69     u32 dwDuration;              // time span in stream ticks\r
70 } avisuperindex_entry;\r
71 \r
72 typedef struct _avistdindex_entry {\r
73     u32 dwOffset;                // qwBaseOffset + this is absolute file offset\r
74     u32 dwSize;                  // bit 31 is set if this is NOT a keyframe\r
75 } avistdindex_entry;\r
76 \r
77 // Standard index \r
78 typedef struct _avistdindex_chunk {\r
79     char           fcc[4];                 // ix##\r
80     u32 dwSize;                 // size of this chunk\r
81     u16 wLongsPerEntry;         // must be sizeof(aIndex[0])/sizeof(DWORD)\r
82     u8  bIndexSubType;          // must be 0\r
83     u8  bIndexType;             // must be AVI_INDEX_OF_CHUNKS\r
84     u32  nEntriesInUse;          //\r
85     char           dwChunkId[4];           // '##dc' or '##db' or '##wb' etc..\r
86     u64 qwBaseOffset;       // all dwOffsets in aIndex array are relative to this\r
87     u32  dwReserved3;            // must be 0\r
88     avistdindex_entry *aIndex;\r
89 } avistdindex_chunk;\r
90     \r
91 \r
92 // Base Index Form 'indx'\r
93 typedef struct _avisuperindex_chunk {\r
94     char           fcc[4];\r
95     u32  dwSize;                 // size of this chunk\r
96     u16 wLongsPerEntry;         // size of each entry in aIndex array (must be 8 for us)\r
97     u8  bIndexSubType;          // future use. must be 0\r
98     u8 bIndexType;             // one of AVI_INDEX_* codes\r
99     u32 nEntriesInUse;          // index of first unused member in aIndex array\r
100     char           dwChunkId[4];           // fcc of what is indexed\r
101     u32 dwReserved[3];          // meaning differs for each index type/subtype.\r
102                                            // 0 if unused\r
103     avisuperindex_entry *aIndex;           // where are the ix## chunks\r
104     avistdindex_chunk **stdindex;          // the ix## chunks itself (array)\r
105 } avisuperindex_chunk;\r
106     \r
107 \r
108 \r
109 typedef struct track_s\r
110 {\r
111 \r
112     long   a_fmt;             /* Audio format, see #defines below */\r
113     long   a_chans;           /* Audio channels, 0 for no audio */\r
114     long   a_rate;            /* Rate in Hz */\r
115     long   a_bits;            /* bits per audio sample */\r
116     long   mp3rate;           /* mp3 bitrate kbs*/\r
117     long   a_vbr;             /* 0 == no Variable BitRate */\r
118     long   padrate;           /* byte rate used for zero padding */\r
119 \r
120     long   audio_strn;        /* Audio stream number */\r
121     u64  audio_bytes;       /* Total number of bytes of audio data */\r
122     long   audio_chunks;      /* Chunks of audio data in the file */\r
123 \r
124     char   audio_tag[4];      /* Tag of audio data */\r
125     long   audio_posc;        /* Audio position: chunk */\r
126     long   audio_posb;        /* Audio position: byte within chunk */\r
127  \r
128     u64  a_codech_off;       /* absolut offset of audio codec information */ \r
129     u64  a_codecf_off;       /* absolut offset of audio codec information */ \r
130 \r
131     audio_index_entry *audio_index;\r
132     avisuperindex_chunk *audio_superindex;\r
133 \r
134 } track_t;\r
135 \r
136 typedef struct\r
137 {\r
138   u32  bi_size;\r
139   u32  bi_width;\r
140   u32  bi_height;\r
141   u16  bi_planes;\r
142   u16  bi_bit_count;\r
143   u32  bi_compression;\r
144   u32  bi_size_image;\r
145   u32  bi_x_pels_per_meter;\r
146   u32  bi_y_pels_per_meter;\r
147   u32  bi_clr_used;\r
148   u32  bi_clr_important;\r
149 } alBITMAPINFOHEADER;\r
150 \r
151 typedef struct\r
152 {\r
153   u16  w_format_tag;\r
154   u16  n_channels;\r
155   u32  n_samples_per_sec;\r
156   u32  n_avg_bytes_per_sec;\r
157   u16  n_block_align;\r
158   u16  w_bits_per_sample;\r
159   u16  cb_size;\r
160 } alWAVEFORMATEX;\r
161 \r
162 typedef struct\r
163 {\r
164   u32 fcc_type; \r
165   u32 fcc_handler; \r
166   u32 dw_flags; \r
167   u32 dw_caps; \r
168   u16 w_priority;\r
169   u16 w_language;\r
170   u32 dw_scale;\r
171   u32 dw_rate;\r
172   u32 dw_start;\r
173   u32 dw_length;\r
174   u32 dw_initial_frames;\r
175   u32 dw_suggested_buffer_size;\r
176   u32 dw_quality;\r
177   u32 dw_sample_size;\r
178   u16 dw_left;\r
179   u16 dw_top;\r
180   u16 dw_right;\r
181   u16 dw_bottom;\r
182 } alAVISTREAMHEADER;\r
183 \r
184 typedef struct\r
185 {\r
186   \r
187   FILE *fdes;              /* File descriptor of AVI file */\r
188   long   mode;              /* 0 for reading, 1 for writing */\r
189   \r
190   long   width;             /* Width  of a video frame */\r
191   long   height;            /* Height of a video frame */\r
192   double fps;               /* Frames per second */\r
193   char   compressor[8];     /* Type of compressor, 4 bytes + padding for 0 byte */\r
194   char   compressor2[8];     /* Type of compressor, 4 bytes + padding for 0 byte */\r
195   u32   video_strn;        /* Video stream number */\r
196   long   video_frames;      /* Number of video frames */\r
197   char   video_tag[4];      /* Tag of video data */\r
198   long   video_pos;         /* Number of next frame to be read\r
199                                (if index present) */\r
200   alAVISTREAMHEADER video_stream_header;\r
201   \r
202   u32 max_len;    /* maximum video chunk present */\r
203   \r
204   track_t track[AVI_MAX_TRACKS];  // up to AVI_MAX_TRACKS audio tracks supported\r
205   \r
206   s64  pos;               /* position in file */\r
207   long   n_idx;             /* number of index entries actually filled */\r
208   long   max_idx;           /* number of index entries actually allocated */\r
209   \r
210   s64  v_codech_off;      /* absolut offset of video codec (strh) info */ \r
211   s64  v_codecf_off;      /* absolut offset of video codec (strf) info */ \r
212   \r
213   u8 (*idx)[16]; /* index entries (AVI idx1 tag) */\r
214 \r
215   video_index_entry *video_index;\r
216   avisuperindex_chunk *video_superindex;  /* index of indices */\r
217   int is_opendml;           /* set to 1 if this is an odml file with multiple index chunks */\r
218   \r
219   s64  last_pos;          /* Position of last frame written */\r
220   u32 last_len;   /* Length of last frame written */\r
221   int must_use_index;       /* Flag if frames are duplicated */\r
222   s64  movi_start;\r
223   int total_frames;         /* total number of frames if dmlh is present */\r
224   \r
225   u32 anum;            // total number of audio tracks \r
226   u32 aptr;            // current audio working track \r
227   char *index_file;    // read the avi index from this file\r
228   \r
229   alBITMAPINFOHEADER *bitmap_info_header;\r
230   alWAVEFORMATEX *wave_format_ex[AVI_MAX_TRACKS];\r
231   alAVISTREAMHEADER stream_headers[AVI_MAX_TRACKS];\r
232 \r
233   void*         extradata;\r
234   unsigned long extradata_size;\r
235 } avi_t;\r
236 \r
237 #define AVI_MODE_WRITE  0\r
238 #define AVI_MODE_READ   1\r
239 \r
240 /* The error codes delivered by avi_open_input_file */\r
241 \r
242 #define AVI_ERR_SIZELIM      1     /* The write of the data would exceed\r
243                                       the maximum size of the AVI file.\r
244                                       This is more a warning than an error\r
245                                       since the file may be closed safely */\r
246 \r
247 #define AVI_ERR_OPEN         2     /* Error opening the AVI file - wrong path\r
248                                       name or file nor readable/writable */\r
249 \r
250 #define AVI_ERR_READ         3     /* Error reading from AVI File */\r
251 \r
252 #define AVI_ERR_WRITE        4     /* Error writing to AVI File,\r
253                                       disk full ??? */\r
254 \r
255 #define AVI_ERR_WRITE_INDEX  5     /* Could not write index to AVI file\r
256                                       during close, file may still be\r
257                                       usable */\r
258 \r
259 #define AVI_ERR_CLOSE        6     /* Could not write header to AVI file\r
260                                       or not truncate the file during close,\r
261                                       file is most probably corrupted */\r
262 \r
263 #define AVI_ERR_NOT_PERM     7     /* Operation not permitted:\r
264                                       trying to read from a file open\r
265                                       for writing or vice versa */\r
266 \r
267 #define AVI_ERR_NO_MEM       8     /* malloc failed */\r
268 \r
269 #define AVI_ERR_NO_AVI       9     /* Not an AVI file */\r
270 \r
271 #define AVI_ERR_NO_HDRL     10     /* AVI file has no has no header list,\r
272                                       corrupted ??? */\r
273 \r
274 #define AVI_ERR_NO_MOVI     11     /* AVI file has no has no MOVI list,\r
275                                       corrupted ??? */\r
276 \r
277 #define AVI_ERR_NO_VIDS     12     /* AVI file contains no video data */\r
278 \r
279 #define AVI_ERR_NO_IDX      13     /* The file has been opened with\r
280                                       getIndex==0, but an operation has been\r
281                                       performed that needs an index */\r
282 \r
283 /* Possible Audio formats */\r
284 \r
285 #ifndef WAVE_FORMAT_PCM\r
286 #define WAVE_FORMAT_UNKNOWN             (0x0000)\r
287 #ifndef WAVE_FORMAT_PCM\r
288 #define WAVE_FORMAT_PCM                 (0x0001)\r
289 #endif\r
290 #define WAVE_FORMAT_ADPCM               (0x0002)\r
291 #define WAVE_FORMAT_IBM_CVSD            (0x0005)\r
292 #define WAVE_FORMAT_ALAW                (0x0006)\r
293 #define WAVE_FORMAT_MULAW               (0x0007)\r
294 #define WAVE_FORMAT_OKI_ADPCM           (0x0010)\r
295 #define WAVE_FORMAT_DVI_ADPCM           (0x0011)\r
296 #define WAVE_FORMAT_DIGISTD             (0x0015)\r
297 #define WAVE_FORMAT_DIGIFIX             (0x0016)\r
298 #define WAVE_FORMAT_YAMAHA_ADPCM        (0x0020)\r
299 #define WAVE_FORMAT_DSP_TRUESPEECH      (0x0022)\r
300 #define WAVE_FORMAT_GSM610              (0x0031)\r
301 #define IBM_FORMAT_MULAW                (0x0101)\r
302 #define IBM_FORMAT_ALAW                 (0x0102)\r
303 #define IBM_FORMAT_ADPCM                (0x0103)\r
304 #endif\r
305 \r
306 avi_t* AVI_open_output_file(char * filename);\r
307 void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);\r
308 void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);\r
309 int  AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);\r
310 int  AVI_dup_frame(avi_t *AVI);\r
311 int  AVI_write_audio(avi_t *AVI, char *data, long bytes);\r
312 int  AVI_append_audio(avi_t *AVI, char *data, long bytes);\r
313 u64 AVI_bytes_remain(avi_t *AVI);\r
314 int  AVI_close(avi_t *AVI);\r
315 u64 AVI_bytes_written(avi_t *AVI);\r
316 \r
317 avi_t *AVI_open_input_file(char *filename, int getIndex);\r
318 avi_t *AVI_open_input_indexfile(char *filename, int getIndex, char *indexfile);\r
319 avi_t *AVI_open_fd(FILE *fd, int getIndex);\r
320 avi_t *AVI_open_indexfd(FILE *fd, int getIndex, char *indexfile);\r
321 int avi_parse_input_file(avi_t *AVI, int getIndex);\r
322 int avi_parse_index_from_file(avi_t *AVI, char *filename);\r
323 long AVI_audio_mp3rate(avi_t *AVI);\r
324 long AVI_audio_padrate(avi_t *AVI);\r
325 long AVI_video_frames(avi_t *AVI);\r
326 int  AVI_video_width(avi_t *AVI);\r
327 int  AVI_video_height(avi_t *AVI);\r
328 double AVI_frame_rate(avi_t *AVI);\r
329 char* AVI_video_compressor(avi_t *AVI);\r
330 \r
331 int  AVI_audio_channels(avi_t *AVI);\r
332 int  AVI_audio_bits(avi_t *AVI);\r
333 int  AVI_audio_format(avi_t *AVI);\r
334 long AVI_audio_rate(avi_t *AVI);\r
335 u64 AVI_audio_bytes(avi_t *AVI);\r
336 long AVI_audio_chunks(avi_t *AVI);\r
337 int  AVI_can_read_audio(avi_t *AVI);\r
338 \r
339 long AVI_max_video_chunk(avi_t *AVI);\r
340 \r
341 long AVI_frame_size(avi_t *AVI, long frame);\r
342 long AVI_audio_size(avi_t *AVI, long frame);\r
343 int  AVI_seek_start(avi_t *AVI);\r
344 int  AVI_set_video_position(avi_t *AVI, long frame);\r
345 u64 AVI_get_video_position(avi_t *AVI, long frame);\r
346 long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);\r
347 \r
348 int  AVI_set_audio_position(avi_t *AVI, long byte);\r
349 int  AVI_set_audio_bitrate(avi_t *AVI, long bitrate);\r
350 \r
351 long AVI_get_audio_position_index(avi_t *AVI);\r
352 int  AVI_set_audio_position_index(avi_t *AVI, long indexpos);\r
353 \r
354 long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes, int *continuous);\r
355 \r
356 int  AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,\r
357                                char *audbuf, long max_audbuf,\r
358                                long *len);\r
359 \r
360 int AVI_scan(char *name);\r
361 int AVI_dump(char *name, int mode);\r
362 \r
363 char *AVI_codec2str(short cc);\r
364 int AVI_file_check(char *import_file);\r
365 \r
366 void AVI_info(avi_t *avifile);\r
367 u64 AVI_max_size(void);\r
368 int avi_update_header(avi_t *AVI);\r
369 \r
370 int AVI_set_audio_track(avi_t *AVI, u32 track);\r
371 int AVI_get_audio_track(avi_t *AVI);\r
372 int AVI_audio_tracks(avi_t *AVI);\r
373 \r
374 void AVI_set_audio_vbr(avi_t *AVI, long is_vbr);\r
375 long AVI_get_audio_vbr(avi_t *AVI);\r
376 \r
377 void AVI_set_comment_fd(avi_t *AVI, int fd);\r
378 int  AVI_get_comment_fd(avi_t *AVI);\r
379 \r
380 struct riff_struct \r
381 {\r
382   u8 id[4];   /* RIFF */\r
383   u32 len;\r
384   u8 wave_id[4]; /* WAVE */\r
385 };\r
386 \r
387 \r
388 struct chunk_struct \r
389 {\r
390         u8 id[4];\r
391         u32 len;\r
392 };\r
393 \r
394 struct common_struct \r
395 {\r
396         u16 wFormatTag;\r
397         u16 wChannels;\r
398         u32 dwSamplesPerSec;\r
399         u32 dwAvgBytesPerSec;\r
400         u16 wBlockAlign;\r
401         u16 wBitsPerSample;  /* Only for PCM */\r
402 };\r
403 \r
404 struct wave_header \r
405 {\r
406         struct riff_struct   riff;\r
407         struct chunk_struct  format;\r
408         struct common_struct common;\r
409         struct chunk_struct  data;\r
410 };\r
411 \r
412 // Simple WAV IO\r
413 int AVI_read_wave_header( int fd, struct wave_header * wave );\r
414 int AVI_write_wave_header( int fd, const struct wave_header * wave );\r
415 size_t AVI_read_wave_pcm_data( int fd, void * buffer, size_t buflen );\r
416 size_t AVI_write_wave_pcm_data( int fd, const void * buffer, size_t buflen );\r
417 \r
418 \r
419 struct AVIStreamHeader {\r
420   long  fccType;\r
421   long  fccHandler;\r
422   long  dwFlags;\r
423   long  dwPriority;\r
424   long  dwInitialFrames;\r
425   long  dwScale;\r
426   long  dwRate;\r
427   long  dwStart;\r
428   long  dwLength;\r
429   long  dwSuggestedBufferSize;\r
430   long  dwQuality;\r
431   long  dwSampleSize;\r
432 };\r
433 \r
434 #endif  /*_GF_AVILIB_H_*/\r