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.

676 lines
15 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 "multi.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,PMINIPORTWAVECYCLIC);
  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. RtlZeroMemory
  171. (
  172. m_pStream,
  173. MAX_INPUT_STREAMS * sizeof(PCMiniportWaveCyclicStream)
  174. );
  175. }
  176. return ntStatus;
  177. } // Init
  178. //=============================================================================
  179. STDMETHODIMP_(NTSTATUS)
  180. CMiniportWaveCyclic::NewStream
  181. (
  182. OUT PMINIPORTWAVECYCLICSTREAM * OutStream,
  183. IN PUNKNOWN OuterUnknown,
  184. IN POOL_TYPE PoolType,
  185. IN ULONG Pin,
  186. IN BOOLEAN Capture,
  187. IN PKSDATAFORMAT DataFormat,
  188. OUT PDMACHANNEL * OutDmaChannel,
  189. OUT PSERVICEGROUP * OutServiceGroup
  190. )
  191. /*++
  192. Routine Description:
  193. The NewStream function creates a new instance of a logical stream
  194. associated with a specified physical channel. Callers of NewStream should
  195. run at IRQL PASSIVE_LEVEL.
  196. Arguments:
  197. OutStream -
  198. OuterUnknown -
  199. PoolType -
  200. Pin -
  201. Capture -
  202. DataFormat -
  203. OutDmaChannel -
  204. OutServiceGroup -
  205. Return Value:
  206. NT status code.
  207. --*/
  208. {
  209. PAGED_CODE();
  210. ASSERT(OutStream);
  211. ASSERT(DataFormat);
  212. ASSERT(OutDmaChannel);
  213. ASSERT(OutServiceGroup);
  214. DPF_ENTER(("[CMiniportWaveCyclic::NewStream]"));
  215. NTSTATUS ntStatus = STATUS_SUCCESS;
  216. PCMiniportWaveCyclicStream stream = NULL;
  217. ULONG streamIndex;
  218. // MSVAD supports one capture stream.
  219. //
  220. if (Capture)
  221. {
  222. if (m_fCaptureAllocated)
  223. {
  224. DPF(D_TERSE, ("[Only one capture stream supported]"));
  225. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  226. }
  227. }
  228. // This version supports multiple playback streams.
  229. //
  230. else
  231. {
  232. for (streamIndex = 0; streamIndex < m_MaxInputStreams; streamIndex++)
  233. {
  234. if (!m_pStream[streamIndex])
  235. {
  236. break;
  237. }
  238. }
  239. if (streamIndex == m_MaxInputStreams)
  240. {
  241. DPF(D_TERSE, ("[All render streams are in use]"));
  242. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  243. }
  244. }
  245. // Determine if the format is valid.
  246. //
  247. if (NT_SUCCESS(ntStatus))
  248. {
  249. ntStatus = ValidateFormat(DataFormat);
  250. }
  251. // Instantiate a stream. Stream must be in
  252. // NonPagedPool because of file saving.
  253. //
  254. if (NT_SUCCESS(ntStatus))
  255. {
  256. stream = new (NonPagedPool, MSVAD_POOLTAG)
  257. CMiniportWaveCyclicStream(OuterUnknown);
  258. if (stream)
  259. {
  260. stream->AddRef();
  261. ntStatus =
  262. stream->Init
  263. (
  264. this,
  265. Pin,
  266. Capture,
  267. DataFormat
  268. );
  269. }
  270. else
  271. {
  272. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  273. }
  274. }
  275. if (NT_SUCCESS(ntStatus))
  276. {
  277. if (Capture)
  278. {
  279. m_fCaptureAllocated = TRUE;
  280. }
  281. else
  282. {
  283. m_pStream[streamIndex] = stream;
  284. }
  285. *OutStream = PMINIPORTWAVECYCLICSTREAM(stream);
  286. (*OutStream)->AddRef();
  287. *OutDmaChannel = PDMACHANNEL(stream);
  288. (*OutDmaChannel)->AddRef();
  289. *OutServiceGroup = m_ServiceGroup;
  290. (*OutServiceGroup)->AddRef();
  291. // The stream, the DMA channel, and the service group have
  292. // references now for the caller. The caller expects these
  293. // references to be there.
  294. }
  295. // This is our private reference to the stream. The caller has
  296. // its own, so we can release in any case.
  297. //
  298. if (stream)
  299. {
  300. stream->Release();
  301. }
  302. return ntStatus;
  303. } // NewStream
  304. //=============================================================================
  305. STDMETHODIMP_(NTSTATUS)
  306. CMiniportWaveCyclic::NonDelegatingQueryInterface
  307. (
  308. IN REFIID Interface,
  309. OUT PVOID * Object
  310. )
  311. /*++
  312. Routine Description:
  313. QueryInterface
  314. Arguments:
  315. Interface - GUID
  316. Object - interface pointer to be returned.
  317. Return Value:
  318. NT status code.
  319. --*/
  320. {
  321. PAGED_CODE();
  322. ASSERT(Object);
  323. if (IsEqualGUIDAligned(Interface, IID_IUnknown))
  324. {
  325. *Object = PVOID(PUNKNOWN(PMINIPORTWAVECYCLIC(this)));
  326. }
  327. else if (IsEqualGUIDAligned(Interface, IID_IMiniport))
  328. {
  329. *Object = PVOID(PMINIPORT(this));
  330. }
  331. else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveCyclic))
  332. {
  333. *Object = PVOID(PMINIPORTWAVECYCLIC(this));
  334. }
  335. else if (IsEqualGUIDAligned(Interface, IID_IPinCount))
  336. {
  337. *Object = PVOID(PPINCOUNT(this));
  338. }
  339. else
  340. {
  341. *Object = NULL;
  342. }
  343. if (*Object)
  344. {
  345. // We reference the interface for the caller.
  346. PUNKNOWN(*Object)->AddRef();
  347. return STATUS_SUCCESS;
  348. }
  349. return STATUS_INVALID_PARAMETER;
  350. } // NonDelegatingQueryInterface
  351. //=============================================================================
  352. STDMETHODIMP_(void)
  353. CMiniportWaveCyclic::PinCount
  354. (
  355. IN ULONG PinId,
  356. IN OUT PULONG FilterNecessary,
  357. IN OUT PULONG FilterCurrent,
  358. IN OUT PULONG FilterPossible,
  359. IN OUT PULONG GlobalCurrent,
  360. IN OUT PULONG GlobalPossible
  361. )
  362. /*++
  363. Routine Description:
  364. Provide a way for the miniport to modify the pin counts for this miniport.
  365. Arguments:
  366. PinId - KS pin number being referenced
  367. FilterNecessary - number of pins required on this pin factory
  368. FilterCurrent - number of pins opened on this pin factory
  369. FilterPossible - number of pins possible on this pin factory
  370. GlobalCurrent - total number of pins opened, across all pin instances on this filter
  371. GlobalPossible - total number of pins possible, across all pin factories on this filter
  372. Return Value:
  373. OUT parameters for the five pin counts.
  374. --*/
  375. {
  376. PAGED_CODE();
  377. _DbgPrintF( DEBUGLVL_VERBOSE,
  378. ("PinCount PID:0x%08x FN(0x%08x):%d FC(0x%08x):%d FP(0x%08x):%d GC(0x%08x):%d GP(0x%08x):%d",
  379. PinId,
  380. FilterNecessary,*FilterNecessary,
  381. FilterCurrent, *FilterCurrent,
  382. FilterPossible, *FilterPossible,
  383. GlobalCurrent, *GlobalCurrent,
  384. GlobalPossible, *GlobalPossible ) );
  385. //
  386. // Something like the following:
  387. //
  388. // if (0 == PinId)
  389. // {
  390. // *FilterPossible += 1;
  391. // }
  392. } // PinCount
  393. //=============================================================================
  394. // CMiniportWaveStreamCyclicSimple
  395. //=============================================================================
  396. //=============================================================================
  397. CMiniportWaveCyclicStream::~CMiniportWaveCyclicStream
  398. (
  399. void
  400. )
  401. /*++
  402. Routine Description:
  403. Destructor for wavecyclicstream
  404. Arguments:
  405. Return Value:
  406. NT status code.
  407. --*/
  408. {
  409. PAGED_CODE();
  410. DPF_ENTER(("[CMiniportWaveCyclicStream::~CMiniportWaveCyclicStream]"));
  411. if (NULL != m_pMiniportLocal)
  412. {
  413. // Tell the Miniport that the slot is freed now.
  414. //
  415. if (m_fCapture)
  416. {
  417. m_pMiniportLocal->m_fCaptureAllocated = FALSE;
  418. }
  419. else
  420. {
  421. for (ULONG i = 0; i < m_pMiniportLocal->m_MaxInputStreams; i++)
  422. {
  423. if (this == m_pMiniportLocal->m_pStream[i])
  424. {
  425. m_pMiniportLocal->m_pStream[i] = NULL;
  426. break;
  427. }
  428. }
  429. }
  430. }
  431. } // ~CMiniportWaveCyclicStream
  432. //=============================================================================
  433. NTSTATUS
  434. CMiniportWaveCyclicStream::Init
  435. (
  436. IN PCMiniportWaveCyclic Miniport_,
  437. IN ULONG Pin_,
  438. IN BOOLEAN Capture_,
  439. IN PKSDATAFORMAT DataFormat_
  440. )
  441. /*++
  442. Routine Description:
  443. Initializes the stream object. Allocate a DMA buffer, timer and DPC
  444. Arguments:
  445. Miniport_ -
  446. Pin_ -
  447. Capture_ -
  448. DataFormat -
  449. DmaChannel_ -
  450. Return Value:
  451. NT status code.
  452. --*/
  453. {
  454. PAGED_CODE();
  455. m_pMiniportLocal = Miniport_;
  456. return
  457. CMiniportWaveCyclicStreamMSVAD::Init
  458. (
  459. Miniport_,
  460. Pin_,
  461. Capture_,
  462. DataFormat_
  463. );
  464. } // Init
  465. //=============================================================================
  466. STDMETHODIMP_(NTSTATUS)
  467. CMiniportWaveCyclicStream::NonDelegatingQueryInterface
  468. (
  469. IN REFIID Interface,
  470. OUT PVOID * Object
  471. )
  472. /*++
  473. Routine Description:
  474. QueryInterface
  475. Arguments:
  476. Interface - GUID
  477. Object - interface pointer to be returned
  478. Return Value:
  479. NT status code.
  480. --*/
  481. {
  482. PAGED_CODE();
  483. ASSERT(Object);
  484. if (IsEqualGUIDAligned(Interface, IID_IUnknown))
  485. {
  486. *Object = PVOID(PUNKNOWN(PMINIPORTWAVECYCLICSTREAM(this)));
  487. }
  488. else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveCyclicStream))
  489. {
  490. *Object = PVOID(PMINIPORTWAVECYCLICSTREAM(this));
  491. }
  492. else if (IsEqualGUIDAligned(Interface, IID_IDmaChannel))
  493. {
  494. *Object = PVOID(PDMACHANNEL(this));
  495. }
  496. else
  497. {
  498. *Object = NULL;
  499. }
  500. if (*Object)
  501. {
  502. PUNKNOWN(*Object)->AddRef();
  503. return STATUS_SUCCESS;
  504. }
  505. return STATUS_INVALID_PARAMETER;
  506. } // NonDelegatingQueryInterface
  507. #pragma code_seg()