-
Notifications
You must be signed in to change notification settings - Fork 4
/
winmain.cpp.bak
8353 lines (7038 loc) · 220 KB
/
winmain.cpp.bak
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
//////////////////////////////////////////////////////////////////////////
//
// winmain.cpp : Application entry-point
//
//////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iomanip>
#include <Dshow.h>
#include <strmif.h>
#include <ks.h>
#include <ksproxy.h>
#include <vidcap.h>
#include <ksmedia.h>
#include <comdef.h>
#include <objbase.h>
#include "qedit.h"
#include "MFCaptureD3D.h"
#include "resource.h"
#include "SampleCGB.h"
//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
#define ABS(x) (((x) > 0) ? (x) : -(x))
// window messages
#define WM_FGNOTIFY WM_USER+1
//#undef DEBUG
//#define DEBUG
#ifdef DEBUG
//#define REGISTER_FILTERGRAPH
#endif
// Include the v6 common controls in the manifest
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
float aspRetio = 0;
struct EXT_KS_TREE
{
// for Extension controls
IKsControl *pKsControl;
UINT nodeID;
BOOL isOK;
// IAMVideoProcAmp ptrs
IAMVideoProcAmp *pProcAmp;
IKsControl *pProcAmpKsControl;
UINT nodeIDProcAmpKsControl;
BOOL isOKpProcAmp;
BOOL isOKpProcAmpKsControl;
// IAMCameraControl
IAMCameraControl *pCamControl;
IKsControl *pCamControlKsControl;
UINT nodeIDCamControlKsControl;
BOOL isOKpCamControl;
BOOL isOKpCamControlKsControl;
IAMVideoControl *pVideoControl;
BOOL isOKpVideoControl;
// video straming ks node
IKsControl *pKsControlVideoStreaming;
UINT nodeIDVideoStreaming;
BOOL isOKVideoStreaming;
IPin *pStillPin;
}ksNodeTree;
struct _capstuff
{
WCHAR wszCaptureFile[_MAX_PATH];
WORD wCapFileSize; // size in Meg
ISampleCaptureGraphBuilder *pBuilder;
IVideoWindow *pVW;
IMediaEventEx *pME;
IAMDroppedFrames *pDF;
IAMVideoCompression *pVC;
IAMVfwCaptureDialogs *pDlg;
IAMStreamConfig *pASC; // for audio cap
IAMStreamConfig *pVSC; // for video cap
IBaseFilter *pRender;
IBaseFilter *pVCap, *pACap;
IGraphBuilder *pFg;
IFileSinkFilter *pSink;
IConfigAviMux *pConfigAviMux;
int iMasterStream;
BOOL fCaptureGraphBuilt;
BOOL fPreviewGraphBuilt;
BOOL fCapturing;
BOOL fPreviewing;
BOOL fMPEG2;
BOOL fCapAudio;
BOOL fCapCC;
BOOL fCCAvail;
BOOL fCapAudioIsRelevant;
bool fDeviceMenuPopulated;
int defaultVideoLogyCamID;
IMoniker *rgpmVideoMenu[10];
WCHAR rgpmVideoFriendlyName[10][120];
IMoniker *rgpmAudioMenu[10];
WCHAR rgpmAudioFriendlyName[10][120];
IMoniker *pmVideo;
IMoniker *pmAudio;
double FrameRate;
BOOL fWantPreview;
long lCapStartTime;
long lCapStopTime;
WCHAR wachFriendlyName[120];
BOOL fUseTimeLimit;
BOOL fUseFrameRate;
DWORD dwTimeLimit;
int iFormatDialogPos;
int iSourceDialogPos;
int iDisplayDialogPos;
int iVCapDialogPos;
int iVCrossbarDialogPos;
int iTVTunerDialogPos;
int iACapDialogPos;
int iACrossbarDialogPos;
int iTVAudioDialogPos;
int iVCapCapturePinDialogPos;
int iVCapPreviewPinDialogPos;
int iACapCapturePinDialogPos;
long lDroppedBase;
long lNotBase;
BOOL fPreviewFaked;
int iVideoInputMenuPos;
LONG NumberOfVideoInputs;
HMENU hMenuPopup;
int iNumVCapDevices;
int iSelectedDeviceIndex;
// For capture pin
IBaseFilter *pSampleGrabberFilter;
ISampleGrabber *pSampleGrabber;
IBaseFilter *pNullRenderer;
// for still pin
IBaseFilter *pSampleGrabberFilterStill;
ISampleGrabber *pSampleGrabberStill;
IBaseFilter *pNullRendererStill;
} gcap;
struct InitControlsSetting
{
// Extension controls
int ShutterControl;
int SenseUpMode;
int MirrorMode;
int NoiseReductionMode;
int NoiseReductionControl;
int DayNightMode;
int DayNightSwitchDelay;
int DaytoNightStartLevel;
int NighttoDayStartLevel;
int ExposureMode;
int AGCLevel;
int AEReferenceLevel;
int CameraMode;
int CameraParametersRecovery;
int I2Ccommand;
int BLCWeightFactor;
int BLCGrid;
//Standard Controls
int BacklightCompensation;
int Brightness;
int Contrast;
int MainsFrequency;
int Hue;
int Saturation;
int Sharpness;
int gamma;
int WhiteBalance;
int WhiteBalanceComponentRed;
int WhiteBalanceComponentBlue;
int DigitalMultiplier;
//Camera Terminal Controls
int AEMode;
int AEPriority;
int ExposureTimeAbsolute;
int FocusMode;
int FocusTrk;
int FocusMode_bak;
int FocusTrk_bak;
}initCtrlSetting;
//Videoloy Extension control
//void InitProcAmp(IMFActivate *pActivate);
//void InitCameraControl(IMFActivate *pActivate);
void createMFInterfaceVideoSettings();
BOOL InitCapFilters();
void FreeCapFilters();
BOOL StopPreview();
BOOL StartPreview();
void TearDownGraph();
void RemoveDownstream(IBaseFilter *pf);
BOOL MakeBuilder();
BOOL MakeGraph();
void ResizeWindow(int w, int h);
BOOL BuildPreviewGraph();
BOOL StopCapture();
HRESULT getExtionControlPropertySize(ULONG PropertyId, ULONG *pulSize);
HRESULT getExtionControlProperty(ULONG PropertyId, ULONG ulSize, BYTE pValue[]);
HRESULT setExtionControlProperty(ULONG PropertyId, ULONG ulSize, BYTE pValue[]);
HRESULT getExtionControlProperty(int ID, int *Value);
// Standard Controls
HRESULT getStandardControlPropertyRange(long PropertyID, long *lMin, long *lMax, long *lStep, long *lDefault, long *lCaps);
HRESULT getStandardControlPropertyCurrentValue(long PropertyID, long *currValue, long *lCaps);
//Camera Terminal Controls
HRESULT getCameraTerminalControlPropertyRange(long PropertyID, long *lMin, long *lMax, long *lStep, long *lDefault, long *lCaps);
HRESULT getCameraTerminalControlPropertyCurrentValue(long PropertyID, long *currValue, long *lCaps);
void AddDevicesToMenu();
void IMonRelease(IMoniker *&pm);
void readSnapPath();
void writeSnapPath();
BOOL InitializeApplication();
BOOL InitializeWindow(HWND *pHwnd);
void CleanUp();
INT MessageLoop(HWND hwnd);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK CameraControlDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DayNightSettingsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK VideoQualityControlDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK NoiseReductionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK I2CControlDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK ZoomControlDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK IrisControlDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK ImageCaptureDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK CameraRecoveryParamDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK LoginDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void ShowErrorMessage(PCWSTR format, HRESULT hr);
// Window message handlers
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct);
void OnClose(HWND hwnd);
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
void OnSize(HWND hwnd, UINT state, int cx, int cy);
void OnDeviceChange(HWND hwnd, DEV_BROADCAST_HDR *pHdr);
// Command handlers
void OnChooseDevice(HWND hwnd, BOOL bPrompt);
void OnCameraControlMenu(HWND hwnd);
void OnDayNightMenu(HWND hwnd);
void OnVideoQualityControlMenu(HWND hwnd);
void On3DNoiseReduction(HWND hwnd);
void OnAboutMenu(HWND hwnd);
void OnI2CControlMenu(HWND hwnd);
void OnZoomControlMenu(HWND hwnd);
void OnIrisControlMenu(HWND hwnd);
void OnImageCaptureMenu(HWND hwnd);
void OnCameraRecoveryParamMenu(HWND hwnd);
// Constants
const WCHAR CLASS_NAME[] = L"MFCapture Window Class";
const WCHAR WINDOW_NAME[] = L"Videology USB 3.0 Custom Viewer";
const GUID EXTGUID = { 0x3757CA7A, 0x1AA3, 0x495B, { 0x96, 0x8D, 0x8E, 0x36, 0x1F, 0x96, 0x76, 0x50 } };
const char BrandNameFile[] = "BrandName.txt";
const char BrandLogoFile[] = "BrandLogo.bmp";
const char snapCountFile[] = "snapCount.txt";
const char irisModeFile[] = "irisMode.txt";
const char snapPathFile[] = "snapPath.txt";
// Global variables
HDEVNOTIFY g_hdevnotify = NULL;
static int snapshotIndex = 1;
HWND ghwndApp;
int indexOf_shift(char* base, char* str, int startIndex);
int lastIndexOf(char* base, char* str);
//-------------------------------------------------------------------
// WinMain
//
// Application entry-point.
//-------------------------------------------------------------------
char pathStr[MAX_PATH];
char pathExe[MAX_PATH];
char pathSnapImg[MAX_PATH];
char logMessage[2000];
INT WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, INT)
{
HWND hwnd = 0;
// get Exe Directory path
HMODULE hModule = GetModuleHandleW(NULL);
WCHAR path[MAX_PATH];
GetModuleFileNameW(hModule, path, MAX_PATH);
//convert from wide char to narrow char array
//char pathStr[MAX_PATH];
char DefChar = ' ';
WideCharToMultiByte(CP_ACP, 0, path, -1, pathStr, MAX_PATH, &DefChar, NULL);
// change .exe to .log
char *pch;
pch = strstr(pathStr, ".exe");
strncpy(pch, ".log", 4);
int lastIndex = lastIndexOf(pathStr, "\\");
if (lastIndex != -1)
{
strncpy(pathExe, pathStr, lastIndex + 1);
pathExe[lastIndex + 1] = '\0';
}
readSnapPath();
(void)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
if (InitializeApplication() && InitializeWindow(&hwnd))
{
MessageLoop(hwnd);
}
CleanUp();
return 0;
}
void printLogMessage(const char* strMessage)
{
FILE *fpDbgLog;
fpDbgLog = fopen(pathStr, "a");
if (fpDbgLog)
{
fprintf(fpDbgLog, "%s", strMessage);
fclose(fpDbgLog);
}
}
int indexOf_shift(char* base, char* str, int startIndex) {
int result;
int baselen = strlen(base);
// str should not longer than base
if (strlen(str) > baselen || startIndex > baselen) {
result = -1;
}
else {
if (startIndex < 0) {
startIndex = 0;
}
char* pos = strstr(base + startIndex, str);
if (pos == NULL) {
result = -1;
}
else {
result = pos - base;
}
}
return result;
}
int lastIndexOf(char* base, char* str) {
int result;
// str should not longer than base
if (strlen(str) > strlen(base)) {
result = -1;
}
else {
int start = 0;
int endinit = strlen(base) - strlen(str);
int end = endinit;
int endtmp = endinit;
while (start != end) {
start = indexOf_shift(base, str, start);
end = indexOf_shift(base, str, end);
// not found from start
if (start == -1) {
end = -1; // then break;
}
else if (end == -1) {
// found from start
// but not found from end
// move end to middle
if (endtmp == (start + 1)) {
end = start; // then break;
}
else {
end = endtmp - (endtmp - start) / 2;
if (end <= start) {
end = start + 1;
}
endtmp = end;
}
}
else {
// found from both start and end
// move start to end and
// move end to base - strlen(str)
start = end;
end = endinit;
}
}
result = start;
}
return result;
}
// Class to hold the callback function for the Sample Grabber filter.
class SampleGrabberCallback : public ISampleGrabberCB
{
public:
// Fake referance counting.
STDMETHODIMP_(ULONG) AddRef() { return 1; }
STDMETHODIMP_(ULONG) Release() { return 2; }
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject)
{
if (NULL == ppvObject) return E_POINTER;
if (riid == __uuidof(IUnknown))
{
*ppvObject = static_cast<IUnknown*>(this);
return S_OK;
}
if (riid == __uuidof(ISampleGrabberCB))
{
*ppvObject = static_cast<ISampleGrabberCB*>(this);
return S_OK;
}
return E_NOTIMPL;
}
STDMETHODIMP SampleCB(double Time, IMediaSample *pSample)
{
return E_NOTIMPL;
}
STDMETHODIMP BufferCB(double Time, BYTE *pBuffer, long BufferLen)
{
_AMMediaType mt;
HRESULT hr = gcap.pSampleGrabberStill->GetConnectedMediaType((_AMMediaType *)&mt);
if (!SUCCEEDED(hr))
return VFW_E_INVALIDMEDIATYPE;
if ((mt.majortype != MEDIATYPE_Video) ||
(mt.formattype != FORMAT_VideoInfo) ||
(mt.cbFormat < sizeof(VIDEOINFOHEADER)) ||
(mt.pbFormat == NULL))
{
return VFW_E_INVALIDMEDIATYPE;
}
wchar_t snapHwTrigger[1000];
wchar_t pathExeWch[2 * MAX_PATH];
wchar_t tempFileName[80];
if (pathExeWch)
{
memset(pathExeWch, 0, sizeof(pathExeWch));
MultiByteToWideChar(CP_UTF8, 0, &pathSnapImg[0], (int)strlen(pathSnapImg), &pathExeWch[0], sizeof(pathExeWch));
}
wcscpy(snapHwTrigger, pathExeWch);
SYSTEMTIME st;
GetSystemTime(&st);
hr = StringCbPrintf(tempFileName, sizeof(tempFileName), L"Snap_HW_Trigger_%d_%d_%d_%d_%d_%d_%d.bmp", st.wMonth, st.wYear, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
wcscat(snapHwTrigger, tempFileName);
HANDLE hf = CreateFile(snapHwTrigger, GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
if (hf == INVALID_HANDLE_VALUE)
{
return E_FAIL;
}
// Create bitmap structure
long cbBitmapInfoSize = mt.cbFormat - SIZE_PREHEADER;
VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)mt.pbFormat;
BITMAPFILEHEADER bfh;
ZeroMemory(&bfh, sizeof(bfh));
bfh.bfType = 'MB'; // Little-endian for "BM".
bfh.bfSize = sizeof(bfh)+BufferLen + cbBitmapInfoSize;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+cbBitmapInfoSize;
// Write the file header.
DWORD dwWritten = 0;
WriteFile(hf, &bfh, sizeof(bfh), &dwWritten, NULL);
WriteFile(hf, HEADER(pVideoHeader), cbBitmapInfoSize, &dwWritten, NULL);
WriteFile(hf, pBuffer, BufferLen, &dwWritten, NULL);
CloseHandle(hf);
return S_OK;
}
};
// Global instance of the class.
SampleGrabberCallback g_StillCapCB;
void createMFInterfaceVideoSettings()
{
HRESULT hr = S_OK;
ksNodeTree.isOK = false;
ksNodeTree.isOKpProcAmpKsControl = false;
ksNodeTree.isOKpProcAmp = false;
if (gcap.pVCap != 0)
{
hr = gcap.pVCap->QueryInterface(__uuidof(IAMVideoProcAmp), (VOID**)&ksNodeTree.pProcAmp);
if (SUCCEEDED(hr))
ksNodeTree.isOKpProcAmp = TRUE;
else
ksNodeTree.isOKpProcAmp = FALSE;
hr = gcap.pVCap->QueryInterface(__uuidof(IAMCameraControl), (VOID**)&ksNodeTree.pCamControl);
if (SUCCEEDED(hr))
ksNodeTree.isOKpCamControl = TRUE;
else
ksNodeTree.isOKpCamControl = FALSE;
hr = gcap.pVCap->QueryInterface(__uuidof(IAMVideoControl), (VOID**)&ksNodeTree.pVideoControl);
if (SUCCEEDED(hr))
ksNodeTree.isOKpVideoControl = TRUE;
else
ksNodeTree.isOKpVideoControl = FALSE;
if (SUCCEEDED(hr))
{
DWORD uiNumNodes;
GUID guidNodeType;
IKsTopologyInfo *pKsTopologyInfo = nullptr;
IUnknown *pUnk = nullptr;
IKsControl *pKsControl = nullptr;
hr = gcap.pVCap->QueryInterface(__uuidof(IKsTopologyInfo),
(VOID**)&pKsTopologyInfo);
if (SUCCEEDED(hr))
{
// get nodes number in usb video device capture filter
if (pKsTopologyInfo->get_NumNodes(&uiNumNodes) == S_OK)
{
// go thru all nodes searching for the node of the KSNODETYPE_DEV_SPECIFIC type,
// node of this type - represents extension unit of the USB device
#ifdef DEBUG
sprintf(logMessage, " \nFunction : createMFInterfaceVideoSettings \t Msg : uiNumNodes %d", uiNumNodes);
printLogMessage(logMessage);
#endif
for (UINT i = 0; i < uiNumNodes + 1; i++)
{
if (pKsTopologyInfo->get_NodeType(i, &guidNodeType) == S_OK)
{
if (guidNodeType == KSNODETYPE_DEV_SPECIFIC)
{
#ifdef DEBUG
sprintf(logMessage, " \nFunction : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_DEV_SPECIFIC");
printLogMessage(logMessage);
#endif
// create node instance
hr = pKsTopologyInfo->CreateNodeInstance(i, __uuidof(IUnknown), (VOID**)&pUnk);
// get IKsControl interface from node
if (hr == S_OK)
{
hr = pUnk->QueryInterface(__uuidof(IKsControl), (VOID**)&pKsControl);
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : create node instance failed for KSNODETYPE_DEV_SPECIFIC");
printLogMessage(logMessage);
#endif
}
// trying to read first control of the extension unit
if (hr == S_OK)
{
ksNodeTree.nodeID = i;
ksNodeTree.pKsControl = pKsControl;
ksNodeTree.isOK = true;
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pUnk->QueryInterface failed for KSNODETYPE_DEV_SPECIFIC");
printLogMessage(logMessage);
#endif
}
}
else if (guidNodeType == KSNODETYPE_VIDEO_PROCESSING)
{
#ifdef DEBUG
sprintf(logMessage, " \nFunction : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_PROCESSING");
printLogMessage(logMessage);
#endif
// create node instance
hr = pKsTopologyInfo->CreateNodeInstance(i, __uuidof(IUnknown), (VOID**)&pUnk);
// get IKsControl interface from node
if (hr == S_OK)
{
hr = pUnk->QueryInterface(__uuidof(IKsControl), (VOID**)&pKsControl);
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_PROCESSING failed");
printLogMessage(logMessage);
#endif
}
// trying to read first control of the extension unit
if (hr == S_OK)
{
ksNodeTree.nodeIDProcAmpKsControl = i;
ksNodeTree.pProcAmpKsControl = pKsControl;
ksNodeTree.isOKpProcAmpKsControl = true;
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pUnk->QueryInterface failed for KSNODETYPE_VIDEO_PROCESSING");
printLogMessage(logMessage);
#endif
}
}
else if (guidNodeType == KSNODETYPE_VIDEO_CAMERA_TERMINAL)
{
#ifdef DEBUG
sprintf(logMessage, " \nFunction : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_CAMERA_TERMINAL");
printLogMessage(logMessage);
#endif
// create node instance
hr = pKsTopologyInfo->CreateNodeInstance(i, __uuidof(IUnknown), (VOID**)&pUnk);
// get IKsControl interface from node
if (hr == S_OK)
{
hr = pUnk->QueryInterface(__uuidof(IKsControl), (VOID**)&pKsControl);
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_CAMERA_TERMINAL failed");
printLogMessage(logMessage);
#endif
}
// trying to read first control of the extension unit
if (hr == S_OK)
{
ksNodeTree.nodeIDCamControlKsControl = i;
ksNodeTree.pCamControlKsControl = pKsControl;
ksNodeTree.isOKpCamControlKsControl = true;
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pUnk->QueryInterface failed for KSNODETYPE_VIDEO_CAMERA_TERMINAL");
printLogMessage(logMessage);
#endif
}
}
else if (guidNodeType == KSNODETYPE_VIDEO_STREAMING)
{
#ifdef DEBUG
sprintf(logMessage, " \nFunction : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_STREAMING");
printLogMessage(logMessage);
#endif
// create node instance
hr = pKsTopologyInfo->CreateNodeInstance(i, __uuidof(IUnknown), (VOID**)&pUnk);
// get IKsControl interface from node
if (hr == S_OK)
{
hr = pUnk->QueryInterface(__uuidof(IKsControl), (VOID**)&pKsControl);
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : create node instance for KSNODETYPE_VIDEO_STREAMING failed");
printLogMessage(logMessage);
#endif
}
// trying to read first control of the extension unit
if (hr == S_OK)
{
ksNodeTree.nodeIDVideoStreaming = i;
ksNodeTree.pKsControlVideoStreaming = pKsControl;
ksNodeTree.isOKVideoStreaming = true;
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pUnk->QueryInterface failed for KSNODETYPE_VIDEO_STREAMING");
printLogMessage(logMessage);
#endif
}
}
}
}
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pKsTopologyInfo->get_NumNodes(&uiNumNodes) == S_OK failed");
printLogMessage(logMessage);
#endif
}
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : gcap.pVCap->QueryInterface failed");
printLogMessage(logMessage);
#endif
}
}
else
{
#ifdef DEBUG
sprintf(logMessage, " \nERROR \t Function : createMFInterfaceVideoSettings \t Msg : gcap.pmVideo->BindToObject failed");
printLogMessage(logMessage);
#endif
}
}
else
{
#ifdef DEBUG
sprintf(logMessage, "\nERROR \t Function : createMFInterfaceVideoSettings \t Msg : pmSelDevice is NULL");
printLogMessage(logMessage);
#endif
}
}
void ChooseDevices(IMoniker *pmVideo, IMoniker *pmAudio)
{
#define VERSIZE 40
#define DESCSIZE 80
int versize = VERSIZE;
int descsize = DESCSIZE;
WCHAR wachVer[VERSIZE] = { 0 }, wachDesc[DESCSIZE] = { 0 };
TCHAR tachStatus[VERSIZE + DESCSIZE + 5] = { 0 };
// they chose a new device. rebuild the graphs
if (gcap.pmVideo != pmVideo || gcap.pmAudio != pmAudio)
{
if (pmVideo)
{
pmVideo->AddRef();
}
if (pmAudio)
{
pmAudio->AddRef();
}
IMonRelease(gcap.pmVideo);
IMonRelease(gcap.pmAudio);
gcap.pmVideo = pmVideo;
gcap.pmAudio = pmAudio;
if (gcap.fPreviewing)
StopPreview();
if (gcap.fCaptureGraphBuilt || gcap.fPreviewGraphBuilt)
TearDownGraph();
FreeCapFilters();
InitCapFilters();
gcap.fWantPreview = TRUE;
if (gcap.fWantPreview) // were we previewing?
{
BuildPreviewGraph();
StartPreview();
}
//MakeMenuOptions(); // the UI choices change per device
}
}
HRESULT getExtionControlPropertySize(ULONG PropertyId, ULONG *pulSize)
{
HRESULT hr = S_OK;
try
{
if (ksNodeTree.isOK)
{
ULONG ulBytesReturned;
KSP_NODE ExtensionProp;
if (!pulSize) return E_POINTER;
ExtensionProp.Property.Set = EXTGUID;
ExtensionProp.Property.Id = PropertyId;
ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_TOPOLOGY;
ExtensionProp.NodeId = ksNodeTree.nodeID;
hr = ksNodeTree.pKsControl->KsProperty((PKSPROPERTY)&ExtensionProp, sizeof(ExtensionProp), NULL, 0, &ulBytesReturned);
if (hr == HRESULT_FROM_WIN32(ERROR_MORE_DATA))
{
*pulSize = ulBytesReturned;
hr = S_OK;
}
}
else
{
hr = E_FAIL;
}
}
catch (...)
{
#ifdef DEBUG
sprintf(logMessage, "\nERROR \t Function:getExtionControlPropertySize \t Message:Exception occur while getting size of Node[%d].", PropertyId);
printLogMessage(logMessage);
#endif
hr = S_FALSE;
}
return hr;
}
HRESULT getExtionControlProperty(ULONG PropertyId, ULONG ulSize, BYTE pValue[])
{
HRESULT hr = S_OK;
try
{
if (ksNodeTree.isOK)
{
KSP_NODE ExtensionProp;
ULONG ulBytesReturned;
ExtensionProp.Property.Set = EXTGUID;
ExtensionProp.Property.Id = PropertyId;
ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_TOPOLOGY;
ExtensionProp.NodeId = ksNodeTree.nodeID;
hr = ksNodeTree.pKsControl->KsProperty((PKSPROPERTY)&ExtensionProp, sizeof(ExtensionProp), (PVOID)pValue, ulSize, &ulBytesReturned);
#ifdef DEBUG
sprintf(logMessage, "\nbmRequestType:GET \t bRequest:GET_CUR \t wValue:%ld \t wIndex:0x03\t retValue:", PropertyId);
printLogMessage(logMessage);
for (int i = 0; i < (int)ulBytesReturned; i++)
{
sprintf(logMessage, " %.2x", (PCHAR)pValue[i]);
printLogMessage(logMessage);
}
#endif
}
else
{
hr = E_FAIL;
}
}
catch (...)
{
#ifdef DEBUG
sprintf(logMessage, "\nERROR \t Function:getExtionControlProperty \t Message:Exception occur while getting value of Node[%d].", PropertyId);
printLogMessage(logMessage);
#endif
hr = S_FALSE;
}
return hr;
}
HRESULT setExtionControlProperty(ULONG PropertyId, ULONG ulSize, BYTE pValue[])
{
HRESULT hr = S_OK;
try
{
if (ksNodeTree.isOK)
{
KSP_NODE ExtensionProp;
ULONG ulBytesReturned;
ExtensionProp.Property.Set = EXTGUID;
ExtensionProp.Property.Id = PropertyId;
ExtensionProp.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
ExtensionProp.NodeId = ksNodeTree.nodeID;
#ifdef DEBUG
sprintf(logMessage, "\nbmRequestType:SET \t bRequest:SET_CUR \t wValue:%ld \t wIndex:0x03\t PutValue:", PropertyId);
printLogMessage(logMessage);
for (int i = 0; i < (int)ulSize; i++)
{
sprintf(logMessage, " %.2x", (PCHAR)pValue[i]);
printLogMessage(logMessage);
}
#endif
hr = ksNodeTree.pKsControl->KsProperty((PKSPROPERTY)&ExtensionProp, sizeof(ExtensionProp), (PVOID)pValue, ulSize, &ulBytesReturned);
}
else
{
hr = E_FAIL;
}
}
catch (...)
{
#ifdef DEBUG
sprintf(logMessage, "\nERROR \t Function:setExtionControlProperty \t Message:Exception occur while setting Node[%d].", PropertyId);
printLogMessage(logMessage);
#endif
hr = S_FALSE;
}
return hr;
}
HRESULT getStandardControlPropertyRange(long PropertyID, long *lMin, long *lMax, long *lStep, long *lDefault, long *lCaps)
{
HRESULT hr = S_OK;
if (ksNodeTree.isOKpProcAmp)
{
// Get the range
hr = ksNodeTree.pProcAmp->GetRange(PropertyID, lMin, lMax, lStep, lDefault, lCaps);
#ifdef DEBUG
sprintf(logMessage, " \nFunction : getStandardControlPropertyRange \t Msg : PropertyID %d Min %ld Max %ld Default %ld", PropertyID, *lMin, *lMax, *lDefault);
printLogMessage(logMessage);
#endif
}
if (!SUCCEEDED(hr))
{
*lMin = 0;
*lMax = 0;
*lStep = 0;
*lDefault = 0;
*lCaps = 0;
#ifdef DEBUG
sprintf(logMessage, "\nERROR \t Function : getStandardControlPropertyRange \t Msg : pProcAmp->GetRange failed for PropertyID %d ", PropertyID);
printLogMessage(logMessage);
#endif