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.

313 lines
7.5 KiB

  1. /****************************************************************************
  2. *
  3. * FAKEFILE.C
  4. *
  5. * routines for simulating the IAVIFile interface from a bunch of streams
  6. *
  7. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  8. *
  9. * You have a royalty-free right to use, modify, reproduce and
  10. * distribute the Sample Files (and/or any modified version) in
  11. * any way you find useful, provided that you agree that
  12. * Microsoft has no warranty obligations or liability for any
  13. * Sample Application Files which are modified.
  14. *
  15. ***************************************************************************/
  16. #include <win32.h>
  17. #include <vfw.h>
  18. #include "fakefile.h"
  19. #include "debug.h"
  20. ///////////////////////////////////////////////////////////////////////////
  21. ///////////////////////////////////////////////////////////////////////////
  22. ///////////////////////////////////////////////////////////////////////////
  23. /* - - - - - - - - */
  24. /**************************************************************************
  25. * @doc EXTERNAL AVIMakeFileFromStreams
  26. *
  27. * @api HRESULT | AVIMakeFileFromStreams | Constructs an AVIFile interface
  28. * pointer out of separate streams. If <f AVIFileGetStream>
  29. * is called with the returned file interface pointer, it will
  30. * return the specified
  31. * streams.
  32. *
  33. * @parm PAVIFILE FAR * | ppfile | Specifies a pointer to the location
  34. * used to return the new file interface pointer.
  35. *
  36. * @parm int | nStreams | Specifies the number of streams in
  37. * the array of stream interface pointers referenced by
  38. * <p papStreams>.
  39. *
  40. * @parm PAVISTREAM FAR * | papStreams | Specifies a pointer to
  41. * an array of stream interface pointers.
  42. *
  43. * @comm Use <f AVIFileRelease> to close the file. This function is
  44. * useful for putting streams onto the Clipboard.
  45. *
  46. * @rdesc Returns zero if successful; otherwise it returns an error code.
  47. *
  48. * @xref <f AVIFileClose> <f AVIFileGetStream>
  49. *
  50. *************************************************************************/
  51. STDAPI AVIMakeFileFromStreams(PAVIFILE FAR * ppfile,
  52. int nStreams,
  53. PAVISTREAM FAR * papStreams)
  54. {
  55. CFakeFile FAR* pAVIFile;
  56. pAVIFile = new FAR CFakeFile(nStreams, papStreams);
  57. if (!pAVIFile)
  58. return ResultFromScode(E_OUTOFMEMORY);
  59. *ppfile = (PAVIFILE) (LPVOID) pAVIFile;
  60. AVIFileAddRef((PAVIFILE) (LPVOID) pAVIFile);
  61. return AVIERR_OK;
  62. }
  63. /* - - - - - - - - */
  64. CFakeFile::CFakeFile(int nStreams, PAVISTREAM FAR * papStreams)
  65. {
  66. int i;
  67. AVISTREAMINFOW si;
  68. DWORD dwLength;
  69. m_pUnknownOuter = this;
  70. m_refs = 0;
  71. _fmemset(&avihdr, 0, sizeof(avihdr));
  72. aps = 0;
  73. avihdr.dwStreams = nStreams;
  74. if (nStreams > 0) {
  75. aps = (PAVISTREAM NEAR *) LocalAlloc(LPTR, nStreams * sizeof(PAVISTREAM));
  76. // make sure none of the streams go away without our consent
  77. for (i = 0; i < nStreams; i++) {
  78. aps[i] = papStreams[i];
  79. AVIStreamAddRef(aps[i]);
  80. // !!! should error check here, to make sure streams are valid
  81. aps[i]->Info(&si, sizeof(si));
  82. if (i == 0) {
  83. avihdr.dwScale = si.dwScale;
  84. avihdr.dwRate = si.dwRate;
  85. if ((avihdr.dwScale == 0 || avihdr.dwRate == 0) ||
  86. muldiv32(1000000, si.dwScale, si.dwRate) < 10000) {
  87. avihdr.dwScale = 1;
  88. avihdr.dwRate = 100;
  89. }
  90. }
  91. dwLength = muldiv32(AVIStreamSampleToTime(aps[i], si.dwLength),
  92. avihdr.dwRate,
  93. avihdr.dwScale * 1000);
  94. avihdr.dwLength = max(avihdr.dwLength, dwLength);
  95. avihdr.dwWidth = max((DWORD) si.rcFrame.right, avihdr.dwWidth);
  96. avihdr.dwHeight = max((DWORD) si.rcFrame.bottom, avihdr.dwHeight);
  97. avihdr.dwWidth = max((DWORD) si.rcFrame.right, avihdr.dwWidth);
  98. avihdr.dwHeight = max((DWORD) si.rcFrame.bottom, avihdr.dwHeight);
  99. }
  100. }
  101. }
  102. STDMETHODIMP CFakeFile::QueryInterface(
  103. const IID FAR& iid,
  104. void FAR* FAR* ppv)
  105. {
  106. if (iid == IID_IUnknown)
  107. *ppv = this;
  108. else if (iid == IID_IAVIFile)
  109. *ppv = this;
  110. else {
  111. *ppv = NULL;
  112. return ResultFromScode(E_NOINTERFACE);
  113. }
  114. AddRef();
  115. return AVIERR_OK;
  116. }
  117. /* - - - - - - - - */
  118. STDMETHODIMP_(ULONG) CFakeFile::AddRef()
  119. {
  120. DPF("Fake %p: Usage++=%lx\n", (DWORD_PTR) (LPVOID) this, m_refs + 1);
  121. return ++m_refs;
  122. }
  123. /* - - - - - - - - */
  124. #ifndef _WIN32
  125. STDMETHODIMP CFakeFile::Open(LPCTSTR szFile, UINT mode)
  126. {
  127. return ResultFromScode(AVIERR_UNSUPPORTED);
  128. }
  129. #endif
  130. STDMETHODIMP CFakeFile::GetStream(PAVISTREAM FAR * ppavi,
  131. DWORD fccType,
  132. LONG lParam)
  133. {
  134. HRESULT hr;
  135. int i;
  136. if (fccType == 0) {
  137. // just return nth stream
  138. if (lParam < (LONG) avihdr.dwStreams) {
  139. *ppavi = aps[lParam];
  140. AVIStreamAddRef(*ppavi);
  141. return AVIERR_OK;
  142. } else {
  143. *ppavi = NULL;
  144. return ResultFromScode(AVIERR_UNSUPPORTED);
  145. }
  146. }
  147. // otherwise loop through and find the one we want...
  148. for (i = 0; i < (int) avihdr.dwStreams; i++) {
  149. AVISTREAMINFO strhdr;
  150. hr = AVIStreamInfo(aps[i], &strhdr, sizeof(strhdr));
  151. if (strhdr.fccType == fccType) {
  152. if (lParam == 0) {
  153. *ppavi = aps[i];
  154. AVIStreamAddRef(*ppavi);
  155. return AVIERR_OK;
  156. }
  157. --lParam;
  158. }
  159. }
  160. // !!!
  161. return ResultFromScode(AVIERR_UNSUPPORTED);
  162. }
  163. #ifndef _WIN32
  164. STDMETHODIMP CFakeFile::Save(LPCTSTR szFile,
  165. AVICOMPRESSOPTIONS FAR *lpOptions,
  166. AVISAVECALLBACK lpfnCallback)
  167. {
  168. return ResultFromScode(AVIERR_UNSUPPORTED);
  169. }
  170. #endif
  171. STDMETHODIMP CFakeFile::CreateStream(PAVISTREAM FAR *ppstream,
  172. AVISTREAMINFOW FAR *psi)
  173. {
  174. return ResultFromScode(AVIERR_UNSUPPORTED);
  175. }
  176. #if 0
  177. STDMETHODIMP CFakeFile::AddStream(PAVISTREAM pstream,
  178. PAVISTREAM FAR *ppstreamNew)
  179. {
  180. return ResultFromScode(AVIERR_UNSUPPORTED);
  181. }
  182. #endif
  183. STDMETHODIMP CFakeFile::WriteData(DWORD ckid,
  184. LPVOID lpData,
  185. LONG cbData)
  186. {
  187. return ResultFromScode(AVIERR_UNSUPPORTED);
  188. }
  189. STDMETHODIMP CFakeFile::ReadData(DWORD ckid,
  190. LPVOID lpData,
  191. LONG FAR *lpcbData)
  192. {
  193. return ResultFromScode(AVIERR_UNSUPPORTED);
  194. }
  195. STDMETHODIMP CFakeFile::EndRecord(void)
  196. {
  197. return ResultFromScode(AVIERR_OK);
  198. }
  199. #ifdef _WIN32
  200. STDMETHODIMP CFakeFile::DeleteStream(
  201. DWORD fccType,
  202. LONG lParam)
  203. {
  204. // !!!
  205. return ResultFromScode(AVIERR_UNSUPPORTED);
  206. }
  207. #endif
  208. STDMETHODIMP CFakeFile::Info(
  209. AVIFILEINFOW FAR * pfi,
  210. LONG lSize)
  211. {
  212. hmemcpy(pfi, &avihdr, min(lSize,sizeof(avihdr)));
  213. // return sizeof(avihdr);
  214. return 0;
  215. }
  216. STDMETHODIMP_(ULONG) CFakeFile::Release()
  217. {
  218. int i;
  219. DPF("Fake %p: Usage--=%lx\n", (DWORD_PTR) (LPVOID) this, m_refs - 1);
  220. if (!--m_refs) {
  221. LONG lRet = AVIERR_OK;
  222. if (aps) {
  223. // Release our hold on the sub-streams
  224. for (i = 0; i < (int) avihdr.dwStreams; i++) {
  225. AVIStreamClose(aps[i]);
  226. }
  227. LocalFree((HLOCAL) aps);
  228. }
  229. delete this;
  230. return 0;
  231. }
  232. return m_refs;
  233. }
  234. #ifndef _WIN32
  235. STDMETHODIMP CFakeFile::Reserved1(void)
  236. {
  237. return ResultFromScode(AVIERR_UNSUPPORTED);
  238. }
  239. STDMETHODIMP CFakeFile::Reserved2(void)
  240. {
  241. return ResultFromScode(AVIERR_UNSUPPORTED);
  242. }
  243. STDMETHODIMP CFakeFile::Reserved3(void)
  244. {
  245. return ResultFromScode(AVIERR_UNSUPPORTED);
  246. }
  247. STDMETHODIMP CFakeFile::Reserved4(void)
  248. {
  249. return ResultFromScode(AVIERR_UNSUPPORTED);
  250. }
  251. STDMETHODIMP CFakeFile::Reserved5(void)
  252. {
  253. return ResultFromScode(AVIERR_UNSUPPORTED);
  254. }
  255. #endif