Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / base / video_capture_types.h
blob4790ea52e1e12414226a882142495ed03c4b3eaa
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_
8 #include <vector>
10 #include "build/build_config.h"
11 #include "media/base/media_export.h"
12 #include "media/base/video_types.h"
13 #include "ui/gfx/geometry/size.h"
15 namespace media {
17 // TODO(wjia): this type should be defined in a common place and
18 // shared with device manager.
19 typedef int VideoCaptureSessionId;
21 // Storage type for the pixels. In principle, all combinations of Storage and
22 // Format are possible, though some are very typical, such as texture + ARGB,
23 // and others are only available if the platform allows it e.g. GpuMemoryBuffer.
24 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
25 enum VideoPixelStorage {
26 PIXEL_STORAGE_CPU,
27 PIXEL_STORAGE_TEXTURE,
28 PIXEL_STORAGE_GPUMEMORYBUFFER,
29 PIXEL_STORAGE_MAX = PIXEL_STORAGE_GPUMEMORYBUFFER,
32 // Policies for capture devices that have source content that varies in size.
33 // It is up to the implementation how the captured content will be transformed
34 // (e.g., scaling and/or letterboxing) in order to produce video frames that
35 // strictly adheree to one of these policies.
36 enum ResolutionChangePolicy {
37 // Capture device outputs a fixed resolution all the time. The resolution of
38 // the first frame is the resolution for all frames.
39 RESOLUTION_POLICY_FIXED_RESOLUTION,
41 // Capture device is allowed to output frames of varying resolutions. The
42 // width and height will not exceed the maximum dimensions specified. The
43 // aspect ratio of the frames will match the aspect ratio of the maximum
44 // dimensions as closely as possible.
45 RESOLUTION_POLICY_FIXED_ASPECT_RATIO,
47 // Capture device is allowed to output frames of varying resolutions not
48 // exceeding the maximum dimensions specified.
49 RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
51 // Must always be equal to largest entry in the enum.
52 RESOLUTION_POLICY_LAST = RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
55 // Potential values of the googPowerLineFrequency optional constraint passed to
56 // getUserMedia. Note that the numeric values are currently significant, and are
57 // used to map enum values to corresponding frequency values.
58 // TODO(ajose): http://crbug.com/525167 Consider making this a class.
59 enum class PowerLineFrequency {
60 FREQUENCY_DEFAULT = 0,
61 FREQUENCY_50HZ = 50,
62 FREQUENCY_60HZ = 60,
63 FREQUENCY_MAX = FREQUENCY_60HZ
65 // Assert that the int:frequency mapping is correct.
66 static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_DEFAULT) == 0,
67 "static_cast<int>(FREQUENCY_DEFAULT) must equal 0.");
68 static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_50HZ) == 50,
69 "static_cast<int>(FREQUENCY_DEFAULT) must equal 50.");
70 static_assert(static_cast<int>(PowerLineFrequency::FREQUENCY_60HZ) == 60,
71 "static_cast<int>(FREQUENCY_DEFAULT) must equal 60.");
73 // Some drivers use rational time per frame instead of float frame rate, this
74 // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
75 const int kFrameRatePrecision = 10000;
77 // Video capture format specification.
78 // This class is used by the video capture device to specify the format of every
79 // frame captured and returned to a client. It is also used to specify a
80 // supported capture format by a device.
81 struct MEDIA_EXPORT VideoCaptureFormat {
82 VideoCaptureFormat();
83 VideoCaptureFormat(const gfx::Size& frame_size,
84 float frame_rate,
85 VideoPixelFormat pixel_format);
86 VideoCaptureFormat(const gfx::Size& frame_size,
87 float frame_rate,
88 VideoPixelFormat pixel_format,
89 VideoPixelStorage pixel_storage);
91 static std::string ToString(const VideoCaptureFormat& format);
92 static std::string PixelStorageToString(VideoPixelStorage storage);
94 // Compares the priority of the pixel formats. Returns true if |lhs| is the
95 // preferred pixel format in comparison with |rhs|. Returns false otherwise.
96 static bool ComparePixelFormatPreference(const VideoPixelFormat& lhs,
97 const VideoPixelFormat& rhs);
99 // Returns the required buffer size to hold an image of a given
100 // VideoCaptureFormat with no padding and tightly packed.
101 size_t ImageAllocationSize() const;
103 // Checks that all values are in the expected range. All limits are specified
104 // in media::Limits.
105 bool IsValid() const;
107 bool operator==(const VideoCaptureFormat& other) const {
108 return frame_size == other.frame_size &&
109 frame_rate == other.frame_rate &&
110 pixel_format == other.pixel_format;
113 gfx::Size frame_size;
114 float frame_rate;
115 VideoPixelFormat pixel_format;
116 VideoPixelStorage pixel_storage;
119 typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
121 // Parameters for starting video capture.
122 // This class is used by the client of a video capture device to specify the
123 // format of frames in which the client would like to have captured frames
124 // returned.
125 struct MEDIA_EXPORT VideoCaptureParams {
126 VideoCaptureParams();
128 bool operator==(const VideoCaptureParams& other) const {
129 return requested_format == other.requested_format &&
130 resolution_change_policy == other.resolution_change_policy &&
131 power_line_frequency == other.power_line_frequency;
134 // Requests a resolution and format at which the capture will occur.
135 VideoCaptureFormat requested_format;
137 // Policy for resolution change.
138 ResolutionChangePolicy resolution_change_policy;
140 // User-specified power line frequency.
141 PowerLineFrequency power_line_frequency;
144 } // namespace media
146 #endif // MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_