1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
|
#include <sysvad.h>
#include <limits.h>
#include <ks.h>
#include "simple.h"
#include "minwavert.h"
#include "minwavertstream.h"
#include "UnittestData.h"
#include "AudioModuleHelper.h"
#define MINWAVERTSTREAM_POOLTAG 'SRWM'
#pragma warning (disable : 4127)
//=============================================================================
// CMiniportWaveRTStream
//=============================================================================
//=============================================================================
#pragma code_seg("PAGE")
CMiniportWaveRTStream::~CMiniportWaveRTStream
(
void
)
/*++
Routine Description:
Destructor for wavertstream
Arguments:
Return Value:
NT status code.
--*/
{
PAGED_CODE();
if (NULL != m_pMiniport)
{
if (m_pAudioModules)
{
m_pMiniport->FreeStreamAudioModules(m_pAudioModules, m_AudioModuleCount);
m_pAudioModules = NULL;
m_AudioModuleCount = 0;
}
if (m_bUnregisterStream)
{
m_pMiniport->StreamClosed(m_ulPin, this);
m_bUnregisterStream = FALSE;
}
m_pMiniport->Release();
m_pMiniport = NULL;
}
if (m_pDpc)
{
ExFreePoolWithTag( m_pDpc, MINWAVERTSTREAM_POOLTAG );
m_pDpc = NULL;
}
if (m_pTimer)
{
ExFreePoolWithTag( m_pTimer, MINWAVERTSTREAM_POOLTAG );
m_pTimer = NULL;
}
if (m_pbMuted)
{
ExFreePoolWithTag( m_pbMuted, MINWAVERTSTREAM_POOLTAG );
m_pbMuted = NULL;
}
if (m_plVolumeLevel)
{
ExFreePoolWithTag( m_plVolumeLevel, MINWAVERTSTREAM_POOLTAG );
m_plVolumeLevel = NULL;
}
if (m_plPeakMeter)
{
ExFreePoolWithTag( m_plPeakMeter, MINWAVERTSTREAM_POOLTAG );
m_plPeakMeter = NULL;
}
if (m_pWfExt)
{
ExFreePoolWithTag( m_pWfExt, MINWAVERTSTREAM_POOLTAG );
m_pWfExt = NULL;
}
if (m_pNotificationTimer)
{
ExDeleteTimer
(
m_pNotificationTimer,
TRUE, // Cancel the timer if it is currently set.
TRUE, // Wait for the timer to finish expiring and for any callback to a ExTimerCallback routine to finish.
NULL
);
}
// Since we just cancelled the notification timer, wait for all queued
// DPCs to complete before we free the notification DPC.
//
KeFlushQueuedDpcs();
#ifdef SYSVAD_BTH_BYPASS
ASSERT(m_SidebandOpen == FALSE);
ASSERT(m_SidebandStarted == FALSE);
#endif // SYSVAD_BTH_BYPASS
DPF_ENTER(("[CMiniportWaveRTStream::~CMiniportWaveRTStream]"));
} // ~CMiniportWaveRTStream
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::ReadRegistrySettings()
{
PAGED_CODE();
NTSTATUS ntStatus;
PDRIVER_OBJECT DriverObject;
HANDLE DriverKey;
RTL_QUERY_REGISTRY_TABLE paramTable[] = {
// QueryRoutine Flags Name EntryContext DefaultType DefaultData DefaultLength
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"HostCaptureToneFrequency", &m_ulHostCaptureToneFrequency, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_ulHostCaptureToneFrequency, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"LoopbackCaptureToneFrequency", &m_ulLoopbackCaptureToneFrequency, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_ulLoopbackCaptureToneFrequency, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"HostCaptureToneAmplitude", &m_dwHostCaptureToneAmplitude, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwHostCaptureToneAmplitude, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"LoopbackCaptureToneAmplitude", &m_dwLoopbackCaptureToneAmplitude, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwLoopbackCaptureToneAmplitude, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"HostCaptureToneDCOffset", &m_dwHostCaptureToneDCOffset, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwHostCaptureToneDCOffset, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"LoopbackCaptureToneDCOffset", &m_dwLoopbackCaptureToneDCOffset, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwLoopbackCaptureToneDCOffset, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"HostCaptureToneInitialPhase", &m_dwHostCaptureToneInitialPhase, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwHostCaptureToneInitialPhase, sizeof(DWORD) },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK, L"LoopbackCaptureToneInitialPhase", &m_dwLoopbackCaptureToneInitialPhase, (REG_DWORD << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT) | REG_DWORD, &m_dwLoopbackCaptureToneInitialPhase, sizeof(DWORD) },
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
};
DriverObject = WdfDriverWdmGetDriverObject(WdfGetDriver());
DriverKey = NULL;
ntStatus = IoOpenDriverRegistryKey(DriverObject,
DriverRegKeyParameters,
KEY_READ,
0,
&DriverKey);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
ntStatus = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
(PCWSTR) DriverKey,
¶mTable[0],
NULL,
NULL);
if (!NT_SUCCESS(ntStatus))
{
DPF(D_VERBOSE, ("RtlQueryRegistryValues failed, using default values, 0x%x", ntStatus));
//
// Don't return error because we will operate with default values.
//
}
if (DriverKey)
{
ZwClose(DriverKey);
}
return ntStatus;
}
NTSTATUS
CMiniportWaveRTStream::Init
(
_In_ PCMiniportWaveRT Miniport_,
_In_ PPORTWAVERTSTREAM PortStream_,
_In_ ULONG Pin_,
_In_ BOOLEAN Capture_,
_In_ PKSDATAFORMAT DataFormat_,
_In_ GUID SignalProcessingMode
)
/*++
Routine Description:
Initializes the stream object.
Arguments:
Miniport_ -
Pin_ -
Capture_ -
DataFormat -
SignalProcessingMode - The driver uses the signalProcessingMode to configure
driver and/or hardware specific signal processing to be applied to this new
stream.
Return Value:
NT status code.
--*/
{
PAGED_CODE();
PWAVEFORMATEX pWfEx = NULL;
NTSTATUS ntStatus = STATUS_SUCCESS;
m_pMiniport = NULL;
m_ulPin = 0;
m_bUnregisterStream = FALSE;
m_bCapture = FALSE;
m_ulDmaBufferSize = 0;
m_pDmaBuffer = NULL;
m_ulNotificationsPerBuffer = 0;
m_KsState = KSSTATE_STOP;
m_pTimer = NULL;
m_pDpc = NULL;
m_llPacketCounter = 0;
m_ullPlayPosition = 0;
m_ullWritePosition = 0;
m_ullDmaTimeStamp = 0;
m_hnsElapsedTimeCarryForward = 0;
m_ullLastDPCTimeStamp = 0;
m_hnsDPCTimeCarryForward = 0;
m_ulDmaMovementRate = 0;
m_byteDisplacementCarryForward = 0;
m_bLfxEnabled = FALSE;
m_pbMuted = NULL;
m_plVolumeLevel = NULL;
m_plPeakMeter = NULL;
m_pWfExt = NULL;
m_ullLinearPosition = 0;
m_ullPresentationPosition = 0;
m_ulContentId = 0;
m_ulCurrentWritePosition = 0;
m_ulLastOsReadPacket = ULONG_MAX;
m_ulLastOsWritePacket = ULONG_MAX;
m_IsCurrentWritePositionUpdated = 0;
m_SignalProcessingMode = SignalProcessingMode;
m_bEoSReceived = FALSE;
m_bLastBufferRendered = FALSE;
m_pAudioModules = NULL;
m_AudioModuleCount = 0;
m_ulHostCaptureToneFrequency = IsEqualGUID(SignalProcessingMode, AUDIO_SIGNALPROCESSINGMODE_RAW) ? 1000 : 2000;
m_ulLoopbackCaptureToneFrequency = 3000; // 3 kHz
m_dwHostCaptureToneAmplitude = 50;
m_dwLoopbackCaptureToneAmplitude = 50;
m_dwHostCaptureToneDCOffset = 0;
m_dwLoopbackCaptureToneDCOffset = 0;
m_dwHostCaptureToneInitialPhase = 0;
m_dwLoopbackCaptureToneInitialPhase = 0;
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
m_SidebandOpen = FALSE;
m_SidebandStarted = FALSE;
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
m_pPortStream = PortStream_;
InitializeListHead(&m_NotificationList);
m_ulNotificationIntervalMs = 0;
// Initialize the spinlock to synchronize position updates
KeInitializeSpinLock(&m_PositionSpinLock);
m_pNotificationTimer = ExAllocateTimer(
TimerNotifyRT,
this,
EX_TIMER_HIGH_RESOLUTION
);
if (!m_pNotificationTimer)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
pWfEx = GetWaveFormatEx(DataFormat_);
if (NULL == pWfEx)
{
return STATUS_UNSUCCESSFUL;
}
m_pMiniport = reinterpret_cast<CMiniportWaveRT*>(Miniport_);
if (m_pMiniport == NULL)
{
return STATUS_INVALID_PARAMETER;
}
m_pMiniport->AddRef();
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
m_ulPin = Pin_;
m_bCapture = Capture_;
m_ulDmaMovementRate = pWfEx->nAvgBytesPerSec;
m_pDpc = (PRKDPC)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(KDPC), MINWAVERTSTREAM_POOLTAG);
if (!m_pDpc)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
m_pWfExt = (PWAVEFORMATEXTENSIBLE)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(WAVEFORMATEX) + pWfEx->cbSize, MINWAVERTSTREAM_POOLTAG);
if (m_pWfExt == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlCopyMemory(m_pWfExt, pWfEx, sizeof(WAVEFORMATEX) + pWfEx->cbSize);
m_pbMuted = (PBOOL)ExAllocatePool2(POOL_FLAG_NON_PAGED, m_pWfExt->Format.nChannels * sizeof(BOOL), MINWAVERTSTREAM_POOLTAG);
if (m_pbMuted == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
m_plVolumeLevel = (PLONG)ExAllocatePool2(POOL_FLAG_NON_PAGED, m_pWfExt->Format.nChannels * sizeof(LONG), MINWAVERTSTREAM_POOLTAG);
if (m_plVolumeLevel == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
m_plPeakMeter = (PLONG)ExAllocatePool2(POOL_FLAG_NON_PAGED, m_pWfExt->Format.nChannels * sizeof(LONG), MINWAVERTSTREAM_POOLTAG);
if (m_plPeakMeter == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
//
// Allocate stream audio module resources.
//
ntStatus = m_pMiniport->AllocStreamAudioModules(&SignalProcessingMode,
&m_pAudioModules,
&m_AudioModuleCount);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
if (m_bCapture)
{
ReadRegistrySettings();
DWORD toneFrequency = 0;
DWORD toneAmplitude = 0;
DWORD toneDCOffset = 0;
DWORD toneInitialPhase = 0;
double toneAmplitudeDouble = 0;
double toneDCOffsetDouble = 0;
double toneInitialPhaseDouble = 0;
if (m_pMiniport->IsLoopbackPin(Pin_))
{
//
// Loopbacks pins use a different frequency for test validation.
//
toneFrequency = m_ulLoopbackCaptureToneFrequency;
toneAmplitude = m_dwLoopbackCaptureToneAmplitude;
toneDCOffset = m_dwLoopbackCaptureToneDCOffset;
toneInitialPhase = m_dwLoopbackCaptureToneInitialPhase;
}
else
{
//
// Init sine wave generator. To exercise the SignalProcessingMode parameter
// this sample driver selects the frequency based on the parameter.
//
toneFrequency = m_ulHostCaptureToneFrequency;
toneAmplitude = m_dwHostCaptureToneAmplitude;
toneDCOffset = m_dwHostCaptureToneDCOffset;
toneInitialPhase = m_dwHostCaptureToneInitialPhase;
}
if (labs(toneAmplitude) > 100)
{
toneAmplitude = toneAmplitude > 0 ? 100 : -100;
}
if (labs(toneDCOffset) > 100)
{
toneDCOffset = toneDCOffset > 0 ? 100 : -100;
}
DWORD abssum = labs(toneAmplitude) + labs(toneDCOffset);
if ( abssum > 100)
{
toneAmplitudeDouble = ((double)toneAmplitude) / abssum;
toneDCOffsetDouble = ((double)toneDCOffset) / abssum;
}
else
{
toneAmplitudeDouble = ((double)toneAmplitude) / 100.0;
toneDCOffsetDouble = ((double)toneDCOffset) / 100.0;
}
if (labs(toneInitialPhase) > 31416)
{
toneInitialPhase = toneInitialPhase > 0 ? 31416 : -31416;
}
toneInitialPhaseDouble = (double)toneInitialPhase / 10000;
ntStatus = m_ToneGenerator.Init(toneFrequency, toneAmplitudeDouble, toneDCOffsetDouble, toneInitialPhaseDouble, m_pWfExt);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
}
else if (!g_DoNotCreateDataFiles)
{
//
// Create an output file for the render data.
//
DPF(D_TERSE, ("SaveData %p", &m_SaveData));
ntStatus = m_SaveData.SetDataFormat(DataFormat_);
if (NT_SUCCESS(ntStatus))
{
ntStatus = m_SaveData.Initialize(m_pMiniport->IsOffloadPin(Pin_));
}
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
}
//
// Register this stream.
//
ntStatus = m_pMiniport->StreamCreated(m_ulPin, this);
if (NT_SUCCESS(ntStatus))
{
m_bUnregisterStream = TRUE;
}
return ntStatus;
} // Init
//=============================================================================
#pragma code_seg("PAGE")
STDMETHODIMP_(NTSTATUS)
CMiniportWaveRTStream::NonDelegatingQueryInterface
(
_In_ REFIID Interface,
_COM_Outptr_ PVOID * Object
)
/*++
Routine Description:
QueryInterface
Arguments:
Interface - GUID
Object - interface pointer to be returned
Return Value:
NT status code.
--*/
{
PAGED_CODE();
ASSERT(Object);
if (IsEqualGUIDAligned(Interface, IID_IUnknown))
{
*Object = PVOID(PUNKNOWN(PMINIPORTWAVERTSTREAM(this)));
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveRTStream))
{
*Object = PVOID(PMINIPORTWAVERTSTREAM(this));
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveRTStreamNotification))
{
*Object = PVOID(PMINIPORTWAVERTSTREAMNOTIFICATION(this));
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveRTInputStream) && (this->m_bCapture))
{
// This interface is supported only on capture streams
*Object = PVOID(PMINIPORTWAVERTINPUTSTREAM(this));
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportWaveRTOutputStream) && (!this->m_bCapture)
&& (!this->m_pMiniport->IsOffloadPin(this->m_ulPin)))
{
// This interface is supported only on host render streams
*Object = PVOID(PMINIPORTWAVERTOUTPUTSTREAM(this));
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportStreamAudioEngineNode))
{
*Object = (PVOID)(IMiniportStreamAudioEngineNode*)this;
}
else if (IsEqualGUIDAligned(Interface, IID_IMiniportStreamAudioEngineNode2))
{
*Object = (PVOID)(IMiniportStreamAudioEngineNode2*)this;
}
else if (IsEqualGUIDAligned(Interface, IID_IDrmAudioStream))
{
*Object = (PVOID)(IDrmAudioStream*)this;
}
else
{
*Object = NULL;
}
if (*Object)
{
PUNKNOWN(*Object)->AddRef();
return STATUS_SUCCESS;
}
return STATUS_INVALID_PARAMETER;
} // NonDelegatingQueryInterface
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::AllocateBufferWithNotification
(
_In_ ULONG NotificationCount_,
_In_ ULONG RequestedSize_,
_Out_ PMDL *AudioBufferMdl_,
_Out_ ULONG *ActualSize_,
_Out_ ULONG *OffsetFromFirstPage_,
_Out_ MEMORY_CACHING_TYPE *CacheType_
)
{
PAGED_CODE();
ULONG ulBufferDurationMs = 0;
if ( (0 == RequestedSize_) || (RequestedSize_ < m_pWfExt->Format.nBlockAlign) )
{
return STATUS_UNSUCCESSFUL;
}
if ((NotificationCount_ == 0) || (RequestedSize_ % NotificationCount_ != 0))
{
return STATUS_INVALID_PARAMETER;
}
RequestedSize_ -= RequestedSize_ % (m_pWfExt->Format.nBlockAlign);
if (!m_bCapture && !g_DoNotCreateDataFiles)
{
NTSTATUS ntStatus;
// Sysvad uses following buffer to hold data before writing to a file.
// Allocating larger buffer will reduce File I/O operations.
ntStatus = m_SaveData.SetMaxWriteSize(RequestedSize_ * 4);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
}
PHYSICAL_ADDRESS highAddress;
highAddress.HighPart = 0;
highAddress.LowPart = MAXULONG;
PMDL pBufferMdl = m_pPortStream->AllocatePagesForMdl (highAddress, RequestedSize_);
if (NULL == pBufferMdl)
{
return STATUS_UNSUCCESSFUL;
}
// From MSDN:
// "Since the Windows audio stack does not support a mechanism to express memory access
// alignment requirements for buffers, audio drivers must select a caching type for mapped
// memory buffers that does not impose platform-specific alignment requirements. In other
// words, the caching type used by the audio driver for mapped memory buffers, must not make
// assumptions about the memory alignment requirements for any specific platform.
//
// This method maps the physical memory pages in the MDL into kernel-mode virtual memory.
// Typically, the miniport driver calls this method if it requires software access to the
// scatter-gather list for an audio buffer. In this case, the storage for the scatter-gather
// list must have been allocated by the IPortWaveRTStream::AllocatePagesForMdl or
// IPortWaveRTStream::AllocateContiguousPagesForMdl method.
//
// A WaveRT miniport driver should not require software access to the audio buffer itself."
//
m_pDmaBuffer = (BYTE*)m_pPortStream->MapAllocatedPages(pBufferMdl, MmCached);
m_ulNotificationsPerBuffer = NotificationCount_;
m_ulDmaBufferSize = RequestedSize_;
ulBufferDurationMs = (RequestedSize_ * 1000) / m_ulDmaMovementRate;
m_ulNotificationIntervalMs = ulBufferDurationMs / NotificationCount_;
*AudioBufferMdl_ = pBufferMdl;
*ActualSize_ = RequestedSize_;
*OffsetFromFirstPage_ = 0;
*CacheType_ = MmCached;
return STATUS_SUCCESS;
}
//=============================================================================
#pragma code_seg("PAGE")
VOID CMiniportWaveRTStream::FreeBufferWithNotification
(
_In_ PMDL Mdl_,
_In_ ULONG Size_
)
{
UNREFERENCED_PARAMETER(Size_);
PAGED_CODE();
if (Mdl_ != NULL)
{
if (m_pDmaBuffer != NULL)
{
m_pPortStream->UnmapAllocatedPages(m_pDmaBuffer, Mdl_);
m_pDmaBuffer = NULL;
}
m_pPortStream->FreePagesFromMdl(Mdl_);
}
m_ulDmaBufferSize = 0;
m_ulNotificationsPerBuffer = 0;
return;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::RegisterNotificationEvent
(
_In_ PKEVENT NotificationEvent_
)
{
UNREFERENCED_PARAMETER(NotificationEvent_);
PAGED_CODE();
NotificationListEntry *nleNew = (NotificationListEntry*)ExAllocatePool2(
POOL_FLAG_NON_PAGED,
sizeof(NotificationListEntry),
MINWAVERTSTREAM_POOLTAG);
if (NULL == nleNew)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
nleNew->NotificationEvent = NotificationEvent_;
// Fail if the notification event already exists in our list.
if (!IsListEmpty(&m_NotificationList))
{
PLIST_ENTRY leCurrent = m_NotificationList.Flink;
while (leCurrent != &m_NotificationList)
{
NotificationListEntry* nleCurrent = CONTAINING_RECORD( leCurrent, NotificationListEntry, ListEntry);
if (nleCurrent->NotificationEvent == NotificationEvent_)
{
ExFreePoolWithTag( nleNew, MINWAVERTSTREAM_POOLTAG );
return STATUS_UNSUCCESSFUL;
}
leCurrent = leCurrent->Flink;
}
}
InsertTailList(&m_NotificationList, &(nleNew->ListEntry));
return STATUS_SUCCESS;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::UnregisterNotificationEvent
(
_In_ PKEVENT NotificationEvent_
)
{
UNREFERENCED_PARAMETER(NotificationEvent_);
PAGED_CODE();
if (!IsListEmpty(&m_NotificationList))
{
PLIST_ENTRY leCurrent = m_NotificationList.Flink;
while (leCurrent != &m_NotificationList)
{
NotificationListEntry* nleCurrent = CONTAINING_RECORD( leCurrent, NotificationListEntry, ListEntry);
if (nleCurrent->NotificationEvent == NotificationEvent_)
{
RemoveEntryList( leCurrent );
ExFreePoolWithTag( nleCurrent, MINWAVERTSTREAM_POOLTAG );
return STATUS_SUCCESS;
}
leCurrent = leCurrent->Flink;
}
}
return STATUS_NOT_FOUND;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::GetClockRegister
(
_Out_ PKSRTAUDIO_HWREGISTER Register_
)
{
UNREFERENCED_PARAMETER(Register_);
PAGED_CODE();
return STATUS_NOT_IMPLEMENTED;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::GetPositionRegister
(
_Out_ PKSRTAUDIO_HWREGISTER Register_
)
{
UNREFERENCED_PARAMETER(Register_);
PAGED_CODE();
return STATUS_NOT_IMPLEMENTED;
}
//=============================================================================
#pragma code_seg("PAGE")
VOID CMiniportWaveRTStream::GetHWLatency
(
_Out_ PKSRTAUDIO_HWLATENCY Latency_
)
{
PAGED_CODE();
ASSERT(Latency_);
Latency_->ChipsetDelay = 0;
Latency_->CodecDelay = 0;
Latency_->FifoSize = 0;
}
//=============================================================================
#pragma code_seg("PAGE")
VOID CMiniportWaveRTStream::FreeAudioBuffer
(
_In_opt_ PMDL Mdl_,
_In_ ULONG Size_
)
{
UNREFERENCED_PARAMETER(Size_);
PAGED_CODE();
if (Mdl_ != NULL)
{
if (m_pDmaBuffer != NULL)
{
m_pPortStream->UnmapAllocatedPages(m_pDmaBuffer, Mdl_);
m_pDmaBuffer = NULL;
}
m_pPortStream->FreePagesFromMdl(Mdl_);
}
m_ulDmaBufferSize = 0;
m_ulNotificationsPerBuffer = 0;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::AllocateAudioBuffer
(
_In_ ULONG RequestedSize_,
_Out_ PMDL *AudioBufferMdl_,
_Out_ ULONG *ActualSize_,
_Out_ ULONG *OffsetFromFirstPage_,
_Out_ MEMORY_CACHING_TYPE *CacheType_
)
{
PAGED_CODE();
if ((0 == RequestedSize_) || (RequestedSize_ < m_pWfExt->Format.nBlockAlign))
{
return STATUS_UNSUCCESSFUL;
}
RequestedSize_ -= RequestedSize_ % (m_pWfExt->Format.nBlockAlign);
PHYSICAL_ADDRESS highAddress;
highAddress.HighPart = 0;
highAddress.LowPart = MAXULONG;
PMDL pBufferMdl = m_pPortStream->AllocatePagesForMdl(highAddress, RequestedSize_);
if (NULL == pBufferMdl)
{
return STATUS_UNSUCCESSFUL;
}
// From MSDN:
// "Since the Windows audio stack does not support a mechanism to express memory access
// alignment requirements for buffers, audio drivers must select a caching type for mapped
// memory buffers that does not impose platform-specific alignment requirements. In other
// words, the caching type used by the audio driver for mapped memory buffers, must not make
// assumptions about the memory alignment requirements for any specific platform.
//
// This method maps the physical memory pages in the MDL into kernel-mode virtual memory.
// Typically, the miniport driver calls this method if it requires software access to the
// scatter-gather list for an audio buffer. In this case, the storage for the scatter-gather
// list must have been allocated by the IPortWaveRTStream::AllocatePagesForMdl or
// IPortWaveRTStream::AllocateContiguousPagesForMdl method.
//
// A WaveRT miniport driver should not require software access to the audio buffer itself."
//
m_pDmaBuffer = (BYTE*)m_pPortStream->MapAllocatedPages(pBufferMdl, MmCached);
m_ulDmaBufferSize = RequestedSize_;
m_ulNotificationsPerBuffer = 0;
*AudioBufferMdl_ = pBufferMdl;
*ActualSize_ = RequestedSize_;
*OffsetFromFirstPage_ = 0;
*CacheType_ = MmCached;
return STATUS_SUCCESS;
}
//=============================================================================
#pragma code_seg()
NTSTATUS CMiniportWaveRTStream::GetPosition
(
_Out_ KSAUDIO_POSITION *Position_
)
{
NTSTATUS ntStatus;
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (m_SidebandStarted)
{
ntStatus = GetSidebandStreamNtStatus();
IF_FAILED_JUMP(ntStatus, Done);
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
// Return failure if this is the keyword detector pin
if (m_pMiniport->IsKeywordDetectorPin(m_ulPin))
{
return STATUS_NOT_SUPPORTED;
}
KIRQL oldIrql;
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
if (m_KsState == KSSTATE_RUN)
{
//
// Get the current time and update position.
//
LARGE_INTEGER ilQPC = KeQueryPerformanceCounter(NULL);
UpdatePosition(ilQPC);
}
Position_->PlayOffset = m_ullPlayPosition;
Position_->WriteOffset = m_ullWritePosition;
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
ntStatus = STATUS_SUCCESS;
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
Done:
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
return ntStatus;
}
//=============================================================================
// CMiniportWaveRTStream::GetReadPacket
//
// Returns information about the next packet for the OS to read.
//
// Return value
//
// Returns STATUS_DEVICE_NOT_READY if no new packets are available.
//
// IRQL - PASSIVE_LEVEL
//
// Remarks
// Although called at passive level, this routine is non-paged code because
// it is called in the streaming path where page faults should be avoided.
//
// ISSUE-2014/10/4 Will this work correctly across pause/play?
#pragma code_seg()
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS CMiniportWaveRTStream::GetReadPacket
(
_Out_ ULONG *PacketNumber,
_Out_ DWORD *Flags,
_Out_ ULONG64 *PerformanceCounterValue,
_Out_ BOOL *MoreData
)
{
NTSTATUS ntStatus;
ULONG availablePacketNumber;
ULONG droppedPackets;
// The call must be from event driven mode
if(m_ulNotificationsPerBuffer == 0)
{
return STATUS_NOT_SUPPORTED;
}
*Flags = 0;
if (m_KsState < KSSTATE_PAUSE)
{
return STATUS_INVALID_DEVICE_STATE;
}
// If this is the keyword detector pin, then stream from the keyword FIFO
if (m_pMiniport->IsKeywordDetectorPin(m_ulPin))
{
// FUTURE-2014/11/18 Drive this with packet counter
ntStatus = m_pMiniport->m_KeywordDetector.GetReadPacket(m_ulNotificationsPerBuffer, m_ulDmaBufferSize, m_pDmaBuffer, PacketNumber, PerformanceCounterValue, MoreData);
if (NT_SUCCESS(ntStatus))
{
m_ulLastOsReadPacket = *PacketNumber;
}
return ntStatus;
}
KIRQL oldIrql;
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
LONGLONG packetCounter = m_llPacketCounter;
ULONGLONG ullLinearPosition = m_ullLinearPosition;
ULONGLONG hnsElapsedTimeCarryForward = m_hnsElapsedTimeCarryForward;
ULONGLONG ullDmaTimeStamp = m_ullDmaTimeStamp;
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
// The 0-based number of the last completed packet
// FUTURE-2014/10/27 Update to allow different numbers of packets per WaveRT buffer
availablePacketNumber = LODWORD(packetCounter - 1); // Note this might be ULONG_MAX if called during the first packet
// If no new packets are available...
if (availablePacketNumber == m_ulLastOsReadPacket)
{
return STATUS_DEVICE_NOT_READY;
}
// If more than one packet has transferred since the last packet read by
// the OS, then those were dropped. That is, a glitch occurred.
droppedPackets = availablePacketNumber - m_ulLastOsReadPacket - 1;
if (droppedPackets > 0)
{
// Trace a glitch
}
// Return next packet number to be read
*PacketNumber = availablePacketNumber;
// Compute and return timestamp corresponding to the end of the available packet. In a real hardware
// driver, the timestamp would be computed in a driver and hardware specific manner. In this sample
// driver, it is extrapolated from the sample driver's internal simulated position correlation
// [m_ullLinearPosition @ m_ullDmaTimeStamp] and the sample's internal 64-bit packet counter, subtracting
// 1 from the packet counter to compute the time at the start of that last completed packet.
ULONGLONG linearPositionOfAvailablePacket = packetCounter * (m_ulDmaBufferSize / m_ulNotificationsPerBuffer);
// Need to divide by (1000 * 10000 because m_ulDmaMovementRate is average bytes per sec
ULONGLONG carryForwardBytes = (hnsElapsedTimeCarryForward * m_ulDmaMovementRate) / 10000000;
ULONGLONG deltaLinearPosition = ullLinearPosition + carryForwardBytes - linearPositionOfAvailablePacket;
ULONGLONG deltaTimeInHns = deltaLinearPosition * 10000000 / m_ulDmaMovementRate;
ULONGLONG timeOfAvailablePacketInHns = ullDmaTimeStamp - deltaTimeInHns;
ULONGLONG timeOfAvailablePacketInQpc = timeOfAvailablePacketInHns * m_ullPerformanceCounterFrequency.QuadPart / 10000000;
*PerformanceCounterValue = timeOfAvailablePacketInQpc;
// No flags are defined yet
*Flags = 0;
// This sample does not internally buffer data so there is never more data
// than revealed by the results from this routine.
*MoreData = FALSE;
// Update the last packet read by the OS
m_ulLastOsReadPacket = availablePacketNumber;
return STATUS_SUCCESS;
}
#pragma code_seg()
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS CMiniportWaveRTStream::SetWritePacket
(
_In_ ULONG PacketNumber,
_In_ DWORD Flags,
_In_ ULONG EosPacketLength
)
{
NTSTATUS ntStatus;
// The call must be from event driven mode
if (m_ulNotificationsPerBuffer == 0)
{
return STATUS_NOT_SUPPORTED;
}
ULONG oldLastOsWritePacket = m_ulLastOsWritePacket;
// This function should not be called once EoS has been set.
if (m_bEoSReceived)
{
return STATUS_INVALID_DEVICE_STATE;
}
KIRQL oldIrql;
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
// 1-based count of completed packets, 0-based packet number of current packet
LONGLONG currentPacket = m_llPacketCounter;
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
// If not running, the current packet hasn't actually started transfering so OS should be writing
// to the current packet. If running, then the current packing is already transfering to hardware
// so the OS should write the packet after the current packet.
ULONG expectedPacket = LODWORD(currentPacket);
if (m_KsState == KSSTATE_RUN)
{
expectedPacket++;
}
// Check if OS PacketNumber is behind or too far ahead of current packet
LONG deltaFromExpectedPacket = PacketNumber - expectedPacket; // Modulo arithemetic
if (deltaFromExpectedPacket < 0)
{
return STATUS_DATA_LATE_ERROR;
}
else if (deltaFromExpectedPacket > 0)
{
return STATUS_DATA_OVERRUN;
}
ULONG packetSize = (m_ulDmaBufferSize / m_ulNotificationsPerBuffer);
ULONG packetIndex = PacketNumber % m_ulNotificationsPerBuffer;
ULONG ulCurrentWritePosition = packetIndex * packetSize;
// Check if EOS flag was passed
if (Flags & KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM)
{
if (EosPacketLength > packetSize)
{
return STATUS_INVALID_PARAMETER;
}
else {
// EOS position will be after the total completed packets, plus the packet in progress,
// plus this EOS packet length
m_ulLastOsWritePacket = PacketNumber;
ulCurrentWritePosition += EosPacketLength;
ntStatus = SetStreamCurrentWritePositionForLastBuffer(ulCurrentWritePosition);
}
}
else
{
m_ulLastOsWritePacket = PacketNumber;
// This function sets the current write position to the specified byte in the DMA buffer.
// Will check if the write position is smaller than the DMA buffer size.
// Will not return an error when the passed in parameter is 0.
// Will also check if this function was called with the same write position(in event mode only)
// Underruning will also be checked via timer mechanism
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
ntStatus = SetCurrentWritePositionInternal(ulCurrentWritePosition);
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
}
if (!NT_SUCCESS(ntStatus))
{
m_ulLastOsWritePacket = oldLastOsWritePacket;
}
return ntStatus;
}
//=============================================================================
#pragma code_seg()
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS CMiniportWaveRTStream::GetOutputStreamPresentationPosition
(
_Out_ KSAUDIO_PRESENTATION_POSITION *pPresentationPosition
)
{
ASSERT (pPresentationPosition);
// The call must be from event driven mode
if(m_ulNotificationsPerBuffer == 0)
{
return STATUS_NOT_SUPPORTED;
}
return GetPresentationPosition(pPresentationPosition);
}
//=============================================================================
#pragma code_seg()
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS CMiniportWaveRTStream::GetPacketCount
(
_Out_ ULONG *pPacketCount
)
{
ASSERT(pPacketCount);
// The call must be from event driven mode
if(m_ulNotificationsPerBuffer == 0)
{
return STATUS_NOT_SUPPORTED;
}
KIRQL oldIrql;
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
if (m_KsState == KSSTATE_RUN)
{
// Get the current time and update simulated position.
LARGE_INTEGER ilQPC = KeQueryPerformanceCounter(NULL);
UpdatePosition(ilQPC);
}
*pPacketCount = LODWORD(m_llPacketCounter);
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
return STATUS_SUCCESS;
}
//=============================================================================
#pragma code_seg()
NTSTATUS CMiniportWaveRTStream::SetState
(
_In_ KSSTATE State_
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PADAPTERCOMMON pAdapterComm = m_pMiniport->GetAdapterCommObj();
KIRQL oldIrql;
// Spew an event for a pin state change request from portcls
//Event type: eMINIPORT_PIN_STATE
//Parameter 1: Current linear buffer position
//Parameter 2: Current WaveRtBufferWritePosition
//Parameter 3: Pin State 0->KS_STOP, 1->KS_ACQUIRE, 2->KS_PAUSE, 3->KS_RUN
//Parameter 4: 0
pAdapterComm->WriteEtwEvent(eMINIPORT_PIN_STATE,
m_ullLinearPosition, // replace with the correct "Current linear buffer position"
m_ulCurrentWritePosition, // replace with the previous WaveRtBufferWritePosition that the driver received
State_, // replace with the correct "Data length completed"
0); // always zero
switch (State_)
{
case KSSTATE_STOP:
if (m_KsState == KSSTATE_ACQUIRE)
{
// Acquire stream resources
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (m_SidebandOpen)
{
PSIDEBANDDEVICECOMMON sidebandDevice;
ASSERT(m_pMiniport->IsSidebandDevice());
sidebandDevice = m_pMiniport->GetSidebandDevice(); // weak ref.
ASSERT(sidebandDevice != NULL);
//
// Close the Sideband connection.
//
ntStatus = sidebandDevice->StreamClose(m_pMiniport->m_DeviceType);
if (!NT_SUCCESS(ntStatus))
{
DPF(D_ERROR, ("SetState: KSSTATE_PAUSE, StreamClose failed, 0x%x", ntStatus));
}
m_SidebandOpen = FALSE;
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
}
KeAcquireSpinLock(&m_PositionSpinLock, &oldIrql);
// Reset DMA
m_llPacketCounter = 0;
m_ullPlayPosition = 0;
m_ullWritePosition = 0;
m_ullLinearPosition = 0;
m_ullPresentationPosition = 0;
// Reset OS read/write positions
m_ulLastOsReadPacket = ULONG_MAX;
m_ulCurrentWritePosition = 0;
m_ulLastOsWritePacket = ULONG_MAX;
m_bEoSReceived = FALSE;
m_bLastBufferRendered = FALSE;
KeReleaseSpinLock(&m_PositionSpinLock, oldIrql);
// Wait until all work items are completed.
if (!m_bCapture && !g_DoNotCreateDataFiles)
{
m_SaveData.WaitAllWorkItems();
}
break;
case KSSTATE_ACQUIRE:
if (m_KsState == KSSTATE_STOP)
{
// Acquire stream resources
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (m_pMiniport->IsSidebandDevice())
{
if (m_SidebandOpen == FALSE)
{
PSIDEBANDDEVICECOMMON sidebandDevice;
sidebandDevice = m_pMiniport->GetSidebandDevice(); // weak ref.
ASSERT(sidebandDevice != NULL);
//
// Open the Sideband connection.
//
ntStatus = sidebandDevice->StreamOpen(m_pMiniport->m_DeviceType);
IF_FAILED_ACTION_JUMP(
ntStatus,
DPF(D_ERROR, ("SetState: KSSTATE_ACQUIRE, StreamOpen failed, 0x%x", ntStatus)),
Done);
m_SidebandOpen = TRUE;
}
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
}
break;
case KSSTATE_PAUSE:
if (m_KsState > KSSTATE_PAUSE)
{
//
// Run -> Pause
//
if (m_pMiniport->IsKeywordDetectorPin(m_ulPin))
{
m_pMiniport->m_KeywordDetector.Stop();
}
// Pause DMA
if (m_ulNotificationIntervalMs > 0)
{
ExCancelTimer(m_pNotificationTimer, NULL);
KeFlushQueuedDpcs();
// If pin is transitioning from RUN, save the time since last buffer completion event was sent
// so if the pin goes to RUN state again we can send the buffer completion event at correct time.
if (m_ullLastDPCTimeStamp > 0)
{
LARGE_INTEGER qpc;
LARGE_INTEGER qpcFrequency;
LONGLONG hnsCurrentTime;
qpc = KeQueryPerformanceCounter(&qpcFrequency);
// Convert ticks to 100ns units.
hnsCurrentTime = KSCONVERT_PERFORMANCE_TIME(m_ullPerformanceCounterFrequency.QuadPart, qpc);
m_hnsDPCTimeCarryForward = hnsCurrentTime - m_ullLastDPCTimeStamp + m_hnsDPCTimeCarryForward;
}
}
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (m_SidebandStarted)
{
PSIDEBANDDEVICECOMMON sidebandDevice;
ASSERT(m_pMiniport->IsSidebandDevice());
sidebandDevice = m_pMiniport->GetSidebandDevice(); // weak ref.
ASSERT(sidebandDevice != NULL);
//
// Close the Sideband connection.
//
ntStatus = sidebandDevice->StreamSuspend(m_pMiniport->m_DeviceType);
if (!NT_SUCCESS(ntStatus))
{
DPF(D_ERROR, ("SetState: KSSTATE_PAUSE, StreamClose failed, 0x%x", ntStatus));
}
m_SidebandStarted = FALSE;
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
}
// This call updates the linear buffer and presentation positions.
GetPositions(NULL, NULL, NULL);
break;
case KSSTATE_RUN:
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (m_pMiniport->IsSidebandDevice())
{
if (m_SidebandStarted == FALSE)
{
PSIDEBANDDEVICECOMMON sidebandDevice;
sidebandDevice = m_pMiniport->GetSidebandDevice(); // weak ref.
ASSERT(sidebandDevice != NULL);
//
// Start the Sideband connection.
//
ntStatus = sidebandDevice->StreamStart(m_pMiniport->m_DeviceType);
IF_FAILED_ACTION_JUMP(
ntStatus,
DPF(D_ERROR, ("SetState: KSSTATE_RUN, StreamStart failed, 0x%x", ntStatus)),
Done);
m_SidebandStarted = TRUE;
}
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
// Start DMA
LARGE_INTEGER ullPerfCounterTemp;
if (m_pMiniport->IsKeywordDetectorPin(m_ulPin))
{
m_pMiniport->m_KeywordDetector.Run();
}
ullPerfCounterTemp = KeQueryPerformanceCounter(&m_ullPerformanceCounterFrequency);
m_ullLastDPCTimeStamp = m_ullDmaTimeStamp = KSCONVERT_PERFORMANCE_TIME(m_ullPerformanceCounterFrequency.QuadPart, ullPerfCounterTemp);
if (m_ulNotificationIntervalMs > 0)
{
// Set timer for 1 ms. This will cause DPC to run every 1 ms but driver will send out
// notification events only after notification interval. This timer is used by Sysvad to
// emulate hardware and send out notification event. Real hardware should not use this
// timer to fire notification event as it will drain power if the timer is running at 1 msec.
ExSetTimer
(
m_pNotificationTimer,
(-1) * HNSTIME_PER_MILLISECOND,
HNSTIME_PER_MILLISECOND, // 1 ms
NULL
);
}
break;
}
m_KsState = State_;
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
Done:
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
return ntStatus;
}
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS CMiniportWaveRTStream::SetFormat
(
_In_ KSDATAFORMAT *DataFormat_
)
{
UNREFERENCED_PARAMETER(DataFormat_);
PAGED_CODE();
//if (!m_fCapture && !g_DoNotCreateDataFiles)
//{
// ntStatus = m_SaveData.SetDataFormat(Format);
//}
return STATUS_NOT_SUPPORTED;
}
#pragma code_seg()
//=============================================================================
#pragma code_seg()
VOID CMiniportWaveRTStream::UpdatePosition
(
_In_ LARGE_INTEGER ilQPC
)
{
// Convert ticks to 100ns units.
LONGLONG hnsCurrentTime = KSCONVERT_PERFORMANCE_TIME(m_ullPerformanceCounterFrequency.QuadPart, ilQPC);
// Calculate the time elapsed since the last call to GetPosition() or since the
// DMA engine started. Note that the division by 10000 to convert to milliseconds
// may cause us to lose some of the time, so we will carry the remainder forward
// to the next GetPosition() call.
//
ULONG TimeElapsedInMS = (ULONG)(hnsCurrentTime - m_ullDmaTimeStamp + m_hnsElapsedTimeCarryForward)/10000;
// Carry forward the remainder of this division so we don't fall behind with our position too much.
//
m_hnsElapsedTimeCarryForward = (hnsCurrentTime - m_ullDmaTimeStamp + m_hnsElapsedTimeCarryForward) % 10000;
// Calculate how many bytes in the DMA buffer would have been processed in the elapsed
// time. Note that the division by 1000 to convert to milliseconds may cause us to
// lose some bytes, so we will carry the remainder forward to the next GetPosition() call.
//
// need to divide by 1000 because m_ulDmaMovementRate is average bytes per sec.
ULONG ByteDisplacement = ((m_ulDmaMovementRate * TimeElapsedInMS) + m_byteDisplacementCarryForward) / 1000 ;
m_byteDisplacementCarryForward = ((m_ulDmaMovementRate * TimeElapsedInMS) + m_byteDisplacementCarryForward) % 1000;
// Increment presentation position even after last buffer is rendered.
m_ullPresentationPosition += ByteDisplacement;
if (m_bCapture)
{
// Write sine wave to buffer.
WriteBytes(ByteDisplacement);
}
else
{
if (m_bEoSReceived)
{
// since EoS flag is set, we'll need to make sure not to read data beyond EOS position.
// If driver's current position is less than EoS position, then make sure not to read data beyond EoS.
if (m_ullWritePosition <= m_ulCurrentWritePosition)
{
ByteDisplacement = min(ByteDisplacement, m_ulCurrentWritePosition - (ULONG)m_ullWritePosition);
}
// If our current position is ahead of EoS position and we'll wrap around after new position then adjust
// new position if it crosses EoS.
else if ((m_ullWritePosition + ByteDisplacement) % m_ulDmaBufferSize < m_ullWritePosition)
{
if ((m_ullWritePosition + ByteDisplacement) % m_ulDmaBufferSize > m_ulCurrentWritePosition)
{
ByteDisplacement = ByteDisplacement - (((ULONG)m_ullWritePosition + ByteDisplacement) % m_ulDmaBufferSize - m_ulCurrentWritePosition);
}
}
}
// If the last packet was rendered(read in the sample driver's case), send out an etw event.
if ( m_bEoSReceived && !m_bLastBufferRendered
&& (m_ullWritePosition + ByteDisplacement) % m_ulDmaBufferSize == m_ulCurrentWritePosition)
{
m_bLastBufferRendered = TRUE;
PADAPTERCOMMON pAdapterComm = m_pMiniport->GetAdapterCommObj();
//Event type : eMINIPORT_LAST_BUFFER_RENDERED
//Parameter 1 : Current linear buffer position
//Parameter 2 : the very last WaveRtBufferWritePosition that the driver received
//Parameter 3 : 0
//Parameter 4 : 0
pAdapterComm->WriteEtwEvent(eMINIPORT_LAST_BUFFER_RENDERED,
m_ullLinearPosition + ByteDisplacement, // Current linear buffer position
m_ulCurrentWritePosition, // The very last WaveRtBufferWritePosition that the driver received
0,
0);
}
if (!g_DoNotCreateDataFiles)
{
// Read from buffer and write to a file.
ReadBytes(ByteDisplacement);
}
}
// Increment the DMA position by the number of bytes displaced since the last
// call to UpdatePosition() and ensure we properly wrap at buffer length.
//
m_ullPlayPosition = m_ullWritePosition =
(m_ullWritePosition + ByteDisplacement) % m_ulDmaBufferSize;
// m_ullDmaTimeStamp is updated in both GetPostion and GetLinearPosition calls
// so m_ullLinearPosition needs to be updated accordingly here
//
m_ullLinearPosition += ByteDisplacement;
// Update the DMA time stamp for the next call to GetPosition()
//
m_ullDmaTimeStamp = hnsCurrentTime;
}
//=============================================================================
#pragma code_seg()
VOID CMiniportWaveRTStream::WriteBytes
(
_In_ ULONG ByteDisplacement
)
/*++
Routine Description:
This function writes the audio buffer using a sine wave generator
Arguments:
ByteDisplacement - # of bytes to process.
--*/
{
ULONG bufferOffset = m_ullLinearPosition % m_ulDmaBufferSize;
// Normally this will loop no more than once for a single wrap, but if
// many bytes have been displaced then this may loops many times.
while (ByteDisplacement > 0)
{
ULONG runWrite = min(ByteDisplacement, m_ulDmaBufferSize - bufferOffset);
m_ToneGenerator.GenerateSine(m_pDmaBuffer + bufferOffset, runWrite);
bufferOffset = (bufferOffset + runWrite) % m_ulDmaBufferSize;
ByteDisplacement -= runWrite;
}
}
//=============================================================================
#pragma code_seg()
VOID CMiniportWaveRTStream::ReadBytes
(
_In_ ULONG ByteDisplacement
)
/*++
Routine Description:
This function reads the audio buffer and saves the data in a file.
Arguments:
ByteDisplacement - # of bytes to process.
--*/
{
ULONG bufferOffset = m_ullLinearPosition % m_ulDmaBufferSize;
// Normally this will loop no more than once for a single wrap, but if
// many bytes have been displaced then this may loops many times.
while (ByteDisplacement > 0)
{
ULONG runWrite = min(ByteDisplacement, m_ulDmaBufferSize - bufferOffset);
m_SaveData.WriteData(m_pDmaBuffer + bufferOffset, runWrite);
bufferOffset = (bufferOffset + runWrite) % m_ulDmaBufferSize;
ByteDisplacement -= runWrite;
}
}
//=============================================================================
#pragma code_seg("PAGE")
STDMETHODIMP_(NTSTATUS)
CMiniportWaveRTStream::SetContentId
(
_In_ ULONG contentId,
_In_ PCDRMRIGHTS drmRights
)
/*++
Routine Description:
Sets DRM content Id for this stream. Also updates the Mixed content Id.
Arguments:
contentId - new content id
drmRights - rights for this stream.
Return Value:
NT status code.
--*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportWaveRT::SetContentId]"));
NTSTATUS ntStatus;
ULONG ulOldContentId = contentId;
m_ulContentId = contentId;
//
// Miniport should create a mixed DrmRights.
//
ntStatus = m_pMiniport->UpdateDrmRights();
//
// Restore the passed-in content Id.
//
if (!NT_SUCCESS(ntStatus))
{
m_ulContentId = ulOldContentId;
}
//
// SYSVAD writes each stream seperately to disk. If the rights for this
// stream indicates that the stream is CopyProtected, stop writing to disk.
//
m_SaveData.Disable(drmRights->CopyProtect);
//
// From MSDN:
//
// This sample doesn't forward protected content, but if your driver uses
// lower layer drivers or a different stack to properly work, please see the
// following info from MSDN:
//
// "Before allowing protected content to flow through a data path, the system
// verifies that the data path is secure. To do so, the system authenticates
// each module in the data path beginning at the upstream end of the data path
// and moving downstream. As each module is authenticated, that module gives
// the system information about the next module in the data path so that it
// can also be authenticated. To be successfully authenticated, a module's
// binary file must be signed as DRM-compliant.
//
// Two adjacent modules in the data path can communicate with each other in
// one of several ways. If the upstream module calls the downstream module
// through IoCallDriver, the downstream module is part of a WDM driver. In
// this case, the upstream module calls the DrmForwardContentToDeviceObject
// function to provide the system with the device object representing the
// downstream module. (If the two modules communicate through the downstream
// module's COM interface or content handlers, the upstream module calls
// DrmForwardContentToInterface or DrmAddContentHandlers instead.)
//
// DrmForwardContentToDeviceObject performs the same function as
// PcForwardContentToDeviceObject and IDrmPort2::ForwardContentToDeviceObject."
//
// Other supported DRM DDIs for down-level module validation are:
// DrmForwardContentToInterfaces and DrmAddContentHandlers.
//
// For more information, see MSDN's DRM Functions and Interfaces.
//
return ntStatus;
} // SetContentId
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
//=============================================================================
#pragma code_seg()
NTSTATUS
CMiniportWaveRTStream::GetSidebandStreamNtStatus()
/*++
Routine Description:
Checks if the Sideband stream connection is up, if not, an error is returned.
Return Value:
NT status code.
--*/
{
DPF_ENTER(("[CMiniportWaveRTStream::GetSidebandStreamNtStatus]"));
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_STATE;
if (m_SidebandStarted)
{
PSIDEBANDDEVICECOMMON sidebandDevice;
ASSERT(m_pMiniport->IsSidebandDevice());
sidebandDevice = m_pMiniport->GetSidebandDevice(); // weak ref.
ASSERT(sidebandDevice != NULL);
if (sidebandDevice->GetStreamStatus(m_pMiniport->m_DeviceType))
{
ntStatus = STATUS_SUCCESS;
}
}
return ntStatus;
}
#endif // defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS
CMiniportWaveRTStream::PropertyHandlerModulesListRequest
(
_In_ PPCPROPERTY_REQUEST PropertyRequest
)
{
// This specific APO->driver communication example is mainly added to show
// how this communication is done. The instance module list lives on the
// stream object and it can only have modules associated with the underline
// stream's pin.
PAGED_CODE();
DPF_ENTER(("[CMiniportWaveRTStream::PropertyHandlerModulesListRequest]"));
return AudioModule_GenericHandler_ModulesListRequest(
PropertyRequest,
GetAudioModuleList(),
GetAudioModuleListCount());
} // PropertyHandlerModulesListRequest
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS
CMiniportWaveRTStream::PropertyHandlerModuleCommand
(
_In_ PPCPROPERTY_REQUEST PropertyRequest
)
{
PAGED_CODE();
DPF_ENTER(("[CMiniportWaveRTStream::PropertyHandlerModuleCommand]"));
return AudioModule_GenericHandler_ModuleCommand(
PropertyRequest,
GetAudioModuleList(),
GetAudioModuleListCount());
} // PropertyHandlerModuleCommand
//=============================================================================
#pragma code_seg()
void
TimerNotifyRT
(
_In_ PEX_TIMER Timer,
_In_opt_ PVOID DeferredContext
)
{
LARGE_INTEGER qpc;
LARGE_INTEGER qpcFrequency;
BOOL bufferCompleted = FALSE;
UNREFERENCED_PARAMETER(Timer);
_IRQL_limited_to_(DISPATCH_LEVEL);
CMiniportWaveRTStream* _this = (CMiniportWaveRTStream*)DeferredContext;
if (NULL == _this)
{
return;
}
KIRQL oldIrql;
KeAcquireSpinLock(&_this->m_PositionSpinLock, &oldIrql);
qpc = KeQueryPerformanceCounter(&qpcFrequency);
// Convert ticks to 100ns units.
LONGLONG hnsCurrentTime = KSCONVERT_PERFORMANCE_TIME(_this->m_ullPerformanceCounterFrequency.QuadPart, qpc);
// Calculate the time elapsed since the last we ran DPC that matched Notification interval. Note that the division by 10000
// to convert to milliseconds may cause us to lose some of the time, so we will carry the remainder forward.
ULONG TimeElapsedInMS = (ULONG)(hnsCurrentTime - _this->m_ullLastDPCTimeStamp + _this->m_hnsDPCTimeCarryForward)/10000;
if (TimeElapsedInMS >= _this->m_ulNotificationIntervalMs)
{
// Carry forward the time greater than notification interval to adjust time to signal next buffer completion event accordingly.
_this->m_hnsDPCTimeCarryForward = hnsCurrentTime - _this->m_ullLastDPCTimeStamp + _this->m_hnsDPCTimeCarryForward - (_this->m_ulNotificationIntervalMs * 10000);
// Save the last time DPC ran at notification interval
_this->m_ullLastDPCTimeStamp = hnsCurrentTime;
bufferCompleted = TRUE;
}
if (!bufferCompleted && !_this->m_bEoSReceived)
{
goto End;
}
_this->UpdatePosition(qpc);
if (!_this->m_bEoSReceived)
{
_this->m_llPacketCounter++;
}
#if defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
if (_this->m_SidebandStarted)
{
if (!NT_SUCCESS(_this->GetSidebandStreamNtStatus()))
{
goto End;
}
}
#endif //defined(SYSVAD_BTH_BYPASS) || defined(SYSVAD_USB_SIDEBAND)
_this->m_pMiniport->DpcRoutine(qpc.QuadPart, qpcFrequency.QuadPart);
if (_this->m_KsState != KSSTATE_RUN)
{
goto End;
}
PADAPTERCOMMON pAdapterComm = _this->m_pMiniport->GetAdapterCommObj();
// Simple buffer underrun detection.
if (!_this->IsCurrentWaveRTWritePositionUpdated() && !_this->m_bEoSReceived)
{
//Event type: eMINIPORT_GLITCH_REPORT
//Parameter 1: Current linear buffer position
//Parameter 2: Previous WaveRtBufferWritePosition that the driver received
//Parameter 3: Major glitch code: 1:WaveRT buffer is underrun
//Parameter 4: Minor code for the glitch cause
pAdapterComm->WriteEtwEvent(eMINIPORT_GLITCH_REPORT,
_this->m_ullLinearPosition,
_this->GetCurrentWaveRTWritePosition(),
1, // WaveRT buffer is underrun
0);
}
// Send buffer completion event if either of the following is true
// 1. Driver consumed a complete buffer for this stream
// 2. Driver consumed a partial buffer containing EoS for this stream
if (!IsListEmpty(&_this->m_NotificationList) &&
(bufferCompleted || _this->m_bLastBufferRendered))
{
PLIST_ENTRY leCurrent = _this->m_NotificationList.Flink;
while (leCurrent != &_this->m_NotificationList)
{
NotificationListEntry* nleCurrent = CONTAINING_RECORD( leCurrent, NotificationListEntry, ListEntry);
//Event type: eMINIPORT_BUFFER_COMPLETE
//Parameter 1: Current linear buffer position
//Parameter 2: Previous WaveRtBufferWritePosition that the driver received
//Parameter 3: Data length completed
//Parameter 4: 0
pAdapterComm->WriteEtwEvent(eMINIPORT_BUFFER_COMPLETE,
_this->m_ullLinearPosition,
_this->GetCurrentWaveRTWritePosition(),
_this->m_ulDmaBufferSize/_this->m_ulNotificationsPerBuffer, // replace with the correct "Data length completed"
0); // always zero
KeSetEvent(nleCurrent->NotificationEvent, 0, 0);
leCurrent = leCurrent->Flink;
}
}
if (_this->m_bLastBufferRendered)
{
ExCancelTimer(_this->m_pNotificationTimer, NULL);
}
End:
KeReleaseSpinLock(&_this->m_PositionSpinLock, oldIrql);
return;
}
//=============================================================================
|