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.

343 lines
8.5 KiB

  1. // Copyright (c) 1997 - 1998 Microsoft Corporation. All Rights Reserved.
  2. // austrm.h : Declaration of the CAudioStream
  3. /*
  4. Basic design
  5. ------------
  6. For simplification purposes we will always provide our own
  7. allocator buffer and copy into the application's buffer. This
  8. will fix 2 problems:
  9. 1. Confusion caused by the filter no filling the allocator's
  10. buffers.
  11. 2. Problems when the application doesn't supply a big enough buffer.
  12. NOTES
  13. -----
  14. Continuous update might be a bit dumb to use for audio
  15. */
  16. #ifndef __AUSTREAM_H_
  17. #define __AUSTREAM_H_
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAudioStream
  20. class ATL_NO_VTABLE CAudioStream :
  21. public CComCoClass<CAudioStream, &CLSID_AMAudioStream>,
  22. public CByteStream,
  23. public IAudioMediaStream
  24. {
  25. public:
  26. //
  27. // METHODS
  28. //
  29. CAudioStream();
  30. //
  31. // IMediaStream
  32. //
  33. //
  34. // IMediaStream
  35. //
  36. // HACK HACK - the first 2 are duplicates but it won't link
  37. // without
  38. STDMETHODIMP GetMultiMediaStream(
  39. /* [out] */ IMultiMediaStream **ppMultiMediaStream)
  40. {
  41. return CStream::GetMultiMediaStream(ppMultiMediaStream);
  42. }
  43. STDMETHODIMP GetInformation(
  44. /* [optional][out] */ MSPID *pPurposeId,
  45. /* [optional][out] */ STREAM_TYPE *pType)
  46. {
  47. return CStream::GetInformation(pPurposeId, pType);
  48. }
  49. STDMETHODIMP SetState(
  50. /* [in] */ FILTER_STATE State
  51. )
  52. {
  53. return CByteStream::SetState(State);
  54. }
  55. STDMETHODIMP SetSameFormat(IMediaStream *pStream, DWORD dwFlags);
  56. STDMETHODIMP AllocateSample(
  57. /* [in] */ DWORD dwFlags,
  58. /* [out] */ IStreamSample **ppSample
  59. );
  60. STDMETHODIMP CreateSharedSample(
  61. /* [in] */ IStreamSample *pExistingSample,
  62. /* [in] */ DWORD dwFlags,
  63. /* [out] */ IStreamSample **ppNewSample
  64. );
  65. STDMETHODIMP SendEndOfStream(DWORD dwFlags)
  66. {
  67. return CStream::SendEndOfStream(dwFlags);
  68. }
  69. //
  70. // IPin
  71. //
  72. STDMETHODIMP ReceiveConnection(IPin * pConnector, const AM_MEDIA_TYPE *pmt);
  73. //
  74. // IMemAllocator
  75. //
  76. STDMETHODIMP SetProperties(ALLOCATOR_PROPERTIES* pRequest, ALLOCATOR_PROPERTIES* pActual);
  77. STDMETHODIMP GetProperties(ALLOCATOR_PROPERTIES* pProps);
  78. //
  79. // IAudioMediaStream
  80. //
  81. STDMETHODIMP GetFormat(
  82. /* [optional][out] */ LPWAVEFORMATEX lpWaveFormatCurrent
  83. );
  84. STDMETHODIMP SetFormat(
  85. /* [in] */ const WAVEFORMATEX *lpWaveFormat
  86. );
  87. STDMETHODIMP CreateSample(
  88. /* [in] */ IAudioData *pAudioData,
  89. /* [in] */ DWORD dwFlags,
  90. /* [out] */ IAudioStreamSample **ppSample
  91. );
  92. //
  93. // Special CStream methods
  94. //
  95. HRESULT GetMediaType(ULONG Index, AM_MEDIA_TYPE **ppMediaType);
  96. LONG GetChopSize()
  97. {
  98. #ifdef MY_CHOP_SIZE
  99. if (m_Direction == PINDIR_OUTPUT) {
  100. return MY_CHOP_SIZE;
  101. }
  102. #endif
  103. return 65536;
  104. }
  105. DECLARE_REGISTRY_RESOURCEID(IDR_AUDIOSTREAM)
  106. protected:
  107. HRESULT InternalSetFormat(const WAVEFORMATEX *pFormat, bool bFromPin);
  108. HRESULT CheckFormat(const WAVEFORMATEX *pFormat, bool bForce=false);
  109. BEGIN_COM_MAP(CAudioStream)
  110. COM_INTERFACE_ENTRY(IAudioMediaStream)
  111. COM_INTERFACE_ENTRY_CHAIN(CStream)
  112. END_COM_MAP()
  113. protected:
  114. /* Format */
  115. WAVEFORMATEX m_Format;
  116. bool m_fForceFormat;
  117. };
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CAudioStreamSample
  120. class ATL_NO_VTABLE CAudioStreamSample :
  121. public CByteStreamSample,
  122. public IAudioStreamSample
  123. {
  124. public:
  125. CAudioStreamSample() {}
  126. // DELEGATE TO BASE CLASS
  127. //
  128. // IStreamSample
  129. //
  130. STDMETHODIMP GetMediaStream(
  131. /* [in] */ IMediaStream **ppMediaStream)
  132. {
  133. return CSample::GetMediaStream(ppMediaStream);
  134. }
  135. STDMETHODIMP GetSampleTimes(
  136. /* [optional][out] */ STREAM_TIME *pStartTime,
  137. /* [optional][out] */ STREAM_TIME *pEndTime,
  138. /* [optional][out] */ STREAM_TIME *pCurrentTime)
  139. {
  140. return CSample::GetSampleTimes(
  141. pStartTime,
  142. pEndTime,
  143. pCurrentTime
  144. );
  145. }
  146. STDMETHODIMP SetSampleTimes(
  147. /* [optional][in] */ const STREAM_TIME *pStartTime,
  148. /* [optional][in] */ const STREAM_TIME *pEndTime)
  149. {
  150. return CSample::SetSampleTimes(pStartTime, pEndTime);
  151. }
  152. STDMETHODIMP Update(
  153. /* [in] */ DWORD dwFlags,
  154. /* [optional][in] */ HANDLE hEvent,
  155. /* [optional][in] */ PAPCFUNC pfnAPC,
  156. /* [optional][in] */ DWORD_PTR dwAPCData)
  157. {
  158. return CByteStreamSample::Update(dwFlags, hEvent, pfnAPC, dwAPCData);
  159. }
  160. STDMETHODIMP CompletionStatus(
  161. /* [in] */ DWORD dwFlags,
  162. /* [optional][in] */ DWORD dwMilliseconds)
  163. {
  164. return CSample::CompletionStatus(dwFlags, dwMilliseconds);
  165. }
  166. BEGIN_COM_MAP(CAudioStreamSample)
  167. COM_INTERFACE_ENTRY(IAudioStreamSample)
  168. COM_INTERFACE_ENTRY_CHAIN(CSample)
  169. END_COM_MAP()
  170. // IAudioStreamSample
  171. STDMETHODIMP GetAudioData(IAudioData **ppAudioData)
  172. {
  173. return m_pMemData->QueryInterface(IID_IAudioData, (void **)ppAudioData);
  174. }
  175. // Set the pointer
  176. HRESULT SetSizeAndPointer(BYTE *pbData, LONG lActual, LONG lSize)
  177. {
  178. m_pbData = pbData;
  179. m_cbSize = (DWORD)lSize;
  180. m_cbData = (DWORD)lActual;
  181. return S_OK;
  182. }
  183. };
  184. // Audio data object
  185. class ATL_NO_VTABLE CAudioData :
  186. public CComObjectRootEx<CComMultiThreadModel>,
  187. public IAudioData,
  188. public CComCoClass<CAudioData, &CLSID_AMAudioData>
  189. {
  190. public:
  191. CAudioData();
  192. ~CAudioData();
  193. DECLARE_REGISTRY_RESOURCEID(IDR_AUDIODATA)
  194. BEGIN_COM_MAP(CAudioData)
  195. COM_INTERFACE_ENTRY(IAudioData)
  196. END_COM_MAP()
  197. //
  198. // IMemoryData
  199. //
  200. STDMETHODIMP SetBuffer(
  201. /* [in] */ DWORD cbSize,
  202. /* [in] */ BYTE * pbData,
  203. /* [in] */ DWORD dwFlags
  204. )
  205. {
  206. if (dwFlags != 0 || cbSize == 0) {
  207. return E_INVALIDARG;
  208. }
  209. //
  210. // Free anything we allocated ourselves -- We allow multiple calls to this method
  211. //
  212. if (m_bWeAllocatedData) {
  213. CoTaskMemFree(m_pbData);
  214. m_bWeAllocatedData = false;
  215. }
  216. m_cbSize = cbSize;
  217. if (pbData) {
  218. m_pbData = pbData;
  219. return S_OK;
  220. } else {
  221. m_pbData = (BYTE *)CoTaskMemAlloc(cbSize);
  222. if (m_pbData) {
  223. m_bWeAllocatedData = true;
  224. return S_OK;
  225. }
  226. return E_OUTOFMEMORY;
  227. }
  228. }
  229. STDMETHODIMP GetInfo(
  230. /* [out] */ DWORD *pdwLength,
  231. /* [out] */ BYTE **ppbData,
  232. /* [out] */ DWORD *pcbActualData
  233. )
  234. {
  235. if (m_cbSize == 0) {
  236. return MS_E_NOTINIT;
  237. }
  238. if (pdwLength) {
  239. *pdwLength = m_cbSize;
  240. }
  241. if (ppbData) {
  242. *ppbData = m_pbData;
  243. }
  244. if (pcbActualData) {
  245. *pcbActualData = m_cbData;
  246. }
  247. return S_OK;
  248. }
  249. STDMETHODIMP SetActual(
  250. /* [in] */ DWORD cbDataValid
  251. )
  252. {
  253. if (cbDataValid > m_cbSize) {
  254. return E_INVALIDARG;
  255. }
  256. m_cbData = cbDataValid;
  257. return S_OK;
  258. }
  259. //
  260. // IAudioData
  261. //
  262. STDMETHODIMP GetFormat(
  263. /* [out] [optional] */ WAVEFORMATEX *pWaveFormatCurrent
  264. )
  265. {
  266. if (pWaveFormatCurrent == NULL) {
  267. return E_POINTER;
  268. }
  269. *pWaveFormatCurrent = m_Format;
  270. return S_OK;
  271. }
  272. STDMETHODIMP SetFormat(
  273. /* [in] */ const WAVEFORMATEX *lpWaveFormat
  274. )
  275. {
  276. if (lpWaveFormat == NULL) {
  277. return E_POINTER;
  278. }
  279. if (lpWaveFormat->wFormatTag != WAVE_FORMAT_PCM) {
  280. return E_INVALIDARG;
  281. }
  282. m_Format = *lpWaveFormat;
  283. return S_OK;
  284. }
  285. protected:
  286. PBYTE m_pbData;
  287. DWORD m_cbSize;
  288. DWORD m_cbData;
  289. WAVEFORMATEX m_Format;
  290. bool m_bWeAllocatedData;
  291. };
  292. #endif // __AUSTREAM_H_