-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathio.cpp
1265 lines (1050 loc) · 29.8 KB
/
io.cpp
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
#include "pch.h"
#include "io.h"
#if 0
VOID
IoAudioEvtControlUrb(
_In_
WDFQUEUE Queue,
_In_
WDFREQUEST Request,
_In_
size_t OutputBufferLength,
_In_
size_t InputBufferLength,
_In_
ULONG IoControlCode
)
{
UNREFERENCED_PARAMETER(Queue);
UNREFERENCED_PARAMETER(Request);
UNREFERENCED_PARAMETER(IoControlCode);
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
NTSTATUS status = 0;
PUCHAR transferBuffer;
DbgPrint("Unhandled audio control evt!!!!!\n");
status = UdecxUrbRetrieveBuffer(Request, &transferBuffer, NULL);
if (NT_SUCCESS(status)) {
if (OutputBufferLength > 0)
{
RtlZeroMemory(transferBuffer, OutputBufferLength);
}
}
CompleteURB(Request, OutputBufferLength, 0);
return;
}
#endif
VOID
IoEvtControlUrb(
_In_
WDFQUEUE Queue,
_In_
WDFREQUEST Request,
_In_
size_t OutputBufferLength,
_In_
size_t InputBufferLength,
_In_
ULONG IoControlCode
)
{
WDF_USB_CONTROL_SETUP_PACKET setupPacket;
NTSTATUS status;
PUCHAR transferBuffer;
ULONG transferBufferLength, transferedLength = 0;
WDFDEVICE wdfDevice;
PUSB_CONTEXT usbContext;
UNREFERENCED_PARAMETER(Queue);
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
NT_VERIFY(IoControlCode == IOCTL_INTERNAL_USB_SUBMIT_URB);
wdfDevice = WdfIoQueueGetDevice(Queue);
usbContext = WdfDeviceGetUsbContext(wdfDevice);
status = UdecxUrbRetrieveBuffer(Request, &transferBuffer, &transferBufferLength);
if (!NT_SUCCESS(status)) {
// Could mean there is no buffer on the request
transferBuffer = NULL;
transferBufferLength = 0;
status = STATUS_SUCCESS;
DbgPrint("No transfer buffer provided\n");
goto exit;
}
//Initlize transferedLength and update it later to real length if it was changed.
//transferedLength = transferBufferLength;
status = UdecxUrbRetrieveControlSetupPacket(Request, &setupPacket);
if (!NT_SUCCESS(status)) {
DbgPrint("WdfRequest %p is not a control URB? UdecxUrbRetrieveControlSetupPacket %d", Request, status);
UdecxUrbCompleteWithNtStatus(Request, status);
goto exit;
}
if (setupPacket.Packet.bm.Request.Recipient != BmRequestToInterface ||
setupPacket.Packet.bm.Request.Type != BmRequestClass || transferBufferLength < setupPacket.Packet.wLength)
{
status = STATUS_INVALID_DEVICE_REQUEST;
DbgPrint("Unrecognized control request \n");
goto exit;
}
#if 0
int selector = setupPacket.Packet.wValue.Bytes.HiByte;
int req = setupPacket.Packet.bRequest;
DbgPrint("selector:%d,req:%d\n", selector,req);
#endif
if (setupPacket.Packet.wIndex.Value == 1)
{
status = videoControl(usbContext, setupPacket, transferBuffer, &transferedLength);
}
else
{
status = ptzControl(usbContext, setupPacket, transferBuffer, &transferedLength);
}
exit:
//DbgPrint("CompleteURB:%d,%d\n", transferedLength, status);
CompleteURB(Request, transferedLength, status);
return;
}
void init_ptz_ctrl_data(PUSB_CONTEXT usbContext)
{
usbContext->ptzData.focus_rel_data[0] = 0;//bFocusRelative
usbContext->ptzData.focus_rel_data[1] = FOCUS_REL_DEFAULT;//bSpeed
usbContext->ptzData.zoom_abs_data[0] = ZOOM_ABS_DEFAULT;
usbContext->ptzData.zoom_rel_data[0] = 0;//bZoom
usbContext->ptzData.zoom_rel_data[1] = 0;//bDigitalZoom
usbContext->ptzData.zoom_rel_data[2] = ZOOM_REL_DEFAULT;//bSpeed
usbContext->ptzData.pantilt_rel_data[0] = 0; // bPanRelative
usbContext->ptzData.pantilt_rel_data[1] = PANTILT_REL_SPEED_DEFAULT; // bPanSpeed
usbContext->ptzData.pantilt_rel_data[2] = 0; // bTiltRelative
usbContext->ptzData.pantilt_rel_data[3] = PANTILT_REL_SPEED_DEFAULT; // bTiltSpeed
}
void ptzNotifyApp(PUSB_CONTEXT usbContext, int controlType, int v1, int v2, int v3, int v4)
{
PTZ_CTRL_Data cmd;
cmd.controlType = controlType;
cmd.v1 = v1;
cmd.v2 = v2;
cmd.v3 = v3;
cmd.v4 = v4;
PTZ_CTRL_LIST_ITEM* pItem = (PTZ_CTRL_LIST_ITEM*)ExAllocatePool(NonPagedPool, sizeof(PTZ_CTRL_LIST_ITEM));
if (pItem == NULL)
{
PRINTLINE("No mem");
return;
}
RtlCopyMemory((void*)(&pItem->ctrl), (void*)&cmd, sizeof(cmd));
InsertHeadList(&usbContext->ptzListHdr, &pItem->ListEntry);
PRINTLINE("Insert ptz cmd to list");
}
NTSTATUS ptzControl(
_In_ PUSB_CONTEXT usbContext,
_In_
WDF_USB_CONTROL_SETUP_PACKET setupPacket,
_In_
PUCHAR transferBuffer,
_Out_
PULONG transferedLen
)
{
NTSTATUS status = 0;
*transferedLen = setupPacket.Packet.wLength;
int selector = setupPacket.Packet.wValue.Bytes.HiByte;
int req = setupPacket.Packet.bRequest;
//DbgPrint("selector:%d,req:%d\n", selector,req);
if (selector == UVC_CT_ZOOM_ABSOLUTE_CONTROL)
{
/*
A value of 1 indicates that the zoom lens is moved towards the telephoto direction. A value
of zero indicates that the zoom lens is stopped, and a value of 0xFF indicates that the zoom lens
is moved towards the wide-angle direction
*/
//INT8 zoom = (INT8)zoom_rel_data[0];
//DbgPrint("UVC_CT_ZOOM_ABSOLUTE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
//INT8 val = transferBuffer[2];
//zoom_rel_data[0] = val == 0 ? 0 : (val > 0) ? 1 : 0xff;
memcpy(usbContext->ptzData.zoom_abs_data, transferBuffer, sizeof(UINT16));
UINT16 wObjectiveFocalLength = 0;
memcpy(&wObjectiveFocalLength, transferBuffer, sizeof(UINT16));
////logMessage("wObjectiveFocalLength is %d", wObjectiveFocalLength);
if (wObjectiveFocalLength < ZOOM_ABS_MIN) {
wObjectiveFocalLength = ZOOM_ABS_MIN;
}
if (wObjectiveFocalLength > ZOOM_ABS_MAX) {
wObjectiveFocalLength = ZOOM_ABS_MAX;
}
ptzNotifyApp(usbContext, NDI_PTZ_ZOOM_ABS, wObjectiveFocalLength, 0, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
memcpy(transferBuffer, usbContext->ptzData.zoom_abs_data, sizeof(UINT16));
break;
}
case UVC_GET_MIN:
{
UINT16 wObjectiveFocalLength = ZOOM_ABS_MIN;
memcpy(transferBuffer, &wObjectiveFocalLength, sizeof(UINT16));
break;
}
case UVC_GET_MAX:
{
UINT16 wObjectiveFocalLength = ZOOM_ABS_MAX;
memcpy(transferBuffer, &wObjectiveFocalLength, sizeof(UINT16));
break;
}
case UVC_GET_RES:
{
UINT16 wObjectiveFocalLength = 1;
memcpy(transferBuffer, &wObjectiveFocalLength, sizeof(UINT16));
break;
}
case UVC_GET_DEF:
{
UINT16 wObjectiveFocalLength = ZOOM_ABS_DEFAULT;
memcpy(transferBuffer, &wObjectiveFocalLength, sizeof(UINT16));
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_ZOOM_RELATIVE_CONTROL)
{
/*
A value of 1 indicates that the zoom lens is moved towards the telephoto direction. A value
of zero indicates that the zoom lens is stopped, and a value of 0xFF indicates that the zoom lens
is moved towards the wide-angle direction
*/
//INT8 zoom = (INT8)zoom_rel_data[0];
//DbgPrint("UVC_CT_ZOOM_RELATIVE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
//INT8 val = transferBuffer[2];
//zoom_rel_data[0] = val == 0 ? 0 : (val > 0) ? 1 : 0xff;
usbContext->ptzData.zoom_rel_data[0] = transferBuffer[0];
usbContext->ptzData.zoom_rel_data[2] = transferBuffer[2];
//logMessage("bZoom is %02x,bSpeed is %d", zoom_rel_data[0], zoom_rel_data[2]);
UINT8 bSpeed = usbContext->ptzData.zoom_rel_data[2];
//bSpeed -= ZOOM_REL_MIN;
if (bSpeed < 1) {
bSpeed = 1;
}
if (bSpeed > 10) {
bSpeed = 10;
}
ptzNotifyApp(usbContext, NDI_PTZ_ZOOM, usbContext->ptzData.zoom_rel_data[0], bSpeed, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
transferBuffer[0] = usbContext->ptzData.zoom_rel_data[0];//bZoom
transferBuffer[1] = 1;//bDigitalZoom
transferBuffer[2] = usbContext->ptzData.zoom_rel_data[2];//bSpeed
break;
}
case UVC_GET_MIN:
{
transferBuffer[0] = 0;//bZoom
transferBuffer[1] = 0;//bDigitalZoom
transferBuffer[2] = ZOOM_REL_MIN;//bSpeed
break;
}
case UVC_GET_MAX:
{
transferBuffer[0] = 0;//bZoom
transferBuffer[1] = 0;//bDigitalZoom
transferBuffer[2] = ZOOM_REL_MAX;//bSpeed
break;
}
case UVC_GET_RES:
{
transferBuffer[0] = 0;//bZoom
transferBuffer[1] = 0;//bDigitalZoom
transferBuffer[2] = 1;//bSpeed
break;
}
case UVC_GET_DEF:
{
transferBuffer[0] = 0;//bZoom
transferBuffer[1] = 1;//bDigitalZoom
transferBuffer[2] = ZOOM_REL_DEFAULT;//bSpeed
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_PANTILT_ABSOLUTE_CONTROL)
{
//DbgPrint("UVC_CT_PANTILT_ABSOLUTE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
INT32 dwPanAbsolute, dwTiltAbsolute;
memcpy(usbContext->ptzData.pantilt_abs_data, transferBuffer, sizeof(INT32) * 2);
dwPanAbsolute = usbContext->ptzData.pantilt_abs_data[0];
dwTiltAbsolute = usbContext->ptzData.pantilt_abs_data[1];
//logMessage("dwPanAbsolute is %d,dwTiltAbsolute is %d", dwPanAbsolute, dwTiltAbsolute);
//bPanSpeed -= PANTILT_REL_SPEED_MIN;
//bTiltSpeed -= PANTILT_REL_SPEED_MIN;
/*if (dwPanAbsolute < 1)
{
dwPanAbsolute = 1;
}
if (dwPanAbsolute > 10)
{
dwPanAbsolute = 10;
}
if (dwTiltAbsolute < 1)
{
dwTiltAbsolute = 1;
}
if (dwTiltAbsolute > 10)
{
dwTiltAbsolute = 10;
}*/
ptzNotifyApp(usbContext, NDI_PTZ_PAN_TILT_ABS, dwPanAbsolute, dwTiltAbsolute, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
memcpy(transferBuffer, usbContext->ptzData.pantilt_abs_data, sizeof(INT32) * 2);
break;
}
case UVC_GET_MIN:
{
INT32 dwPanAbsolute, dwTiltAbsolute;
dwPanAbsolute = 1;
dwTiltAbsolute = 1;
memcpy(transferBuffer, &dwPanAbsolute, sizeof(INT32));
memcpy(transferBuffer + 4, &dwTiltAbsolute, sizeof(INT32));
break;
}
case UVC_GET_MAX:
{
INT32 dwPanAbsolute, dwTiltAbsolute;
dwPanAbsolute = 10;
dwTiltAbsolute = 10;
memcpy(transferBuffer, &dwPanAbsolute, sizeof(INT32));
memcpy(transferBuffer + 4, &dwTiltAbsolute, sizeof(INT32));
break;
}
case UVC_GET_RES:
{
INT32 dwPanAbsolute, dwTiltAbsolute;
dwPanAbsolute = 1;
dwTiltAbsolute = 1;
memcpy(transferBuffer, &dwPanAbsolute, sizeof(INT32));
memcpy(transferBuffer + 4, &dwTiltAbsolute, sizeof(INT32));
break;
}
case UVC_GET_DEF:
{
INT32 dwPanAbsolute, dwTiltAbsolute;
dwPanAbsolute = 5;
dwTiltAbsolute = 5;
memcpy(transferBuffer, &dwPanAbsolute, sizeof(INT32));
memcpy(transferBuffer + 4, &dwTiltAbsolute, sizeof(INT32));
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_PANTILT_RELATIVE_CONTROL)
{
//DbgPrint("UVC_CT_PANTILT_RELATIVE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
memcpy(usbContext->ptzData.pantilt_rel_data, transferBuffer, sizeof(usbContext->ptzData.pantilt_rel_data));
//logMessage("bPanRelative is %x,bPanSpeed is %d,bTiltRelative is %x,bTiltSpeed is %d", pantilt_rel_data[0], pantilt_rel_data[1], pantilt_rel_data[2], pantilt_rel_data[3]);
UINT8 bPanRelative, bTiltRelative, bPanSpeed, bTiltSpeed;
bPanRelative = usbContext->ptzData.pantilt_rel_data[0];
bPanSpeed = usbContext->ptzData.pantilt_rel_data[1];
bTiltRelative = usbContext->ptzData.pantilt_rel_data[2];
bTiltSpeed = usbContext->ptzData.pantilt_rel_data[3];
//bPanSpeed -= PANTILT_REL_SPEED_MIN;
//bTiltSpeed -= PANTILT_REL_SPEED_MIN;
if (bPanSpeed < 1)
{
bPanSpeed = 1;
}
if (bPanSpeed > 10)
{
bPanSpeed = 10;
}
if (bTiltSpeed < 1)
{
bTiltSpeed = 1;
}
if (bTiltSpeed > 10)
{
bTiltSpeed = 10;
}
ptzNotifyApp(usbContext, NDI_PTZ_PAN_TILT, bPanRelative, bPanSpeed, bTiltRelative, bTiltSpeed);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
/*transferBuffer[0] = 0; //bPanRelative
transferBuffer[1] = 10; //bPanSpeed
transferBuffer[2] = 0; // bTiltRelative
transferBuffer[3] = 10; //bTiltSpeed */
memcpy(transferBuffer, usbContext->ptzData.pantilt_rel_data, sizeof(usbContext->ptzData.pantilt_rel_data));
break;
}
case UVC_GET_MIN:
{
transferBuffer[0] = 0; // bPanRelative
transferBuffer[1] = PANTILT_REL_SPEED_MIN; // bPanSpeed
transferBuffer[2] = 0; // bTiltRelative
transferBuffer[3] = PANTILT_REL_SPEED_MIN; // bTiltSpeed
break;
}
case UVC_GET_MAX:
{
transferBuffer[0] = 0; // bPanRelative
transferBuffer[1] = PANTILT_REL_SPEED_MAX; // bPanSpeed
transferBuffer[2] = 0; // bTiltRelative
transferBuffer[3] = PANTILT_REL_SPEED_MAX; // bTiltSpeed
break;
}
case UVC_GET_RES:
{
transferBuffer[0] = 0; // bPanRelative
transferBuffer[1] = 1; // bPanSpeed
transferBuffer[2] = 0; // bTiltRelative
transferBuffer[3] = 1; // bTiltSpeed
break;
}
case UVC_GET_DEF:
{
transferBuffer[0] = 0; // bPanRelative
transferBuffer[1] = PANTILT_REL_SPEED_DEFAULT; // bPanSpeed
transferBuffer[2] = 0; // bTiltRelative
transferBuffer[3] = PANTILT_REL_SPEED_DEFAULT; // bTiltSpeed
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_FOCUS_ABSOLUTE_CONTROL)
{
//UINT8 bFocus = (UINT8)focus_rel_data[0];
//DbgPrint("UVC_CT_FOCUS_ABSOLUTE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
memcpy(usbContext->ptzData.focus_abs_data, transferBuffer, sizeof(INT16));
INT16 wFocusAbsolute = usbContext->ptzData.focus_abs_data[0];
//logMessage("wFocusAbsolute is %d", wFocusAbsolute);
if (wFocusAbsolute < 1) {
wFocusAbsolute = 1;
}
if (wFocusAbsolute > 10) {
wFocusAbsolute = 10;
}
ptzNotifyApp(usbContext, NDI_PTZ_FOCUS_ABS, wFocusAbsolute, 0, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
memcpy(transferBuffer, usbContext->ptzData.focus_abs_data, sizeof(INT16));
break;
}
case UVC_GET_MIN:
{
INT16 wFocusAbsolute = 1;
memcpy(transferBuffer, &wFocusAbsolute, sizeof(INT16));
break;
}
case UVC_GET_MAX:
{
INT16 wFocusAbsolute = 10;
memcpy(transferBuffer, &wFocusAbsolute, sizeof(INT16));
break;
}
case UVC_GET_RES:
{
INT16 wFocusAbsolute = 1;
memcpy(transferBuffer, &wFocusAbsolute, sizeof(INT16));
break;
}
case UVC_GET_DEF:
{
INT16 wFocusAbsolute = 5;
memcpy(transferBuffer, &wFocusAbsolute, sizeof(INT16));
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_FOCUS_RELATIVE_CONTROL)
{
//UINT8 bFocus = (UINT8)focus_rel_data[0];
//DbgPrint("UVC_CT_FOCUS_RELATIVE_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
usbContext->ptzData.focus_rel_data[0] = transferBuffer[0];
usbContext->ptzData.focus_rel_data[1] = transferBuffer[1];
//logMessage("bFocus is %02x,bSpeed is %d", focus_rel_data[0], focus_rel_data[1]);
UINT8 bSpeed = usbContext->ptzData.focus_rel_data[1];
//bSpeed -= ZOOM_REL_MIN;
if (bSpeed < 1) {
bSpeed = 1;
}
if (bSpeed > 10) {
bSpeed = 10;
}
ptzNotifyApp(usbContext, NDI_PTZ_FOCUS, usbContext->ptzData.focus_rel_data[0], bSpeed, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
transferBuffer[0] = usbContext->ptzData.focus_rel_data[0];//bFocus
transferBuffer[1] = usbContext->ptzData.focus_rel_data[1];//bSpeed
break;
}
case UVC_GET_MIN:
{
transferBuffer[0] = 0;//bFocus
transferBuffer[1] = FOCUS_REL_MIN;//bSpeed
break;
}
case UVC_GET_MAX:
{
transferBuffer[0] = 0;//bFocus
transferBuffer[1] = FOCUS_REL_MAX;//bSpeed
break;
}
case UVC_GET_RES:
{
transferBuffer[0] = 0;//bFocus
transferBuffer[1] = 1;//bSpeed
break;
}
case UVC_GET_DEF:
{
transferBuffer[0] = 0;//bFocus
transferBuffer[1] = FOCUS_REL_DEFAULT;//bSpeed
break;
}
}
status = 0;
return status;
}
if (selector == UVC_CT_FOCUS_AUTO_CONTROL)
{
//UINT8 bFocus = (UINT8)focus_rel_data[0];
//DbgPrint("UVC_CT_FOCUS_AUTO_CONTROL\n");
switch (req)
{
case UVC_GET_INFO:
{
transferBuffer[0] = 0x02; /// GET / SET
break;
}
case UVC_SET_CUR:
{
usbContext->ptzData.focus_auto_data[0] = transferBuffer[0];
//logMessage("bFocusAuto is %d", transferBuffer[0]);
ptzNotifyApp(usbContext, NDI_PTZ_FOCUS_AUTO, transferBuffer[0], 0, 0, 0);
*transferedLen = 0;
break;
}
case UVC_GET_CUR:
{
transferBuffer[0] = usbContext->ptzData.focus_auto_data[0];//bFocus
break;
}
case UVC_GET_MIN:
{
transferBuffer[0] = 0;//bFocus
break;
}
case UVC_GET_MAX:
{
transferBuffer[0] = 1;//bFocus
break;
}
case UVC_GET_RES:
{
transferBuffer[0] = 1;//bFocus
break;
}
case UVC_GET_DEF:
{
transferBuffer[0] = 1;//bFocus
break;
}
}
status = 0;
return status;
}
#if 0
DbgPrint("Unhandled UVC selector %x\n", selector);
DbgPrint(" bRequest:0x%02x wValue: 0x%04x wIndex: 0x%04x wLength: 0x%04x\n",
setupPacket.Packet.bRequest, setupPacket.Packet.wValue.Bytes.HiByte,
setupPacket.Packet.wIndex.Value, setupPacket.Packet.wLength);
#endif
return status;
}
NTSTATUS videoControl(
_In_ PUSB_CONTEXT usbContext,
_In_
WDF_USB_CONTROL_SETUP_PACKET setupPacket,
_In_
PUCHAR transferBuffer,
_Out_
PULONG transferedLen
)
{
NTSTATUS status = 0;
*transferedLen = 0;
if (setupPacket.Packet.wIndex.Value != 1)
{
//not video interface
return STATUS_UNSUCCESSFUL;
}
if (setupPacket.Packet.wLength != sizeof(uvc_streaming_control))
{
DbgPrint("data len wrong\n");
goto exit;
}
uvc_streaming_control* sc = (uvc_streaming_control*)transferBuffer;
if (setupPacket.Packet.bRequest == UVC_SET_CUR)
{
//curr_format_index = sc->bFormatIndex;
//curr_frame_index = sc->bFrameIndex;
*transferedLen = 0;
status = 0;
DbgPrint("Video UVC_SET_CUR:curr_format_index is %d,curr_frame_index is %d\n", sc->bFormatIndex, sc->bFrameIndex);
if (sc->bFrameIndex != usbContext->frameData.bFrameIndex)
{
DbgPrint("Video set cur:STATUS_INVALID_PARAMETER: now supported frameIdx is %d", usbContext->frameData.bFrameIndex);
status = STATUS_INVALID_PARAMETER;
}
else
{
usbContext->frameData.needChangeFormat = 0;
}
goto exit;
}
RtlZeroBytes(sc, sizeof(uvc_streaming_control));
sc->bmHint = 0x01; /// supported dwFrameInterval
sc->bFormatIndex = usbContext->frameData.bFormatIndex;
sc->bFrameIndex = usbContext->frameData.bFrameIndex;
sc->dwFrameInterval = 0x00051615; // (33 ms -> 30.00 fps)
sc->wKeyFrameRate = 0;
sc->wPFrameRate = 0;
sc->wCompQuality = 0;
sc->wCompWindowSize = 0;
sc->wDelay = 0x0A; //// 停留 毫秒 ms ???
sc->dwMaxVideoFrameSize = usbContext->frameData.frame_length; ////
sc->dwMaxPayloadTransferSize = 2048; //// ????
status = 0;
*transferedLen = setupPacket.Packet.wLength;
switch (setupPacket.Packet.bRequest)
{
case UVC_GET_DEF:
{
//RtlZeroBytes(transferBuffer, setupPacket.Packet.wLength);
//*transferedLen = setupPacket.Packet.wLength;
//DbgPrint("video interface UVC_GET_DEF\n");
break;
}
case UVC_GET_CUR:
{
DbgPrint("video interface UVC_GET_CUR\n");
break;
}
case UVC_GET_MIN:
{
DbgPrint("video interface UVC_GET_MIN\n");
sc->bFrameIndex = 7;
break;
}
case UVC_GET_MAX:
{
DbgPrint("video interface UVC_GET_MAX\n");
sc->bFrameIndex = 1;
break;
}
default:
{
DbgPrint("Unhandled video interface %d\n", setupPacket.Packet.bRequest);
break;
}
}
exit:
return status;
}
VOID CompleteURB(
_In_ WDFREQUEST request,
_In_ ULONG transferBufferLength,
NTSTATUS status
)
{
if (NT_SUCCESS(status)) {
UdecxUrbSetBytesCompleted(request, transferBufferLength);
}
UdecxUrbCompleteWithNtStatus(request, status);
}
#if 0
#define DELAY_ONE_MICROSECOND (-10)
#define DELAY_ONE_MILLISECOND (DELAY_ONE_MICROSECOND*1000)
VOID MySleep(LONG msec)
{
LARGE_INTEGER my_interval;
my_interval.QuadPart = DELAY_ONE_MILLISECOND;
my_interval.QuadPart *= msec;
KeDelayExecutionThread(KernelMode, 0, &my_interval);
}
#endif
#if 0
VOID DpcCompleteAudioIsoUrb(
IN WDFDPC Dpc
)
{
PUSB_CONTEXT usbContext;
WDFREQUEST Request;
NTSTATUS status = STATUS_SUCCESS;
usbContext = WdfDeviceGetUsbContext(WdfDpcGetParentObject(Dpc));
PUCHAR vBuf;
ULONG vBufLen = 0;
ULONG transfered = 0;
WDF_REQUEST_PARAMETERS requestParams;
Request = usbContext->currentAudioRequest;
WDF_REQUEST_PARAMETERS_INIT(&requestParams);
WdfRequestGetParameters(Request, &requestParams);
PURB urb = (PURB)requestParams.Parameters.Others.Arg1;
if (urb->UrbHeader.Function != URB_FUNCTION_ISOCH_TRANSFER)
{
PRINTLINE("Incorrect URB");
status = STATUS_INVALID_PARAMETER;
WdfRequestComplete(Request, status);
return;
}
status = UdecxUrbRetrieveBuffer(Request, &vBuf, &vBufLen);
if (!NT_SUCCESS(status))
{
DbgPrint("WdfRequest %p unable to retrieve buffer %d", Request, status);
WdfRequestComplete(Request, status);
return;
}
for (int i = 0; i < (int)urb->UrbIsochronousTransfer.NumberOfPackets; ++i)
{
int dtlen = 0x800;
ULONG offset = urb->UrbIsochronousTransfer.IsoPacket[i].Offset;
UCHAR* buf = vBuf + offset;
int r = 0;
int len = min(usbContext->audioData.frame_length - usbContext->audioData.frame_pos, dtlen); ///
#if 0
RtlCopyMemory((UCHAR*)(buf), usbContext->audioData.frame_buf + usbContext->audioData.frame_pos, len);
#else
static int colorToFill = 0;
RtlFillMemory((UCHAR*)(buf), len, ++colorToFill);
#endif
usbContext->audioData.frame_pos += len; ////
r = len;
urb->UrbIsochronousTransfer.IsoPacket[i].Length = len;
transfered += r;
if (usbContext->audioData.frame_pos >= usbContext->audioData.frame_length) { ///帧结束
break;
}
//DbgPrint("IsoPacket[%d].Offset:%d,Length:%d]\n", i, urb->UrbIsochronousTransfer.IsoPacket[i].Offset, urb->UrbIsochronousTransfer.IsoPacket[i].Length);
}
UdecxUrbSetBytesCompleted(Request, transfered);
UdecxUrbCompleteWithNtStatus(Request, 0);
}
#endif
VOID DpcCompleteVidoeIsoUrb(
IN WDFDPC Dpc
)
{
PUSB_CONTEXT usbContext;
WDFREQUEST Request;
NTSTATUS status = STATUS_SUCCESS;
usbContext = WdfDeviceGetUsbContext(WdfDpcGetParentObject(Dpc));
PUCHAR vBuf;
ULONG vBufLen = 0;
ULONG transfered = 0;
WDF_REQUEST_PARAMETERS requestParams;
Request = usbContext->currentRequest;
WDF_REQUEST_PARAMETERS_INIT(&requestParams);
WdfRequestGetParameters(Request, &requestParams);
PURB urb = (PURB)requestParams.Parameters.Others.Arg1;
if (urb->UrbHeader.Function != URB_FUNCTION_ISOCH_TRANSFER)
{
DbgPrint("Incorrect URB\n");
status = STATUS_INVALID_PARAMETER;
WdfRequestComplete(Request, status);
return;
}
if (usbContext->frameData.frame_buf == NULL)
{
//PRINTLINE("E");
UdecxUrbSetBytesCompleted(Request, 0);
UdecxUrbCompleteWithNtStatus(Request, 0);
return;
}
status = UdecxUrbRetrieveBuffer(Request, &vBuf, &vBufLen);
if (!NT_SUCCESS(status))
{