video_capture_device_descriptor.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_DESCRIPTOR_H_
  5. #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_DESCRIPTOR_H_
  6. #include <string>
  7. #include <vector>
  8. #include "media/base/video_facing.h"
  9. #include "media/capture/capture_export.h"
  10. namespace media {
  11. // A Java counterpart will be generated for this enum.
  12. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media
  13. enum class VideoCaptureApi {
  14. LINUX_V4L2_SINGLE_PLANE,
  15. WIN_MEDIA_FOUNDATION,
  16. WIN_MEDIA_FOUNDATION_SENSOR,
  17. WIN_DIRECT_SHOW,
  18. MACOSX_AVFOUNDATION,
  19. MACOSX_DECKLINK,
  20. ANDROID_API1,
  21. ANDROID_API2_LEGACY,
  22. ANDROID_API2_FULL,
  23. ANDROID_API2_LIMITED,
  24. FUCHSIA_CAMERA3,
  25. VIRTUAL_DEVICE,
  26. UNKNOWN
  27. };
  28. // Represents capture device's support for different controls.
  29. struct VideoCaptureControlSupport {
  30. bool pan = false;
  31. bool tilt = false;
  32. bool zoom = false;
  33. };
  34. enum class VideoCaptureTransportType {
  35. // For AVFoundation Api, identify devices that are built-in or USB.
  36. MACOSX_USB_OR_BUILT_IN,
  37. OTHER_TRANSPORT
  38. };
  39. // Represents information about a capture device as returned by
  40. // VideoCaptureDeviceFactory::GetDeviceDescriptors().
  41. // |device_id| represents a unique id of a physical device. Since the same
  42. // physical device may be accessible through different APIs |capture_api|
  43. // disambiguates the API.
  44. // TODO(tommi): Given that this struct has become more complex with private
  45. // members, methods that are not just direct getters/setters
  46. // (e.g., GetNameAndModel), let's turn it into a class in order to properly
  47. // conform with the style guide and protect the integrity of the data that the
  48. // class owns.
  49. struct CAPTURE_EXPORT VideoCaptureDeviceDescriptor {
  50. public:
  51. VideoCaptureDeviceDescriptor();
  52. VideoCaptureDeviceDescriptor(
  53. const std::string& display_name,
  54. const std::string& device_id,
  55. VideoCaptureApi capture_api = VideoCaptureApi::UNKNOWN,
  56. const VideoCaptureControlSupport& control_support =
  57. VideoCaptureControlSupport(),
  58. VideoCaptureTransportType transport_type =
  59. VideoCaptureTransportType::OTHER_TRANSPORT);
  60. VideoCaptureDeviceDescriptor(
  61. const std::string& display_name,
  62. const std::string& device_id,
  63. const std::string& model_id,
  64. VideoCaptureApi capture_api,
  65. const VideoCaptureControlSupport& control_support,
  66. VideoCaptureTransportType transport_type =
  67. VideoCaptureTransportType::OTHER_TRANSPORT,
  68. VideoFacingMode facing = VideoFacingMode::MEDIA_VIDEO_FACING_NONE);
  69. VideoCaptureDeviceDescriptor(const VideoCaptureDeviceDescriptor& other);
  70. ~VideoCaptureDeviceDescriptor();
  71. // These operators are needed due to storing the name in an STL container.
  72. // In the shared build, all methods from the STL container will be exported
  73. // so even though they're not used, they're still depended upon.
  74. bool operator==(const VideoCaptureDeviceDescriptor& other) const {
  75. return (other.device_id == device_id) && (other.capture_api == capture_api);
  76. }
  77. bool operator<(const VideoCaptureDeviceDescriptor& other) const;
  78. const char* GetCaptureApiTypeString() const;
  79. // Friendly name of a device, plus the model identifier in parentheses.
  80. std::string GetNameAndModel() const;
  81. // Name that is intended for display in the UI.
  82. const std::string& display_name() const { return display_name_; }
  83. void set_display_name(const std::string& name);
  84. const VideoCaptureControlSupport& control_support() const {
  85. return control_support_;
  86. }
  87. void set_control_support(const VideoCaptureControlSupport& control_support) {
  88. control_support_ = control_support;
  89. }
  90. std::string device_id;
  91. // A unique hardware identifier of the capture device.
  92. // It is of the form "[vid]:[pid]" when a USB device is detected, and empty
  93. // otherwise.
  94. std::string model_id;
  95. VideoFacingMode facing;
  96. VideoCaptureApi capture_api;
  97. VideoCaptureTransportType transport_type;
  98. private:
  99. std::string display_name_; // Name that is intended for display in the UI
  100. VideoCaptureControlSupport control_support_;
  101. };
  102. using VideoCaptureDeviceDescriptors = std::vector<VideoCaptureDeviceDescriptor>;
  103. } // namespace media
  104. #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_DESCRIPTOR_H_