avi_demuxer.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #ifndef H_AVI_STR
  2. #define H_AVI_STR
  3. #undef BYTE
  4. #undef DWORD
  5. #undef LONG
  6. #undef WORD
  7. #undef FOURCC
  8. #undef NULL
  9. typedef unsigned char BYTE;
  10. typedef unsigned long DWORD;
  11. typedef long LONG;
  12. typedef unsigned short WORD;
  13. typedef unsigned int FOURCC; /* a four character code */
  14. #define NULL 0
  15. #define MAX_PACKET_LEN 2048
  16. typedef struct tagRECT {
  17. WORD left;
  18. WORD top;
  19. WORD right;
  20. WORD bottom;
  21. } RECT;
  22. /**
  23. ** 56 bytes
  24. **/
  25. typedef struct
  26. {
  27. DWORD dwMicroSecPerFrame; // frame display rate (or 0L)
  28. DWORD dwMaxBytesPerSec; // max. transfer rate
  29. DWORD dwPaddingGranularity; // pad to multiples of this
  30. // size; normally 2K.
  31. DWORD dwFlags; // the ever-present flags
  32. DWORD dwTotalFrames; // # frames in file
  33. DWORD dwInitialFrames;
  34. DWORD dwStreams;
  35. DWORD dwSuggestedBufferSize;
  36. // 视频宽度
  37. DWORD dwWidth;
  38. // 视频高度
  39. DWORD dwHeight;
  40. DWORD dwReserved[4]; //amv 内容为释掉的代码
  41. #if 0
  42. amv:
  43. DWORD dwScale; /* */
  44. DWORD dwRate; /* */
  45. DWORD dwStart; /* the reference value of starting point for timing */
  46. DWORD dwLength; /* the length in the time */
  47. #endif
  48. } MainAVIHeader;
  49. typedef struct {
  50. FOURCC fccType;
  51. FOURCC fccHandler;
  52. DWORD dwFlags; /* Contains AVITF_* flags */
  53. WORD wPriority;
  54. WORD wLanguage;
  55. DWORD dwInitialFrames;
  56. DWORD dwScale;
  57. DWORD dwRate; /* dwRate / dwScale == samples/second */
  58. DWORD dwStart;
  59. DWORD dwLength; /* In units above... */
  60. DWORD dwSuggestedBufferSize;
  61. DWORD dwQuality;
  62. DWORD dwSampleSize;
  63. RECT rcFrame;
  64. } AVIStreamHeader;
  65. typedef struct tagBITMAPINFOHEADER{
  66. DWORD biSize;
  67. LONG biWidth;
  68. LONG biHeight;
  69. WORD biPlanes;
  70. WORD biBitCount;
  71. DWORD biCompression;
  72. DWORD biSizeImage;
  73. LONG biXPelsPerMeter;
  74. LONG biYPelsPerMeter;
  75. DWORD biClrUsed;
  76. DWORD biClrImportant;
  77. } BITMAPINFOHEADER;
  78. #pragma pack(2)
  79. typedef struct tWAVEFORMATEX
  80. {
  81. WORD wFormatTag; /* format type */
  82. WORD nChannels; /* number of channels (i.e. mono, stereo...) */
  83. DWORD nSamplesPerSec; /* sample rate */
  84. DWORD nAvgBytesPerSec; /* for buffer estimation */
  85. WORD nBlockAlign; /* block size of data */
  86. WORD wBitsPerSample; /* Number of bits per sample of mono data */
  87. WORD cbSize; /* The count in bytes of the size of
  88. extra information (after cbSize) */
  89. } WAVEFORMATEX;
  90. #pragma pack()
  91. /* the format of the audio stream(strf) and its data structure */
  92. typedef struct {
  93. WORD wFormat_tag; /* the format of the audio data in this AMV file */
  94. WORD wChannels; /* the number of audio channels */
  95. DWORD dwSamples_per_sec; /* the number of the samples stored in one second */
  96. DWORD dwAvg_bytes_per_sec; /* samples_per_sec * block_align */
  97. WORD wBlock_align; /* channels * bits_per_sample / 8 */
  98. WORD wBits_per_sample; /* the number of bits which are used by every sample (8 or 16) */
  99. WORD wSize_extra; /* 0 (Not available temporarily) */
  100. WORD reserved;
  101. } AMVAudioStreamFormat;
  102. typedef enum{
  103. STREAMSTART = -4,
  104. STREAMEND,
  105. UNKNOWNCON,
  106. MEMERROR,
  107. NORMAL,
  108. }STATUSINFO;
  109. #ifndef mmioFOURCC
  110. #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
  111. ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
  112. ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
  113. #endif
  114. /* Macro to make a TWOCC out of two characters */
  115. #ifndef aviTWOCC
  116. #define aviTWOCC(ch0, ch1) ((WORD)(BYTE)(ch0) | ((WORD)(BYTE)(ch1) << 8))
  117. #endif
  118. /* form types, list types, and chunk types */
  119. #define RIFFTAG mmioFOURCC('R', 'I', 'F', 'F')
  120. #define LISTTAG mmioFOURCC('L', 'I', 'S', 'T')
  121. #define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
  122. #define formtypeAMV mmioFOURCC('A', 'M', 'V', ' ')
  123. #define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
  124. #define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
  125. #define ckidAMVMAINHDR mmioFOURCC('a', 'm', 'v', 'h')
  126. #define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
  127. #define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
  128. #define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
  129. #define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
  130. #define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n')
  131. #define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
  132. #define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
  133. #define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
  134. #define ckidAMVEND mmioFOURCC('A', 'M', 'V', '_')
  135. /*
  136. ** Stream types for the <fccType> field of the stream header.
  137. */
  138. #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
  139. #define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
  140. #define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
  141. #define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
  142. /* Basic chunk types */
  143. #define cktypeDIBbits aviTWOCC('d', 'b')
  144. #define cktypeDIBcompressed aviTWOCC('d', 'c')
  145. #define cktypePALchange aviTWOCC('p', 'c')
  146. #define cktypeWAVEbytes aviTWOCC('w', 'b')
  147. /* Chunk id to use for extra chunks for padding. */
  148. #define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
  149. #define TIMESCALE 1000
  150. #define DATA_MASK 0x0000ffff
  151. //#define CHUNKPADD(len, amv) ((len)&(!(amv)))
  152. #define CHUNKPADD(len, amv) ((amv)?0:((4 - ((len)&(0x3)))&0x3))
  153. typedef struct
  154. {
  155. int es_type;
  156. unsigned int pts;
  157. unsigned char *data;
  158. unsigned int data_len;
  159. }avi_packet_t;
  160. typedef struct
  161. {
  162. ///////////header info//////////////
  163. void *stream;
  164. DWORD index_offset;
  165. DWORD index_flag;
  166. //DWORD filetype;
  167. DWORD framerate;
  168. DWORD framenum;
  169. DWORD movitagpos;
  170. DWORD TotalFrames;
  171. //AVIStreamHeader sheader;
  172. DWORD dwScale;
  173. //帧率,每秒钟的帧数
  174. DWORD dwRate;
  175. DWORD framecounter;
  176. DWORD amvformat; //len is align 1, must differ from avi
  177. DWORD dwSamples_per_sec;
  178. DWORD wChannels;
  179. BITMAPINFOHEADER bmpheader;
  180. WAVEFORMATEX waveheader;
  181. AMVAudioStreamFormat amvwaveheader;
  182. ////////////
  183. }avi_contex_t;
  184. int read_header(void *avict);
  185. int get_es_chunk(void *avict, avi_packet_t *raw_packet);
  186. int read4bytes(void *io);
  187. int search_es_chunk(void *avict, avi_packet_t *raw_packet);
  188. int read_data(void *io, void *buf, unsigned int len);
  189. int read_skip(void *io, int len);
  190. int file_seek_back(void *io, int len);
  191. int file_seek_set(void *io, int len);
  192. int file_tell(void *io);
  193. #endif