Source code of Windows XP (NT5)
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.

195 lines
6.3 KiB

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