video_capture_types.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Copyright (c) 2012 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_CAPTURE_TYPES_H_
  5. #define MEDIA_CAPTURE_VIDEO_CAPTURE_TYPES_H_
  6. #include <stddef.h>
  7. #include <vector>
  8. #include "base/unguessable_token.h"
  9. #include "build/build_config.h"
  10. #include "media/base/video_types.h"
  11. #include "media/capture/capture_export.h"
  12. #include "ui/gfx/geometry/size.h"
  13. namespace media {
  14. // TODO(wjia): this type should be defined in a common place and
  15. // shared with device manager.
  16. using VideoCaptureSessionId = base::UnguessableToken;
  17. // Policies for capture devices that have source content that varies in size.
  18. // It is up to the implementation how the captured content will be transformed
  19. // (e.g., scaling and/or letterboxing) in order to produce video frames that
  20. // strictly adheree to one of these policies.
  21. enum class ResolutionChangePolicy {
  22. // Capture device outputs a fixed resolution all the time. The resolution of
  23. // the first frame is the resolution for all frames.
  24. FIXED_RESOLUTION,
  25. // Capture device is allowed to output frames of varying resolutions. The
  26. // width and height will not exceed the maximum dimensions specified. The
  27. // aspect ratio of the frames will match the aspect ratio of the maximum
  28. // dimensions as closely as possible.
  29. FIXED_ASPECT_RATIO,
  30. // Capture device is allowed to output frames of varying resolutions not
  31. // exceeding the maximum dimensions specified.
  32. ANY_WITHIN_LIMIT,
  33. // Must always be equal to largest entry in the enum.
  34. LAST = ANY_WITHIN_LIMIT,
  35. };
  36. // Potential values of the googPowerLineFrequency optional constraint passed to
  37. // getUserMedia. Note that the numeric values are currently significant, and are
  38. // used to map enum values to corresponding frequency values.
  39. // TODO(ajose): http://crbug.com/525167 Consider making this a class.
  40. enum class PowerLineFrequency {
  41. FREQUENCY_DEFAULT = 0,
  42. FREQUENCY_50HZ = 50,
  43. FREQUENCY_60HZ = 60,
  44. FREQUENCY_MAX = FREQUENCY_60HZ
  45. };
  46. enum class VideoCaptureBufferType {
  47. kSharedMemory,
  48. kSharedMemoryViaRawFileDescriptor,
  49. kMailboxHolder,
  50. kGpuMemoryBuffer
  51. };
  52. // WARNING: Do not change the values assigned to the entries. They are used for
  53. // UMA logging.
  54. enum class VideoCaptureError {
  55. kNone = 0,
  56. kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested =
  57. 1,
  58. kVideoCaptureControllerIsAlreadyInErrorState = 2,
  59. kVideoCaptureManagerDeviceConnectionLost = 3,
  60. kFrameSinkVideoCaptureDeviceAlreadyEndedOnFatalError = 4,
  61. kFrameSinkVideoCaptureDeviceEncounteredFatalError = 5,
  62. kV4L2FailedToOpenV4L2DeviceDriverFile = 6,
  63. kV4L2ThisIsNotAV4L2VideoCaptureDevice = 7,
  64. kV4L2FailedToFindASupportedCameraFormat = 8,
  65. kV4L2FailedToSetVideoCaptureFormat = 9,
  66. kV4L2UnsupportedPixelFormat = 10,
  67. kV4L2FailedToSetCameraFramerate = 11,
  68. kV4L2ErrorRequestingMmapBuffers = 12,
  69. kV4L2AllocateBufferFailed = 13,
  70. kV4L2VidiocStreamonFailed = 14,
  71. kV4L2VidiocStreamoffFailed = 15,
  72. kV4L2FailedToVidiocReqbufsWithCount0 = 16,
  73. kV4L2PollFailed = 17,
  74. kV4L2MultipleContinuousTimeoutsWhileReadPolling = 18,
  75. kV4L2FailedToDequeueCaptureBuffer = 19,
  76. kV4L2FailedToEnqueueCaptureBuffer = 20,
  77. kSingleClientVideoCaptureHostLostConnectionToDevice = 21,
  78. kSingleClientVideoCaptureDeviceLaunchAborted = 22,
  79. kDesktopCaptureDeviceWebrtcDesktopCapturerHasFailed = 23,
  80. kFileVideoCaptureDeviceCouldNotOpenVideoFile = 24,
  81. kDeviceCaptureLinuxFailedToCreateVideoCaptureDelegate = 25,
  82. kErrorFakeDeviceIntentionallyEmittingErrorEvent = 26,
  83. kDeviceClientTooManyFramesDroppedY16 = 28,
  84. kDeviceMediaToMojoAdapterEncounteredUnsupportedBufferType = 29,
  85. kVideoCaptureManagerProcessDeviceStartQueueDeviceInfoNotFound = 30,
  86. kInProcessDeviceLauncherFailedToCreateDeviceInstance = 31,
  87. kServiceDeviceLauncherLostConnectionToDeviceFactoryDuringDeviceStart = 32,
  88. kServiceDeviceLauncherServiceRespondedWithDeviceNotFound = 33,
  89. kServiceDeviceLauncherConnectionLostWhileWaitingForCallback = 34,
  90. kIntentionalErrorRaisedByUnitTest = 35,
  91. kCrosHalV3FailedToStartDeviceThread = 36,
  92. kCrosHalV3DeviceDelegateMojoConnectionError = 37,
  93. kCrosHalV3DeviceDelegateFailedToGetCameraInfo = 38,
  94. kCrosHalV3DeviceDelegateMissingSensorOrientationInfo = 39,
  95. kCrosHalV3DeviceDelegateFailedToOpenCameraDevice = 40,
  96. kCrosHalV3DeviceDelegateFailedToInitializeCameraDevice = 41,
  97. kCrosHalV3DeviceDelegateFailedToConfigureStreams = 42,
  98. kCrosHalV3DeviceDelegateWrongNumberOfStreamsConfigured = 43,
  99. kCrosHalV3DeviceDelegateFailedToGetDefaultRequestSettings = 44,
  100. kCrosHalV3BufferManagerHalRequestedTooManyBuffers = 45,
  101. kCrosHalV3BufferManagerFailedToCreateGpuMemoryBuffer = 46,
  102. kCrosHalV3BufferManagerFailedToMapGpuMemoryBuffer = 47,
  103. kCrosHalV3BufferManagerUnsupportedVideoPixelFormat = 48,
  104. kCrosHalV3BufferManagerFailedToDupFd = 49,
  105. kCrosHalV3BufferManagerFailedToWrapGpuMemoryHandle = 50,
  106. kCrosHalV3BufferManagerFailedToRegisterBuffer = 51,
  107. kCrosHalV3BufferManagerProcessCaptureRequestFailed = 52,
  108. kCrosHalV3BufferManagerInvalidPendingResultId = 53,
  109. kCrosHalV3BufferManagerReceivedDuplicatedPartialMetadata = 54,
  110. kCrosHalV3BufferManagerIncorrectNumberOfOutputBuffersReceived = 55,
  111. kCrosHalV3BufferManagerInvalidTypeOfOutputBuffersReceived = 56,
  112. kCrosHalV3BufferManagerReceivedMultipleResultBuffersForFrame = 57,
  113. kCrosHalV3BufferManagerUnknownStreamInCamera3NotifyMsg = 58,
  114. kCrosHalV3BufferManagerReceivedInvalidShutterTime = 59,
  115. kCrosHalV3BufferManagerFatalDeviceError = 60,
  116. kCrosHalV3BufferManagerReceivedFrameIsOutOfOrder = 61,
  117. kCrosHalV3BufferManagerFailedToUnwrapReleaseFenceFd = 62,
  118. kCrosHalV3BufferManagerSyncWaitOnReleaseFenceTimedOut = 63,
  119. kCrosHalV3BufferManagerInvalidJpegBlob = 64,
  120. kAndroidFailedToAllocate = 65,
  121. kAndroidFailedToStartCapture = 66,
  122. kAndroidFailedToStopCapture = 67,
  123. kAndroidApi1CameraErrorCallbackReceived = 68,
  124. kAndroidApi2CameraDeviceErrorReceived = 69,
  125. kAndroidApi2CaptureSessionConfigureFailed = 70,
  126. kAndroidApi2ImageReaderUnexpectedImageFormat = 71,
  127. kAndroidApi2ImageReaderSizeDidNotMatchImageSize = 72,
  128. kAndroidApi2ErrorRestartingPreview = 73,
  129. kAndroidScreenCaptureUnsupportedFormat = 74,
  130. kAndroidScreenCaptureFailedToStartCaptureMachine = 75,
  131. kAndroidScreenCaptureTheUserDeniedScreenCapture = 76,
  132. kAndroidScreenCaptureFailedToStartScreenCapture = 77,
  133. kWinDirectShowCantGetCaptureFormatSettings = 78,
  134. kWinDirectShowFailedToGetNumberOfCapabilities = 79,
  135. kWinDirectShowFailedToGetCaptureDeviceCapabilities = 80,
  136. kWinDirectShowFailedToSetCaptureDeviceOutputFormat = 81,
  137. kWinDirectShowFailedToConnectTheCaptureGraph = 82,
  138. kWinDirectShowFailedToPauseTheCaptureDevice = 83,
  139. kWinDirectShowFailedToStartTheCaptureDevice = 84,
  140. kWinDirectShowFailedToStopTheCaptureGraph = 85,
  141. kWinMediaFoundationEngineIsNull = 86,
  142. kWinMediaFoundationEngineGetSourceFailed = 87,
  143. kWinMediaFoundationFillPhotoCapabilitiesFailed = 88,
  144. kWinMediaFoundationFillVideoCapabilitiesFailed = 89,
  145. kWinMediaFoundationNoVideoCapabilityFound = 90,
  146. kWinMediaFoundationGetAvailableDeviceMediaTypeFailed = 91,
  147. kWinMediaFoundationSetCurrentDeviceMediaTypeFailed = 92,
  148. kWinMediaFoundationEngineGetSinkFailed = 93,
  149. kWinMediaFoundationSinkQueryCapturePreviewInterfaceFailed = 94,
  150. kWinMediaFoundationSinkRemoveAllStreamsFailed = 95,
  151. kWinMediaFoundationCreateSinkVideoMediaTypeFailed = 96,
  152. kWinMediaFoundationConvertToVideoSinkMediaTypeFailed = 97,
  153. kWinMediaFoundationSinkAddStreamFailed = 98,
  154. kWinMediaFoundationSinkSetSampleCallbackFailed = 99,
  155. kWinMediaFoundationEngineStartPreviewFailed = 100,
  156. kWinMediaFoundationGetMediaEventStatusFailed = 101,
  157. kMacSetCaptureDeviceFailed = 102,
  158. kMacCouldNotStartCaptureDevice = 103,
  159. kMacReceivedFrameWithUnexpectedResolution = 104,
  160. kMacUpdateCaptureResolutionFailed = 105,
  161. kMacDeckLinkDeviceIdNotFoundInTheSystem = 106,
  162. kMacDeckLinkErrorQueryingInputInterface = 107,
  163. kMacDeckLinkErrorCreatingDisplayModeIterator = 108,
  164. kMacDeckLinkCouldNotFindADisplayMode = 109,
  165. kMacDeckLinkCouldNotSelectTheVideoFormatWeLike = 110,
  166. kMacDeckLinkCouldNotStartCapturing = 111,
  167. kMacDeckLinkUnsupportedPixelFormat = 112,
  168. kMacAvFoundationReceivedAVCaptureSessionRuntimeErrorNotification = 113,
  169. kAndroidApi2ErrorConfiguringCamera = 114,
  170. kCrosHalV3DeviceDelegateFailedToFlush = 115,
  171. kFuchsiaCameraDeviceDisconnected = 116,
  172. kFuchsiaCameraStreamDisconnected = 117,
  173. kFuchsiaSysmemDidNotSetImageFormat = 118,
  174. kFuchsiaSysmemInvalidBufferIndex = 119,
  175. kFuchsiaSysmemInvalidBufferSize = 120,
  176. kFuchsiaUnsupportedPixelFormat = 121,
  177. kFuchsiaFailedToMapSysmemBuffer = 122,
  178. kCrosHalV3DeviceContextDuplicatedClient = 123,
  179. kDesktopCaptureDeviceMacFailedStreamCreate = 124,
  180. kDesktopCaptureDeviceMacFailedStreamStart = 125,
  181. kCrosHalV3BufferManagerFailedToReserveBuffers = 126,
  182. kWinMediaFoundationSystemPermissionDenied = 127,
  183. kVideoCaptureImplTimedOutOnStart = 128,
  184. kLacrosVideoCaptureDeviceProxyAlreadyEndedOnFatalError = 129,
  185. kLacrosVideoCaptureDeviceProxyEncounteredFatalError = 130,
  186. kScreenCaptureKitFailedGetShareableContent = 131,
  187. kScreenCaptureKitFailedAddStreamOutput = 132,
  188. kScreenCaptureKitFailedStartCapture = 133,
  189. kScreenCaptureKitFailedStopCapture = 134,
  190. kScreenCaptureKitStreamError = 135,
  191. kScreenCaptureKitFailedToFindSCDisplay = 136,
  192. kMaxValue = 136
  193. };
  194. // WARNING: Do not change the values assigned to the entries. They are used for
  195. // UMA logging.
  196. enum class VideoCaptureFrameDropReason {
  197. kNone = 0,
  198. kDeviceClientFrameHasInvalidFormat = 1,
  199. kDeviceClientLibyuvConvertToI420Failed = 3,
  200. kV4L2BufferErrorFlagWasSet = 4,
  201. kV4L2InvalidNumberOfBytesInBuffer = 5,
  202. kAndroidThrottling = 6,
  203. kAndroidGetByteArrayElementsFailed = 7,
  204. kAndroidApi1UnexpectedDataLength = 8,
  205. kAndroidApi2AcquiredImageIsNull = 9,
  206. kWinDirectShowUnexpectedSampleLength = 10,
  207. kWinDirectShowFailedToGetMemoryPointerFromMediaSample = 11,
  208. kWinMediaFoundationReceivedSampleIsNull = 12,
  209. kWinMediaFoundationLockingBufferDelieveredNullptr = 13,
  210. kWinMediaFoundationGetBufferByIndexReturnedNull = 14,
  211. kBufferPoolMaxBufferCountExceeded = 15,
  212. kBufferPoolBufferAllocationFailed = 16,
  213. kVideoCaptureImplNotInStartedState = 17,
  214. kVideoCaptureImplFailedToWrapDataAsMediaVideoFrame = 18,
  215. kVideoTrackAdapterHasNoResolutionAdapters = 19,
  216. kResolutionAdapterFrameIsNotValid = 20,
  217. kResolutionAdapterWrappingFrameForCroppingFailed = 21,
  218. kResolutionAdapterTimestampTooCloseToPrevious = 22,
  219. kResolutionAdapterFrameRateIsHigherThanRequested = 23,
  220. kResolutionAdapterHasNoCallbacks = 24,
  221. kVideoTrackFrameDelivererNotEnabledReplacingWithBlackFrame = 25,
  222. kRendererSinkFrameDelivererIsNotStarted = 26,
  223. kMaxValue = 26
  224. };
  225. // Assert that the int:frequency mapping is correct.
  226. static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_DEFAULT) == 0,
  227. "static_cast<int>(FREQUENCY_DEFAULT) must equal 0.");
  228. static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_50HZ) == 50,
  229. "static_cast<int>(FREQUENCY_DEFAULT) must equal 50.");
  230. static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_60HZ) == 60,
  231. "static_cast<int>(FREQUENCY_DEFAULT) must equal 60.");
  232. // Some drivers use rational time per frame instead of float frame rate, this
  233. // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
  234. const int kFrameRatePrecision = 10000;
  235. // Video capture format specification.
  236. // This class is used by the video capture device to specify the format of every
  237. // frame captured and returned to a client. It is also used to specify a
  238. // supported capture format by a device.
  239. struct CAPTURE_EXPORT VideoCaptureFormat {
  240. VideoCaptureFormat();
  241. VideoCaptureFormat(const gfx::Size& frame_size,
  242. float frame_rate,
  243. VideoPixelFormat pixel_format);
  244. static std::string ToString(const VideoCaptureFormat& format);
  245. // Compares the priority of the pixel formats. Returns true if |lhs| is the
  246. // preferred pixel format in comparison with |rhs|. Returns false otherwise.
  247. static bool ComparePixelFormatPreference(const VideoPixelFormat& lhs,
  248. const VideoPixelFormat& rhs);
  249. // Checks that all values are in the expected range. All limits are specified
  250. // in media::Limits.
  251. bool IsValid() const;
  252. bool operator==(const VideoCaptureFormat& other) const {
  253. return frame_size == other.frame_size && frame_rate == other.frame_rate &&
  254. pixel_format == other.pixel_format;
  255. }
  256. gfx::Size frame_size;
  257. float frame_rate;
  258. VideoPixelFormat pixel_format;
  259. };
  260. typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
  261. // Parameters for starting video capture.
  262. // This class is used by the client of a video capture device to specify the
  263. // format of frames in which the client would like to have captured frames
  264. // returned.
  265. struct CAPTURE_EXPORT VideoCaptureParams {
  266. // Result struct for SuggestContraints() method.
  267. struct SuggestedConstraints {
  268. gfx::Size min_frame_size;
  269. gfx::Size max_frame_size;
  270. bool fixed_aspect_ratio;
  271. };
  272. VideoCaptureParams();
  273. // Returns true if requested_format.IsValid() and all other values are within
  274. // their expected ranges.
  275. bool IsValid() const;
  276. // Computes and returns suggested capture constraints based on the requested
  277. // format and resolution change policy: minimum resolution, maximum
  278. // resolution, and whether a fixed aspect ratio is required.
  279. SuggestedConstraints SuggestConstraints() const;
  280. bool operator==(const VideoCaptureParams& other) const {
  281. return requested_format == other.requested_format &&
  282. resolution_change_policy == other.resolution_change_policy &&
  283. power_line_frequency == other.power_line_frequency;
  284. }
  285. // Requests a resolution and format at which the capture will occur.
  286. VideoCaptureFormat requested_format;
  287. VideoCaptureBufferType buffer_type;
  288. // Policy for resolution change.
  289. ResolutionChangePolicy resolution_change_policy;
  290. // User-specified power line frequency.
  291. PowerLineFrequency power_line_frequency;
  292. // Flag indicating if face detection should be enabled. This is for
  293. // allowing the driver to apply appropriate settings for optimal
  294. // exposures around the face area. Currently only applicable on
  295. // Android platform with Camera2 driver support.
  296. bool enable_face_detection;
  297. };
  298. } // namespace media
  299. #endif // MEDIA_CAPTURE_VIDEO_CAPTURE_TYPES_H_