CameraImpl.h 2.9 KB

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