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.

363 lines
6.5 KiB

  1. /* - - - - - - - - */
  2. /*
  3. ** Copyright (C) Microsoft Corporation 1993-1995. All rights reserved.
  4. */
  5. /* - - - - - - - - */
  6. #include <win32.h>
  7. #include <vfw.h>
  8. #include "avifilei.h"
  9. #include "debug.h"
  10. /* - - - - - - - - */
  11. UINT uUseCount;
  12. BOOL fLocked;
  13. /* - - - - - - - - */
  14. STDAPI DllCanUnloadNow(
  15. void)
  16. {
  17. DPF("DllCanUnloadNow: Usage = %u\n", uUseCount);
  18. return ResultFromScode((fLocked || uUseCount) ? S_FALSE : S_OK);
  19. }
  20. /* - - - - - - - - */
  21. HRESULT CAVIFile::Create(
  22. IUnknown FAR* pUnknownOuter,
  23. const IID FAR& riid,
  24. void FAR* FAR* ppv)
  25. {
  26. IUnknown FAR* pUnknown;
  27. CAVIFile FAR* pAVIFile;
  28. HRESULT hresult;
  29. pAVIFile = new FAR CAVIFile(pUnknownOuter, &pUnknown);
  30. if (!pAVIFile)
  31. return ResultFromScode(E_OUTOFMEMORY);
  32. hresult = pUnknown->QueryInterface(riid, ppv);
  33. if (FAILED(GetScode(hresult)))
  34. delete pAVIFile;
  35. return hresult;
  36. }
  37. /* - - - - - - - - */
  38. CAVIFile::CAVIFile(
  39. IUnknown FAR* pUnknownOuter,
  40. IUnknown FAR* FAR* ppUnknown) :
  41. m_Unknown(this),
  42. m_PersistS(this),
  43. m_PersistF(this),
  44. m_AVIFile(this)
  45. #ifdef CUSTOMMARSHAL
  46. , m_Marshal(this)
  47. #endif
  48. {
  49. hshfile = 0;
  50. achFile[0] = TEXT('\0');
  51. fInRecord = FALSE;
  52. lWriteLoc = 0;
  53. fDirty = 0;
  54. extra.lp = 0;
  55. extra.cb = 0;
  56. _fmemset(&avihdr, 0, sizeof(avihdr));
  57. _fmemset(ps, 0, sizeof(ps));
  58. avihdr.dwStreams = 0;
  59. lHeaderSize = 0;
  60. px = NULL;
  61. pb = NULL;
  62. if (pUnknownOuter) {
  63. DPF("(F) Being aggregated!\n");
  64. m_pUnknownOuter = pUnknownOuter;
  65. } else
  66. m_pUnknownOuter = &m_Unknown;
  67. *ppUnknown = &m_Unknown;
  68. #ifdef WIN32
  69. InitializeCriticalSection(&m_critsec);
  70. #endif
  71. }
  72. /* - - - - - - - - */
  73. CAVIFile::CUnknownImpl::CUnknownImpl(
  74. CAVIFile FAR* pAVIFile)
  75. {
  76. m_pAVIFile = pAVIFile;
  77. m_refs = 0;
  78. }
  79. /* - - - - - - - - */
  80. STDMETHODIMP CAVIFile::CUnknownImpl::QueryInterface(
  81. const IID FAR& iid,
  82. void FAR* FAR* ppv)
  83. {
  84. if (iid == IID_IUnknown
  85. #ifdef CUSTOMMARSHAL
  86. || iid == CLSID_AVISimpleUnMarshal
  87. #endif
  88. )
  89. *ppv = &m_pAVIFile->m_Unknown;
  90. else if (iid == IID_IAVIFile)
  91. *ppv = &m_pAVIFile->m_AVIFile;
  92. #if 0
  93. else if (iid == IID_IPersistStorage)
  94. *ppv = &m_pAVIFile->m_PersistS;
  95. #endif
  96. else if (iid == IID_IPersistFile)
  97. *ppv = &m_pAVIFile->m_PersistF;
  98. #ifdef CUSTOMMARSHAL
  99. else if (iid == IID_IMarshal) {
  100. DPF("(F) QueryInterface (IMarshal)\n");
  101. *ppv = &m_pAVIFile->m_Marshal;
  102. }
  103. #endif
  104. else {
  105. *ppv = NULL;
  106. return ResultFromScode(E_NOINTERFACE);
  107. }
  108. AddRef();
  109. return AVIERR_OK;
  110. }
  111. /* - - - - - - - - */
  112. STDMETHODIMP_(ULONG) CAVIFile::CUnknownImpl::AddRef()
  113. {
  114. DPF2("File %p: Usage++=%lx\n", (DWORD_PTR) (LPVOID) this, m_refs + 1);
  115. if (m_pAVIFile->hshfile)
  116. shfileAddRef(m_pAVIFile->hshfile);
  117. uUseCount++;
  118. return ++m_refs;
  119. }
  120. /* - - - - - - - - */
  121. CAVIFile::CAVIFileImpl::CAVIFileImpl(
  122. CAVIFile FAR* pAVIFile)
  123. {
  124. m_pAVIFile = pAVIFile;
  125. }
  126. /* - - - - - - - - */
  127. CAVIFile::CAVIFileImpl::~CAVIFileImpl()
  128. {
  129. }
  130. /* - - - - - - - - */
  131. STDMETHODIMP CAVIFile::CAVIFileImpl::QueryInterface(
  132. const IID FAR& iid,
  133. void FAR* FAR* ppv)
  134. {
  135. return m_pAVIFile->m_pUnknownOuter->QueryInterface(iid, ppv);
  136. }
  137. /* - - - - - - - - */
  138. STDMETHODIMP_(ULONG) CAVIFile::CAVIFileImpl::AddRef()
  139. {
  140. return m_pAVIFile->m_pUnknownOuter->AddRef();
  141. }
  142. /* - - - - - - - - */
  143. STDMETHODIMP_(ULONG) CAVIFile::CAVIFileImpl::Release()
  144. {
  145. return m_pAVIFile->m_pUnknownOuter->Release();
  146. }
  147. /* - - - - - - - - */
  148. /* - - - - - - - - */
  149. CAVIStream::CAVIStream(
  150. IUnknown FAR* pUnknownOuter,
  151. IUnknown FAR* FAR* ppUnknown) :
  152. m_Unknown(this),
  153. m_AVIStream(this),
  154. #ifdef CUSTOMMARSHAL
  155. m_Marshal(this),
  156. #endif
  157. m_Streaming(this)
  158. {
  159. paviBase = NULL;
  160. hshfile = 0;
  161. lpFormat = NULL;
  162. cbFormat = 0;
  163. lpData = NULL;
  164. cbData = 0;
  165. extra.lp = NULL;
  166. extra.cb = 0;
  167. psx = NULL;
  168. lPal = 0;
  169. pb = NULL;
  170. fInit = FALSE;
  171. if (pUnknownOuter) {
  172. DPF("(S) Being aggregated!\n");
  173. m_pUnknownOuter = pUnknownOuter;
  174. }
  175. else
  176. m_pUnknownOuter = &m_Unknown;
  177. *ppUnknown = &m_Unknown;
  178. }
  179. /* - - - - - - - - */
  180. CAVIStream::~CAVIStream()
  181. {
  182. if (lpFormat)
  183. GlobalFreePtr(lpFormat);
  184. if (lpData)
  185. GlobalFreePtr(lpData);
  186. if (extra.lp) {
  187. DPF2("Freeing %ld bytes of extra stream data.\n", extra.cb);
  188. GlobalFreePtr(extra.lp);
  189. }
  190. if (paviBase)
  191. AVIStreamClose(paviBase);
  192. }
  193. /* - - - - - - - - */
  194. CAVIStream::CUnknownImpl::CUnknownImpl(
  195. CAVIStream FAR* pAVIStream)
  196. {
  197. m_pAVIStream = pAVIStream;
  198. m_refs = 0;
  199. }
  200. /* - - - - - - - - */
  201. STDMETHODIMP CAVIStream::CUnknownImpl::QueryInterface(
  202. const IID FAR& iid,
  203. void FAR* FAR* ppv)
  204. {
  205. if (iid == IID_IUnknown
  206. #ifdef CUSTOMMARSHAL
  207. || iid == CLSID_AVISimpleUnMarshal
  208. #endif
  209. )
  210. *ppv = &m_pAVIStream->m_Unknown;
  211. else if (iid == IID_IAVIStream)
  212. *ppv = &m_pAVIStream->m_AVIStream;
  213. else if (iid == IID_IAVIStreaming)
  214. *ppv = &m_pAVIStream->m_Streaming;
  215. #ifdef CUSTOMMARSHAL
  216. else if (iid == IID_IMarshal) {
  217. DPF("(S) QueryInterface (IMarshal)\n");
  218. *ppv = &m_pAVIStream->m_Marshal;
  219. }
  220. #endif
  221. else {
  222. *ppv = NULL;
  223. return ResultFromScode(E_NOINTERFACE);
  224. }
  225. AddRef();
  226. return NULL;
  227. }
  228. /* - - - - - - - - */
  229. STDMETHODIMP_(ULONG) CAVIStream::CUnknownImpl::AddRef()
  230. {
  231. uUseCount++;
  232. if (m_pAVIStream->hshfile)
  233. shfileAddRef(m_pAVIStream->hshfile);
  234. if (m_refs < 20) {
  235. DPF2("Stream %p: Usage++=%lx\n", (DWORD_PTR) (LPVOID) this, m_refs + 1);
  236. }
  237. return ++m_refs;
  238. }
  239. /* - - - - - - - - */
  240. CAVIStream::CAVIStreamImpl::CAVIStreamImpl(
  241. CAVIStream FAR* pAVIStream)
  242. {
  243. m_pAVIStream = pAVIStream;
  244. }
  245. /* - - - - - - - - */
  246. CAVIStream::CAVIStreamImpl::~CAVIStreamImpl()
  247. {
  248. }
  249. /* - - - - - - - - */
  250. STDMETHODIMP CAVIStream::CAVIStreamImpl::QueryInterface(
  251. const IID FAR& iid,
  252. void FAR* FAR* ppv)
  253. {
  254. return m_pAVIStream->m_pUnknownOuter->QueryInterface(iid, ppv);
  255. }
  256. /* - - - - - - - - */
  257. STDMETHODIMP_(ULONG) CAVIStream::CAVIStreamImpl::AddRef()
  258. {
  259. return m_pAVIStream->m_pUnknownOuter->AddRef();
  260. }
  261. /* - - - - - - - - */
  262. STDMETHODIMP_(ULONG) CAVIStream::CAVIStreamImpl::Release()
  263. {
  264. return m_pAVIStream->m_pUnknownOuter->Release();
  265. }
  266. /* - - - - - - - - */
  267. CAVIStream::CStreamingImpl::CStreamingImpl(
  268. CAVIStream FAR* pAVIStream)
  269. {
  270. m_pAVIStream = pAVIStream;
  271. }
  272. /* - - - - - - - - */
  273. CAVIStream::CStreamingImpl::~CStreamingImpl()
  274. {
  275. }
  276. /* - - - - - - - - */
  277. STDMETHODIMP CAVIStream::CStreamingImpl::QueryInterface(
  278. const IID FAR& iid,
  279. void FAR* FAR* ppv)
  280. {
  281. return m_pAVIStream->m_pUnknownOuter->QueryInterface(iid, ppv);
  282. }
  283. /* - - - - - - - - */
  284. STDMETHODIMP_(ULONG) CAVIStream::CStreamingImpl::AddRef()
  285. {
  286. return m_pAVIStream->m_pUnknownOuter->AddRef();
  287. }
  288. /* - - - - - - - - */
  289. STDMETHODIMP_(ULONG) CAVIStream::CStreamingImpl::Release()
  290. {
  291. return m_pAVIStream->m_pUnknownOuter->Release();
  292. }
  293. /* - - - - - - - - */