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.

394 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. inpin.cpp
  5. Abstract:
  6. Antenna input pin code.
  7. --*/
  8. #include "BDATuner.h"
  9. #ifdef ALLOC_DATA_PRAGMA
  10. #pragma const_seg("PAGECONST")
  11. #endif // ALLOC_DATA_PRAGMA
  12. #ifdef ALLOC_PRAGMA
  13. #pragma code_seg("PAGE")
  14. #endif // ALLOC_PRAGMA
  15. /*
  16. ** (Static) PinCreate() method of the CAntennaPin class
  17. **
  18. ** Creates the input pin object and
  19. ** associates it with the filter object.
  20. **
  21. */
  22. NTSTATUS
  23. CAntennaPin::PinCreate(
  24. IN OUT PKSPIN pKSPin,
  25. IN PIRP Irp
  26. )
  27. {
  28. NTSTATUS Status = STATUS_SUCCESS;
  29. CAntennaPin* pPin;
  30. CFilter* pFilter;
  31. _DbgPrintF(DEBUGLVL_VERBOSE,("CAntennaPin::PinCreate"));
  32. ASSERT(pKSPin);
  33. ASSERT(Irp);
  34. // Obtain a pointer to the filter object for which the input pin is created.
  35. //
  36. pFilter = reinterpret_cast<CFilter*>(KsGetFilterFromIrp(Irp)->Context);
  37. // Create the Antenna input pin object.
  38. //
  39. pPin = new(PagedPool,MS_SAMPLE_TUNER_POOL_TAG) CAntennaPin; // Tags the allocated memory
  40. if (pPin)
  41. {
  42. // Link the input pin object to the filter object.
  43. // That is, set the input pin's filter pointer data member to the obtained filter pointer.
  44. //
  45. pPin->SetFilter( pFilter);
  46. // Link the Antenna input pin object to the passed in pointer to the KSPIN structure
  47. // by assigning the pointer to the pin object to the KSPIN structure's context member.
  48. //
  49. pKSPin->Context = pPin;
  50. }
  51. else
  52. {
  53. Status = STATUS_INSUFFICIENT_RESOURCES;
  54. }
  55. return Status;
  56. }
  57. /*
  58. ** PinClose() method of the CAntennaPin class
  59. **
  60. ** Deletes the previously created input pin object.
  61. **
  62. */
  63. NTSTATUS
  64. CAntennaPin::PinClose(
  65. IN OUT PKSPIN Pin,
  66. IN PIRP Irp
  67. )
  68. {
  69. _DbgPrintF(DEBUGLVL_VERBOSE,("CAntennaPin::PinClose"));
  70. ASSERT(Pin);
  71. ASSERT(Irp);
  72. // Retrieve the Antenna input pin object from the passed in
  73. // KSPIN structure's context member.
  74. //
  75. CAntennaPin* pPin = reinterpret_cast<CAntennaPin*>(Pin->Context);
  76. ASSERT(pPin);
  77. delete pPin;
  78. return STATUS_SUCCESS;
  79. }
  80. /*
  81. ** IntersectDataFormat() method of the CAntennaPin class
  82. **
  83. ** Enables connection of the input pin with an upstream filter.
  84. **
  85. */
  86. NTSTATUS
  87. CAntennaPin::IntersectDataFormat(
  88. IN PVOID pContext,
  89. IN PIRP pIrp,
  90. IN PKSP_PIN Pin,
  91. IN PKSDATARANGE DataRange,
  92. IN PKSDATARANGE MatchingDataRange,
  93. IN ULONG DataBufferSize,
  94. OUT PVOID Data OPTIONAL,
  95. OUT PULONG DataSize
  96. )
  97. {
  98. if ( DataBufferSize < sizeof(KS_DATARANGE_BDA_ANTENNA) )
  99. {
  100. *DataSize = sizeof( KS_DATARANGE_BDA_ANTENNA );
  101. return STATUS_BUFFER_OVERFLOW;
  102. }
  103. else if (DataRange->FormatSize < sizeof(KS_DATARANGE_BDA_ANTENNA))
  104. {
  105. return STATUS_NO_MATCH;
  106. } else
  107. {
  108. ASSERT(DataBufferSize == sizeof(KS_DATARANGE_BDA_ANTENNA));
  109. *DataSize = sizeof( KS_DATARANGE_BDA_ANTENNA );
  110. RtlCopyMemory( Data, (PVOID)DataRange, sizeof(KS_DATARANGE_BDA_ANTENNA));
  111. return STATUS_SUCCESS;
  112. }
  113. }
  114. /*
  115. ** PinSetDeviceState() method of the CAntennaPin class
  116. **
  117. ** Because the most upstream pin (input pin) is the last to transition,
  118. ** use this pin's state to set the state of the filter.
  119. **
  120. ** Also, release filter resouces if the pin's state transitions to stop, and
  121. ** acquire resources if the pin's state transitions from stop.
  122. **
  123. */
  124. NTSTATUS
  125. CAntennaPin::PinSetDeviceState(
  126. IN PKSPIN Pin,
  127. IN KSSTATE ToState,
  128. IN KSSTATE FromState
  129. )
  130. {
  131. NTSTATUS Status = STATUS_SUCCESS;
  132. PKSDEVICE pKSDevice;
  133. CAntennaPin * pPin;
  134. CDevice * pDevice;
  135. _DbgPrintF( DEBUGLVL_VERBOSE,
  136. ("CAntennaPin::PinSetDeviceState"));
  137. ASSERT(Pin);
  138. // Obtain a pointer to the device object from
  139. // the passed in pointer to the KSPIN structure.
  140. //
  141. pKSDevice = KsPinGetDevice( Pin);
  142. // Obtain a pointer to the pin object from context member of
  143. // the passed in pointer to the KSPIN structure.
  144. //
  145. pPin = reinterpret_cast<CAntennaPin*>(Pin->Context);
  146. ASSERT( pPin);
  147. // Obtain a pointer to the device object from context member of
  148. // the retrieved pointer to the KSDEVICE structure.
  149. //
  150. pDevice = reinterpret_cast<CDevice *>(pKSDevice->Context);
  151. ASSERT(pDevice);
  152. pPin->m_pFilter->SetDeviceState( pPin->m_KsState);
  153. if ((ToState == KSSTATE_STOP) && (FromState != KSSTATE_STOP))
  154. {
  155. // Because the driver allocates resources on a filter wide basis,
  156. // inform the filter to release resources when the last pin
  157. // (that is, the most upstream pin) transitions to the stop state.
  158. //
  159. // The input pin is the last pin to transition to the stop state,
  160. // therefore inform the filter to release its resources.
  161. //
  162. Status = pPin->m_pFilter->ReleaseResources();
  163. pPin->m_KsState = ToState;
  164. }
  165. else if ((ToState == KSSTATE_ACQUIRE) && (FromState == KSSTATE_STOP))
  166. {
  167. // Because the driver allocates resources on a filter wide basis,
  168. // inform the filter to acquire resources when the last pin
  169. // (that is, the most upstream pin) transitions from the stop state.
  170. //
  171. // The input pin is the last pin to transition from the stop state,
  172. // therefore inform the filter to acquire its resources.
  173. //
  174. Status = pPin->m_pFilter->AcquireResources();
  175. if (NT_SUCCESS( Status))
  176. {
  177. pPin->m_KsState = ToState;
  178. }
  179. }
  180. else if (ToState > KSSTATE_RUN)
  181. {
  182. _DbgPrintF( DEBUGLVL_TERSE,
  183. ("CAntennaPin::PinSetDeviceState - Invalid Device State. ToState 0x%08x. FromState 0x%08x.",
  184. ToState, FromState));
  185. Status = STATUS_INVALID_PARAMETER;
  186. }
  187. else
  188. {
  189. pPin->m_KsState = ToState;
  190. }
  191. return Status;
  192. }
  193. /*
  194. ** GetSignalStatus() method of the CAntennaPin class
  195. **
  196. ** Retrieves the value of the tuner node signal statistics properties.
  197. **
  198. */
  199. NTSTATUS
  200. CAntennaPin::GetSignalStatus(
  201. IN PIRP pIrp,
  202. IN PKSPROPERTY pKSProperty,
  203. IN PULONG pulProperty
  204. )
  205. {
  206. NTSTATUS Status = STATUS_SUCCESS;
  207. CAntennaPin * pPin;
  208. CFilter* pFilter;
  209. BDATUNER_DEVICE_STATUS DeviceStatus;
  210. _DbgPrintF(DEBUGLVL_VERBOSE,("CAntennaPin::GetSignalStatus"));
  211. ASSERT(pIrp);
  212. ASSERT(pKSProperty);
  213. ASSERT(pulProperty);
  214. // Call the BDA support library to
  215. // validate that the node type is associated with this pin.
  216. //
  217. Status = BdaValidateNodeProperty( pIrp, pKSProperty);
  218. if (NT_SUCCESS( Status))
  219. {
  220. // Obtain a pointer to the pin object.
  221. //
  222. // Because the property dispatch table calls the CAntennaPin::GetTunerSignalStatus()
  223. // method directly, the method must retrieve a pointer to the underlying pin object.
  224. //
  225. pPin = reinterpret_cast<CAntennaPin *>(KsGetPinFromIrp(pIrp)->Context);
  226. ASSERT(pPin);
  227. // Retrieve the filter context from the pin context.
  228. //
  229. pFilter = pPin->GetFilter();
  230. ASSERT( pFilter);
  231. Status = pFilter->GetStatus( &DeviceStatus);
  232. if (Status == STATUS_SUCCESS)
  233. {
  234. switch (pKSProperty->Id)
  235. {
  236. case KSPROPERTY_BDA_SIGNAL_PRESENT:
  237. *pulProperty = DeviceStatus.fCarrierPresent;
  238. break;
  239. default:
  240. Status = STATUS_INVALID_PARAMETER;
  241. }
  242. }
  243. }
  244. return Status;
  245. }
  246. /*
  247. ** GetCenterFrequency() method of the CAntennaPin class
  248. **
  249. ** Retrieves the value of the type 1 property of node 1.
  250. **
  251. */
  252. NTSTATUS
  253. CAntennaPin::GetCenterFrequency(
  254. IN PIRP pIrp,
  255. IN PKSPROPERTY pKSProperty,
  256. IN PULONG pulProperty
  257. )
  258. {
  259. NTSTATUS Status = STATUS_SUCCESS;
  260. CAntennaPin* pPin;
  261. CFilter* pFilter;
  262. _DbgPrintF(DEBUGLVL_VERBOSE,("CAntennaPin::GetCenterFrequency"));
  263. ASSERT(pIrp);
  264. ASSERT(pKSProperty);
  265. ASSERT(pulProperty);
  266. // Call the BDA support library to
  267. // validate that the node type is associated with this pin.
  268. //
  269. Status = BdaValidateNodeProperty( pIrp, pKSProperty);
  270. if (NT_SUCCESS( Status))
  271. {
  272. // Obtain a pointer to the pin object.
  273. //
  274. // Because the property dispatch table calls the CAntennaPin::GetCenterFrequency()
  275. // method directly, the method must retrieve a pointer to the underlying pin object.
  276. //
  277. pPin = reinterpret_cast<CAntennaPin *>(KsGetPinFromIrp(pIrp)->Context);
  278. ASSERT(pPin);
  279. // Retrieve the filter context from the pin context.
  280. //
  281. pFilter = pPin->GetFilter();
  282. ASSERT( pFilter);
  283. // Retrieve the actual filter parameter.
  284. //
  285. Status = pFilter->GetFrequency( pulProperty);
  286. }
  287. return Status;
  288. }
  289. /*
  290. ** PutCenterFrequency() method of the CAntennaPin class
  291. **
  292. ** Sets the value of the type 1 property of node 1 along with the
  293. ** resource of the filter to which the node belongs.
  294. **
  295. */
  296. NTSTATUS
  297. CAntennaPin::PutCenterFrequency(
  298. IN PIRP pIrp,
  299. IN PKSPROPERTY pKSProperty,
  300. IN PULONG pulProperty
  301. )
  302. {
  303. NTSTATUS Status = STATUS_SUCCESS;
  304. CAntennaPin* pPin;
  305. CFilter* pFilter;
  306. _DbgPrintF(DEBUGLVL_VERBOSE,("CAntennaPin::PutCenterFrequency"));
  307. ASSERT(pIrp);
  308. ASSERT(pKSProperty);
  309. ASSERT(pulProperty);
  310. // Call the BDA support library to
  311. // validate that the node type is associated with this pin.
  312. //
  313. Status = BdaValidateNodeProperty( pIrp, pKSProperty);
  314. if (NT_SUCCESS( Status))
  315. {
  316. // Obtain a pointer to the pin object.
  317. //
  318. // Because the property dispatch table calls the CAntennaPin::PutCenterFrequency()
  319. // method directly, the method must retrieve a pointer to the underlying pin object.
  320. //
  321. pPin = reinterpret_cast<CAntennaPin *>(KsGetPinFromIrp(pIrp)->Context);
  322. ASSERT( pPin);
  323. // Retrieve the filter context from the pin context.
  324. //
  325. pFilter = pPin->GetFilter();
  326. ASSERT( pFilter);
  327. // Change the actual filter parameter.
  328. //
  329. Status = pFilter->PutFrequency( *pulProperty);
  330. }
  331. return Status;
  332. }