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.
5 #ifndef MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_
6 #define MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_
10 #include "build/build_config.h"
11 #include "media/base/media_export.h"
12 #include "ui/gfx/geometry/size.h"
16 // TODO(wjia): this type should be defined in a common place and
17 // shared with device manager.
18 typedef int VideoCaptureSessionId
;
20 // TODO(dshwang): replace it with media::VideoPixelFormat. crbug.com/489744
21 // Color formats from camera. This list is sorted in order of preference.
22 // TODO(emircan): http://crbug.com/521068 Consider if this list can be merged
23 // with media::Format.
24 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
25 enum VideoCapturePixelFormat
{
26 VIDEO_CAPTURE_PIXEL_FORMAT_I420
,
27 VIDEO_CAPTURE_PIXEL_FORMAT_YV12
,
28 VIDEO_CAPTURE_PIXEL_FORMAT_NV12
,
29 VIDEO_CAPTURE_PIXEL_FORMAT_NV21
,
30 VIDEO_CAPTURE_PIXEL_FORMAT_UYVY
,
31 VIDEO_CAPTURE_PIXEL_FORMAT_YUY2
,
32 VIDEO_CAPTURE_PIXEL_FORMAT_RGB24
,
33 VIDEO_CAPTURE_PIXEL_FORMAT_RGB32
,
34 VIDEO_CAPTURE_PIXEL_FORMAT_ARGB
,
35 VIDEO_CAPTURE_PIXEL_FORMAT_MJPEG
,
36 VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN
, // Color format not set.
37 VIDEO_CAPTURE_PIXEL_FORMAT_MAX
= VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN
,
40 // Storage type for the pixels. In principle, all combinations of Storage and
41 // Format are possible, though some are very typical, such as texture + ARGB,
42 // and others are only available if the platform allows it e.g. GpuMemoryBuffer.
43 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
44 enum VideoPixelStorage
{
46 PIXEL_STORAGE_TEXTURE
,
47 PIXEL_STORAGE_GPUMEMORYBUFFER
,
48 PIXEL_STORAGE_MAX
= PIXEL_STORAGE_GPUMEMORYBUFFER
,
51 // Policies for capture devices that have source content that varies in size.
52 // It is up to the implementation how the captured content will be transformed
53 // (e.g., scaling and/or letterboxing) in order to produce video frames that
54 // strictly adheree to one of these policies.
55 enum ResolutionChangePolicy
{
56 // Capture device outputs a fixed resolution all the time. The resolution of
57 // the first frame is the resolution for all frames.
58 RESOLUTION_POLICY_FIXED_RESOLUTION
,
60 // Capture device is allowed to output frames of varying resolutions. The
61 // width and height will not exceed the maximum dimensions specified. The
62 // aspect ratio of the frames will match the aspect ratio of the maximum
63 // dimensions as closely as possible.
64 RESOLUTION_POLICY_FIXED_ASPECT_RATIO
,
66 // Capture device is allowed to output frames of varying resolutions not
67 // exceeding the maximum dimensions specified.
68 RESOLUTION_POLICY_ANY_WITHIN_LIMIT
,
70 // Must always be equal to largest entry in the enum.
71 RESOLUTION_POLICY_LAST
= RESOLUTION_POLICY_ANY_WITHIN_LIMIT
,
74 // Some drivers use rational time per frame instead of float frame rate, this
75 // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
76 const int kFrameRatePrecision
= 10000;
78 // Video capture format specification.
79 // This class is used by the video capture device to specify the format of every
80 // frame captured and returned to a client. It is also used to specify a
81 // supported capture format by a device.
82 struct MEDIA_EXPORT VideoCaptureFormat
{
84 VideoCaptureFormat(const gfx::Size
& frame_size
,
86 VideoCapturePixelFormat pixel_format
);
87 VideoCaptureFormat(const gfx::Size
& frame_size
,
89 VideoCapturePixelFormat pixel_format
,
90 VideoPixelStorage pixel_storage
);
92 static std::string
ToString(const VideoCaptureFormat
& format
);
93 static std::string
PixelFormatToString(VideoCapturePixelFormat format
);
94 static std::string
PixelStorageToString(VideoPixelStorage storage
);
96 // Returns the required buffer size to hold an image of a given
97 // VideoCaptureFormat with no padding and tightly packed.
98 size_t ImageAllocationSize() const;
100 // Checks that all values are in the expected range. All limits are specified
102 bool IsValid() const;
104 bool operator==(const VideoCaptureFormat
& other
) const {
105 return frame_size
== other
.frame_size
&&
106 frame_rate
== other
.frame_rate
&&
107 pixel_format
== other
.pixel_format
;
110 gfx::Size frame_size
;
112 VideoCapturePixelFormat pixel_format
;
113 VideoPixelStorage pixel_storage
;
116 typedef std::vector
<VideoCaptureFormat
> VideoCaptureFormats
;
118 // Parameters for starting video capture.
119 // This class is used by the client of a video capture device to specify the
120 // format of frames in which the client would like to have captured frames
122 struct MEDIA_EXPORT VideoCaptureParams
{
123 VideoCaptureParams();
125 bool operator==(const VideoCaptureParams
& other
) const {
126 return requested_format
== other
.requested_format
&&
127 resolution_change_policy
== other
.resolution_change_policy
;
130 // Requests a resolution and format at which the capture will occur.
131 VideoCaptureFormat requested_format
;
133 // Policy for resolution change.
134 ResolutionChangePolicy resolution_change_policy
;
139 #endif // MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_