+++ /dev/null
-/*\r
- * avilib.h\r
- *\r
- * Copyright (C) Thomas Östreich - June 2001\r
- * multiple audio track support Copyright (C) 2002 Thomas Östreich\r
- *\r
- * Original code:\r
- * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> \r
- *\r
- * This file is part of transcode, a linux video stream processing tool\r
- * \r
- * transcode is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- * \r
- * transcode is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Lesser General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; see the file COPYING. If not, write to\r
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
- *\r
- */\r
-\r
-#ifndef _GF_AVILIB_H_\r
-#define _GF_AVILIB_H_\r
-\r
-#include <gpac/tools.h>\r
-\r
-#define AVI_MAX_TRACKS 8\r
-\r
-typedef struct\r
-{\r
- u64 key;\r
- u64 pos;\r
- u64 len;\r
-} video_index_entry;\r
-\r
-typedef struct\r
-{\r
- u64 pos;\r
- u64 len;\r
- u64 tot;\r
-} audio_index_entry;\r
-\r
-\r
-// Index types\r
-\r
-\r
-#define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex\r
- // array points to an index chunk\r
-#define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex\r
- // array points to a chunk in the file\r
-#define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is\r
- // really the data\r
-// bIndexSubtype codes for INDEX_OF_CHUNKS\r
-//\r
-#define AVI_INDEX_2FIELD 0x01 // when fields within frames\r
- // are also indexed\r
-\r
-\r
-\r
-typedef struct _avisuperindex_entry {\r
- u64 qwOffset; // absolute file offset\r
- u32 dwSize; // size of index chunk at this offset\r
- u32 dwDuration; // time span in stream ticks\r
-} avisuperindex_entry;\r
-\r
-typedef struct _avistdindex_entry {\r
- u32 dwOffset; // qwBaseOffset + this is absolute file offset\r
- u32 dwSize; // bit 31 is set if this is NOT a keyframe\r
-} avistdindex_entry;\r
-\r
-// Standard index \r
-typedef struct _avistdindex_chunk {\r
- char fcc[4]; // ix##\r
- u32 dwSize; // size of this chunk\r
- u16 wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)\r
- u8 bIndexSubType; // must be 0\r
- u8 bIndexType; // must be AVI_INDEX_OF_CHUNKS\r
- u32 nEntriesInUse; //\r
- char dwChunkId[4]; // '##dc' or '##db' or '##wb' etc..\r
- u64 qwBaseOffset; // all dwOffsets in aIndex array are relative to this\r
- u32 dwReserved3; // must be 0\r
- avistdindex_entry *aIndex;\r
-} avistdindex_chunk;\r
- \r
-\r
-// Base Index Form 'indx'\r
-typedef struct _avisuperindex_chunk {\r
- char fcc[4];\r
- u32 dwSize; // size of this chunk\r
- u16 wLongsPerEntry; // size of each entry in aIndex array (must be 8 for us)\r
- u8 bIndexSubType; // future use. must be 0\r
- u8 bIndexType; // one of AVI_INDEX_* codes\r
- u32 nEntriesInUse; // index of first unused member in aIndex array\r
- char dwChunkId[4]; // fcc of what is indexed\r
- u32 dwReserved[3]; // meaning differs for each index type/subtype.\r
- // 0 if unused\r
- avisuperindex_entry *aIndex; // where are the ix## chunks\r
- avistdindex_chunk **stdindex; // the ix## chunks itself (array)\r
-} avisuperindex_chunk;\r
- \r
-\r
-\r
-typedef struct track_s\r
-{\r
-\r
- long a_fmt; /* Audio format, see #defines below */\r
- long a_chans; /* Audio channels, 0 for no audio */\r
- long a_rate; /* Rate in Hz */\r
- long a_bits; /* bits per audio sample */\r
- long mp3rate; /* mp3 bitrate kbs*/\r
- long a_vbr; /* 0 == no Variable BitRate */\r
- long padrate; /* byte rate used for zero padding */\r
-\r
- long audio_strn; /* Audio stream number */\r
- u64 audio_bytes; /* Total number of bytes of audio data */\r
- long audio_chunks; /* Chunks of audio data in the file */\r
-\r
- char audio_tag[4]; /* Tag of audio data */\r
- long audio_posc; /* Audio position: chunk */\r
- long audio_posb; /* Audio position: byte within chunk */\r
- \r
- u64 a_codech_off; /* absolut offset of audio codec information */ \r
- u64 a_codecf_off; /* absolut offset of audio codec information */ \r
-\r
- audio_index_entry *audio_index;\r
- avisuperindex_chunk *audio_superindex;\r
-\r
-} track_t;\r
-\r
-typedef struct\r
-{\r
- u32 bi_size;\r
- u32 bi_width;\r
- u32 bi_height;\r
- u16 bi_planes;\r
- u16 bi_bit_count;\r
- u32 bi_compression;\r
- u32 bi_size_image;\r
- u32 bi_x_pels_per_meter;\r
- u32 bi_y_pels_per_meter;\r
- u32 bi_clr_used;\r
- u32 bi_clr_important;\r
-} alBITMAPINFOHEADER;\r
-\r
-typedef struct\r
-{\r
- u16 w_format_tag;\r
- u16 n_channels;\r
- u32 n_samples_per_sec;\r
- u32 n_avg_bytes_per_sec;\r
- u16 n_block_align;\r
- u16 w_bits_per_sample;\r
- u16 cb_size;\r
-} alWAVEFORMATEX;\r
-\r
-typedef struct\r
-{\r
- u32 fcc_type; \r
- u32 fcc_handler; \r
- u32 dw_flags; \r
- u32 dw_caps; \r
- u16 w_priority;\r
- u16 w_language;\r
- u32 dw_scale;\r
- u32 dw_rate;\r
- u32 dw_start;\r
- u32 dw_length;\r
- u32 dw_initial_frames;\r
- u32 dw_suggested_buffer_size;\r
- u32 dw_quality;\r
- u32 dw_sample_size;\r
- u16 dw_left;\r
- u16 dw_top;\r
- u16 dw_right;\r
- u16 dw_bottom;\r
-} alAVISTREAMHEADER;\r
-\r
-typedef struct\r
-{\r
- \r
- FILE *fdes; /* File descriptor of AVI file */\r
- long mode; /* 0 for reading, 1 for writing */\r
- \r
- long width; /* Width of a video frame */\r
- long height; /* Height of a video frame */\r
- double fps; /* Frames per second */\r
- char compressor[8]; /* Type of compressor, 4 bytes + padding for 0 byte */\r
- char compressor2[8]; /* Type of compressor, 4 bytes + padding for 0 byte */\r
- u32 video_strn; /* Video stream number */\r
- long video_frames; /* Number of video frames */\r
- char video_tag[4]; /* Tag of video data */\r
- long video_pos; /* Number of next frame to be read\r
- (if index present) */\r
- alAVISTREAMHEADER video_stream_header;\r
- \r
- u32 max_len; /* maximum video chunk present */\r
- \r
- track_t track[AVI_MAX_TRACKS]; // up to AVI_MAX_TRACKS audio tracks supported\r
- \r
- s64 pos; /* position in file */\r
- long n_idx; /* number of index entries actually filled */\r
- long max_idx; /* number of index entries actually allocated */\r
- \r
- s64 v_codech_off; /* absolut offset of video codec (strh) info */ \r
- s64 v_codecf_off; /* absolut offset of video codec (strf) info */ \r
- \r
- u8 (*idx)[16]; /* index entries (AVI idx1 tag) */\r
-\r
- video_index_entry *video_index;\r
- avisuperindex_chunk *video_superindex; /* index of indices */\r
- int is_opendml; /* set to 1 if this is an odml file with multiple index chunks */\r
- \r
- s64 last_pos; /* Position of last frame written */\r
- u32 last_len; /* Length of last frame written */\r
- int must_use_index; /* Flag if frames are duplicated */\r
- s64 movi_start;\r
- int total_frames; /* total number of frames if dmlh is present */\r
- \r
- u32 anum; // total number of audio tracks \r
- u32 aptr; // current audio working track \r
- char *index_file; // read the avi index from this file\r
- \r
- alBITMAPINFOHEADER *bitmap_info_header;\r
- alWAVEFORMATEX *wave_format_ex[AVI_MAX_TRACKS];\r
- alAVISTREAMHEADER stream_headers[AVI_MAX_TRACKS];\r
-\r
- void* extradata;\r
- unsigned long extradata_size;\r
-} avi_t;\r
-\r
-#define AVI_MODE_WRITE 0\r
-#define AVI_MODE_READ 1\r
-\r
-/* The error codes delivered by avi_open_input_file */\r
-\r
-#define AVI_ERR_SIZELIM 1 /* The write of the data would exceed\r
- the maximum size of the AVI file.\r
- This is more a warning than an error\r
- since the file may be closed safely */\r
-\r
-#define AVI_ERR_OPEN 2 /* Error opening the AVI file - wrong path\r
- name or file nor readable/writable */\r
-\r
-#define AVI_ERR_READ 3 /* Error reading from AVI File */\r
-\r
-#define AVI_ERR_WRITE 4 /* Error writing to AVI File,\r
- disk full ??? */\r
-\r
-#define AVI_ERR_WRITE_INDEX 5 /* Could not write index to AVI file\r
- during close, file may still be\r
- usable */\r
-\r
-#define AVI_ERR_CLOSE 6 /* Could not write header to AVI file\r
- or not truncate the file during close,\r
- file is most probably corrupted */\r
-\r
-#define AVI_ERR_NOT_PERM 7 /* Operation not permitted:\r
- trying to read from a file open\r
- for writing or vice versa */\r
-\r
-#define AVI_ERR_NO_MEM 8 /* malloc failed */\r
-\r
-#define AVI_ERR_NO_AVI 9 /* Not an AVI file */\r
-\r
-#define AVI_ERR_NO_HDRL 10 /* AVI file has no has no header list,\r
- corrupted ??? */\r
-\r
-#define AVI_ERR_NO_MOVI 11 /* AVI file has no has no MOVI list,\r
- corrupted ??? */\r
-\r
-#define AVI_ERR_NO_VIDS 12 /* AVI file contains no video data */\r
-\r
-#define AVI_ERR_NO_IDX 13 /* The file has been opened with\r
- getIndex==0, but an operation has been\r
- performed that needs an index */\r
-\r
-/* Possible Audio formats */\r
-\r
-#ifndef WAVE_FORMAT_PCM\r
-#define WAVE_FORMAT_UNKNOWN (0x0000)\r
-#ifndef WAVE_FORMAT_PCM\r
-#define WAVE_FORMAT_PCM (0x0001)\r
-#endif\r
-#define WAVE_FORMAT_ADPCM (0x0002)\r
-#define WAVE_FORMAT_IBM_CVSD (0x0005)\r
-#define WAVE_FORMAT_ALAW (0x0006)\r
-#define WAVE_FORMAT_MULAW (0x0007)\r
-#define WAVE_FORMAT_OKI_ADPCM (0x0010)\r
-#define WAVE_FORMAT_DVI_ADPCM (0x0011)\r
-#define WAVE_FORMAT_DIGISTD (0x0015)\r
-#define WAVE_FORMAT_DIGIFIX (0x0016)\r
-#define WAVE_FORMAT_YAMAHA_ADPCM (0x0020)\r
-#define WAVE_FORMAT_DSP_TRUESPEECH (0x0022)\r
-#define WAVE_FORMAT_GSM610 (0x0031)\r
-#define IBM_FORMAT_MULAW (0x0101)\r
-#define IBM_FORMAT_ALAW (0x0102)\r
-#define IBM_FORMAT_ADPCM (0x0103)\r
-#endif\r
-\r
-avi_t* AVI_open_output_file(char * filename);\r
-void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);\r
-void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);\r
-int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);\r
-int AVI_dup_frame(avi_t *AVI);\r
-int AVI_write_audio(avi_t *AVI, char *data, long bytes);\r
-int AVI_append_audio(avi_t *AVI, char *data, long bytes);\r
-u64 AVI_bytes_remain(avi_t *AVI);\r
-int AVI_close(avi_t *AVI);\r
-u64 AVI_bytes_written(avi_t *AVI);\r
-\r
-avi_t *AVI_open_input_file(char *filename, int getIndex);\r
-avi_t *AVI_open_input_indexfile(char *filename, int getIndex, char *indexfile);\r
-avi_t *AVI_open_fd(FILE *fd, int getIndex);\r
-avi_t *AVI_open_indexfd(FILE *fd, int getIndex, char *indexfile);\r
-int avi_parse_input_file(avi_t *AVI, int getIndex);\r
-int avi_parse_index_from_file(avi_t *AVI, char *filename);\r
-long AVI_audio_mp3rate(avi_t *AVI);\r
-long AVI_audio_padrate(avi_t *AVI);\r
-long AVI_video_frames(avi_t *AVI);\r
-int AVI_video_width(avi_t *AVI);\r
-int AVI_video_height(avi_t *AVI);\r
-double AVI_frame_rate(avi_t *AVI);\r
-char* AVI_video_compressor(avi_t *AVI);\r
-\r
-int AVI_audio_channels(avi_t *AVI);\r
-int AVI_audio_bits(avi_t *AVI);\r
-int AVI_audio_format(avi_t *AVI);\r
-long AVI_audio_rate(avi_t *AVI);\r
-u64 AVI_audio_bytes(avi_t *AVI);\r
-long AVI_audio_chunks(avi_t *AVI);\r
-int AVI_can_read_audio(avi_t *AVI);\r
-\r
-long AVI_max_video_chunk(avi_t *AVI);\r
-\r
-long AVI_frame_size(avi_t *AVI, long frame);\r
-long AVI_audio_size(avi_t *AVI, long frame);\r
-int AVI_seek_start(avi_t *AVI);\r
-int AVI_set_video_position(avi_t *AVI, long frame);\r
-u64 AVI_get_video_position(avi_t *AVI, long frame);\r
-long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);\r
-\r
-int AVI_set_audio_position(avi_t *AVI, long byte);\r
-int AVI_set_audio_bitrate(avi_t *AVI, long bitrate);\r
-\r
-long AVI_get_audio_position_index(avi_t *AVI);\r
-int AVI_set_audio_position_index(avi_t *AVI, long indexpos);\r
-\r
-long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes, int *continuous);\r
-\r
-int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,\r
- char *audbuf, long max_audbuf,\r
- long *len);\r
-\r
-int AVI_scan(char *name);\r
-int AVI_dump(char *name, int mode);\r
-\r
-char *AVI_codec2str(short cc);\r
-int AVI_file_check(char *import_file);\r
-\r
-void AVI_info(avi_t *avifile);\r
-u64 AVI_max_size(void);\r
-int avi_update_header(avi_t *AVI);\r
-\r
-int AVI_set_audio_track(avi_t *AVI, u32 track);\r
-int AVI_get_audio_track(avi_t *AVI);\r
-int AVI_audio_tracks(avi_t *AVI);\r
-\r
-void AVI_set_audio_vbr(avi_t *AVI, long is_vbr);\r
-long AVI_get_audio_vbr(avi_t *AVI);\r
-\r
-void AVI_set_comment_fd(avi_t *AVI, int fd);\r
-int AVI_get_comment_fd(avi_t *AVI);\r
-\r
-struct riff_struct \r
-{\r
- u8 id[4]; /* RIFF */\r
- u32 len;\r
- u8 wave_id[4]; /* WAVE */\r
-};\r
-\r
-\r
-struct chunk_struct \r
-{\r
- u8 id[4];\r
- u32 len;\r
-};\r
-\r
-struct common_struct \r
-{\r
- u16 wFormatTag;\r
- u16 wChannels;\r
- u32 dwSamplesPerSec;\r
- u32 dwAvgBytesPerSec;\r
- u16 wBlockAlign;\r
- u16 wBitsPerSample; /* Only for PCM */\r
-};\r
-\r
-struct wave_header \r
-{\r
- struct riff_struct riff;\r
- struct chunk_struct format;\r
- struct common_struct common;\r
- struct chunk_struct data;\r
-};\r
-\r
-// Simple WAV IO\r
-int AVI_read_wave_header( int fd, struct wave_header * wave );\r
-int AVI_write_wave_header( int fd, const struct wave_header * wave );\r
-size_t AVI_read_wave_pcm_data( int fd, void * buffer, size_t buflen );\r
-size_t AVI_write_wave_pcm_data( int fd, const void * buffer, size_t buflen );\r
-\r
-\r
-struct AVIStreamHeader {\r
- long fccType;\r
- long fccHandler;\r
- long dwFlags;\r
- long dwPriority;\r
- long dwInitialFrames;\r
- long dwScale;\r
- long dwRate;\r
- long dwStart;\r
- long dwLength;\r
- long dwSuggestedBufferSize;\r
- long dwQuality;\r
- long dwSampleSize;\r
-};\r
-\r
-#endif /*_GF_AVILIB_H_*/\r