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.

466 lines
12 KiB

  1. #include "extra.h"
  2. #include "fileshar.h"
  3. #include "aviidx.h"
  4. #include "buffer.h"
  5. #include <ole2.h>
  6. /* - - - - - - - - */
  7. /*
  8. ** Copyright (C) Microsoft Corporation 1993-1995. All rights reserved.
  9. */
  10. /* - - - - - - - - */
  11. #define CFactoryImpl CI // Can't handle long exported names
  12. #define CAVIFileImpl CF // Can't handle long exported names
  13. #define CAVIStreamImpl CS // Can't handle long exported names
  14. /* Remove warning of using object during initialization. */
  15. #pragma warning(disable:4355)
  16. #ifndef OLESTR // work with old OLE headers
  17. typedef char OLECHAR;
  18. typedef LPSTR LPOLESTR;
  19. typedef LPCSTR LPCOLESTR;
  20. #define OLESTR(str) str
  21. #endif
  22. /* - - - - - - - - */
  23. #define implement struct
  24. #define implementations private
  25. /*
  26. ** _StdClassImplementations
  27. ** Defines the standard implementations for a class object.
  28. */
  29. #define _StdClassImplementations(Impl) \
  30. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv); \
  31. STDMETHODIMP_(ULONG) AddRef(); \
  32. STDMETHODIMP_(ULONG) Release()
  33. /* - - - - - - - - */
  34. class FAR CAVIFileCF {
  35. public:
  36. static HRESULT Create(const CLSID FAR& rclsid, REFIID riid, LPVOID FAR* ppv);
  37. private:
  38. CAVIFileCF(const CLSID FAR& rclsid, IUnknown FAR* FAR* ppUnknown);
  39. implementations:
  40. implement CUnknownImpl : IUnknown {
  41. public:
  42. _StdClassImplementations(CUnknownImpl);
  43. CUnknownImpl(CAVIFileCF FAR* pAVIFileCF);
  44. private:
  45. CAVIFileCF FAR* m_pAVIFileCF;
  46. ULONG m_refs;
  47. };
  48. implement CFactoryImpl : IClassFactory {
  49. public:
  50. _StdClassImplementations(CFactoryImpl);
  51. CFactoryImpl(CAVIFileCF FAR* pAVIFileCF);
  52. STDMETHODIMP CreateInstance(IUnknown FAR* pUnknownOuter, REFIID riid, LPVOID FAR* ppv);
  53. STDMETHODIMP LockServer(BOOL fLock);
  54. private:
  55. CAVIFileCF FAR* m_pAVIFileCF;
  56. };
  57. public:
  58. CUnknownImpl m_Unknown;
  59. CFactoryImpl m_Factory;
  60. public:
  61. CLSID m_clsid;
  62. };
  63. /* - - - - - - - - */
  64. class FAR CAVIFile;
  65. class FAR CAVIStream {
  66. public:
  67. CAVIStream(IUnknown FAR* pUnknownOuter, IUnknown FAR* FAR* ppUnknown);
  68. ~CAVIStream();
  69. private:
  70. implementations:
  71. implement CUnknownImpl : IUnknown {
  72. public:
  73. _StdClassImplementations(CUnknownImpl);
  74. CUnknownImpl(CAVIStream FAR* pAVIStream);
  75. private:
  76. CAVIStream FAR* m_pAVIStream;
  77. ULONG m_refs;
  78. };
  79. implement CAVIStreamImpl : IAVIStream {
  80. public:
  81. _StdClassImplementations(CAVIStreamImpl);
  82. CAVIStreamImpl(CAVIStream FAR* pAVIStream);
  83. ~CAVIStreamImpl();
  84. STDMETHODIMP Create (THIS_ LPARAM lParam1, LPARAM lParam2);
  85. STDMETHODIMP Info (THIS_ AVISTREAMINFOW FAR * psi, LONG lSize);
  86. STDMETHODIMP_(LONG) FindSample(THIS_ LONG lPos, LONG lFlags);
  87. STDMETHODIMP ReadFormat (THIS_ LONG lPos,
  88. LPVOID lpFormat, LONG FAR *cbFormat);
  89. STDMETHODIMP SetFormat (THIS_ LONG lPos,
  90. LPVOID lpFormat, LONG cbFormat);
  91. STDMETHODIMP Read (THIS_ LONG lStart, LONG lSamples,
  92. LPVOID lpBuffer, LONG cbBuffer,
  93. LONG FAR * plBytes, LONG FAR * plSamples);
  94. STDMETHODIMP Write (THIS_ LONG lStart, LONG lSamples,
  95. LPVOID lpBuffer, LONG cbBuffer,
  96. DWORD dwFlags,
  97. LONG FAR *plSampWritten,
  98. LONG FAR *plBytesWritten);
  99. STDMETHODIMP Delete (THIS_ LONG lStart, LONG lSamples);
  100. STDMETHODIMP ReadData (THIS_ DWORD fcc, LPVOID lp, LONG FAR *lpcb);
  101. STDMETHODIMP WriteData (THIS_ DWORD fcc, LPVOID lp, LONG cb);
  102. #ifdef _WIN32
  103. STDMETHODIMP SetInfo(AVISTREAMINFOW FAR *lpInfo, LONG cbInfo);
  104. #else
  105. STDMETHODIMP Reserved1 (THIS);
  106. STDMETHODIMP Reserved2 (THIS);
  107. STDMETHODIMP Reserved3 (THIS);
  108. STDMETHODIMP Reserved4 (THIS);
  109. STDMETHODIMP Reserved5 (THIS);
  110. #endif
  111. private:
  112. void ReadPalette(LONG lPos, LONG lPal, LPRGBQUAD prgb);
  113. // private functions here?
  114. CAVIStream FAR* m_pAVIStream;
  115. };
  116. implement CStreamingImpl : IAVIStreaming {
  117. public:
  118. _StdClassImplementations(CStreamingImpl);
  119. CStreamingImpl(CAVIStream FAR* pAVIStream);
  120. ~CStreamingImpl();
  121. STDMETHODIMP Begin (THIS_
  122. LONG lStart,
  123. LONG lEnd,
  124. LONG lRate);
  125. STDMETHODIMP End (THIS);
  126. private:
  127. // private functions here?
  128. CAVIStream FAR* m_pAVIStream;
  129. };
  130. #ifdef CUSTOMMARSHAL
  131. struct CMarshalImpl : IMarshal {
  132. public:
  133. CMarshalImpl(CAVIStream FAR* pAVIStream);
  134. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv);
  135. STDMETHODIMP_(ULONG) AddRef();
  136. STDMETHODIMP_(ULONG) Release();
  137. // *** IMarshal methods ***
  138. STDMETHODIMP GetUnmarshalClass (THIS_ REFIID riid, LPVOID pv,
  139. DWORD dwDestContext, LPVOID pvDestContext,
  140. DWORD mshlflags, LPCLSID pCid);
  141. STDMETHODIMP GetMarshalSizeMax (THIS_ REFIID riid, LPVOID pv,
  142. DWORD dwDestContext, LPVOID pvDestContext,
  143. DWORD mshlflags, LPDWORD pSize);
  144. STDMETHODIMP MarshalInterface (THIS_ LPSTREAM pStm, REFIID riid,
  145. LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  146. DWORD mshlflags);
  147. STDMETHODIMP UnmarshalInterface (THIS_ LPSTREAM pStm, REFIID riid,
  148. LPVOID FAR* ppv);
  149. STDMETHODIMP ReleaseMarshalData (THIS_ LPSTREAM pStm);
  150. STDMETHODIMP DisconnectObject (THIS_ DWORD dwReserved);
  151. CAVIStream FAR* m_pAVIStream;
  152. };
  153. #endif // CUSTOMMARSHAL
  154. public:
  155. CUnknownImpl m_Unknown;
  156. CAVIStreamImpl m_AVIStream;
  157. #ifdef CUSTOMMARSHAL
  158. CMarshalImpl m_Marshal;
  159. #endif
  160. CStreamingImpl m_Streaming;
  161. public:
  162. IUnknown FAR* m_pUnknownOuter;
  163. // AVIStream Instance data
  164. AVISTREAMINFOW avistream; // stream info
  165. CAVIFile FAR * pfile;
  166. int iStream;
  167. PAVISTREAM paviBase;
  168. //
  169. // stream instance data
  170. //
  171. HSHFILE hshfile; // file I/O
  172. LONG lPal; // last palette change
  173. RGBQUAD argbq[256]; // current palette
  174. LPVOID lpFormat; // stream format
  175. LONG cbFormat;
  176. LPVOID lpData; // stream handler data
  177. LONG cbData;
  178. EXTRA extra;
  179. PBUFSYSTEM pb;
  180. BOOL fInit;
  181. PSTREAMINDEX psx;
  182. };
  183. /* - - - - - - - - */
  184. #define MAXSTREAMS 64
  185. class FAR CAVIFile {
  186. public:
  187. static HRESULT Create(IUnknown FAR* pUnknownOuter, REFIID riid, LPVOID FAR* ppv);
  188. STDMETHODIMP OpenInternal(DWORD mode);
  189. private:
  190. CAVIFile(IUnknown FAR* pUnknownOuter, IUnknown FAR* FAR* ppUnknown);
  191. implementations:
  192. implement CUnknownImpl : IUnknown {
  193. public:
  194. _StdClassImplementations(CUnknownImpl);
  195. CUnknownImpl(CAVIFile FAR* pAVIFile);
  196. private:
  197. CAVIFile FAR* m_pAVIFile;
  198. ULONG m_refs;
  199. };
  200. implement CAVIFileImpl : IAVIFile {
  201. public:
  202. _StdClassImplementations(CAVIFileImpl);
  203. CAVIFileImpl(CAVIFile FAR* pAVIFile);
  204. ~CAVIFileImpl();
  205. #ifndef _WIN32
  206. STDMETHODIMP Open (THIS_
  207. LPCTSTR szFile,
  208. UINT mode);
  209. #endif
  210. STDMETHODIMP Info (THIS_
  211. AVIFILEINFOW FAR * pfi,
  212. LONG lSize);
  213. STDMETHODIMP GetStream (THIS_
  214. PAVISTREAM FAR * ppStream,
  215. DWORD fccType,
  216. LONG lParam);
  217. STDMETHODIMP CreateStream (THIS_
  218. PAVISTREAM FAR * ppStream,
  219. AVISTREAMINFOW FAR * psi);
  220. #ifndef _WIN32
  221. STDMETHODIMP Save (THIS_
  222. LPCTSTR szFile,
  223. AVICOMPRESSOPTIONS FAR *lpOptions,
  224. AVISAVECALLBACK lpfnCallback);
  225. #endif
  226. STDMETHODIMP WriteData (THIS_
  227. DWORD ckid,
  228. LPVOID lpData,
  229. LONG cbData);
  230. STDMETHODIMP ReadData (THIS_
  231. DWORD ckid,
  232. LPVOID lpData,
  233. LONG FAR *lpcbData);
  234. STDMETHODIMP EndRecord (THIS);
  235. #ifdef _WIN32
  236. STDMETHODIMP DeleteStream (THIS_
  237. DWORD fccType,
  238. LONG lParam);
  239. #else
  240. STDMETHODIMP Reserved1 (THIS);
  241. STDMETHODIMP Reserved2 (THIS);
  242. STDMETHODIMP Reserved3 (THIS);
  243. STDMETHODIMP Reserved4 (THIS);
  244. STDMETHODIMP Reserved5 (THIS);
  245. #endif
  246. private:
  247. // private functions here?
  248. CAVIFile FAR* m_pAVIFile;
  249. };
  250. #ifdef CUSTOMMARSHAL
  251. struct CMarshalImpl : IMarshal {
  252. public:
  253. CMarshalImpl(CAVIFile FAR* pAVIFile);
  254. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv);
  255. STDMETHODIMP_(ULONG) AddRef();
  256. STDMETHODIMP_(ULONG) Release();
  257. // *** IMarshal methods ***
  258. STDMETHODIMP GetUnmarshalClass (THIS_ REFIID riid, LPVOID pv,
  259. DWORD dwDestContext, LPVOID pvDestContext,
  260. DWORD mshlflags, LPCLSID pCid);
  261. STDMETHODIMP GetMarshalSizeMax (THIS_ REFIID riid, LPVOID pv,
  262. DWORD dwDestContext, LPVOID pvDestContext,
  263. DWORD mshlflags, LPDWORD pSize);
  264. STDMETHODIMP MarshalInterface (THIS_ LPSTREAM pStm, REFIID riid,
  265. LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  266. DWORD mshlflags);
  267. STDMETHODIMP UnmarshalInterface (THIS_ LPSTREAM pStm, REFIID riid,
  268. LPVOID FAR* ppv);
  269. STDMETHODIMP ReleaseMarshalData (THIS_ LPSTREAM pStm);
  270. STDMETHODIMP DisconnectObject (THIS_ DWORD dwReserved);
  271. CAVIFile FAR* m_pAVIFile;
  272. };
  273. #endif // CUSTOMMARSHAL
  274. struct CPersistStorageImpl : IPersistStorage {
  275. public:
  276. CPersistStorageImpl(CAVIFile FAR* pAVIFile);
  277. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv);
  278. STDMETHODIMP_(ULONG) AddRef();
  279. STDMETHODIMP_(ULONG) Release();
  280. // *** IPersist methods ***
  281. STDMETHODIMP GetClassID (LPCLSID lpClassID);
  282. // *** IPersistStorage methods ***
  283. STDMETHODIMP IsDirty ();
  284. STDMETHODIMP InitNew (LPSTORAGE pStg);
  285. STDMETHODIMP Load (LPSTORAGE pStg);
  286. STDMETHODIMP Save (LPSTORAGE pStgSave, BOOL fSameAsLoad);
  287. STDMETHODIMP SaveCompleted (LPSTORAGE pStgNew);
  288. STDMETHODIMP HandsOffStorage ();
  289. CAVIFile FAR* m_pAVIFile;
  290. };
  291. struct CPersistFileImpl : IPersistFile {
  292. public:
  293. CPersistFileImpl(CAVIFile FAR* pAVIFile);
  294. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv);
  295. STDMETHODIMP_(ULONG) AddRef();
  296. STDMETHODIMP_(ULONG) Release();
  297. // *** IPersist methods ***
  298. STDMETHODIMP GetClassID (LPCLSID lpClassID);
  299. // *** IPersistFile methods ***
  300. STDMETHODIMP IsDirty ();
  301. STDMETHODIMP Load (LPCOLESTR lpszFileName, DWORD grfMode);
  302. STDMETHODIMP Save (LPCOLESTR lpszFileName, BOOL fRemember);
  303. STDMETHODIMP SaveCompleted (LPCOLESTR lpszFileName);
  304. STDMETHODIMP GetCurFile (LPOLESTR FAR * lplpszFileName);
  305. CAVIFile FAR* m_pAVIFile;
  306. };
  307. public:
  308. CUnknownImpl m_Unknown;
  309. CAVIFileImpl m_AVIFile;
  310. #ifdef CUSTOMMARSHAL
  311. CMarshalImpl m_Marshal;
  312. #endif
  313. CPersistStorageImpl m_PersistS;
  314. CPersistFileImpl m_PersistF;
  315. public:
  316. IUnknown FAR* m_pUnknownOuter;
  317. //
  318. // AVIFile instance data
  319. //
  320. MainAVIHeader FARSTRUCT avihdr; // file info
  321. LONG lHeaderSize;
  322. TCHAR achFile[260];
  323. DWORD mode;
  324. HSHFILE hshfile; // file I/O
  325. LONG lDataListStart;
  326. BOOL fInRecord;
  327. LONG lRecordIndex;
  328. MMCKINFO ckRecord;
  329. LONG lWriteLoc;
  330. EXTRA extra;
  331. BOOL fDirty;
  332. CAVIStream FAR * ps[MAXSTREAMS];
  333. PAVIINDEX px; // the index
  334. PBUFSYSTEM pb;
  335. #ifdef _WIN32
  336. CRITICAL_SECTION m_critsec;
  337. #endif
  338. };
  339. // this class can be used to provide thread locking by declaring
  340. // an automatic instance on the stack. The non-win32 class does nothing
  341. class FAR CLock {
  342. #ifdef _WIN32
  343. private:
  344. LPCRITICAL_SECTION pcritsec;
  345. public:
  346. CLock(CAVIFile FAR* pfile)
  347. {
  348. pcritsec = &pfile->m_critsec;
  349. EnterCriticalSection(pcritsec);
  350. };
  351. ~CLock()
  352. {
  353. if (pcritsec != NULL) { // Because we may explicitly leave before
  354. // the automatic instance is destroyed
  355. LeaveCriticalSection(pcritsec);
  356. }
  357. };
  358. // Normally we enter/leave the critical section automatically by
  359. // creating an automatic instance of the Class, and letting C++ call
  360. // the destructor when the instance goes out of scope. Exit is
  361. // provided to allow the user to explicitly release the critsec.
  362. void Exit()
  363. {
  364. LPCRITICAL_SECTION ptmp = pcritsec;
  365. pcritsec = NULL;
  366. if (ptmp != NULL) {
  367. LeaveCriticalSection(ptmp);
  368. }
  369. };
  370. #else
  371. public:
  372. CLock(CAVIFile FAR* pfile)
  373. {
  374. };
  375. ~CLock()
  376. {
  377. };
  378. void Exit()
  379. {
  380. };
  381. #endif
  382. };
  383. #ifdef _WIN32
  384. // for C files
  385. #define EnterCrit(pfile) (EnterCriticalSection(&pfile->m_critsec))
  386. #define LeaveCrit(p) (LeaveCriticalSection(&pfile->m_critsec))
  387. #else
  388. #define EnterCrit(p)
  389. #define LeaveCrit(p)
  390. #endif
  391. /*
  392. ** The usage counter keeps track of the overall usage of objects based on
  393. ** implementations provided by the component. This allows one to determine
  394. ** when the implementation is no longer in use.
  395. */
  396. extern UINT uUseCount;
  397. extern BOOL fLocked;
  398. /* - - - - - - - - */
  399. DEFINE_AVIGUID(CLSID_ACMCmprs, 0x0002000F, 0, 0);