Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.1 KiB

  1. /******************************************************************************
  2. Copyright (C) Microsoft Corporation 1985 - 1995. All rights reserved.
  3. AVIIDX.H - AVI Index stuff
  4. *****************************************************************************/
  5. #ifndef _INC_AVIFMT
  6. #include <vfw.h>
  7. #endif
  8. #ifndef EXTERN_C
  9. #ifdef __cplusplus
  10. #define EXTERN_C extern "C"
  11. #else
  12. #define EXTERN_C extern
  13. #endif
  14. #endif
  15. #define ERR_POS (-100) // bad position
  16. #define ERR_IDX (-1) // bad index
  17. typedef AVIINDEXENTRY _huge *PAVIINDEXENTRY;
  18. // to some customers, this 1Gb limit is not worth the few bytes it saves.
  19. #ifndef _WIN32
  20. //
  21. // this is the in memory form of a AVI INDEX, we want this to be 8 bytes
  22. // to save memory.
  23. //
  24. // the bit fields may not be portable, so a new structure will be needed.
  25. //
  26. // we always access via macros, so changing the structure should be posible
  27. //
  28. // this stucture sotres the following:
  29. //
  30. // offset 0-1GB (30 bits) we assume even number so only need 29bits
  31. // flags (4 bits)
  32. // stream 0-127 (7 bits)
  33. // length 0-4MB (24 bits)
  34. //
  35. #pragma pack(1)
  36. typedef union {
  37. struct {
  38. DWORD offset; // 0-1GB
  39. DWORD length; // 0-4MB
  40. };
  41. struct {
  42. BYTE ack[3]; // 24 bits of the offset
  43. WORD flags; // access to all flags
  44. BYTE smag[3]; // length (24 bits)
  45. };
  46. #if 0 // I hate bit-fields
  47. struct {
  48. DWORD offset:29; // 0-1GB
  49. DWORD key:1;
  50. DWORD nonkey:1;
  51. DWORD pal:1;
  52. DWORD stream:7; // 0-127
  53. DWORD half:1;
  54. DWORD length:24; // 0-4MB
  55. };
  56. #endif
  57. } AVIIDX;
  58. #pragma pack()
  59. //
  60. // limits
  61. //
  62. #define MAX_OFFSET (1l<<30)
  63. #define MAX_LENGTH (1l<<24)
  64. #define MAX_STREAM (1l<<7)
  65. //
  66. // index flags
  67. //
  68. #define IDX_OFFHI 0x001F // hi part of offset.
  69. #define IDX_KEY 0x0020 // key frame
  70. #define IDX_NONKEY 0x0040 // not a key frame (but not blank either)
  71. #define IDX_PAL 0x0080 // palette change
  72. #define IDX_STREAM 0x7F00 // stream number
  73. #define IDX_HALF 0x8000 // RLE half frame.
  74. #define IDX_NOTIME IDX_PAL
  75. //
  76. // macros to acces index to help porting
  77. //
  78. #define Index(px, lx) ((AVIIDX _huge *)px)[lx+1]
  79. #define IndexOffset(px, lx) (LONG)((Index(px,lx).offset & 0x1FFFFFFF) * 2)
  80. #define IndexLength(px, lx) (LONG)((Index(px,lx).length) >> 8)
  81. #define IndexStream(px, lx) (BYTE)((Index(px,lx).flags & IDX_STREAM) >> 8)
  82. #define IndexFlags(px, lx) (UINT)(Index(px,lx).flags)
  83. #define IndexSetOffset(px, lx, x) { Index(px,lx).offset &= ~0x1FFFFFFF; Index(px,lx).offset |= (DWORD)(x)>>1; }
  84. #define IndexSetLength(px, lx, x) { Index(px,lx).length &= ~0xFFFFFF00; Index(px,lx).length |= (DWORD)(x)<<8; }
  85. #define IndexSetStream(px, lx, x) { Index(px,lx).flags &= ~IDX_STREAM; Index(px,lx).flags |= (DWORD)(x)<<8; }
  86. #define IndexSetFlags(px, lx, x) { Index(px,lx).flags &= IDX_STREAM|IDX_OFFHI; Index(px,lx).flags |= (UINT)(x); }
  87. #define IndexSetKey(px, lx) { Index(px,lx).flags |= IDX_KEY; Index(px,lx).flags &= ~(IDX_NONKEY); }
  88. #else // --- 4Gb version of index macros ----------------------------------
  89. typedef struct {
  90. WORD flags;
  91. WORD stream;
  92. DWORD offset;
  93. long length;
  94. } AVIIDX;
  95. //
  96. // limits
  97. //
  98. #define MAX_OFFSET ((DWORD)0xffffffff) // signed in some places ??
  99. #define MAX_LENGTH (1l<<30)
  100. #define MAX_STREAM (1l<<16)
  101. //
  102. // index flags
  103. //
  104. #define IDX_KEY 0x0020 // key frame
  105. #define IDX_NONKEY 0x0040 // not a key frame (but not blank either)
  106. #define IDX_PAL 0x0080 // palette change
  107. #define IDX_HALF 0x8000 // RLE half frame.
  108. #define IDX_NOTIME IDX_PAL
  109. //
  110. // macros to acces index to help porting
  111. //
  112. #define Index(px, lx) (px)->idx[lx]
  113. #define IndexOffset(px, lx) (Index(px,lx).offset)
  114. #define IndexLength(px, lx) (Index(px,lx).length)
  115. #define IndexStream(px, lx) (Index(px,lx).stream)
  116. #define IndexFlags(px, lx) (Index(px,lx).flags)
  117. #define IndexSetOffset(px, lx, x) { Index(px,lx).offset = (DWORD)(x); }
  118. #define IndexSetLength(px, lx, x) { Index(px,lx).length = (long)(x); }
  119. #define IndexSetStream(px, lx, x) { Index(px,lx).stream = (WORD)(x); }
  120. #define IndexSetFlags(px, lx, x) { Index(px,lx).flags = (WORD)(x); }
  121. #define IndexSetKey(px, lx) { Index(px,lx).flags |= IDX_KEY; Index(px,lx).flags &= ~(IDX_NONKEY); }
  122. #endif //------------------------------------------------------------------
  123. //
  124. // special streams
  125. //
  126. #define STREAM_REC 0x7F // interleave records.
  127. //
  128. // this is the header we put on a list of AVIIDX entries.
  129. //
  130. #pragma warning(disable:4200)
  131. typedef struct
  132. {
  133. LONG nIndex; // number of entries in index
  134. LONG nIndexSize; // alocated size
  135. AVIIDX idx[]; // the entries.
  136. } AVIINDEX, _huge *PAVIINDEX;
  137. //
  138. // AVI Stream Index
  139. //
  140. typedef LONG (FAR PASCAL *STREAMIOPROC)(HANDLE hFile, LONG off, LONG cb, LPVOID p);
  141. typedef struct
  142. {
  143. UINT stream; // stream number
  144. UINT flags; // combination of all flags in index.
  145. PAVIINDEX px; // main index
  146. LONG lx; // Index index
  147. LONG lPos; // index position
  148. LONG lxStart; // Index start
  149. LONG lStart; // start of stream
  150. LONG lEnd; // end of stream
  151. LONG lMaxSampleSize; // largest sample
  152. LONG lSampleSize; // sample size for stream
  153. LONG lFrames; // total "frames"
  154. LONG lKeyFrames; // total key "frames"
  155. LONG lPalFrames; // total pal "frames"
  156. LONG lNulFrames; // total nul "frames"
  157. HANDLE hFile;
  158. STREAMIOPROC Read;
  159. STREAMIOPROC Write;
  160. } STREAMINDEX, *PSTREAMINDEX;
  161. //
  162. // create and free a index.
  163. //
  164. EXTERN_C PAVIINDEX IndexCreate(void);
  165. #define FreeIndex(px) GlobalFreePtr(px)
  166. //
  167. // convert to and from a file index
  168. //
  169. EXTERN_C PAVIINDEX IndexAddFileIndex(PAVIINDEX px, AVIINDEXENTRY _huge *pidx, LONG cnt, LONG lAdjust, BOOL fRle);
  170. EXTERN_C LONG IndexGetFileIndex(PAVIINDEX px, LONG l, LONG cnt, PAVIINDEXENTRY pidx, LONG lAdjust);
  171. EXTERN_C PSTREAMINDEX MakeStreamIndex(PAVIINDEX px, UINT stream, LONG lStart, LONG lSampleSize, HANDLE hFile, STREAMIOPROC ReadProc, STREAMIOPROC WriteProc);
  172. #define FreeStreamIndex(psx) LocalFree((HLOCAL)psx)
  173. //
  174. // index access functions
  175. //
  176. EXTERN_C LONG IndexFirst(PAVIINDEX px, UINT stream);
  177. EXTERN_C LONG IndexNext (PAVIINDEX px, LONG lx, UINT f);
  178. EXTERN_C LONG IndexPrev (PAVIINDEX px, LONG lx, UINT f);
  179. //
  180. // search index for data
  181. //
  182. #ifndef FIND_DIR
  183. #define FIND_DIR 0x0000000FL // direction
  184. #define FIND_NEXT 0x00000001L // go forward
  185. #define FIND_PREV 0x00000004L // go backward
  186. #define FIND_FROM_START 0x00000008L // start at the logical beginning
  187. #define FIND_TYPE 0x000000F0L // type mask
  188. #define FIND_KEY 0x00000010L // find key frame.
  189. #define FIND_ANY 0x00000020L // find any (non-empty) sample
  190. #define FIND_FORMAT 0x00000040L // find format change
  191. #endif
  192. #ifndef FIND_RET
  193. #define FIND_RET 0x0000F000L // return mask
  194. #define FIND_POS 0x00000000L // return logical position
  195. #define FIND_LENGTH 0x00001000L // return logical size
  196. #define FIND_OFFSET 0x00002000L // return physical position
  197. #define FIND_SIZE 0x00003000L // return physical size
  198. #define FIND_INDEX 0x00004000L // return physical index position
  199. #endif
  200. EXTERN_C LONG StreamFindSample(PSTREAMINDEX psx, LONG lPos, UINT f);
  201. EXTERN_C LONG StreamRead(PSTREAMINDEX psx, LONG lStart, LONG lSamples, LPVOID lpBuffer, LONG cbBuffer);
  202. EXTERN_C LONG StreamWrite(PSTREAMINDEX psx, LONG lStart, LONG lSamples, LPVOID lpBuffer, LONG cbBuffer);