MediaDevices.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "pch.h"
  2. #include "MediaDevices.h"
  3. #include "webrtc/modules/video_capture/video_capture_factory.h"
  4. int __stdcall CreateVideoDeviceInfo(void** hDeviceInfo)
  5. {
  6. try
  7. {
  8. webrtc::VideoCaptureModule::DeviceInfo* deviceInfo = webrtc::VideoCaptureFactory::CreateDeviceInfo();
  9. *hDeviceInfo = deviceInfo;
  10. int num = deviceInfo->NumberOfDevices();
  11. return num;
  12. }
  13. catch (int e)
  14. {
  15. *hDeviceInfo = nullptr;
  16. return 0;
  17. }
  18. }
  19. int __stdcall GetVidoeDeviceInfo(void* hDeviceInfo, uint32_t deviceNumber, void** mediaDeviceInfo)
  20. {
  21. try
  22. {
  23. webrtc::VideoCaptureModule::DeviceInfo* deviceInfo = static_cast<webrtc::VideoCaptureModule::DeviceInfo*>(hDeviceInfo);
  24. std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(deviceInfo);
  25. const uint32_t kSize = 256;
  26. char deviceNameUTF8[kSize] = {0};
  27. char deviceUniqueIdUTF8[kSize] = { 0 };
  28. char productUniqueIdUTF8[kSize] = { 0 };
  29. VideoDeviceInfo* df = (VideoDeviceInfo*)malloc(sizeof(struct VideoDeviceInfo)); //TODO who will free it ?
  30. int32_t iRet = info->GetDeviceName(deviceNumber, deviceNameUTF8, kSize, deviceUniqueIdUTF8, kSize, productUniqueIdUTF8, kSize);
  31. /*MyDeviceInfo df;*/
  32. df->deviceNumber = deviceNumber;
  33. strcpy(df->deviceNameUTF8, deviceNameUTF8);
  34. strcpy(df->deviceUniqueIdUTF8, deviceUniqueIdUTF8);
  35. strcpy(df->productUniqueIdUTF8, productUniqueIdUTF8);
  36. void* result = static_cast<void*>(df);
  37. *mediaDeviceInfo = result;
  38. return (int)iRet;
  39. //return 0;
  40. }
  41. catch (int e)
  42. {
  43. return -1;
  44. }
  45. }