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.

316 lines
6.0 KiB

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