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.

642 lines
16 KiB

  1. #include "common.h"
  2. #include "bdadebug.h"
  3. #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
  4. /**************************************************************/
  5. /* Driver Name - Change the driver name to reflect your executable name! */
  6. /**************************************************************/
  7. #define MODULENAME "BDA Generic Tuner Sample"
  8. #define MODULENAMEUNICODE L"BDA Generic Tuner Sample"
  9. #define STR_MODULENAME MODULENAME
  10. // This defines the name of the WMI device that manages service IOCTLS
  11. #define DEVICENAME (L"\\\\.\\" MODULENAMEUNICODE)
  12. #define SYMBOLICNAME (L"\\DosDevices\\" MODULENAMEUNICODE)
  13. #define ATSC_RECEIVER 1
  14. //#define DVBS_RECEIVER 1
  15. // #define DVBT_RECEIVER 1
  16. // #define CABLE_RECEIVER 1
  17. // Must define exactly one of the 4 above
  18. # if !(defined(ATSC_RECEIVER) || defined(DVBT_RECEIVER) || defined(DVBS_RECEIVER) || defined (CABLE_RECEIVER))
  19. #error "Must define exactly one of ATSC, DVBT, DVBS or CABLE"
  20. #endif
  21. # if defined(ATSC_RECEIVER) && (defined(DVBT_RECEIVER) || defined(DVBS_RECEIVER) || defined (CABLE_RECEIVER))
  22. #error �Multiple tranport definitions"
  23. # elif defined(DVBT_RECEIVER) && (defined(ATSC_RECEIVER) || defined(DVBS_RECEIVER) || defined (CABLE_RECEIVER))
  24. #error �Multiple tranport definitions"
  25. # elif defined(DVBS_RECEIVER) && (defined(ATSC_RECEIVER) || defined(DVBT_RECEIVER) || defined (CABLE_RECEIVER))
  26. #error �Multiple tranport definitions"
  27. # elif defined(CABLE_RECEIVER) && (defined(ATSC_RECEIVER) || defined(DVBS_RECEIVER) || defined (DVBT_RECEIVER))
  28. #error �Multiple tranport definitions"
  29. #endif
  30. #define MS_SAMPLE_TUNER_POOL_TAG 'TadB'
  31. // Define a structure that represents what the underlying device can do.
  32. //
  33. // Note - It is possible to set conflicting settings. In this case, the
  34. // CFilter::CheckChanges method should return an error. Only a
  35. // self-consistent resource should be submitted to the underlying device.
  36. //
  37. typedef struct _BDATUNER_DEVICE_RESOURCE
  38. {
  39. // Tuner Resources
  40. //
  41. ULONG ulCarrierFrequency;
  42. ULONG ulFrequencyMultiplier;
  43. GUID guidDemodulator;
  44. // Demodulator Resources
  45. //
  46. ULONG ulDemodProperty1;
  47. ULONG ulDemodProperty2;
  48. ULONG ulDemodProperty3;
  49. } BDATUNER_DEVICE_RESOURCE, * PBDATUNER_DEVICE_RESOURCE;
  50. // Define a structure that represents the underlying device status.
  51. //
  52. typedef struct _BDATUNER_DEVICE_STATUS
  53. {
  54. // Tuner Status
  55. //
  56. BOOLEAN fCarrierPresent;
  57. // Demodulator Status
  58. //
  59. BOOLEAN fSignalLocked;
  60. } BDATUNER_DEVICE_STATUS, * PBDATUNER_DEVICE_STATUS;
  61. extern const KSDEVICE_DESCRIPTOR DeviceDescriptor;
  62. //
  63. // Define the filter class.
  64. //
  65. class CFilter {
  66. public:
  67. //
  68. // Define the AVStream Filter Dispatch Functions
  69. // Network provider and AVStream use these functions
  70. // to create or remove a filter instance
  71. //
  72. static
  73. STDMETHODIMP_(NTSTATUS)
  74. Create(
  75. IN OUT PKSFILTER Filter,
  76. IN PIRP Irp
  77. );
  78. static
  79. STDMETHODIMP_(NTSTATUS)
  80. FilterClose(
  81. IN OUT PKSFILTER Filter,
  82. IN PIRP Irp
  83. );
  84. /**************************************************************/
  85. /* Only used to process frames.
  86. * Filters that transport data do not implement this dispatch function.
  87. static
  88. STDMETHODIMP
  89. Process(
  90. IN PKSFILTER Filter,
  91. IN PKSPROCESSPIN_INDEXENTRY ProcessPinsIndex
  92. );*/
  93. /**************************************************************/
  94. //
  95. // KSMETHODSETID_BdaChangeSync
  96. // Filter change sync methods
  97. //
  98. static
  99. STDMETHODIMP_(NTSTATUS)
  100. StartChanges(
  101. IN PIRP pIrp,
  102. IN PKSMETHOD pKSMethod,
  103. OPTIONAL PVOID pvIgnored
  104. );
  105. static
  106. STDMETHODIMP_(NTSTATUS)
  107. CheckChanges(
  108. IN PIRP pIrp,
  109. IN PKSMETHOD pKSMethod,
  110. OPTIONAL PVOID pvIgnored
  111. );
  112. static
  113. STDMETHODIMP_(NTSTATUS)
  114. CommitChanges(
  115. IN PIRP pIrp,
  116. IN PKSMETHOD pKSMethod,
  117. OPTIONAL PVOID pvIgnored
  118. );
  119. static
  120. STDMETHODIMP_(NTSTATUS)
  121. GetChangeState(
  122. IN PIRP pIrp,
  123. IN PKSMETHOD pKSMethod,
  124. OUT PULONG pulChangeState
  125. );
  126. static
  127. STDMETHODIMP_(NTSTATUS)
  128. GetMedium(
  129. IN PIRP pIrp,
  130. IN PKSPROPERTY pKSProperty,
  131. IN KSPIN_MEDIUM * pulProperty
  132. );
  133. //
  134. // KSMETHODSETID_BdaDeviceConfiguration
  135. // Methods to modify filter topology.
  136. //
  137. static
  138. STDMETHODIMP_(NTSTATUS)
  139. CreateTopology(
  140. IN PIRP pIrp,
  141. IN PKSMETHOD pKSMethod,
  142. OPTIONAL PVOID pvIgnored
  143. );
  144. //
  145. // Filter Implementation Methods
  146. //
  147. STDMETHODIMP_(class CDevice *)
  148. GetDevice() { return m_pDevice;};
  149. STDMETHODIMP_(NTSTATUS)
  150. PutFrequency(
  151. IN ULONG ulBdaParameter
  152. )
  153. {
  154. m_NewResource.ulCarrierFrequency = ulBdaParameter;
  155. m_BdaChangeState = BDA_CHANGES_PENDING;
  156. return STATUS_SUCCESS;
  157. };
  158. STDMETHODIMP_(NTSTATUS)
  159. GetFrequency(
  160. IN PULONG pulBdaParameter
  161. )
  162. {
  163. *pulBdaParameter = m_CurResource.ulCarrierFrequency;
  164. return STATUS_SUCCESS;
  165. };
  166. STDMETHODIMP_(NTSTATUS)
  167. SetDemodulator(
  168. IN const GUID * pguidDemodulator
  169. );
  170. STDMETHODIMP_(NTSTATUS)
  171. SetDemodProperty1(
  172. IN ULONG ulDemodProperty1
  173. )
  174. {
  175. m_NewResource.ulDemodProperty1 = ulDemodProperty1;
  176. m_BdaChangeState = BDA_CHANGES_PENDING;
  177. return STATUS_SUCCESS;
  178. }
  179. STDMETHODIMP_(NTSTATUS)
  180. GetDemodProperty1(
  181. IN PULONG pulDemodProperty1
  182. )
  183. {
  184. if (pulDemodProperty1)
  185. {
  186. *pulDemodProperty1 = m_CurResource.ulDemodProperty1;
  187. return STATUS_SUCCESS;
  188. }
  189. else
  190. {
  191. return STATUS_INVALID_PARAMETER;
  192. }
  193. }
  194. STDMETHODIMP_(NTSTATUS)
  195. SetDemodProperty2(
  196. IN ULONG ulDemodProperty2
  197. )
  198. {
  199. m_NewResource.ulDemodProperty2 = ulDemodProperty2;
  200. m_BdaChangeState = BDA_CHANGES_PENDING;
  201. return STATUS_SUCCESS;
  202. }
  203. STDMETHODIMP_(NTSTATUS)
  204. GetDemodProperty3(
  205. IN PULONG pulDemodProperty3
  206. )
  207. {
  208. if (pulDemodProperty3)
  209. {
  210. *pulDemodProperty3 = m_CurResource.ulDemodProperty3;
  211. return STATUS_SUCCESS;
  212. }
  213. else
  214. {
  215. return STATUS_INVALID_PARAMETER;
  216. }
  217. }
  218. STDMETHODIMP_(NTSTATUS)
  219. GetStatus(
  220. PBDATUNER_DEVICE_STATUS pDeviceStatus
  221. );
  222. STDMETHODIMP_(NTSTATUS)
  223. SetDeviceState(
  224. KSSTATE newKsState
  225. )
  226. {
  227. m_KsState = newKsState;
  228. return STATUS_SUCCESS;
  229. };
  230. STDMETHODIMP_(NTSTATUS)
  231. AcquireResources();
  232. STDMETHODIMP_(NTSTATUS)
  233. ReleaseResources();
  234. private:
  235. class CDevice * m_pDevice;
  236. // Filter Properties
  237. //
  238. // Filter Resources
  239. //
  240. KSSTATE m_KsState;
  241. BDA_CHANGE_STATE m_BdaChangeState;
  242. BDATUNER_DEVICE_RESOURCE m_CurResource;
  243. BDATUNER_DEVICE_RESOURCE m_NewResource;
  244. ULONG m_ulResourceID;
  245. BOOLEAN m_fResourceAcquired;
  246. };
  247. //
  248. // Define the device class.
  249. //
  250. class CDevice {
  251. public:
  252. //
  253. // Define the AVStream Device Dispatch Functions
  254. // AVStream uses these functions to create and start the device
  255. //
  256. static
  257. STDMETHODIMP_(NTSTATUS)
  258. Create(
  259. IN PKSDEVICE pKSDevice
  260. );
  261. static
  262. STDMETHODIMP_(NTSTATUS)
  263. Start(
  264. IN PKSDEVICE pKSDevice,
  265. IN PIRP pIrp,
  266. IN PCM_RESOURCE_LIST pTranslatedResourceList OPTIONAL,
  267. IN PCM_RESOURCE_LIST pUntranslatedResourceList OPTIONAL
  268. );
  269. //
  270. // Utility functions for the device
  271. // An instance of the filter uses these functions
  272. // to manage resources on the device.
  273. //
  274. STDMETHODIMP_(NTSTATUS)
  275. InitializeHW(
  276. );
  277. STDMETHODIMP_(NTSTATUS)
  278. GetStatus(
  279. PBDATUNER_DEVICE_STATUS pDeviceStatus
  280. );
  281. STDMETHODIMP_(NTSTATUS)
  282. GetImplementationGUID(
  283. GUID * pguidImplementation
  284. )
  285. {
  286. if (pguidImplementation)
  287. {
  288. *pguidImplementation = m_guidImplemenation;
  289. return STATUS_SUCCESS;
  290. }
  291. else
  292. {
  293. return STATUS_INVALID_PARAMETER;
  294. }
  295. }
  296. STDMETHODIMP_(NTSTATUS)
  297. GetDeviceInstance(
  298. ULONG * pulDeviceInstance
  299. )
  300. {
  301. if (pulDeviceInstance)
  302. {
  303. *pulDeviceInstance = m_ulDeviceInstance;
  304. return STATUS_SUCCESS;
  305. }
  306. else
  307. {
  308. return STATUS_INVALID_PARAMETER;
  309. }
  310. }
  311. NTSTATUS
  312. AcquireResources(
  313. PBDATUNER_DEVICE_RESOURCE pNewResource,
  314. PULONG pulAcquiredResourceID
  315. );
  316. NTSTATUS
  317. UpdateResources(
  318. PBDATUNER_DEVICE_RESOURCE pNewResource,
  319. ULONG ulResourceID
  320. );
  321. NTSTATUS
  322. ReleaseResources(
  323. ULONG ulResourceID
  324. );
  325. private:
  326. PKSDEVICE m_pKSDevice;
  327. GUID m_guidImplemenation;
  328. ULONG m_ulDeviceInstance;
  329. BDATUNER_DEVICE_RESOURCE m_CurResource;
  330. ULONG m_ulCurResourceID;
  331. ULONG m_ulcResourceUsers;
  332. };
  333. //
  334. // Define the Input-pin class.
  335. //
  336. class CAntennaPin {
  337. public:
  338. //
  339. // Define the AVStream Pin Dispatch Functions
  340. // Network provider and AVStream use these functions
  341. // to create or remove a pin instance or to change the pin's
  342. // state after the minidriver receives a connection state
  343. // property 'set' IOCTL.
  344. //
  345. static
  346. STDMETHODIMP_(NTSTATUS)
  347. PinCreate(
  348. IN OUT PKSPIN Pin,
  349. IN PIRP Irp
  350. );
  351. static
  352. STDMETHODIMP_(NTSTATUS)
  353. PinClose(
  354. IN OUT PKSPIN Pin,
  355. IN PIRP Irp
  356. );
  357. static
  358. STDMETHODIMP_(NTSTATUS)
  359. PinSetDeviceState(
  360. IN PKSPIN Pin,
  361. IN KSSTATE ToState,
  362. IN KSSTATE FromState
  363. );
  364. //
  365. // Define a data intersection handler function for the
  366. // pin (KSPIN_DESCRIPTOR_EX structure).
  367. // Network provider and AVStream use this function
  368. // to connect the input pin with an upstream filter.
  369. //
  370. static
  371. STDMETHODIMP_(NTSTATUS)
  372. IntersectDataFormat(
  373. IN PVOID pContext,
  374. IN PIRP pIrp,
  375. IN PKSP_PIN Pin,
  376. IN PKSDATARANGE DataRange,
  377. IN PKSDATARANGE MatchingDataRange,
  378. IN ULONG DataBufferSize,
  379. OUT PVOID Data OPTIONAL,
  380. OUT PULONG DataSize
  381. );
  382. //
  383. // Network provider and AVStream use these functions
  384. // to set and get properties of nodes that are controlled
  385. // by the input pin.
  386. //
  387. static
  388. STDMETHODIMP_(NTSTATUS)
  389. GetCenterFrequency(
  390. IN PIRP Irp,
  391. IN PKSPROPERTY pKSProperty,
  392. IN PULONG pulProperty
  393. );
  394. static
  395. STDMETHODIMP_(NTSTATUS)
  396. PutCenterFrequency(
  397. IN PIRP Irp,
  398. IN PKSPROPERTY pKSProperty,
  399. IN PULONG pulProperty
  400. );
  401. static
  402. STDMETHODIMP_(NTSTATUS)
  403. GetSignalStatus(
  404. IN PIRP Irp,
  405. IN PKSPROPERTY pKSProperty,
  406. IN PULONG pulProperty
  407. );
  408. //
  409. // Utility functions for the pin
  410. //
  411. STDMETHODIMP_(class CFilter *)
  412. GetFilter() { return m_pFilter;};
  413. STDMETHODIMP_(void)
  414. SetFilter(class CFilter * pFilter) { m_pFilter = pFilter;};
  415. private:
  416. class CFilter* m_pFilter;
  417. ULONG ulReserved;
  418. KSSTATE m_KsState;
  419. // Node Properties
  420. //
  421. BOOLEAN m_fResourceChanged;
  422. ULONG m_ulCurrentFrequency;
  423. ULONG m_ulPendingFrequency;
  424. };
  425. //
  426. // Define the Output-pin class.
  427. //
  428. class CTransportPin{
  429. public:
  430. //
  431. // Define the AVStream Pin Dispatch Functions
  432. // Network provider and AVStream use these functions
  433. // to create or remove a pin instance or to change the pin's
  434. // state after the minidriver receives a connection state
  435. // property 'set' IOCTL.
  436. //
  437. static
  438. STDMETHODIMP_(NTSTATUS)
  439. PinCreate(
  440. IN OUT PKSPIN Pin,
  441. IN PIRP Irp
  442. );
  443. static
  444. STDMETHODIMP_(NTSTATUS)
  445. PinClose(
  446. IN OUT PKSPIN Pin,
  447. IN PIRP Irp
  448. );
  449. //
  450. // Define a data intersection handler function for the
  451. // pin (KSPIN_DESCRIPTOR_EX structure).
  452. // Network provider and AVStream use this function
  453. // to connect the output pin with a downstream filter.
  454. //
  455. static
  456. STDMETHODIMP_(NTSTATUS)
  457. IntersectDataFormat(
  458. IN PVOID pContext,
  459. IN PIRP pIrp,
  460. IN PKSP_PIN Pin,
  461. IN PKSDATARANGE DataRange,
  462. IN PKSDATARANGE MatchingDataRange,
  463. IN ULONG DataBufferSize,
  464. OUT PVOID Data OPTIONAL,
  465. OUT PULONG DataSize
  466. );
  467. //
  468. // BDA Signal Properties
  469. //
  470. static
  471. STDMETHODIMP_(NTSTATUS)
  472. GetSignalStatus(
  473. IN PIRP Irp,
  474. IN PKSPROPERTY pKSProperty,
  475. IN PULONG pulProperty
  476. );
  477. static
  478. STDMETHODIMP_(NTSTATUS)
  479. PutAutoDemodProperty(
  480. IN PIRP Irp,
  481. IN PKSPROPERTY pKSProperty,
  482. IN PULONG pulProperty
  483. );
  484. #if !ATSC_RECEIVER
  485. static
  486. STDMETHODIMP_(NTSTATUS)
  487. GetDigitalDemodProperty(
  488. IN PIRP Irp,
  489. IN PKSPROPERTY pKSProperty,
  490. IN PULONG pulProperty
  491. );
  492. static
  493. STDMETHODIMP_(NTSTATUS)
  494. PutDigitalDemodProperty(
  495. IN PIRP Irp,
  496. IN PKSPROPERTY pKSProperty,
  497. IN PULONG pulProperty
  498. );
  499. #endif // !ATSC_RECEIVER
  500. static
  501. STDMETHODIMP_(NTSTATUS)
  502. GetExtensionProperties(
  503. IN PIRP Irp,
  504. IN PKSPROPERTY pKSProperty,
  505. IN PULONG pulProperty
  506. );
  507. static
  508. STDMETHODIMP_(NTSTATUS)
  509. PutExtensionProperties(
  510. IN PIRP Irp,
  511. IN PKSPROPERTY pKSProperty,
  512. IN PULONG pulProperty
  513. );
  514. STDMETHODIMP_(class CFilter *)
  515. GetFilter() { return m_pFilter;};
  516. STDMETHODIMP_(void)
  517. SetFilter(class CFilter * pFilter) { m_pFilter = pFilter;};
  518. private:
  519. class CFilter* m_pFilter;
  520. ULONG ulReserved;
  521. KSSTATE m_KsState;
  522. // Node Properties
  523. //
  524. BOOLEAN m_fResourceChanged;
  525. ULONG m_ulCurrentProperty1;
  526. ULONG m_ulPendingProperty1;
  527. ULONG m_ulCurrentProperty2;
  528. ULONG m_ulCurrentProperty3;
  529. ULONG m_ulPendingProperty3;
  530. };
  531. //
  532. // Topology Constants
  533. //
  534. typedef enum {
  535. PIN_TYPE_ANTENNA = 0,
  536. PIN_TYPE_TRANSPORT
  537. } FilterPinTypes;
  538. typedef enum {
  539. INITIAL_ANNTENNA_PIN_ID = 0
  540. } InitialPinIDs;
  541. //
  542. // Data declarations
  543. //
  544. extern const BDA_FILTER_TEMPLATE BdaFilterTemplate;
  545. extern const KSFILTER_DESCRIPTOR InitialFilterDescriptor;
  546. extern const KSFILTER_DESCRIPTOR TemplateFilterDescriptor;