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.

285 lines
6.8 KiB

  1. /****************************************************************************
  2. *
  3. * FAKEFILE.C
  4. *
  5. * routines for simulating the IAVIFile interface from a bunch of streams
  6. *
  7. * Copyright (c) 1992 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 "avifile.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(*ppfile);
  61. return AVIERR_OK;
  62. }
  63. /* - - - - - - - - */
  64. CFakeFile::CFakeFile(int nStreams, PAVISTREAM FAR * papStreams)
  65. {
  66. int i;
  67. AVISTREAMINFO si;
  68. m_pUnknownOuter = this;
  69. m_refs = 0;
  70. _fmemset(&avihdr, 0, sizeof(avihdr));
  71. aps = 0;
  72. avihdr.dwStreams = nStreams;
  73. if (nStreams > 0) {
  74. aps = (PAVISTREAM NEAR *) LocalAlloc(LPTR, nStreams * sizeof(PAVISTREAM));
  75. // make sure none of the streams go away without our consent
  76. for (i = 0; i < nStreams; i++) {
  77. aps[i] = papStreams[i];
  78. AVIStreamAddRef(aps[i]);
  79. // !!! should error check here, to make sure streams are valid
  80. aps[i]->Info(&si, sizeof(si));
  81. if (i == 0) {
  82. avihdr.dwScale = si.dwScale;
  83. avihdr.dwRate = si.dwRate;
  84. }
  85. avihdr.dwLength = max(avihdr.dwLength,
  86. (DWORD) AVIStreamSampleToSample(aps[0],
  87. aps[i],
  88. si.dwLength));
  89. avihdr.dwWidth = max((DWORD) si.rcFrame.right, avihdr.dwWidth);
  90. avihdr.dwHeight = max((DWORD) si.rcFrame.bottom, avihdr.dwHeight);
  91. }
  92. }
  93. }
  94. STDMETHODIMP CFakeFile::QueryInterface(
  95. const IID FAR& iid,
  96. void FAR* FAR* ppv)
  97. {
  98. if (iid == IID_IUnknown)
  99. *ppv = this;
  100. else if (iid == IID_IAVIFile)
  101. *ppv = this;
  102. else
  103. return ResultFromScode(E_NOINTERFACE);
  104. AddRef();
  105. return AVIERR_OK;
  106. }
  107. /* - - - - - - - - */
  108. STDMETHODIMP_(ULONG) CFakeFile::AddRef()
  109. {
  110. DPF("Fake %lx: Usage++=%lx\n", (DWORD) (LPVOID) this, m_refs + 1);
  111. return ++m_refs;
  112. }
  113. /* - - - - - - - - */
  114. STDMETHODIMP CFakeFile::Open(LPCSTR szFile, UINT mode)
  115. {
  116. return ResultFromScode(AVIERR_UNSUPPORTED);
  117. }
  118. STDMETHODIMP CFakeFile::GetStream(PAVISTREAM FAR * ppavi,
  119. DWORD fccType,
  120. LONG lParam)
  121. {
  122. HRESULT hr;
  123. int i;
  124. if (fccType == 0) {
  125. // just return nth stream
  126. if (lParam < (LONG) avihdr.dwStreams) {
  127. *ppavi = aps[lParam];
  128. AVIStreamAddRef(*ppavi);
  129. return AVIERR_OK;
  130. } else {
  131. *ppavi = NULL;
  132. return ResultFromScode(AVIERR_UNSUPPORTED);
  133. }
  134. }
  135. // otherwise loop through and find the one we want...
  136. for (i = 0; i < (int) avihdr.dwStreams; i++) {
  137. AVISTREAMINFO strhdr;
  138. hr = AVIStreamInfo(aps[i], &strhdr, sizeof(strhdr));
  139. if (strhdr.fccType == fccType) {
  140. if (lParam == 0) {
  141. *ppavi = aps[i];
  142. AVIStreamAddRef(*ppavi);
  143. return AVIERR_OK;
  144. }
  145. --lParam;
  146. }
  147. }
  148. // !!!
  149. return ResultFromScode(AVIERR_UNSUPPORTED);
  150. }
  151. STDMETHODIMP CFakeFile::Save(LPCSTR szFile,
  152. AVICOMPRESSOPTIONS FAR *lpOptions,
  153. AVISAVECALLBACK lpfnCallback)
  154. {
  155. return ResultFromScode(AVIERR_UNSUPPORTED);
  156. }
  157. STDMETHODIMP CFakeFile::CreateStream(PAVISTREAM FAR *ppstream,
  158. AVISTREAMINFO FAR *psi)
  159. {
  160. return ResultFromScode(AVIERR_UNSUPPORTED);
  161. }
  162. #if 0
  163. STDMETHODIMP CFakeFile::AddStream(PAVISTREAM pstream,
  164. PAVISTREAM FAR *ppstreamNew)
  165. {
  166. return ResultFromScode(AVIERR_UNSUPPORTED);
  167. }
  168. #endif
  169. STDMETHODIMP CFakeFile::WriteData(DWORD ckid,
  170. LPVOID lpData,
  171. LONG cbData)
  172. {
  173. return ResultFromScode(AVIERR_UNSUPPORTED);
  174. }
  175. STDMETHODIMP CFakeFile::ReadData(DWORD ckid,
  176. LPVOID lpData,
  177. LONG FAR *lpcbData)
  178. {
  179. return ResultFromScode(AVIERR_UNSUPPORTED);
  180. }
  181. STDMETHODIMP CFakeFile::EndRecord(void)
  182. {
  183. return ResultFromScode(AVIERR_OK);
  184. }
  185. STDMETHODIMP CFakeFile::Info(
  186. AVIFILEINFO FAR * pfi,
  187. LONG lSize)
  188. {
  189. hmemcpy(pfi, &avihdr, min(lSize,sizeof(avihdr)));
  190. // return sizeof(avihdr);
  191. return 0;
  192. }
  193. STDMETHODIMP_(ULONG) CFakeFile::Release()
  194. {
  195. int i;
  196. DPF("Fake %lx: Usage--=%lx\n", (DWORD) (LPVOID) this, m_refs - 1);
  197. if (!--m_refs) {
  198. LONG lRet = AVIERR_OK;
  199. if (aps) {
  200. // Release our hold on the sub-streams
  201. for (i = 0; i < (int) avihdr.dwStreams; i++) {
  202. AVIStreamClose(aps[i]);
  203. }
  204. LocalFree((HLOCAL) aps);
  205. }
  206. delete this;
  207. return 0;
  208. }
  209. return m_refs;
  210. }
  211. STDMETHODIMP CFakeFile::Reserved1(void)
  212. {
  213. return ResultFromScode(AVIERR_UNSUPPORTED);
  214. }
  215. STDMETHODIMP CFakeFile::Reserved2(void)
  216. {
  217. return ResultFromScode(AVIERR_UNSUPPORTED);
  218. }
  219. STDMETHODIMP CFakeFile::Reserved3(void)
  220. {
  221. return ResultFromScode(AVIERR_UNSUPPORTED);
  222. }
  223. STDMETHODIMP CFakeFile::Reserved4(void)
  224. {
  225. return ResultFromScode(AVIERR_UNSUPPORTED);
  226. }
  227. STDMETHODIMP CFakeFile::Reserved5(void)
  228. {
  229. return ResultFromScode(AVIERR_UNSUPPORTED);
  230. }