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.

642 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
  3. Module Name:
  4. minwave.cpp
  5. Abstract:
  6. Implementation of wavecyclic miniport.
  7. --*/
  8. #include <msvad.h>
  9. #include <common.h>
  10. #include "drmsimp.h"
  11. #include "minwave.h"
  12. #include "wavtable.h"
  13. #pragma code_seg("PAGE")
  14. //=============================================================================
  15. // CMiniportWaveCyclic
  16. //=============================================================================
  17. //=============================================================================
  18. NTSTATUS
  19. CreateMiniportWaveCyclicMSVAD
  20. (
  21. OUT PUNKNOWN * Unknown,
  22. IN REFCLSID,
  23. IN PUNKNOWN UnknownOuter OPTIONAL,
  24. IN POOL_TYPE PoolType
  25. )
  26. /*++
  27. Routine Description:
  28. Create the wavecyclic miniport.
  29. Arguments:
  30. Unknown -
  31. RefClsId -
  32. UnknownOuter -
  33. PoolType -
  34. Return Value:
  35. NT status code.
  36. --*/
  37. {
  38. PAGED_CODE();
  39. ASSERT(Unknown);
  40. STD_CREATE_BODY(CMiniportWaveCyclic, Unknown, UnknownOuter, PoolType);
  41. }
  42. //=============================================================================
  43. CMiniportWaveCyclic::~CMiniportWaveCyclic
  44. (
  45. void
  46. )
  47. /*++
  48. Routine Description:
  49. Destructor for wavecyclic miniport
  50. Arguments:
  51. Return Value:
  52. NT status code.
  53. --*/
  54. {
  55. PAGED_CODE();
  56. DPF_ENTER(("[CMiniportWaveCyclic::~CMiniportWaveCyclic]"));
  57. } // ~CMiniportWaveCyclic
  58. //=============================================================================
  59. STDMETHODIMP_(NTSTATUS)
  60. CMiniportWaveCyclic::DataRangeIntersection
  61. (
  62. IN ULONG PinId,
  63. IN PKSDATARANGE ClientDataRange,
  64. IN PKSDATARANGE MyDataRange,
  65. IN ULONG OutputBufferLength,
  66. OUT PVOID ResultantFormat,
  67. OUT PULONG ResultantFormatLength
  68. )
  69. /*++
  70. Routine Description:
  71. The DataRangeIntersection function determines the highest quality
  72. intersection of two data ranges.
  73. Arguments:
  74. PinId - Pin for which data intersection is being determined.
  75. ClientDataRange - Pointer to KSDATARANGE structure which contains the data
  76. range submitted by client in the data range intersection
  77. property request.
  78. MyDataRange - Pin's data range to be compared with client's data
  79. range. In this case we actually ignore our own data
  80. range, because we know that we only support one range.
  81. OutputBufferLength - Size of the buffer pointed to by the resultant format
  82. parameter.
  83. ResultantFormat - Pointer to value where the resultant format should be
  84. returned.
  85. ResultantFormatLength - Actual length of the resultant format placed in
  86. ResultantFormat. This should be less than or equal
  87. to OutputBufferLength.
  88. Return Value:
  89. NT status code.
  90. --*/
  91. {
  92. PAGED_CODE();
  93. // This driver only supports PCM formats.
  94. // Portcls will handle the request for us.
  95. //
  96. return STATUS_NOT_IMPLEMENTED;
  97. } // DataRangeIntersection
  98. //=============================================================================
  99. STDMETHODIMP_(NTSTATUS)
  100. CMiniportWaveCyclic::GetDescription
  101. (
  102. OUT PPCFILTER_DESCRIPTOR * OutFilterDescriptor
  103. )
  104. /*++
  105. Routine Description:
  106. The GetDescription function gets a pointer to a filter description.
  107. It provides a location to deposit a pointer in miniport's description
  108. structure. This is the placeholder for the FromNode or ToNode fields in
  109. connections which describe connections to the filter's pins.
  110. Arguments:
  111. OutFilterDescriptor - Pointer to the filter description.
  112. Return Value:
  113. NT status code.
  114. --*/
  115. {
  116. PAGED_CODE();
  117. ASSERT(OutFilterDescriptor);
  118. return
  119. CMiniportWaveCyclicMSVAD::GetDescription(OutFilterDescriptor);
  120. } // GetDescription
  121. //=============================================================================
  122. STDMETHODIMP_(NTSTATUS)
  123. CMiniportWaveCyclic::Init
  124. (
  125. IN PUNKNOWN UnknownAdapter_,
  126. IN PRESOURCELIST ResourceList_,
  127. IN PPORTWAVECYCLIC Port_
  128. )
  129. /*++
  130. Routine Description:
  131. The Init function initializes the miniport. Callers of this function
  132. should run at IRQL PASSIVE_LEVEL
  133. Arguments:
  134. UnknownAdapter - A pointer to the Iuknown interface of the adapter object.
  135. ResourceList - Pointer to the resource list to be supplied to the miniport
  136. during initialization. The port driver is free to examine the
  137. contents of the ResourceList. The port driver will not be
  138. modify the ResourceList contents.
  139. Port - Pointer to the topology port object that is linked with this miniport.
  140. Return Value:
  141. NT status code.
  142. --*/
  143. {
  144. PAGED_CODE();
  145. ASSERT(UnknownAdapter_);
  146. ASSERT(Port_);
  147. NTSTATUS ntStatus;
  148. DPF_ENTER(("[CMiniportWaveCyclic::Init]"));
  149. m_MaxOutputStreams = MAX_OUTPUT_STREAMS;
  150. m_MaxInputStreams = MAX_INPUT_STREAMS;
  151. m_MaxTotalStreams = MAX_TOTAL_STREAMS;
  152. m_MinChannels = MIN_CHANNELS;
  153. m_MaxChannelsPcm = MAX_CHANNELS_PCM;
  154. m_MinBitsPerSamplePcm = MIN_BITS_PER_SAMPLE_PCM;
  155. m_MaxBitsPerSamplePcm = MAX_BITS_PER_SAMPLE_PCM;
  156. m_MinSampleRatePcm = MIN_SAMPLE_RATE;
  157. m_MaxSampleRatePcm = MAX_SAMPLE_RATE;
  158. ntStatus =
  159. CMiniportWaveCyclicMSVAD::Init
  160. (
  161. UnknownAdapter_,
  162. ResourceList_,
  163. Port_
  164. );
  165. if (NT_SUCCESS(ntStatus))
  166. {
  167. // Set filter descriptor.
  168. m_FilterDescriptor = &MiniportFilterDescriptor;
  169. m_fCaptureAllocated = FALSE;
  170. m_fRenderAllocated = FALSE;
  171. }
  172. return ntStatus;
  173. } // Init
  174. //=============================================================================
  175. STDMETHODIMP_(NTSTATUS)
  176. CMiniportWaveCyclic::NewStream
  177. (
  178. OUT PMINIPORTWAVECYCLICSTREAM * OutStream,
  179. IN PUNKNOWN OuterUnknown,
  180. IN POOL_TYPE PoolType,
  181. IN ULONG Pin,
  182. IN BOOLEAN Capture,
  183. IN PKSDATAFORMAT DataFormat,
  184. OUT PDMACHANNEL * OutDmaChannel,
  185. OUT PSERVICEGROUP * OutServiceGroup
  186. )
  187. /*++
  188. Routine Description:
  189. The NewStream function creates a new instance of a logical stream
  190. associated with a specified physical channel. Callers of NewStream should
  191. run at IRQL PASSIVE_LEVEL.
  192. Arguments:
  193. OutStream -
  194. OuterUnknown -
  195. PoolType -
  196. Pin -
  197. Capture -
  198. DataFormat -
  199. OutDmaChannel -
  200. OutServiceGroup -
  201. Return Value:
  202. NT status code.
  203. --*/
  204. {
  205. PAGED_CODE();
  206. ASSERT(OutStream);
  207. ASSERT(DataFormat);
  208. ASSERT(OutDmaChannel);
  209. ASSERT(OutServiceGroup);
  210. DPF_ENTER(("[CMiniportWaveCyclic::NewStream]"));
  211. NTSTATUS ntStatus = STATUS_SUCCESS;
  212. PCMiniportWaveCyclicStream stream = NULL;
  213. // Check if we have enough streams.
  214. if (Capture)
  215. {
  216. if (m_fCaptureAllocated)
  217. {
  218. DPF(D_TERSE, ("[Only one capture stream supported]"));
  219. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  220. }
  221. }
  222. else
  223. {
  224. if (m_fRenderAllocated)
  225. {
  226. DPF(D_TERSE, ("[Only one render stream supported]"));
  227. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  228. }
  229. }
  230. // Determine if the format is valid.
  231. //
  232. if (NT_SUCCESS(ntStatus))
  233. {
  234. ntStatus = ValidateFormat(DataFormat);
  235. }
  236. // Instantiate a stream. Stream must be in
  237. // NonPagedPool because of file saving.
  238. //
  239. if (NT_SUCCESS(ntStatus))
  240. {
  241. stream = new (NonPagedPool, MSVAD_POOLTAG)
  242. CMiniportWaveCyclicStream(OuterUnknown);
  243. if (stream)
  244. {
  245. stream->AddRef();
  246. ntStatus =
  247. stream->Init
  248. (
  249. this,
  250. Pin,
  251. Capture,
  252. DataFormat
  253. );
  254. }
  255. else
  256. {
  257. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  258. }
  259. }
  260. if (NT_SUCCESS(ntStatus))
  261. {
  262. if (Capture)
  263. {
  264. m_fCaptureAllocated = TRUE;
  265. }
  266. else
  267. {
  268. m_fRenderAllocated = TRUE;
  269. }
  270. *OutStream = PMINIPORTWAVECYCLICSTREAM(stream);
  271. (*OutStream)->AddRef();
  272. *OutDmaChannel = PDMACHANNEL(stream);
  273. (*OutDmaChannel)->AddRef();
  274. *OutServiceGroup = m_ServiceGroup;
  275. (*OutServiceGroup)->AddRef();
  276. // The stream, the DMA channel, and the service group have
  277. // references now for the caller. The caller expects these
  278. // references to be there.
  279. }
  280. // This is our private reference to the stream. The caller has
  281. // its own, so we can release in any case.
  282. //
  283. if (stream)
  284. {
  285. stream->Release();
  286. }
  287. return ntStatus;
  288. } // NewStream
  289. //=============================================================================
  290. STDMETHODIMP_(NTSTATUS)
  291. CMiniportWaveCyclic::NonDelegatingQueryInterface
  292. (
  293. IN REFIID Interface,
  294. OUT PVOID * Object
  295. )
  296. /*++
  297. Routine Description:
  298. QueryInterface
  299. Arguments:
  300. Interface - GUID
  301. Object - interface pointer to be returned.
  302. Return Value:
  303. NT status code.
  304. --*/
  305. {
  306. PAGED_CODE();
  307. ASSERT(Object);
  308. if (IsEqualGUIDAligned(Interface, IID_IUnknown))
  309. {
  310. *Object = PVOID(PUNKNOWN(PMINIPORTWAVECYCLIC(this)));
  311. }
  312. else if (IsEqualGUIDAligned(Interface, IID_IMiniport))
  313. {
  314. *Object = PVOID(PMINIPORT(this));
  315. }
  316. else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveCyclic))
  317. {
  318. *Object = PVOID(PMINIPORTWAVECYCLIC(this));
  319. }
  320. else
  321. {
  322. *Object = NULL;
  323. }
  324. if (*Object)
  325. {
  326. // We reference the interface for the caller.
  327. PUNKNOWN(*Object)->AddRef();
  328. return STATUS_SUCCESS;
  329. }
  330. return STATUS_INVALID_PARAMETER;
  331. } // NonDelegatingQueryInterface
  332. //=============================================================================
  333. // CMiniportWaveStreamCyclicSimple
  334. //=============================================================================
  335. //=============================================================================
  336. CMiniportWaveCyclicStream::~CMiniportWaveCyclicStream
  337. (
  338. void
  339. )
  340. /*++
  341. Routine Description:
  342. Destructor for wavecyclicstream
  343. Arguments:
  344. Return Value:
  345. NT status code.
  346. --*/
  347. {
  348. PAGED_CODE();
  349. DPF_ENTER(("[CMiniportWaveCyclicStream::~CMiniportWaveCyclicStream]"));
  350. if (NULL != m_pMiniportLocal)
  351. {
  352. if (m_fCapture)
  353. {
  354. m_pMiniportLocal->m_fCaptureAllocated = FALSE;
  355. }
  356. else
  357. {
  358. m_pMiniportLocal->m_fRenderAllocated = FALSE;
  359. }
  360. }
  361. } // ~CMiniportWaveCyclicStream
  362. //=============================================================================
  363. NTSTATUS
  364. CMiniportWaveCyclicStream::Init
  365. (
  366. IN PCMiniportWaveCyclic Miniport_,
  367. IN ULONG Pin_,
  368. IN BOOLEAN Capture_,
  369. IN PKSDATAFORMAT DataFormat_
  370. )
  371. /*++
  372. Routine Description:
  373. Initializes the stream object. Allocate a DMA buffer, timer and DPC
  374. Arguments:
  375. Miniport_ -
  376. Pin_ -
  377. Capture_ -
  378. DataFormat -
  379. DmaChannel_ -
  380. Return Value:
  381. NT status code.
  382. --*/
  383. {
  384. PAGED_CODE();
  385. m_pMiniportLocal = Miniport_;
  386. return
  387. CMiniportWaveCyclicStreamMSVAD::Init
  388. (
  389. Miniport_,
  390. Pin_,
  391. Capture_,
  392. DataFormat_
  393. );
  394. } // Init
  395. //=============================================================================
  396. STDMETHODIMP_(NTSTATUS)
  397. CMiniportWaveCyclicStream::NonDelegatingQueryInterface
  398. (
  399. IN REFIID Interface,
  400. OUT PVOID * Object
  401. )
  402. /*++
  403. Routine Description:
  404. QueryInterface
  405. Arguments:
  406. Interface - GUID
  407. Object - interface pointer to be returned
  408. Return Value:
  409. NT status code.
  410. --*/
  411. {
  412. PAGED_CODE();
  413. ASSERT(Object);
  414. if (IsEqualGUIDAligned(Interface, IID_IUnknown))
  415. {
  416. *Object = PVOID(PUNKNOWN(PMINIPORTWAVECYCLICSTREAM(this)));
  417. }
  418. else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveCyclicStream))
  419. {
  420. *Object = PVOID(PMINIPORTWAVECYCLICSTREAM(this));
  421. }
  422. else if (IsEqualGUIDAligned(Interface, IID_IDmaChannel))
  423. {
  424. *Object = PVOID(PDMACHANNEL(this));
  425. }
  426. else if (IsEqualGUIDAligned(Interface, IID_IDrmAudioStream))
  427. {
  428. *Object = (PVOID)(PDRMAUDIOSTREAM)this;
  429. }
  430. else
  431. {
  432. *Object = NULL;
  433. }
  434. if (*Object)
  435. {
  436. PUNKNOWN(*Object)->AddRef();
  437. return STATUS_SUCCESS;
  438. }
  439. return STATUS_INVALID_PARAMETER;
  440. } // NonDelegatingQueryInterface
  441. //=============================================================================
  442. STDMETHODIMP_(NTSTATUS)
  443. CMiniportWaveCyclicStream::SetContentId
  444. (
  445. IN ULONG contentId,
  446. IN PCDRMRIGHTS drmRights
  447. )
  448. /*++
  449. Routine Description:
  450. Sets DRM content Id for this stream. Also updates the Mixed content Id.
  451. Arguments:
  452. contentId - new content id
  453. drmRights - rights for this stream.
  454. Return Value:
  455. NT status code.
  456. --*/
  457. {
  458. PAGED_CODE();
  459. DPF_ENTER(("[CMiniportWaveCyclicStream::SetContentId]"));
  460. // if (drmRights.CopyProtect==TRUE)
  461. // Stop writing this stream to disk
  462. //
  463. // if (drmRights.DigitalOutputDisable == TRUE)
  464. // Mute S/PDIF out.
  465. // MSVAD does not support S/PDIF out.
  466. //
  467. // To learn more about managing multiple streams, please look at MSVAD\drmmult
  468. //
  469. m_SaveData.Disable(drmRights->CopyProtect);
  470. return STATUS_SUCCESS;
  471. } // SetContentId
  472. #pragma code_seg()