YituLiveSDK.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include "stdafx.h"
  2. #include "YituLiveSDK.h"
  3. #include "VTMSDK.h"
  4. typedef int (*tPfnInit)(VTM_InitParam* param);
  5. typedef int (*tPfnUninit)();
  6. typedef int (*tPfnStartCapture)(int nType);
  7. typedef int (*tpfnStopCapture)();
  8. typedef int (*tpfnAppendFrame)(VTM_ImageData* pData);
  9. typedef int (*tpfnGetImage)(BITMAP* pbitmap);
  10. typedef int (*tpfnHasHackInSession)(bool* bHasHack);
  11. typedef int (*tpfnGetLiveImageCount)(int* nLiveCount);
  12. typedef int (*tpfnGetLiveImage)(int nLiveImage,BITMAP* pbitmap,int* nLivenessType);
  13. typedef int (*tpfnGetTrackCount)(int nCameraID,int* nCount);
  14. typedef int (*tpfnGetTrackData)(int nCameraID,int nIndex,TrackData* pData);
  15. HINSTANCE h = NULL;
  16. tPfnInit _Init = NULL;
  17. tPfnUninit _Uninit = NULL;
  18. tPfnStartCapture _StartCapture = NULL;
  19. tpfnStopCapture _StopCapture = NULL;
  20. tpfnAppendFrame _AppendFrame = NULL;
  21. tpfnGetImage _GetImage = NULL;
  22. tpfnHasHackInSession _HasHackInSession = NULL;
  23. tpfnGetLiveImageCount _GetLiveImageCount = NULL;
  24. tpfnGetLiveImage _GetLiveImage = NULL;
  25. tpfnGetTrackCount _GetTrackCount = NULL;
  26. tpfnGetTrackData _GetTrackData = NULL;
  27. int YituLiveSDK::YituInit(const char *pszDLLPath, YituLiveSDK::Yitu_InitParam* param)
  28. {
  29. HINSTANCE h = ::LoadLibrary(pszDLLPath);
  30. if (!h)
  31. {
  32. return GetLastError();
  33. }
  34. _Init = (tPfnInit)GetProcAddress(h,"?Init@@YAHPAUVTM_InitParam@@@Z");
  35. _Uninit = (tPfnUninit)GetProcAddress(h,"?Uninit@@YAHXZ");
  36. _StartCapture = (tPfnStartCapture)GetProcAddress(h,"?StartCapture@@YAHH@Z");
  37. _StopCapture = (tpfnStopCapture)GetProcAddress(h,"?StopCapture@@YAHXZ");
  38. _AppendFrame = (tpfnAppendFrame)GetProcAddress(h,"?AppendFrame@@YAHPAUVTM_ImageData@@@Z");
  39. _GetImage = (tpfnGetImage)GetProcAddress(h,"?GetImage@@YAHPAUtagBITMAP@@@Z");
  40. _HasHackInSession = (tpfnHasHackInSession)GetProcAddress(h,"?HasHackInSession@@YAHPA_N@Z");
  41. _GetLiveImageCount = (tpfnGetLiveImageCount)GetProcAddress(h,"?GetLiveImageCount@@YAHPAH@Z");
  42. _GetLiveImage = (tpfnGetLiveImage)GetProcAddress(h,"?GetLiveImage@@YAHHPAUtagBITMAP@@PAH@Z");
  43. _GetTrackCount = (tpfnGetTrackCount)GetProcAddress(h,"?GetTrackCount@@YAHHPAH@Z");
  44. _GetTrackData = (tpfnGetTrackData)GetProcAddress(h,"?GetTrackData@@YAHHHPAUTrackData@@@Z");
  45. if (!(_Init&&_Uninit&&_StartCapture&&_StopCapture&&_AppendFrame&&_GetImage&&
  46. _HasHackInSession&&_GetLiveImageCount&&_GetLiveImage&&_GetTrackCount&&_GetTrackData))
  47. {
  48. int rtn = GetLastError();
  49. ::FreeLibrary(h);
  50. return rtn;
  51. }
  52. return _Init((VTM_InitParam*)param);
  53. }
  54. int YituLiveSDK::YituUninit()
  55. {
  56. int bRet1 = 0;
  57. BOOL bRet2 = TRUE;
  58. if (_Uninit)
  59. {
  60. bRet1 = _Uninit();
  61. }
  62. if (h)
  63. {
  64. bRet2 = ::FreeLibrary(h);
  65. }
  66. h = NULL;
  67. _Init = NULL;
  68. _Uninit = NULL;
  69. _StartCapture = NULL;
  70. _StopCapture = NULL;
  71. _AppendFrame = NULL;
  72. _GetImage = NULL;
  73. _HasHackInSession = NULL;
  74. _GetLiveImageCount = NULL;
  75. _GetLiveImage = NULL;
  76. _GetTrackCount = NULL;
  77. _GetTrackData = NULL;
  78. if (!bRet1&&bRet2)
  79. {
  80. return 0;
  81. }
  82. return 1;
  83. }
  84. int YituLiveSDK::YituStartCapture(int nType)
  85. {
  86. if (!_StartCapture)
  87. {
  88. return 1;
  89. }
  90. return _StartCapture(nType);
  91. }
  92. int YituLiveSDK::YituStopCapture()
  93. {
  94. if (!_StopCapture)
  95. {
  96. return 1;
  97. }
  98. return _StopCapture();
  99. }
  100. int YituLiveSDK::YituAppendFrame(YituLiveSDK::Yitu_ImageData* pData)
  101. {
  102. if (!_AppendFrame)
  103. {
  104. return 1;
  105. }
  106. return _AppendFrame((VTM_ImageData*)pData);
  107. }
  108. int YituLiveSDK::YituGetImage(BITMAP* pbitmap)
  109. {
  110. if (!_GetImage)
  111. {
  112. return 1;
  113. }
  114. return _GetImage(pbitmap);
  115. }
  116. int YituLiveSDK::YituHasHackInSession(bool* bHasHack)
  117. {
  118. if (!_HasHackInSession)
  119. {
  120. return 1;
  121. }
  122. return _HasHackInSession(bHasHack);
  123. }
  124. int YituLiveSDK::YituGetLiveImageCount(int* nLiveCount)
  125. {
  126. if (!_GetLiveImageCount)
  127. {
  128. return 1;
  129. }
  130. return _GetLiveImageCount(nLiveCount);
  131. }
  132. int YituLiveSDK::YituGetLiveImage(int nLiveImage,BITMAP* pbitmap,int* nLivenessType)
  133. {
  134. if (!_GetLiveImage)
  135. {
  136. return 1;
  137. }
  138. return _GetLiveImage(nLiveImage,pbitmap,nLivenessType);
  139. }
  140. int YituLiveSDK::YituGetTrackCount(int nCameraID,int* nCount)
  141. {
  142. if (!_GetTrackCount)
  143. {
  144. return 1;
  145. }
  146. return _GetTrackCount(nCameraID,nCount);
  147. }
  148. int YituLiveSDK::YituGetTrackData(int nCameraID,int nIndex,YituLiveSDK::Yitu_TrackData* pData)
  149. {
  150. if (!_GetTrackData)
  151. {
  152. return 1;
  153. }
  154. return _GetTrackData(nCameraID,nIndex,(TrackData*)pData);
  155. }