Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / media / base / video_capture_types.h
blob2a8c243f27ff7b5403f961b0d5456bf779a96c2a
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 "ui/gfx/geometry/size.h"
14 namespace media {
16 // TODO(wjia): this type should be defined in a common place and
17 // shared with device manager.
18 typedef int VideoCaptureSessionId;
20 // Color formats from camera. This list is sorted in order of preference.
21 // TODO(mcasas): Consider if this list can be merged with media::Format.
22 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
23 enum VideoPixelFormat {
24 PIXEL_FORMAT_I420,
25 PIXEL_FORMAT_YV12,
26 PIXEL_FORMAT_NV12,
27 PIXEL_FORMAT_NV21,
28 PIXEL_FORMAT_UYVY,
29 PIXEL_FORMAT_YUY2,
30 PIXEL_FORMAT_RGB24,
31 PIXEL_FORMAT_RGB32,
32 PIXEL_FORMAT_ARGB,
33 PIXEL_FORMAT_MJPEG,
34 PIXEL_FORMAT_UNKNOWN, // Color format not set.
35 PIXEL_FORMAT_MAX = PIXEL_FORMAT_UNKNOWN,
38 // Storage type for the pixels. In principle, all combinations of Storage and
39 // Format are possible, though some are very typical, such as texture + ARGB,
40 // and others are only available if the platform allows it e.g. GpuMemoryBuffer.
41 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
42 enum VideoPixelStorage {
43 PIXEL_STORAGE_CPU,
44 PIXEL_STORAGE_TEXTURE,
45 PIXEL_STORAGE_GPUMEMORYBUFFER,
46 PIXEL_STORAGE_MAX = PIXEL_STORAGE_GPUMEMORYBUFFER,
49 // Policies for capture devices that have source content that varies in size.
50 // It is up to the implementation how the captured content will be transformed
51 // (e.g., scaling and/or letterboxing) in order to produce video frames that
52 // strictly adheree to one of these policies.
53 enum ResolutionChangePolicy {
54 // Capture device outputs a fixed resolution all the time. The resolution of
55 // the first frame is the resolution for all frames.
56 RESOLUTION_POLICY_FIXED_RESOLUTION,
58 // Capture device is allowed to output frames of varying resolutions. The
59 // width and height will not exceed the maximum dimensions specified. The
60 // aspect ratio of the frames will match the aspect ratio of the maximum
61 // dimensions as closely as possible.
62 RESOLUTION_POLICY_FIXED_ASPECT_RATIO,
64 // Capture device is allowed to output frames of varying resolutions not
65 // exceeding the maximum dimensions specified.
66 RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
68 // Must always be equal to largest entry in the enum.
69 RESOLUTION_POLICY_LAST = RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
72 // Some drivers use rational time per frame instead of float frame rate, this
73 // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
74 const int kFrameRatePrecision = 10000;
76 // Video capture format specification.
77 // This class is used by the video capture device to specify the format of every
78 // frame captured and returned to a client. It is also used to specify a
79 // supported capture format by a device.
80 struct MEDIA_EXPORT VideoCaptureFormat {
81 VideoCaptureFormat();
82 VideoCaptureFormat(const gfx::Size& frame_size,
83 float frame_rate,
84 VideoPixelFormat pixel_format);
85 VideoCaptureFormat(const gfx::Size& frame_size,
86 float frame_rate,
87 VideoPixelFormat pixel_format,
88 VideoPixelStorage pixel_storage);
90 static std::string ToString(const VideoCaptureFormat& format);
91 static std::string PixelFormatToString(VideoPixelFormat format);
92 static std::string PixelStorageToString(VideoPixelStorage storage);
94 // Returns the required buffer size to hold an image of a given
95 // VideoCaptureFormat with no padding and tightly packed.
96 size_t ImageAllocationSize() const;
98 // Checks that all values are in the expected range. All limits are specified
99 // in media::Limits.
100 bool IsValid() const;
102 bool operator==(const VideoCaptureFormat& other) const {
103 return frame_size == other.frame_size &&
104 frame_rate == other.frame_rate &&
105 pixel_format == other.pixel_format;
108 gfx::Size frame_size;
109 float frame_rate;
110 VideoPixelFormat pixel_format;
111 VideoPixelStorage pixel_storage;
114 typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
116 // Parameters for starting video capture.
117 // This class is used by the client of a video capture device to specify the
118 // format of frames in which the client would like to have captured frames
119 // returned.
120 struct MEDIA_EXPORT VideoCaptureParams {
121 VideoCaptureParams();
123 bool operator==(const VideoCaptureParams& other) const {
124 return requested_format == other.requested_format &&
125 use_gpu_memory_buffers == other.use_gpu_memory_buffers &&
126 resolution_change_policy == other.resolution_change_policy;
129 // Requests a resolution and format at which the capture will occur.
130 VideoCaptureFormat requested_format;
132 // Policy for resolution change.
133 ResolutionChangePolicy resolution_change_policy;
135 // Indication to the Driver to try to use GpuMemoryBuffers.
136 bool use_gpu_memory_buffers;
139 } // namespace media
141 #endif // MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_