CameraImpl.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #include "SpBase.h"
  3. #pragma comment(lib,"Strmiids.lib")
  4. #include "EventRevWnd.h"
  5. #include <vector>
  6. #include <algorithm>
  7. #define DETECT_CAMERA_BUSY_ONE 0x21800001
  8. #define DETECT_CAMERA_BUSY_TWO 0x21800002
  9. #if 0
  10. #define SAFE_RELEASE_IDEV(hd) \
  11. do { \
  12. if(hd != NULL) { \
  13. (hd)->lpVtbl -> Release(hd); \
  14. hd = NULL; \
  15. } \
  16. } while (false)
  17. #else
  18. #define SAFE_RELEASE_IDEV(hd) \
  19. do { \
  20. if(hd != NULL) { \
  21. hd->Release(); \
  22. hd = NULL; \
  23. } \
  24. } while (false)
  25. #endif
  26. typedef struct _CAMERA_INFOR_ITEM
  27. {
  28. char szDevName[MAX_PATH];
  29. char szCLSID[MAX_PATH];
  30. char szDevPath[MAX_PATH];
  31. LONG uWaveInID;
  32. void Cleanup() {
  33. uWaveInID = 0;
  34. memset(szDevName, 0, sizeof(szDevName));
  35. memset(szCLSID, 0, sizeof(szCLSID));
  36. memset(szDevPath, 0, sizeof(szDevPath));
  37. }
  38. void Copy(struct _CAMERA_INFOR_ITEM* prhs) {
  39. if(prhs != NULL) {
  40. uWaveInID = prhs->uWaveInID;
  41. strcpy_s(szDevPath, MAX_PATH, prhs->szDevPath);
  42. strcpy_s(szDevName, MAX_PATH, prhs->szDevName);
  43. strcpy_s(szCLSID, MAX_PATH, prhs->szCLSID);
  44. }
  45. }
  46. void Display() {
  47. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%ld]%s(%s)",uWaveInID, szDevName, szDevPath);
  48. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CLSID:%s", szCLSID);
  49. }
  50. } CAMERA_INFOR_ITEM, *PCAMERA_INFOR_ITEM;
  51. static int WrapW2A(VARIANT& varirant, char* szDst, const size_t maxLen) {
  52. int count = 0;
  53. WCHAR tmp[256];
  54. tmp[0] = 0;
  55. memset(szDst, '\0', sizeof(char)*maxLen);
  56. HRESULT hr = StringCchCopyW(tmp, 256, varirant.bstrVal);
  57. if(hr == S_OK) {
  58. count = WideCharToMultiByte(CP_ACP, 0, tmp, -1, szDst, maxLen, 0, NULL);
  59. } else {
  60. while (varirant.bstrVal[count] != 0x00 && count < maxLen) {
  61. szDst[count] = (char)varirant.bstrVal[count];
  62. count++;
  63. }
  64. }
  65. return count;
  66. /*
  67. USES_CONVERSION;
  68. lptstrValue = W2T(Value.bstrVal);
  69. */
  70. }
  71. typedef std::vector<PCAMERA_INFOR_ITEM> CAMERA_BUCKET;
  72. typedef CAMERA_BUCKET::const_iterator CAMERA_BUCKET_CITER;
  73. typedef CAMERA_BUCKET::iterator CAMERA_BUCKET_ITER;
  74. static void DestoryCamereBuckets(CAMERA_BUCKET& vtCameras)
  75. {
  76. if(!vtCameras.empty()) {
  77. for(CAMERA_BUCKET_ITER it=vtCameras.begin(); it!=vtCameras.end(); ++it) {
  78. if(*it) {
  79. delete (*it);
  80. (*it) = NULL;
  81. }
  82. }
  83. vtCameras.clear();
  84. }
  85. }
  86. // return the origin old count of video devices.
  87. int UpdateCameraInfors(CAMERA_BUCKET& vtCameraList);
  88. // return the count of video devices existed for now.
  89. int GetCameraInfors(CAMERA_BUCKET& vtCameraList);
  90. void DisplayCameraInfos(const CAMERA_BUCKET& vtCameraList);
  91. int GetCameraCount();
  92. // returned value:
  93. // -2:inner error; -1:not founed; 0:idle; 1:busy
  94. int IsDeviceBusy(const char* lpcszDeviceName);
  95. // Copy from 35's libvideoframework interface,
  96. // return -1 means failed or no existed.
  97. // param lpDevCombinedName indicated video identifier from root.ini which contains ';' character.
  98. int GetVideoDeviceID(LPCTSTR lpDevCombinedName);
  99. // condition: lhs contains rhs or rhs contains lhs, use size() to judge which is more wider
  100. // return the diff elements
  101. int ExclusiveCameraBuckes(const CAMERA_BUCKET& lhs, const CAMERA_BUCKET& rhs, CAMERA_BUCKET& diff);