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.

2309 lines
78 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // mpe.c
  9. //
  10. // Abstract:
  11. //
  12. //
  13. // Author:
  14. //
  15. // P Porzuczek
  16. //
  17. // Environment:
  18. //
  19. // Revision History:
  20. //
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include <wdm.h>
  24. #include <strmini.h>
  25. #include <ksmedia.h>
  26. #include <BdaTypes.h>
  27. #include <BdaMedia.h>
  28. #include "Mpe.h"
  29. #include "MpeMedia.h"
  30. #include "MpeStream.h"
  31. #include "Main.h"
  32. #include "filter.h"
  33. #pragma pack (1)
  34. typedef struct
  35. {
  36. BYTE table_id;
  37. USHORT section_syntax_indicator : 1;
  38. USHORT private_indicator: 1;
  39. USHORT reserved1: 2;
  40. USHORT section_length: 12;
  41. BYTE MAC_address_6;
  42. BYTE MAC_address_5;
  43. BYTE reserved2 : 2;
  44. BYTE payload_scrambling : 2;
  45. BYTE address_scrambling : 2;
  46. BYTE LLC_SNAP_flag : 1;
  47. BYTE current_next_indicator : 1;
  48. BYTE section_number;
  49. BYTE last_section_number;
  50. BYTE MAC_address_4;
  51. BYTE MAC_address_3;
  52. BYTE MAC_address_2;
  53. BYTE MAC_address_1;
  54. BYTE Data [0];
  55. } SECTION_HEADER, *PSECTION_HEADER;
  56. typedef struct
  57. {
  58. BYTE dsap;
  59. BYTE ssap;
  60. BYTE cntl;
  61. BYTE org [3];
  62. USHORT type;
  63. BYTE Data [0];
  64. } LLC_SNAP, *PLLC_SNAP;
  65. typedef struct
  66. {
  67. BYTE MAC_Dest_Address [6];
  68. BYTE MAC_Src_Address [6];
  69. USHORT usLength;
  70. } MAC_Address, *PMAC_Address;
  71. typedef struct _HEADER_IP_
  72. {
  73. UCHAR ucVersion_Length;
  74. UCHAR ucTOS;
  75. USHORT usLength;
  76. USHORT usId;
  77. USHORT usFlags_Offset;
  78. UCHAR ucTTL;
  79. UCHAR ucProtocol;
  80. USHORT usHdrChecksum;
  81. UCHAR ucSrcAddress [4];
  82. UCHAR ucDestAddress [4];
  83. } HEADER_IP, *PHEADER_IP;
  84. #pragma pack ()
  85. #define ES2(s) ((((s) >> 8) & 0x00FF) + (((s) << 8) & 0xFF00))
  86. #ifdef DBG
  87. //////////////////////////////////////////////////////////////////////////////
  88. VOID
  89. DumpData (
  90. PUCHAR pData,
  91. ULONG ulSize
  92. )
  93. //////////////////////////////////////////////////////////////////////////////
  94. {
  95. ULONG ulCount;
  96. ULONG ul;
  97. UCHAR uc;
  98. while (ulSize)
  99. {
  100. ulCount = 16 < ulSize ? 16 : ulSize;
  101. for (ul = 0; ul < ulCount; ul++)
  102. {
  103. uc = *pData;
  104. TEST_DEBUG (TEST_DBG_RECV, ("%02X ", uc));
  105. ulSize -= 1;
  106. pData += 1;
  107. }
  108. TEST_DEBUG (TEST_DBG_RECV, ("\n"));
  109. }
  110. }
  111. #endif //DBG
  112. //////////////////////////////////////////////////////////////////////////////
  113. BOOLEAN
  114. ValidSection (
  115. PSECTION_HEADER pSection
  116. )
  117. //////////////////////////////////////////////////////////////////////////////
  118. {
  119. if (pSection->table_id != 0x3E)
  120. {
  121. return FALSE;
  122. }
  123. return TRUE;
  124. }
  125. //////////////////////////////////////////////////////////////////////////////
  126. BOOLEAN
  127. ValidSnap (
  128. PLLC_SNAP pSnap
  129. )
  130. //////////////////////////////////////////////////////////////////////////////
  131. {
  132. if (pSnap->dsap != 0xAA)
  133. {
  134. return FALSE;
  135. }
  136. if (pSnap->ssap != 0xAA)
  137. {
  138. return FALSE;
  139. }
  140. if (pSnap->cntl != 0x03)
  141. {
  142. return FALSE;
  143. }
  144. if (pSnap->type != 0x0800)
  145. {
  146. return FALSE;
  147. }
  148. return TRUE;
  149. }
  150. //////////////////////////////////////////////////////////////////////////////
  151. VOID
  152. NormalizeSection (
  153. PBYTE pStream,
  154. PSECTION_HEADER pSection
  155. )
  156. //////////////////////////////////////////////////////////////////////////////
  157. {
  158. PBYTE pb = pStream;
  159. PUSHORT ps = (PUSHORT) pStream;
  160. if (pSection)
  161. {
  162. pSection->table_id = *pb;
  163. pb += 1;
  164. pSection->section_syntax_indicator = (*pb >> 7) & 0x01;
  165. pSection->private_indicator = (*pb >> 6 )& 0x01;
  166. pSection->reserved1 = (*pb >> 4) & 0x03;
  167. ps = (PUSHORT) pb;
  168. pSection->section_length = ES2 (*ps) & 0x0FFF;
  169. pb += 2;
  170. pSection->MAC_address_6 = *pb;
  171. pb += 1;
  172. pSection->MAC_address_5 = *pb;
  173. pb += 1;
  174. pSection->reserved2 = (*pb >> 6) & 0x03;
  175. pSection->payload_scrambling = (*pb >> 4) & 0x3;
  176. pSection->address_scrambling = (*pb >> 2) & 0x3;
  177. pSection->LLC_SNAP_flag = (*pb >> 1) & 0x01;
  178. pSection->current_next_indicator = *pb & 0x01;
  179. pb += 1;
  180. pSection->section_number = *pb;
  181. pb += 1;
  182. pSection->last_section_number = *pb;
  183. pb += 1;
  184. pSection->MAC_address_4 = *pb;
  185. pb += 1;
  186. pSection->MAC_address_3 = *pb;
  187. pb += 1;
  188. pSection->MAC_address_2 = *pb;
  189. pb += 1;
  190. pSection->MAC_address_1 = *pb;
  191. }
  192. return;
  193. }
  194. //////////////////////////////////////////////////////////////////////////////
  195. VOID
  196. NormalizeSnap (
  197. PBYTE pStream,
  198. PLLC_SNAP pSnap
  199. )
  200. //////////////////////////////////////////////////////////////////////////////
  201. {
  202. PUSHORT ps = (PUSHORT) pStream;
  203. if (pSnap)
  204. {
  205. pSnap->type = ES2 (pSnap->type);
  206. }
  207. return;
  208. }
  209. //////////////////////////////////////////////////////////////////////////////
  210. //
  211. //
  212. VOID
  213. DumpDataFormat (
  214. PKSDATAFORMAT pF
  215. );
  216. //////////////////////////////////////////////////////////////////////////////
  217. VOID
  218. MpeGetConnectionProperty(
  219. PHW_STREAM_REQUEST_BLOCK pSrb
  220. )
  221. //////////////////////////////////////////////////////////////////////////////
  222. {
  223. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  224. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  225. ULONG Id = pSPD->Property->Id; // index of the property
  226. ULONG ulStreamNumber = pSrb->StreamObject->StreamNumber;
  227. pSrb->ActualBytesTransferred = 0;
  228. switch (Id)
  229. {
  230. case KSPROPERTY_CONNECTION_ALLOCATORFRAMING:
  231. {
  232. PKSALLOCATOR_FRAMING Framing = (PKSALLOCATOR_FRAMING) pSPD->PropertyInfo;
  233. Framing->RequirementsFlags = KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY |
  234. KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER |
  235. KSALLOCATOR_REQUIREMENTF_PREFERENCES_ONLY;
  236. Framing->PoolType = NonPagedPool;
  237. Framing->Frames = 0;
  238. Framing->FrameSize = 0;
  239. Framing->FileAlignment = 0; // None OR FILE_QUAD_ALIGNMENT-1 OR PAGE_SIZE-1;
  240. Framing->Reserved = 0;
  241. switch (ulStreamNumber)
  242. {
  243. case MPE_IPV4:
  244. Framing->Frames = 16;
  245. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  246. pSrb->Status = STATUS_SUCCESS;
  247. break;
  248. case MPE_STREAM:
  249. Framing->Frames = 32;
  250. Framing->FrameSize = pStream->OpenedFormat.SampleSize;
  251. pSrb->Status = STATUS_SUCCESS;
  252. break;
  253. default:
  254. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  255. break;
  256. }
  257. pSrb->ActualBytesTransferred = sizeof (KSALLOCATOR_FRAMING);
  258. }
  259. break;
  260. default:
  261. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  262. break;
  263. }
  264. return;
  265. }
  266. //////////////////////////////////////////////////////////////////////////////
  267. NTSTATUS
  268. MpeDriverInitialize (
  269. IN PDRIVER_OBJECT DriverObject,
  270. IN PUNICODE_STRING RegistryPath
  271. )
  272. //////////////////////////////////////////////////////////////////////////////
  273. {
  274. NTSTATUS ntStatus = STATUS_SUCCESS;
  275. HW_INITIALIZATION_DATA HwInitData;
  276. UNICODE_STRING DeviceNameString;
  277. UNICODE_STRING SymbolicNameString;
  278. RtlZeroMemory(&HwInitData, sizeof(HwInitData));
  279. HwInitData.HwInitializationDataSize = sizeof(HwInitData);
  280. ////////////////////////////////////////////////////////////////
  281. //
  282. // Setup the stream class dispatch table
  283. //
  284. HwInitData.HwInterrupt = NULL; // HwInterrupt is only for HW devices
  285. HwInitData.HwReceivePacket = CodecReceivePacket;
  286. HwInitData.HwCancelPacket = CodecCancelPacket;
  287. HwInitData.HwRequestTimeoutHandler = CodecTimeoutPacket;
  288. HwInitData.DeviceExtensionSize = sizeof(MPE_FILTER);
  289. HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION);
  290. HwInitData.FilterInstanceExtensionSize = 0;
  291. HwInitData.PerStreamExtensionSize = sizeof(STREAM);
  292. HwInitData.BusMasterDMA = FALSE;
  293. HwInitData.Dma24BitAddresses = FALSE;
  294. HwInitData.BufferAlignment = 3;
  295. HwInitData.TurnOffSynchronization = TRUE;
  296. HwInitData.DmaBufferSize = 0;
  297. ntStatus = StreamClassRegisterAdapter (DriverObject, RegistryPath, &HwInitData);
  298. if (ntStatus != STATUS_SUCCESS)
  299. {
  300. goto ret;
  301. }
  302. ret:
  303. return ntStatus;
  304. }
  305. //
  306. //
  307. //////////////////////////////////////////////////////////////////////////////
  308. BOOLEAN
  309. CodecInitialize (
  310. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  311. )
  312. //////////////////////////////////////////////////////////////////////////////
  313. {
  314. NTSTATUS ntStatus = STATUS_SUCCESS;
  315. BOOLEAN bStatus = FALSE;
  316. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  317. PMPE_FILTER pFilter = (PMPE_FILTER) pConfigInfo->HwDeviceExtension;
  318. //
  319. // Define the default return codes
  320. //
  321. pSrb->Status = STATUS_SUCCESS;
  322. bStatus = TRUE;
  323. //
  324. // Check out init flag so we don't try to init more then once. The Streaming
  325. // Class driver appears to call the init handler several times for some reason.
  326. //
  327. if (pFilter->bInitializationComplete)
  328. {
  329. goto ret;
  330. }
  331. //
  332. // Initialize Statistics block
  333. //
  334. RtlZeroMemory(&pFilter->Stats, sizeof (STATS));
  335. if (pConfigInfo->NumberOfAccessRanges == 0)
  336. {
  337. pConfigInfo->StreamDescriptorSize = sizeof (HW_STREAM_HEADER) +
  338. DRIVER_STREAM_COUNT * sizeof (HW_STREAM_INFORMATION);
  339. }
  340. else
  341. {
  342. pSrb->Status = STATUS_NO_SUCH_DEVICE;
  343. bStatus = FALSE;
  344. goto ret;
  345. }
  346. //
  347. // Create a filter object to represent our context
  348. //
  349. pSrb->Status = CreateFilter (pConfigInfo->ClassDeviceObject->DriverObject, pConfigInfo->ClassDeviceObject, pFilter);
  350. if (pSrb->Status != STATUS_SUCCESS)
  351. {
  352. bStatus = FALSE;
  353. goto ret;
  354. }
  355. pFilter->bInitializationComplete = TRUE;
  356. ret:
  357. return (bStatus);
  358. }
  359. //////////////////////////////////////////////////////////////////////////////
  360. BOOLEAN
  361. CodecUnInitialize (
  362. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  363. )
  364. //////////////////////////////////////////////////////////////////////////////
  365. {
  366. NTSTATUS ntStatus = STATUS_SUCCESS;
  367. BOOLEAN bStatus = FALSE;
  368. PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
  369. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  370. PSTREAM pStream = NULL;
  371. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Codec Unitialize called\n"));
  372. if (pSrb->StreamObject != NULL)
  373. {
  374. pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  375. }
  376. if (pStream)
  377. {
  378. //
  379. // Clean up the NAB_STREAM QUEUE used for deframing
  380. //
  381. //$$BUG
  382. //DeleteNabStreamQueue (pFilter);
  383. //
  384. // Clean up any queues we have and complete any outstanding SRB's
  385. //
  386. while (QueueRemove (&pSrb, &pFilter->StreamUserSpinLock, &pFilter->StreamContxList))
  387. {
  388. pSrb->Status = STATUS_CANCELLED;
  389. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  390. TEST_DEBUG( TEST_DBG_SRB, ("MPE 5Completed SRB %08X\n", pSrb));
  391. }
  392. while (QueueRemove (&pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  393. {
  394. pSrb->Status = STATUS_CANCELLED;
  395. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  396. TEST_DEBUG( TEST_DBG_SRB, ("MPE 6Completed SRB %08X\n", pSrb));
  397. }
  398. while (QueueRemove (&pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  399. {
  400. pSrb->Status = STATUS_CANCELLED;
  401. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  402. TEST_DEBUG( TEST_DBG_SRB, ("MPE 7Completed SRB %08X\n", pSrb));
  403. }
  404. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  405. {
  406. pSrb->Status = STATUS_CANCELLED;
  407. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  408. TEST_DEBUG( TEST_DBG_SRB, ("MPE 8Completed SRB %08X\n", pSrb));
  409. }
  410. }
  411. while (QueueRemove (&pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  412. {
  413. pSrb->Status = STATUS_CANCELLED;
  414. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  415. TEST_DEBUG( TEST_DBG_RECV, ("MPE 9Completed SRB %08X\n", pSrb));
  416. }
  417. bStatus = TRUE;
  418. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Codec Unitialize completed\n"));
  419. return (bStatus);
  420. }
  421. //////////////////////////////////////////////////////////////////////////////
  422. VOID
  423. CodecStreamInfo (
  424. PHW_STREAM_REQUEST_BLOCK pSrb
  425. )
  426. //////////////////////////////////////////////////////////////////////////////
  427. {
  428. int j;
  429. PMPE_FILTER pFilter =
  430. ((PMPE_FILTER)pSrb->HwDeviceExtension);
  431. //
  432. // pick up the pointer to header which preceeds the stream info structs
  433. //
  434. PHW_STREAM_HEADER pstrhdr =
  435. (PHW_STREAM_HEADER)&(pSrb->CommandData.StreamBuffer->StreamHeader);
  436. //
  437. // pick up the pointer to the array of stream information data structures
  438. //
  439. PHW_STREAM_INFORMATION pstrinfo =
  440. (PHW_STREAM_INFORMATION)&(pSrb->CommandData.StreamBuffer->StreamInfo);
  441. //
  442. // Set the header
  443. //
  444. StreamHeader.NumDevPropArrayEntries = 0;
  445. StreamHeader.DevicePropertiesArray = (PKSPROPERTY_SET)NULL;
  446. *pstrhdr = StreamHeader;
  447. //
  448. // stuff the contents of each HW_STREAM_INFORMATION struct
  449. //
  450. for (j = 0; j < DRIVER_STREAM_COUNT; j++)
  451. {
  452. *pstrinfo++ = Streams[j].hwStreamInfo;
  453. }
  454. pSrb->Status = STATUS_SUCCESS;
  455. }
  456. //////////////////////////////////////////////////////////////////////////////
  457. VOID
  458. STREAMAPI
  459. CodecCancelPacket(
  460. PHW_STREAM_REQUEST_BLOCK pSrb
  461. )
  462. //////////////////////////////////////////////////////////////////////////////
  463. {
  464. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  465. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  466. //
  467. // Check whether the SRB to cancel is in use by this stream
  468. //
  469. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: CancelPacket Called\n"));
  470. //
  471. //$$BUG
  472. //
  473. //CancelNabStreamSrb (pFilter, pSrb);
  474. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  475. {
  476. pSrb->Status = STATUS_CANCELLED;
  477. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  478. TEST_DEBUG( TEST_DBG_SRB, ("MPE 10Completed SRB %08X\n", pSrb));
  479. return;
  480. }
  481. if (QueueRemoveSpecific (pSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  482. {
  483. pSrb->Status = STATUS_CANCELLED;
  484. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  485. TEST_DEBUG( TEST_DBG_SRB, ("MPE 11Completed SRB %08X\n", pSrb));
  486. return;
  487. }
  488. if (QueueRemoveSpecific (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  489. {
  490. pSrb->Status = STATUS_CANCELLED;
  491. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  492. TEST_DEBUG( TEST_DBG_SRB, ("MPE 12Completed SRB %08X\n", pSrb));
  493. return;
  494. }
  495. if (QueueRemoveSpecific (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue))
  496. {
  497. pSrb->Status = STATUS_CANCELLED;
  498. StreamClassDeviceNotification (DeviceRequestComplete, pSrb->StreamObject, pSrb);
  499. TEST_DEBUG( TEST_DBG_SRB, ("MPE 13Completed SRB %08X\n", pSrb));
  500. return;
  501. }
  502. return;
  503. }
  504. //////////////////////////////////////////////////////////////////////////////
  505. VOID
  506. STREAMAPI
  507. CodecTimeoutPacket(
  508. PHW_STREAM_REQUEST_BLOCK pSrb
  509. )
  510. //////////////////////////////////////////////////////////////////////////////
  511. {
  512. //
  513. // if we timeout while playing, then we need to consider this
  514. // condition an error, and reset the hardware, and reset everything
  515. // as well as cancelling this and all requests
  516. //
  517. //
  518. // if we are not playing, and this is a CTRL request, we still
  519. // need to reset everything as well as cancelling this and all requests
  520. //
  521. //
  522. // if this is a data request, and the device is paused, we probably have
  523. // run out of data buffer, and need more time, so just reset the timer,
  524. // and let the packet continue
  525. //
  526. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: TimeoutPacket Called\n"));
  527. pSrb->TimeoutCounter = 0;
  528. return;
  529. }
  530. //////////////////////////////////////////////////////////////////////////////
  531. VOID
  532. STREAMAPI
  533. CodecReceivePacket(
  534. IN PHW_STREAM_REQUEST_BLOCK pSrb
  535. )
  536. //////////////////////////////////////////////////////////////////////////////
  537. {
  538. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  539. //
  540. // Make sure queue & SL initted
  541. //
  542. if (!pFilter->bAdapterQueueInitialized)
  543. {
  544. InitializeListHead (&pFilter->AdapterSRBQueue);
  545. KeInitializeSpinLock (&pFilter->AdapterSRBSpinLock);
  546. pFilter->bAdapterQueueInitialized = TRUE;
  547. }
  548. //
  549. // Assume success
  550. //
  551. pSrb->Status = STATUS_SUCCESS;
  552. //
  553. // determine the type of packet.
  554. //
  555. QueueAdd (pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue);
  556. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing SRB %08X\n", pSrb));
  557. while (QueueRemove( &pSrb, &pFilter->AdapterSRBSpinLock, &pFilter->AdapterSRBQueue ))
  558. {
  559. switch (pSrb->Command)
  560. {
  561. case SRB_INITIALIZE_DEVICE:
  562. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_INITIALIZE Command\n"));
  563. CodecInitialize(pSrb);
  564. break;
  565. case SRB_UNINITIALIZE_DEVICE:
  566. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNINITIALIZE Command\n"));
  567. CodecUnInitialize(pSrb);
  568. break;
  569. case SRB_INITIALIZATION_COMPLETE:
  570. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_INITIALIZE_COMPLETE Command\n"));
  571. pSrb->Status = STATUS_SUCCESS;
  572. break;
  573. case SRB_OPEN_STREAM:
  574. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_OPEN_STREAM Command\n"));
  575. OpenStream (pSrb);
  576. break;
  577. case SRB_CLOSE_STREAM:
  578. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CLOSE_STREAM Command\n"));
  579. CloseStream (pSrb);
  580. break;
  581. case SRB_GET_STREAM_INFO:
  582. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_STREAM_INFO Command\n"));
  583. CodecStreamInfo (pSrb);
  584. break;
  585. case SRB_GET_DATA_INTERSECTION:
  586. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_DATA_INTERSECTION Command\n"));
  587. //
  588. // Compare our stream formats. NOTE, the compare functions sets the SRB
  589. // status fields
  590. //
  591. CompareStreamFormat (pSrb);
  592. break;
  593. case SRB_OPEN_DEVICE_INSTANCE:
  594. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_OPEN_DEVICE_INSTANCE Command\n"));
  595. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  596. break;
  597. case SRB_CLOSE_DEVICE_INSTANCE:
  598. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CLOSE_DEVICE_INSTANCE Command\n"));
  599. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  600. break;
  601. case SRB_UNKNOWN_DEVICE_COMMAND:
  602. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNKNOWN_DEVICE Command\n"));
  603. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  604. break;
  605. case SRB_CHANGE_POWER_STATE:
  606. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_CHANGE_POWER_STATE Command\n"));
  607. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  608. break;
  609. case SRB_GET_DEVICE_PROPERTY:
  610. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_GET_DEVICE_PROPERTY Command\n"));
  611. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  612. break;
  613. case SRB_SET_DEVICE_PROPERTY:
  614. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_SET_DEVICE_PROPERTY Command\n"));
  615. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  616. break;
  617. case SRB_UNKNOWN_STREAM_COMMAND:
  618. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_UNKNOWN Command\n"));
  619. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  620. break;
  621. default:
  622. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_DEFAULT Command\n"));
  623. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  624. break;
  625. };
  626. //
  627. // NOTE:
  628. //
  629. // All of the commands that we do, or do not understand can all be completed
  630. // syncronously at this point, so we can use a common callback routine here.
  631. // If any of the above commands require asyncronous processing, this will
  632. // have to change
  633. //
  634. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB Status returned: %08X\n", pSrb->Status));
  635. StreamClassDeviceNotification (DeviceRequestComplete, pFilter, pSrb);
  636. TEST_DEBUG( TEST_DBG_SRB, ("MPE 14Completed SRB %08X\n", pSrb));
  637. }
  638. }
  639. //////////////////////////////////////////////////////////////////////////////
  640. BOOL STREAMAPI
  641. QueueAdd (
  642. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  643. IN PKSPIN_LOCK pQueueSpinLock,
  644. IN PLIST_ENTRY pQueue
  645. )
  646. //////////////////////////////////////////////////////////////////////////////
  647. {
  648. KIRQL Irql;
  649. PSRB_EXTENSION pSrbExtension;
  650. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  651. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  652. pSrbExtension->pSrb = pSrb;
  653. InsertTailList( pQueue, &pSrbExtension->ListEntry );
  654. KeReleaseSpinLock( pQueueSpinLock, Irql );
  655. return TRUE;
  656. }
  657. //////////////////////////////////////////////////////////////////////////////
  658. BOOL STREAMAPI
  659. QueuePush (
  660. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  661. IN PKSPIN_LOCK pQueueSpinLock,
  662. IN PLIST_ENTRY pQueue
  663. )
  664. //////////////////////////////////////////////////////////////////////////////
  665. {
  666. KIRQL Irql;
  667. PSRB_EXTENSION pSrbExtension;
  668. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  669. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  670. pSrbExtension->pSrb = pSrb;
  671. InsertHeadList( pQueue, &pSrbExtension->ListEntry );
  672. KeReleaseSpinLock( pQueueSpinLock, Irql );
  673. return TRUE;
  674. }
  675. //////////////////////////////////////////////////////////////////////////////
  676. BOOL STREAMAPI
  677. QueueAddIfNotEmpty (
  678. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  679. IN PKSPIN_LOCK pQueueSpinLock,
  680. IN PLIST_ENTRY pQueue
  681. )
  682. //////////////////////////////////////////////////////////////////////////////
  683. {
  684. KIRQL Irql;
  685. PSRB_EXTENSION pSrbExtension;
  686. BOOL bAddedSRB = FALSE;
  687. pSrbExtension = ( PSRB_EXTENSION )pSrb->SRBExtension;
  688. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  689. if( !IsListEmpty( pQueue ))
  690. {
  691. pSrbExtension->pSrb = pSrb;
  692. InsertTailList (pQueue, &pSrbExtension->ListEntry );
  693. bAddedSRB = TRUE;
  694. }
  695. KeReleaseSpinLock( pQueueSpinLock, Irql );
  696. return bAddedSRB;
  697. }
  698. //////////////////////////////////////////////////////////////////////////////
  699. BOOL STREAMAPI
  700. QueueRemove (
  701. IN OUT PHW_STREAM_REQUEST_BLOCK * pSrb,
  702. IN PKSPIN_LOCK pQueueSpinLock,
  703. IN PLIST_ENTRY pQueue
  704. )
  705. //////////////////////////////////////////////////////////////////////////////
  706. {
  707. KIRQL Irql;
  708. BOOL bRemovedSRB = FALSE;
  709. KeAcquireSpinLock (pQueueSpinLock, &Irql);
  710. *pSrb = (PHW_STREAM_REQUEST_BLOCK) NULL;
  711. if( !IsListEmpty( pQueue ))
  712. {
  713. PHW_STREAM_REQUEST_BLOCK *pCurrentSrb = NULL;
  714. PUCHAR Ptr = (PUCHAR) RemoveHeadList(pQueue);
  715. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK *) (((PUCHAR)Ptr) + sizeof (LIST_ENTRY));
  716. *pSrb = *pCurrentSrb;
  717. bRemovedSRB = TRUE;
  718. }
  719. KeReleaseSpinLock (pQueueSpinLock, Irql);
  720. return bRemovedSRB;
  721. }
  722. //////////////////////////////////////////////////////////////////////////////
  723. BOOL STREAMAPI
  724. QueueRemoveSpecific (
  725. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  726. IN PKSPIN_LOCK pQueueSpinLock,
  727. IN PLIST_ENTRY pQueue
  728. )
  729. //////////////////////////////////////////////////////////////////////////////
  730. {
  731. KIRQL Irql;
  732. BOOL bRemovedSRB = FALSE;
  733. PLIST_ENTRY pCurrentEntry;
  734. PHW_STREAM_REQUEST_BLOCK * pCurrentSrb;
  735. KeAcquireSpinLock( pQueueSpinLock, &Irql );
  736. if( !IsListEmpty( pQueue ))
  737. {
  738. pCurrentEntry = pQueue->Flink;
  739. while ((pCurrentEntry != pQueue ) && !bRemovedSRB)
  740. {
  741. pCurrentSrb = (PHW_STREAM_REQUEST_BLOCK * ) ((( PUCHAR )pCurrentEntry ) + sizeof( LIST_ENTRY ));
  742. if( *pCurrentSrb == pSrb )
  743. {
  744. RemoveEntryList( pCurrentEntry );
  745. bRemovedSRB = TRUE;
  746. }
  747. pCurrentEntry = pCurrentEntry->Flink;
  748. }
  749. }
  750. KeReleaseSpinLock( pQueueSpinLock, Irql );
  751. return bRemovedSRB;
  752. }
  753. //////////////////////////////////////////////////////////////////////////////
  754. NTSTATUS
  755. StreamIPIndicateEvent (
  756. PVOID pvEvent
  757. )
  758. //////////////////////////////////////////////////////////////////////////////
  759. {
  760. return STATUS_NOT_IMPLEMENTED;
  761. }
  762. //////////////////////////////////////////////////////////////////////////////
  763. BOOL
  764. CompareGUIDsAndFormatSize(
  765. IN PKSDATARANGE pDataRange1,
  766. IN PKSDATARANGE pDataRange2,
  767. BOOLEAN bCheckSize
  768. )
  769. //////////////////////////////////////////////////////////////////////////////
  770. {
  771. BOOL bResult = FALSE;
  772. if ( IsEqualGUID(&pDataRange1->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  773. IsEqualGUID(&pDataRange2->MajorFormat, &KSDATAFORMAT_TYPE_WILDCARD) ||
  774. IsEqualGUID(&pDataRange1->MajorFormat, &pDataRange2->MajorFormat) )
  775. {
  776. if ( IsEqualGUID(&pDataRange1->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  777. IsEqualGUID(&pDataRange2->SubFormat, &KSDATAFORMAT_SUBTYPE_WILDCARD) ||
  778. IsEqualGUID(&pDataRange1->SubFormat, &pDataRange2->SubFormat) )
  779. {
  780. if ( IsEqualGUID(&pDataRange1->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  781. IsEqualGUID(&pDataRange2->Specifier, &KSDATAFORMAT_SPECIFIER_WILDCARD) ||
  782. IsEqualGUID(&pDataRange1->Specifier, &pDataRange2->Specifier) )
  783. {
  784. if ( !bCheckSize || pDataRange1->FormatSize == pDataRange2->FormatSize)
  785. {
  786. bResult = TRUE;
  787. }
  788. }
  789. }
  790. }
  791. return bResult;
  792. }
  793. //////////////////////////////////////////////////////////////////////////////
  794. VOID
  795. DumpDataFormat (
  796. PKSDATAFORMAT pF
  797. )
  798. //////////////////////////////////////////////////////////////////////////////
  799. {
  800. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DATA Format\n"));
  801. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Format Size: %08X\n", pF->FormatSize));
  802. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Flags: %08X\n", pF->Flags));
  803. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SampleSize: %08X\n", pF->SampleSize));
  804. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Reserved: %08X\n", pF->Reserved));
  805. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Major GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  806. pF->MajorFormat.Data1,
  807. pF->MajorFormat.Data2,
  808. pF->MajorFormat.Data3,
  809. pF->MajorFormat.Data4[0],
  810. pF->MajorFormat.Data4[1],
  811. pF->MajorFormat.Data4[2],
  812. pF->MajorFormat.Data4[3],
  813. pF->MajorFormat.Data4[4],
  814. pF->MajorFormat.Data4[5],
  815. pF->MajorFormat.Data4[6],
  816. pF->MajorFormat.Data4[7]
  817. ));
  818. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Sub GUID: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  819. pF->SubFormat.Data1,
  820. pF->SubFormat.Data2,
  821. pF->SubFormat.Data3,
  822. pF->SubFormat.Data4[0],
  823. pF->SubFormat.Data4[1],
  824. pF->SubFormat.Data4[2],
  825. pF->SubFormat.Data4[3],
  826. pF->SubFormat.Data4[4],
  827. pF->SubFormat.Data4[5],
  828. pF->SubFormat.Data4[6],
  829. pF->SubFormat.Data4[7]
  830. ));
  831. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Specifier: %08X %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X\n",
  832. pF->Specifier.Data1,
  833. pF->Specifier.Data2,
  834. pF->Specifier.Data3,
  835. pF->Specifier.Data4[0],
  836. pF->Specifier.Data4[1],
  837. pF->Specifier.Data4[2],
  838. pF->Specifier.Data4[3],
  839. pF->Specifier.Data4[4],
  840. pF->Specifier.Data4[5],
  841. pF->Specifier.Data4[6],
  842. pF->Specifier.Data4[7]
  843. ));
  844. TEST_DEBUG (TEST_DBG_TRACE, ("\n"));
  845. }
  846. //////////////////////////////////////////////////////////////////////////////
  847. BOOL
  848. CompareStreamFormat (
  849. IN PHW_STREAM_REQUEST_BLOCK pSrb
  850. )
  851. //////////////////////////////////////////////////////////////////////////////
  852. {
  853. BOOL bStatus = FALSE;
  854. PSTREAM_DATA_INTERSECT_INFO pIntersectInfo;
  855. PKSDATARANGE pDataRange1;
  856. PKSDATARANGE pDataRange2;
  857. ULONG FormatSize = 0;
  858. ULONG ulStreamNumber;
  859. ULONG j;
  860. ULONG ulNumberOfFormatArrayEntries;
  861. PKSDATAFORMAT *pAvailableFormats;
  862. pIntersectInfo = pSrb->CommandData.IntersectInfo;
  863. ulStreamNumber = pIntersectInfo->StreamNumber;
  864. pSrb->ActualBytesTransferred = 0;
  865. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Comparing Stream Formats\n"));
  866. //
  867. // Check that the stream number is valid
  868. //
  869. if (ulStreamNumber < DRIVER_STREAM_COUNT)
  870. {
  871. ulNumberOfFormatArrayEntries = Streams[ulStreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  872. //
  873. // Get the pointer to the array of available formats
  874. //
  875. pAvailableFormats = Streams[ulStreamNumber].hwStreamInfo.StreamFormatsArray;
  876. //
  877. // Walk the formats supported by the stream searching for a match
  878. // of the three GUIDs which together define a DATARANGE
  879. //
  880. for (pDataRange1 = pIntersectInfo->DataRange, j = 0;
  881. j < ulNumberOfFormatArrayEntries;
  882. j++, pAvailableFormats++)
  883. {
  884. bStatus = FALSE;
  885. pSrb->Status = STATUS_UNSUCCESSFUL;
  886. pDataRange2 = *pAvailableFormats;
  887. if (CompareGUIDsAndFormatSize (pDataRange1, pDataRange2, TRUE))
  888. {
  889. ULONG ulFormatSize = pDataRange2->FormatSize;
  890. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Formats compare\n"));
  891. //
  892. // Is the caller trying to get the format, or the size of the format?
  893. //
  894. if (pIntersectInfo->SizeOfDataFormatBuffer == sizeof (ULONG))
  895. {
  896. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Returning Stream Format size\n"));
  897. *(PULONG) pIntersectInfo->DataFormatBuffer = ulFormatSize;
  898. pSrb->ActualBytesTransferred = sizeof (ULONG);
  899. pSrb->Status = STATUS_SUCCESS;
  900. bStatus = TRUE;
  901. }
  902. else
  903. {
  904. //
  905. // Verify that there is enough room in the supplied buffer for the whole thing
  906. //
  907. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  908. bStatus = FALSE;
  909. if (pIntersectInfo->SizeOfDataFormatBuffer >= ulFormatSize)
  910. {
  911. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Returning Stream Format\n"));
  912. RtlCopyMemory (pIntersectInfo->DataFormatBuffer, pDataRange2, ulFormatSize);
  913. pSrb->ActualBytesTransferred = ulFormatSize;
  914. pSrb->Status = STATUS_SUCCESS;
  915. bStatus = TRUE;
  916. }
  917. else
  918. {
  919. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Format return buffer too small\n"));
  920. }
  921. }
  922. break;
  923. }
  924. else
  925. {
  926. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Stream Formats DO NOT compare\n"));
  927. }
  928. }
  929. if ( j >= ulNumberOfFormatArrayEntries )
  930. {
  931. pSrb->ActualBytesTransferred = 0;
  932. pSrb->Status = STATUS_UNSUCCESSFUL;
  933. bStatus = FALSE;
  934. }
  935. }
  936. else
  937. {
  938. pSrb->ActualBytesTransferred = 0;
  939. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  940. bStatus = FALSE;
  941. }
  942. return bStatus;
  943. }
  944. //////////////////////////////////////////////////////////////////////////////
  945. VOID
  946. CloseStream (
  947. PHW_STREAM_REQUEST_BLOCK pSrb
  948. )
  949. //////////////////////////////////////////////////////////////////////////////
  950. {
  951. //
  952. // the stream extension structure is allocated by the stream class driver
  953. //
  954. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  955. PMPE_FILTER pFilter = (PMPE_FILTER)pSrb->HwDeviceExtension;
  956. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  957. ULONG ulStreamInstance = pStream->ulStreamInstance;
  958. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  959. //
  960. // check that the stream index requested isn't too high
  961. // or that the maximum number of instances hasn't been exceeded
  962. //
  963. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  964. {
  965. //
  966. // Flush the stream data queue
  967. //
  968. while (QueueRemove( &pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  969. {
  970. pCurrentSrb->Status = STATUS_CANCELLED;
  971. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  972. TEST_DEBUG( TEST_DBG_SRB, ("MPE 15Completed SRB %08X\n", pCurrentSrb));
  973. }
  974. //
  975. // Flush the stream data queue
  976. //
  977. while (QueueRemove( &pCurrentSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  978. {
  979. pCurrentSrb->Status = STATUS_CANCELLED;
  980. StreamClassStreamNotification( StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  981. TEST_DEBUG( TEST_DBG_SRB, ("MPE 16Completed SRB %08X\n", pCurrentSrb));
  982. }
  983. //
  984. // Flush the stream control queue
  985. //
  986. while (QueueRemove( &pCurrentSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  987. {
  988. pCurrentSrb->Status = STATUS_CANCELLED;
  989. StreamClassStreamNotification (StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  990. TEST_DEBUG( TEST_DBG_SRB, ("MPE 17Completed SRB %08X\n", pCurrentSrb));
  991. }
  992. //
  993. // Clear this streams spot in the filters stream array
  994. //
  995. pFilter->pStream[ulStreamNumber][ulStreamInstance] = NULL;
  996. //
  997. // decrement the stream instance count for this filter
  998. //
  999. pFilter->ulActualInstances[ulStreamNumber]--;
  1000. //
  1001. // Reset the stream state to stopped
  1002. //
  1003. pStream->KSState = KSSTATE_STOP;
  1004. //
  1005. //
  1006. //
  1007. pStream->hMasterClock = NULL;
  1008. //
  1009. // Cleanup the streams transform buffer
  1010. //
  1011. if (pStream->pTransformBuffer)
  1012. {
  1013. ExFreePool (pStream->pTransformBuffer);
  1014. pStream->pTransformBuffer = NULL;
  1015. }
  1016. //
  1017. // Reset the stream extension blob
  1018. //
  1019. RtlZeroMemory(pStream, sizeof (STREAM));
  1020. pSrb->Status = STATUS_SUCCESS;
  1021. }
  1022. else
  1023. {
  1024. pSrb->Status = STATUS_INVALID_PARAMETER;
  1025. }
  1026. }
  1027. //////////////////////////////////////////////////////////////////////////////
  1028. VOID
  1029. OpenStream (
  1030. PHW_STREAM_REQUEST_BLOCK pSrb
  1031. )
  1032. //////////////////////////////////////////////////////////////////////////////
  1033. {
  1034. //
  1035. // the stream extension structure is allocated by the stream class driver
  1036. //
  1037. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1038. PMPE_FILTER pFilter = ((PMPE_FILTER)pSrb->HwDeviceExtension);
  1039. ULONG ulStreamNumber = (ULONG) pSrb->StreamObject->StreamNumber;
  1040. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT)pSrb->CommandData.OpenFormat;
  1041. //
  1042. // Initialize the next stream life check time.
  1043. //
  1044. KeQuerySystemTime( &pFilter->liLastTimeChecked );
  1045. //
  1046. // check that the stream index requested isn't too high
  1047. // or that the maximum number of instances hasn't been exceeded
  1048. //
  1049. if (ulStreamNumber < DRIVER_STREAM_COUNT )
  1050. {
  1051. ULONG ulStreamInstance;
  1052. ULONG ulMaxInstances = Streams[ulStreamNumber].hwStreamInfo.NumberOfPossibleInstances;
  1053. //
  1054. // Search for next open slot
  1055. //
  1056. for (ulStreamInstance = 0; ulStreamInstance < ulMaxInstances; ++ulStreamInstance)
  1057. {
  1058. if (pFilter->pStream[ulStreamNumber][ulStreamInstance] == NULL)
  1059. {
  1060. break;
  1061. }
  1062. }
  1063. if (ulStreamInstance < ulMaxInstances)
  1064. {
  1065. if (VerifyFormat(pKSDataFormat, ulStreamNumber, &pStream->MatchedFormat))
  1066. {
  1067. //
  1068. // Initialize Data queues and SpinLocks
  1069. //
  1070. InitializeListHead(&pFilter->StreamControlQueue);
  1071. KeInitializeSpinLock(&pFilter->StreamControlSpinLock);
  1072. InitializeListHead(&pFilter->StreamDataQueue);
  1073. KeInitializeSpinLock(&pFilter->StreamDataSpinLock);
  1074. InitializeListHead(&pFilter->IpV4StreamDataQueue);
  1075. KeInitializeSpinLock(&pFilter->IpV4StreamDataSpinLock);
  1076. InitializeListHead(&pFilter->StreamContxList);
  1077. KeInitializeSpinLock(&pFilter->StreamUserSpinLock);
  1078. //
  1079. // Maintain an array of all the StreamEx structures in the HwDevExt
  1080. // so that we can reference IRPs from any stream
  1081. //
  1082. pFilter->pStream[ulStreamNumber][ulStreamInstance] = pStream;
  1083. //
  1084. // Save the Stream Format in the Stream Extension as well.
  1085. //
  1086. pStream->OpenedFormat = *pKSDataFormat;
  1087. //
  1088. // Set up pointers to the handlers for the stream data and control handlers
  1089. //
  1090. pSrb->StreamObject->ReceiveDataPacket =
  1091. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveDataPacket;
  1092. pSrb->StreamObject->ReceiveControlPacket =
  1093. (PVOID) Streams[ulStreamNumber].hwStreamObject.ReceiveControlPacket;
  1094. //
  1095. // The DMA flag must be set when the device will be performing DMA directly
  1096. // to the data buffer addresses passed in to the ReceiveDataPacket routines.
  1097. //
  1098. pSrb->StreamObject->Dma = Streams[ulStreamNumber].hwStreamObject.Dma;
  1099. //
  1100. // The PIO flag must be set when the mini driver will be accessing the data
  1101. // buffers passed in using logical addressing
  1102. //
  1103. pSrb->StreamObject->Pio = Streams[ulStreamNumber].hwStreamObject.Pio;
  1104. pSrb->StreamObject->Allocator = Streams[ulStreamNumber].hwStreamObject.Allocator;
  1105. //
  1106. // How many extra bytes will be passed up from the driver for each frame?
  1107. //
  1108. pSrb->StreamObject->StreamHeaderMediaSpecific =
  1109. Streams[ulStreamNumber].hwStreamObject.StreamHeaderMediaSpecific;
  1110. pSrb->StreamObject->StreamHeaderWorkspace =
  1111. Streams[ulStreamNumber].hwStreamObject.StreamHeaderWorkspace;
  1112. //
  1113. // Indicate the clock support available on this stream
  1114. //
  1115. pSrb->StreamObject->HwClockObject =
  1116. Streams[ulStreamNumber].hwStreamObject.HwClockObject;
  1117. //
  1118. // Increment the instance count on this stream
  1119. //
  1120. pStream->ulStreamInstance = ulStreamInstance;
  1121. pFilter->ulActualInstances[ulStreamNumber]++;
  1122. //
  1123. // Allocate a transform buffer
  1124. //
  1125. pStream->pTransformBuffer = ExAllocatePool (NonPagedPool, sizeof(SECTION_HEADER) + 4096);
  1126. if (pStream->pTransformBuffer == NULL)
  1127. {
  1128. pSrb->Status = STATUS_NO_MEMORY;
  1129. return;
  1130. }
  1131. RtlZeroMemory (pStream->pTransformBuffer, sizeof(SECTION_HEADER) + 4096);
  1132. //
  1133. // Initalize persistent pointer to output buffer to NULL
  1134. //
  1135. pStream->pOut = NULL;
  1136. //
  1137. // Initialize the exepected section number to zero
  1138. //
  1139. pStream->bExpectedSection = 0;
  1140. //
  1141. // Retain a private copy of the HwDevExt and StreamObject in the stream extension
  1142. // so we can use a timer
  1143. //
  1144. pStream->pFilter = pFilter; // For timer use
  1145. pStream->pStreamObject = pSrb->StreamObject; // For timer use
  1146. pSrb->Status = STATUS_SUCCESS;
  1147. }
  1148. else
  1149. {
  1150. pSrb->Status = STATUS_INVALID_PARAMETER;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. pSrb->Status = STATUS_INVALID_PARAMETER;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. pSrb->Status = STATUS_INVALID_PARAMETER;
  1161. }
  1162. }
  1163. //////////////////////////////////////////////////////////////////////////////
  1164. BOOLEAN
  1165. VerifyFormat(
  1166. IN KSDATAFORMAT *pKSDataFormat,
  1167. UINT StreamNumber,
  1168. PKSDATARANGE pMatchedFormat
  1169. )
  1170. //////////////////////////////////////////////////////////////////////////////
  1171. {
  1172. BOOLEAN bResult = FALSE;
  1173. ULONG FormatCount = 0;
  1174. PKS_DATARANGE_VIDEO pThisFormat = NULL;
  1175. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Verify Format\n"));
  1176. for (FormatCount = 0; !bResult && FormatCount < Streams[StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  1177. FormatCount++ )
  1178. {
  1179. pThisFormat = (PKS_DATARANGE_VIDEO) Streams [StreamNumber].hwStreamInfo.StreamFormatsArray [FormatCount];
  1180. if (CompareGUIDsAndFormatSize( pKSDataFormat, &pThisFormat->DataRange, FALSE ) )
  1181. {
  1182. bResult = FALSE;
  1183. if (pThisFormat->DataRange.SampleSize >= pKSDataFormat->SampleSize)
  1184. {
  1185. bResult = TRUE;
  1186. }
  1187. else
  1188. {
  1189. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: VerifyFormat: Data range Sample Sizes don't match\n"));
  1190. }
  1191. }
  1192. }
  1193. if (bResult == TRUE && pMatchedFormat)
  1194. {
  1195. *pMatchedFormat = pThisFormat->DataRange;
  1196. }
  1197. return bResult;
  1198. }
  1199. ///////////////////////////////////////////////////////////////////////////////////////
  1200. NTSTATUS
  1201. GetOutputBuffer (
  1202. PMPE_FILTER pFilter,
  1203. PHW_STREAM_REQUEST_BLOCK *ppSrb,
  1204. PUCHAR *ppBuffer,
  1205. PULONG pulSize
  1206. )
  1207. ///////////////////////////////////////////////////////////////////////////////////////
  1208. {
  1209. NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  1210. PKSSTREAM_HEADER pStreamHdr = NULL;
  1211. PHW_STREAM_REQUEST_BLOCK pSrb = NULL;
  1212. if (QueueRemove( &pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1213. {
  1214. pStreamHdr = pSrb->CommandData.DataBufferArray;
  1215. *ppSrb = pSrb;
  1216. *ppBuffer = pStreamHdr->Data;
  1217. *pulSize = pStreamHdr->FrameExtent;
  1218. status = STATUS_SUCCESS;
  1219. }
  1220. return status;
  1221. }
  1222. //////////////////////////////////////////////////////////////////////////////
  1223. VOID
  1224. STREAMAPI
  1225. ReceiveDataPacket (
  1226. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1227. )
  1228. //////////////////////////////////////////////////////////////////////////////
  1229. {
  1230. PMPE_FILTER pFilter = (PMPE_FILTER) pSrb->HwDeviceExtension;
  1231. PSTREAM pStream = (PSTREAM)pSrb->StreamObject->HwStreamExtension;
  1232. int iStream = (int) pSrb->StreamObject->StreamNumber;
  1233. PKSSTREAM_HEADER pStreamHdr = pSrb->CommandData.DataBufferArray;
  1234. PKSDATAFORMAT pKSDataFormat = (PKSDATAFORMAT) &pStream->MatchedFormat;
  1235. ULONG ul = 0;
  1236. PHW_STREAM_REQUEST_BLOCK pOutSrb = NULL;
  1237. SECTION_HEADER Section = {0};
  1238. PSECTION_HEADER pSection = NULL;
  1239. PUCHAR pIn = NULL;
  1240. PLLC_SNAP pSnap = NULL;
  1241. ULONG ulSize = 0;
  1242. ULONG ulLength = 0;
  1243. PHEADER_IP pIP = NULL;
  1244. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called\n"));
  1245. //
  1246. // Default to success, disable timeouts
  1247. //
  1248. pSrb->TimeoutCounter = 0;
  1249. pSrb->Status = STATUS_SUCCESS;
  1250. //
  1251. // Check for last buffer
  1252. //
  1253. if (pStreamHdr->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM)
  1254. {
  1255. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet is LAST PACKET\n"));
  1256. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1257. TEST_DEBUG( TEST_DBG_SRB, ("MPE 18Completed SRB %08X\n", pSrb));
  1258. return;
  1259. }
  1260. if (pStreamHdr->OptionsFlags != 0)
  1261. {
  1262. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: OptionsFlags: %08X\n", pStreamHdr->OptionsFlags));
  1263. }
  1264. //
  1265. // determine the type of packet.
  1266. //
  1267. switch (pSrb->Command)
  1268. {
  1269. case SRB_WRITE_DATA:
  1270. if (pStream->KSState == KSSTATE_STOP)
  1271. {
  1272. pSrb->Status = STATUS_SUCCESS;
  1273. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_WRITE STOP SRB Status returned: %08X\n", pSrb->Status));
  1274. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1275. TEST_DEBUG( TEST_DBG_SRB, ("MPE 19Completed SRB %08X\n", pSrb));
  1276. break;
  1277. }
  1278. //
  1279. // Update the total number of packets written statistic
  1280. //
  1281. pFilter->Stats.ulTotalSectionsWritten += 1;
  1282. //
  1283. // Handle data input, output requests differently.
  1284. //
  1285. switch (iStream)
  1286. {
  1287. //
  1288. // Frame input stream
  1289. //
  1290. case MPE_STREAM:
  1291. {
  1292. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1293. ULONG ulSkip = 0;
  1294. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler - SRB_WRITE - MPE_STREAM\n"));
  1295. //
  1296. // Initialize SRB Status to success
  1297. //
  1298. pSrb->Status = STATUS_SUCCESS;
  1299. //
  1300. // copy the contents of all buffers into one big buffer
  1301. //
  1302. ASSERT( ulBuffers == 1);
  1303. {
  1304. //ASSERT( pStreamHdr);
  1305. //ASSERT( pStreamHdr->DataUsed <= (sizeof(SECTION_HEADER) + 4096));
  1306. if ( pStreamHdr
  1307. && (pStreamHdr->DataUsed <= (sizeof(SECTION_HEADER) + 4096))
  1308. )
  1309. {
  1310. // Copy the data
  1311. RtlCopyMemory (pStream->pTransformBuffer,
  1312. pStreamHdr->Data,
  1313. pStreamHdr->DataUsed
  1314. );
  1315. }
  1316. else
  1317. {
  1318. pFilter->Stats.ulTotalInvalidSections += 1;
  1319. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1320. pStream->bExpectedSection = 0;
  1321. pStream->pOut = NULL;
  1322. pOutSrb = NULL;
  1323. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Invalid TableID", pSrb));
  1324. break;
  1325. }
  1326. }
  1327. //
  1328. // Process the transform buffer
  1329. //
  1330. pSection = (PSECTION_HEADER) pStream->pTransformBuffer;
  1331. NormalizeSection (pStream->pTransformBuffer, &Section);
  1332. //
  1333. // Do a quick check of the section header to confirm it looks valid
  1334. //
  1335. if (! ValidSection (&Section))
  1336. {
  1337. // Ignore non-MPE sections
  1338. //
  1339. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1340. pStream->bExpectedSection = 0;
  1341. pFilter->Stats.ulTotalInvalidSections += 1;
  1342. //
  1343. // Since we're discarding the data at this point, we'll re-queue the output
  1344. // SRB and re-use it when we get re-synched.
  1345. //
  1346. if (pOutSrb)
  1347. {
  1348. //$REVIEW - Can this cause out of order completion of sections.
  1349. //
  1350. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1351. }
  1352. pStream->pOut = NULL;
  1353. pOutSrb = NULL;
  1354. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Invalid TableID", pSrb));
  1355. break;
  1356. }
  1357. //
  1358. // Update our UnNormalized section header with our normalized one.
  1359. //
  1360. RtlCopyMemory (pStream->pTransformBuffer, &Section, sizeof (SECTION_HEADER));
  1361. //
  1362. // Check our section number and see if it's what we expect
  1363. //
  1364. if (pSection->section_number != pStream->bExpectedSection)
  1365. {
  1366. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1367. pStream->bExpectedSection = 0;
  1368. pFilter->Stats.ulTotalUnexpectedSections += 1;
  1369. //
  1370. // Since we're discarding the data at this point, we'll re-queue the output
  1371. // SRB and re-use it when we get re-synched.
  1372. //
  1373. if (pOutSrb)
  1374. {
  1375. //$REVIEW - Can this cause out of order completion of sections.
  1376. //
  1377. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1378. }
  1379. pStream->pOut = NULL;
  1380. pOutSrb = NULL;
  1381. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Invalid section_number", pSrb));
  1382. break;
  1383. }
  1384. //
  1385. // Process the 1st section
  1386. //
  1387. if (pSection->section_number == 0)
  1388. {
  1389. PMAC_Address pMAC = NULL;
  1390. //
  1391. // Initialize packet length to zero
  1392. //
  1393. ulLength = 0;
  1394. //
  1395. //
  1396. //
  1397. if (GetOutputBuffer (pFilter, &pOutSrb, &pStream->pOut, &ulSize) != STATUS_SUCCESS)
  1398. {
  1399. //
  1400. // Failure....no buffers available most likely
  1401. //
  1402. pFilter->Stats.ulTotalUnavailableOutputBuffers += 1;
  1403. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1404. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Can't get SRB for output pin", pSrb));
  1405. break;
  1406. }
  1407. if (ulSize < (pSection->section_length - (sizeof (SECTION_HEADER) - 3)))
  1408. {
  1409. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1410. pStream->bExpectedSection = 0;
  1411. pFilter->Stats.ulTotalOutputBuffersTooSmall += 1;
  1412. //
  1413. // Since we're discarding the data at this point, we'll re-queue the output
  1414. // SRB and re-use it when we get re-synched.
  1415. //
  1416. if (pOutSrb)
  1417. {
  1418. //$REVIEW - Can this cause out of order completion of sections.
  1419. //
  1420. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1421. }
  1422. pStream->pOut = NULL;
  1423. pOutSrb = NULL;
  1424. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Section too big", pSrb));
  1425. break;
  1426. }
  1427. pIP = (PHEADER_IP) pSection->Data;
  1428. if (pSection->LLC_SNAP_flag == 0x1)
  1429. {
  1430. pSnap = (PLLC_SNAP) pSection->Data;
  1431. pIP = (PHEADER_IP) pSnap->Data;
  1432. ulSkip = sizeof( LLC_SNAP);
  1433. }
  1434. //
  1435. // Add the MAC address to the buffer. The MAC address prefix's the IP packet
  1436. //
  1437. pMAC = (PMAC_Address) pStream->pOut;
  1438. pMAC->MAC_Dest_Address [0] = pSection->MAC_address_1;
  1439. pMAC->MAC_Dest_Address [1] = pSection->MAC_address_2;
  1440. pMAC->MAC_Dest_Address [2] = pSection->MAC_address_3;
  1441. pMAC->MAC_Dest_Address [3] = pSection->MAC_address_4;
  1442. pMAC->MAC_Dest_Address [4] = pSection->MAC_address_5;
  1443. pMAC->MAC_Dest_Address [5] = pSection->MAC_address_6;
  1444. pMAC->MAC_Src_Address [0] = 0x00;
  1445. pMAC->MAC_Src_Address [1] = 0x00;
  1446. pMAC->MAC_Src_Address [2] = 0x00;
  1447. pMAC->MAC_Src_Address [3] = 0x00;
  1448. pMAC->MAC_Src_Address [4] = 0x00;
  1449. pMAC->MAC_Src_Address [5] = 0x00;
  1450. pMAC->usLength = 0x0008;
  1451. //
  1452. // Adjust pointer to output buffer where we'll put data
  1453. //
  1454. pStream->pOut += sizeof (MAC_Address);
  1455. pIn = pSection->Data;
  1456. if (pSection->LLC_SNAP_flag == 0x1)
  1457. {
  1458. pSnap = (PLLC_SNAP) pSection->Data;
  1459. if (pSnap->type != 0x0008)
  1460. {
  1461. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1462. //
  1463. // Next expected Section should be zero
  1464. //
  1465. pStream->bExpectedSection = 0;
  1466. pFilter->Stats.ulTotalInvalidIPSnapHeaders += 1;
  1467. //
  1468. // Since we're discarding the data at this point, we'll re-queue the output
  1469. // SRB and re-use it when we get re-synched.
  1470. //
  1471. if (pOutSrb)
  1472. {
  1473. //$REVIEW - Can this cause out of order completion of sections.
  1474. //
  1475. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1476. }
  1477. pStream->pOut = NULL;
  1478. pOutSrb = NULL;
  1479. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Bad Snap Type", pSrb));
  1480. break;
  1481. }
  1482. pIn = pSnap->Data;
  1483. }
  1484. ulLength = sizeof (MAC_Address);
  1485. }
  1486. //
  1487. // pOut should be NULL unless we've found the 1st section.
  1488. //
  1489. if (pStream->pOut)
  1490. {
  1491. ULONG ulTmp = 0;
  1492. PKSSTREAM_HEADER pOutStreamHdr;
  1493. //
  1494. // Update the datasize field of the Output SRB
  1495. //
  1496. pOutStreamHdr = (PKSSTREAM_HEADER) pOutSrb->CommandData.DataBufferArray;
  1497. //
  1498. // Copy data from transform section to output SRB buffer
  1499. //
  1500. // Compute the number of bytes to copy. We subtract of 9 bytes
  1501. // only if this is a LLSNAP packet.
  1502. //
  1503. ulTmp = pSection->section_length;
  1504. ulTmp -= ulSkip;
  1505. ASSERT(pIn);
  1506. ASSERT(pStream->pOut);
  1507. if (ulSize < (ulTmp +sizeof (MAC_Address) +3))
  1508. {
  1509. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1510. pStream->bExpectedSection = 0;
  1511. pFilter->Stats.ulTotalOutputBuffersTooSmall += 1;
  1512. //
  1513. // Since we're discarding the data at this point, we'll re-queue the output
  1514. // SRB and re-use it when we get re-synched.
  1515. //
  1516. if (pOutSrb)
  1517. {
  1518. //$REVIEW - Can this cause out of order completion of sections.
  1519. //
  1520. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1521. }
  1522. pStream->pOut = NULL;
  1523. pOutSrb = NULL;
  1524. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Section too big", pSrb));
  1525. break;
  1526. }
  1527. RtlCopyMemory (pStream->pOut, pIn, ulTmp);
  1528. ulLength += ulTmp;
  1529. pOutStreamHdr->DataUsed += ulLength;
  1530. ulLength = 0;
  1531. }
  1532. if (pSection->section_number == pSection->last_section_number)
  1533. {
  1534. pFilter->Stats.ulTotalIPPacketsWritten += 1;
  1535. pOutSrb->Status = STATUS_SUCCESS;
  1536. StreamClassStreamNotification (StreamRequestComplete, pOutSrb->StreamObject, pOutSrb);
  1537. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n", pSrb));
  1538. pOutSrb = NULL;
  1539. pStream->pOut = NULL;
  1540. ulSize = 0;
  1541. }
  1542. else
  1543. {
  1544. if (pOutSrb)
  1545. {
  1546. //$REVIEW - Can this cause out of order completion of sections.
  1547. //
  1548. QueuePush (pOutSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1549. }
  1550. }
  1551. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1552. TEST_DEBUG( TEST_DBG_SRB, ("MPE 20Completed SRB %08X\n - Packet Sent", pSrb));
  1553. }
  1554. break;
  1555. default:
  1556. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_WRITE - Default\n"));
  1557. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1558. //
  1559. // Update stats for Unkown packet count
  1560. //
  1561. pFilter->Stats.ulTotalUnknownPacketsWritten += 1;
  1562. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1563. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1564. TEST_DEBUG( TEST_DBG_SRB, ("MPE 22Completed SRB %08X\n", pSrb));
  1565. break;
  1566. }
  1567. break;
  1568. case SRB_READ_DATA:
  1569. if (pStream->KSState == KSSTATE_STOP)
  1570. {
  1571. pSrb->Status = STATUS_SUCCESS;
  1572. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1573. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1574. TEST_DEBUG( TEST_DBG_SRB, ("MPE 23Completed SRB %08X\n", pSrb));
  1575. break;
  1576. }
  1577. //
  1578. // Update stats for Unkown packet count
  1579. //
  1580. pFilter->Stats.ulTotalPacketsRead += 1;
  1581. switch (iStream)
  1582. {
  1583. #ifdef OLD
  1584. case MPE_NET_CONTROL:
  1585. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - STREAM_NET_CONTROL\n"));
  1586. pSrb->Status = STATUS_SUCCESS;
  1587. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MPE_NET_CONTROL SRB Status returned: %08X\n", pSrb->Status));
  1588. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1589. TEST_DEBUG( TEST_DBG_SRB, ("MPE 24Completed SRB %08X\n", pSrb));
  1590. break;
  1591. #endif
  1592. case MPE_IPV4:
  1593. {
  1594. ULONG ulBuffers = pSrb->NumberOfBuffers;
  1595. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - MPE_IPV4\n"));
  1596. if (pSrb->CommandData.DataBufferArray->FrameExtent < pKSDataFormat->SampleSize)
  1597. {
  1598. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  1599. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MPE_IPV4 SRB Buffer too small.... Status returned: %08X\n", pSrb->Status));
  1600. StreamClassStreamNotification(StreamRequestComplete, pSrb->StreamObject, pSrb);
  1601. TEST_DEBUG( TEST_DBG_SRB, ("MPE 25Completed SRB %08X\n", pSrb));
  1602. }
  1603. else
  1604. {
  1605. //
  1606. // Take the SRB we get and queue it up. These Queued SRB's will be filled with data on a WRITE_DATA
  1607. // request, at which point they will be completed.
  1608. //
  1609. QueueAdd (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue);
  1610. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing IPv4 SRB %08X\n", pSrb));
  1611. //
  1612. // Since the stream state may have changed while we were adding the SRB to the queue
  1613. // we'll check it again, and cancel it if necessary
  1614. //
  1615. if (pStream->KSState == KSSTATE_STOP)
  1616. {
  1617. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB_READ STOP SRB Status returned: %08X\n", pSrb->Status));
  1618. if (QueueRemoveSpecific (pSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1619. {
  1620. pSrb->Status = STATUS_CANCELLED;
  1621. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb );
  1622. TEST_DEBUG( TEST_DBG_SRB, ("MPE 26Completed SRB %08X\n", pSrb));
  1623. return;
  1624. }
  1625. break;
  1626. }
  1627. }
  1628. }
  1629. break;
  1630. default:
  1631. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - SRB_READ - Default\n"));
  1632. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1633. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1634. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1635. TEST_DEBUG( TEST_DBG_SRB, ("MPE 27Completed SRB %08X\n", pSrb));
  1636. break;
  1637. }
  1638. break;
  1639. default:
  1640. //
  1641. // invalid / unsupported command. Fail it as such
  1642. //
  1643. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called - Unsupported Command\n"));
  1644. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1645. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: DEFAULT SRB Status returned: %08X\n", pSrb->Status));
  1646. StreamClassStreamNotification( StreamRequestComplete, pSrb->StreamObject, pSrb );
  1647. TEST_DEBUG( TEST_DBG_SRB, ("MPE 28Completed SRB %08X\n", pSrb));
  1648. ASSERT (FALSE);
  1649. break;
  1650. }
  1651. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Data packet handler called...status: %08X\n", pSrb->Status));
  1652. return;
  1653. }
  1654. //////////////////////////////////////////////////////////////////////////////
  1655. VOID
  1656. MpeGetProperty (
  1657. PHW_STREAM_REQUEST_BLOCK pSrb
  1658. )
  1659. //////////////////////////////////////////////////////////////////////////////
  1660. {
  1661. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  1662. pSrb->Status = STATUS_SUCCESS;
  1663. if (IsEqualGUID (&KSPROPSETID_Connection, &pSPD->Property->Set))
  1664. {
  1665. MpeGetConnectionProperty (pSrb);
  1666. }
  1667. else
  1668. {
  1669. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1670. }
  1671. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: MpeGetProperty Status: %08X\n", pSrb->Status));
  1672. return;
  1673. }
  1674. //////////////////////////////////////////////////////////////////////////////
  1675. VOID
  1676. IndicateMasterClock(
  1677. PHW_STREAM_REQUEST_BLOCK pSrb
  1678. )
  1679. //////////////////////////////////////////////////////////////////////////////
  1680. {
  1681. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1682. pStream->hClock = pSrb->CommandData.MasterClockHandle;
  1683. }
  1684. //////////////////////////////////////////////////////////////////////////////
  1685. VOID
  1686. STREAMAPI
  1687. ReceiveCtrlPacket(
  1688. IN PHW_STREAM_REQUEST_BLOCK pSrb
  1689. )
  1690. //////////////////////////////////////////////////////////////////////////////
  1691. {
  1692. PMPE_FILTER pFilter = (PMPE_FILTER) pSrb->HwDeviceExtension;
  1693. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1694. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler called\n"));
  1695. pSrb->Status = STATUS_SUCCESS;
  1696. QueueAdd (pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue);
  1697. TEST_DEBUG( TEST_DBG_SRB, ("MPE Queuing Control Packet SRB %08X\n", pSrb));
  1698. while (QueueRemove (&pSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  1699. {
  1700. //
  1701. // determine the type of packet.
  1702. //
  1703. switch (pSrb->Command)
  1704. {
  1705. case SRB_PROPOSE_DATA_FORMAT:
  1706. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Propose data format\n"));
  1707. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1708. break;
  1709. case SRB_SET_STREAM_STATE:
  1710. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream State\n"));
  1711. pSrb->Status = STATUS_SUCCESS;
  1712. MpeSetState (pSrb);
  1713. break;
  1714. case SRB_GET_STREAM_STATE:
  1715. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Get Stream State\n"));
  1716. pSrb->Status = STATUS_SUCCESS;
  1717. pSrb->CommandData.StreamState = pStream->KSState;
  1718. pSrb->ActualBytesTransferred = sizeof (KSSTATE);
  1719. break;
  1720. case SRB_GET_STREAM_PROPERTY:
  1721. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Get Stream Property\n"));
  1722. MpeGetProperty(pSrb);
  1723. break;
  1724. case SRB_SET_STREAM_PROPERTY:
  1725. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream Property\n"));
  1726. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1727. break;
  1728. case SRB_INDICATE_MASTER_CLOCK:
  1729. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Indicate Master Clock\n"));
  1730. pSrb->Status = STATUS_SUCCESS;
  1731. IndicateMasterClock (pSrb);
  1732. break;
  1733. case SRB_SET_STREAM_RATE:
  1734. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Set Stream Rate\n"));
  1735. pSrb->Status = STATUS_SUCCESS;
  1736. break;
  1737. case SRB_PROPOSE_STREAM_RATE:
  1738. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Propose Stream Rate\n"));
  1739. pSrb->Status = STATUS_SUCCESS;
  1740. break;
  1741. default:
  1742. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Receive Control packet handler - Default case\n"));
  1743. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  1744. break;
  1745. }
  1746. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: SRB Status returned: %08X\n", pSrb->Status));
  1747. StreamClassStreamNotification (StreamRequestComplete, pSrb->StreamObject, pSrb);
  1748. TEST_DEBUG( TEST_DBG_SRB, ("MPE 29Completed SRB %08X\n", pSrb));
  1749. }
  1750. }
  1751. //////////////////////////////////////////////////////////////////////////////
  1752. VOID
  1753. MpeSetState(
  1754. PHW_STREAM_REQUEST_BLOCK pSrb
  1755. )
  1756. //////////////////////////////////////////////////////////////////////////////
  1757. {
  1758. PMPE_FILTER pFilter = ((PMPE_FILTER) pSrb->HwDeviceExtension);
  1759. PSTREAM pStream = (PSTREAM) pSrb->StreamObject->HwStreamExtension;
  1760. PHW_STREAM_REQUEST_BLOCK pCurrentSrb = NULL;
  1761. //
  1762. // For each stream, the following states are used:
  1763. //
  1764. // Stop: Absolute minimum resources are used. No outstanding IRPs.
  1765. // Acquire: KS only state that has no DirectShow correpondence
  1766. // Acquire needed resources.
  1767. // Pause: Getting ready to run. Allocate needed resources so that
  1768. // the eventual transition to Run is as fast as possible.
  1769. // Read SRBs will be queued at either the Stream class
  1770. // or in your driver (depending on when you send "ReadyForNext")
  1771. // Run: Streaming.
  1772. //
  1773. // Moving to Stop to Run always transitions through Pause.
  1774. //
  1775. // But since a client app could crash unexpectedly, drivers should handle
  1776. // the situation of having outstanding IRPs cancelled and open streams
  1777. // being closed WHILE THEY ARE STREAMING!
  1778. //
  1779. // Note that it is quite possible to transition repeatedly between states:
  1780. // Stop -> Pause -> Stop -> Pause -> Run -> Pause -> Run -> Pause -> Stop
  1781. //
  1782. switch (pSrb->CommandData.StreamState)
  1783. {
  1784. case KSSTATE_STOP:
  1785. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_STOP\n"));
  1786. pStream->KSState = pSrb->CommandData.StreamState;
  1787. //
  1788. // If transitioning to STOP state, then complete any outstanding IRPs
  1789. //
  1790. while (QueueRemove(&pCurrentSrb, &pFilter->IpV4StreamDataSpinLock, &pFilter->IpV4StreamDataQueue))
  1791. {
  1792. pCurrentSrb->Status = STATUS_CANCELLED;
  1793. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1794. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1795. TEST_DEBUG( TEST_DBG_SRB, ("MPE 30Completed SRB %08X\n", pCurrentSrb));
  1796. }
  1797. while (QueueRemove(&pCurrentSrb, &pFilter->StreamControlSpinLock, &pFilter->StreamControlQueue))
  1798. {
  1799. pCurrentSrb->Status = STATUS_CANCELLED;
  1800. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1801. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1802. TEST_DEBUG( TEST_DBG_SRB, ("MPE 30Completed SRB %08X\n", pCurrentSrb));
  1803. }
  1804. while (QueueRemove(&pCurrentSrb, &pFilter->StreamDataSpinLock, &pFilter->StreamDataQueue))
  1805. {
  1806. pCurrentSrb->Status = STATUS_CANCELLED;
  1807. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1808. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1809. TEST_DEBUG( TEST_DBG_SRB, ("MPE 30Completed SRB %08X\n", pCurrentSrb));
  1810. }
  1811. while (QueueRemove(&pCurrentSrb, &pFilter->StreamUserSpinLock, &pFilter->StreamContxList))
  1812. {
  1813. pCurrentSrb->Status = STATUS_CANCELLED;
  1814. pCurrentSrb->CommandData.DataBufferArray->DataUsed = 0;
  1815. StreamClassStreamNotification(StreamRequestComplete, pCurrentSrb->StreamObject, pCurrentSrb);
  1816. TEST_DEBUG( TEST_DBG_SRB, ("MPE 30Completed SRB %08X\n", pCurrentSrb));
  1817. }
  1818. pSrb->Status = STATUS_SUCCESS;
  1819. break;
  1820. case KSSTATE_ACQUIRE:
  1821. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_ACQUIRE\n"));
  1822. pStream->KSState = pSrb->CommandData.StreamState;
  1823. pSrb->Status = STATUS_SUCCESS;
  1824. break;
  1825. case KSSTATE_PAUSE:
  1826. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_PAUSE\n"));
  1827. pStream->KSState = pSrb->CommandData.StreamState;
  1828. pSrb->Status = STATUS_SUCCESS;
  1829. break;
  1830. case KSSTATE_RUN:
  1831. TEST_DEBUG (TEST_DBG_TRACE, ("MPE: Set Stream State KSSTATE_RUN\n"));
  1832. pStream->KSState = pSrb->CommandData.StreamState;
  1833. pSrb->Status = STATUS_SUCCESS;
  1834. break;
  1835. } // end switch (pSrb->CommandData.StreamState)
  1836. return;
  1837. }