CameraImpl.h 2.5 KB

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