00001
00002
00003
00004
00005
00006 #define WINVER 0x400
00007 #define _WIN32_IE 0x501
00008 #define _WIN32_WINNT 0x400
00009
00010 #include "fsAVIIdx1Builder.h"
00011 #include <fsString.h>
00012 #include "../system.h"
00013
00014 #ifdef _DEBUG
00015 #undef THIS_FILE
00016 static char THIS_FILE[]=__FILE__;
00017 #define new DEBUG_NEW
00018 #endif
00019
00020 fsAVIIdx1Builder::fsAVIIdx1Builder()
00021 {
00022
00023 }
00024
00025 fsAVIIdx1Builder::~fsAVIIdx1Builder()
00026 {
00027
00028 }
00029
00030 inline BOOL Read (HANDLE hFile, LPVOID pBuf, DWORD dwSize)
00031 {
00032 return ReadFile (hFile, pBuf, dwSize, &dwSize, NULL);
00033 }
00034
00035 inline BOOL Read (HANDLE hFile, LPSTR pStr, DWORD dwSize)
00036 {
00037 pStr [dwSize] = 0;
00038 return ReadFile (hFile, pStr, dwSize, &dwSize, NULL);
00039 }
00040
00041 inline BOOL Write (HANDLE hFile, LPVOID pBuf, DWORD dwSize)
00042 {
00043 return WriteFile (hFile, pBuf, dwSize, &dwSize, NULL);
00044 }
00045
00046 inline void Seek (HANDLE hFile, DWORD dw)
00047 {
00048 SetFilePointer (hFile, dw, NULL, FILE_BEGIN);
00049 }
00050
00051 inline DWORD GetFilePos (HANDLE hFile)
00052 {
00053 return SetFilePointer (hFile, 0, NULL, FILE_CURRENT);
00054 }
00055
00056 inline DWORD GetFileSize (HANDLE hFile)
00057 {
00058 return ::GetFileSize (hFile, NULL);
00059 }
00060
00061 typedef struct {
00062 DWORD ckid;
00063 DWORD dwFlags;
00064 DWORD dwChunkOffset;
00065 DWORD dwChunkLength;
00066 } AVIINDEXENTRY;
00067
00068 BOOL fsAVIIdx1Builder::BuildIdx1(HANDLE in, HANDLE out, UINT64 uInMaxPos)
00069 {
00070 fsString strChunk;
00071 DWORD dw = 0;
00072
00073 if (uInMaxPos == _UI64_MAX)
00074 {
00075 DWORD dw1, dw2;
00076 dw1 = GetFileSize (in, &dw2);
00077 uInMaxPos = UINT64 (dw1) | UINT64 (dw2) << 32;
00078 }
00079
00080 strChunk.alloc (4);
00081
00082 UINT64 uPos = 16;
00083 fsSetFilePointer (in, uPos, FILE_BEGIN);
00084
00085
00086 Read (in, &dw, 4);
00087 uPos += 4+dw;
00088
00089 fsSetFilePointer (in, uPos, FILE_BEGIN);
00090
00091 do
00092 {
00093
00094 Read (in, strChunk, 4);
00095 Read (in, &dw, 4);
00096 uPos += 8;
00097
00098 if (strChunk == "JUNK" || strChunk == "JUNQ")
00099 {
00100 uPos += dw;
00101 fsSetFilePointer (in, uPos, FILE_BEGIN);
00102 continue;
00103 }
00104
00105 if (strChunk != "LIST")
00106 return FALSE;
00107
00108 m_uIdx1Start = uPos + dw;
00109
00110 Read (in, strChunk, 4);
00111 uPos += 4;
00112
00113 if (strChunk != "movi")
00114 {
00115 uPos += dw-4;
00116 fsSetFilePointer (in, uPos, FILE_BEGIN);
00117 continue;
00118 }
00119 }
00120 while (strChunk != "movi");
00121
00122 Write (out, "idx1", 4);
00123 Write (out, &dw, 4);
00124
00125 DWORD dwOffset = 4;
00126
00127 do
00128 {
00129 for (int i = 0; i < 16; i++)
00130 {
00131 Read (in, strChunk, 4);
00132 if (stricmp (strChunk+2, "wb") == 0 ||
00133 stricmp (strChunk+2, "dc") == 0 ||
00134 stricmp (strChunk+2, "db") == 0)
00135 break;
00136
00137 fsSetFilePointer (in, ++uPos, FILE_BEGIN);
00138 dwOffset++;
00139 }
00140
00141 if (stricmp (strChunk+2, "wb") &&
00142 stricmp (strChunk+2, "dc") &&
00143 stricmp (strChunk+2, "db"))
00144 return FALSE;
00145
00146 Read (in, &dw, 4);
00147 uPos += 8;
00148
00149 if (uPos + dw > uInMaxPos)
00150 break;
00151
00152 AVIINDEXENTRY e;
00153 e.ckid = *((LPDWORD)(LPSTR)strChunk);
00154 e.dwChunkLength = dw;
00155 e.dwChunkOffset = dwOffset;
00156 e.dwFlags = 0;
00157 if (strChunk == "LIST")
00158 e.dwFlags |= 0x1;
00159
00160 Write (out, &e, sizeof (e));
00161
00162 uPos += dw;
00163 dwOffset += 8 + dw;
00164 fsSetFilePointer (in, uPos, FILE_BEGIN);
00165 }
00166 while (uPos < m_uIdx1Start);
00167
00168 dw = GetFileSize (out) - 8;
00169 Seek (out, 4);
00170 Write (out, &dw, 4);
00171
00172 return TRUE;
00173 }
00174
00175 UINT64 fsAVIIdx1Builder::Get_Idx1StartPosition()
00176 {
00177 return m_uIdx1Start;
00178 }