Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / media / base / video_capture_types.h
blob53f00f28a282a7f99d8e6327920fd3893011464a
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 // 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(mcasas): Consider if this list can be merged with media::Format.
23 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
24 enum VideoCapturePixelFormat {
25 VIDEO_CAPTURE_PIXEL_FORMAT_I420,
26 VIDEO_CAPTURE_PIXEL_FORMAT_YV12,
27 VIDEO_CAPTURE_PIXEL_FORMAT_NV12,
28 VIDEO_CAPTURE_PIXEL_FORMAT_NV21,
29 VIDEO_CAPTURE_PIXEL_FORMAT_UYVY,
30 VIDEO_CAPTURE_PIXEL_FORMAT_YUY2,
31 VIDEO_CAPTURE_PIXEL_FORMAT_RGB24,
32 VIDEO_CAPTURE_PIXEL_FORMAT_RGB32,
33 VIDEO_CAPTURE_PIXEL_FORMAT_ARGB,
34 VIDEO_CAPTURE_PIXEL_FORMAT_MJPEG,
35 VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN, // Color format not set.
36 VIDEO_CAPTURE_PIXEL_FORMAT_MAX = VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN,
39 // Storage type for the pixels. In principle, all combinations of Storage and
40 // Format are possible, though some are very typical, such as texture + ARGB,
41 // and others are only available if the platform allows it e.g. GpuMemoryBuffer.
42 // TODO(mcasas): http://crbug.com/504160 Consider making this an enum class.
43 enum VideoPixelStorage {
44 PIXEL_STORAGE_CPU,
45 PIXEL_STORAGE_TEXTURE,
46 PIXEL_STORAGE_GPUMEMORYBUFFER,
47 PIXEL_STORAGE_MAX = PIXEL_STORAGE_GPUMEMORYBUFFER,
50 // Policies for capture devices that have source content that varies in size.
51 // It is up to the implementation how the captured content will be transformed
52 // (e.g., scaling and/or letterboxing) in order to produce video frames that
53 // strictly adheree to one of these policies.
54 enum ResolutionChangePolicy {
55 // Capture device outputs a fixed resolution all the time. The resolution of
56 // the first frame is the resolution for all frames.
57 RESOLUTION_POLICY_FIXED_RESOLUTION,
59 // Capture device is allowed to output frames of varying resolutions. The
60 // width and height will not exceed the maximum dimensions specified. The
61 // aspect ratio of the frames will match the aspect ratio of the maximum
62 // dimensions as closely as possible.
63 RESOLUTION_POLICY_FIXED_ASPECT_RATIO,
65 // Capture device is allowed to output frames of varying resolutions not
66 // exceeding the maximum dimensions specified.
67 RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
69 // Must always be equal to largest entry in the enum.
70 RESOLUTION_POLICY_LAST = RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
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 VideoCapturePixelFormat pixel_format);
86 VideoCaptureFormat(const gfx::Size& frame_size,
87 float frame_rate,
88 VideoCapturePixelFormat pixel_format,
89 VideoPixelStorage pixel_storage);
91 static std::string ToString(const VideoCaptureFormat& format);
92 static std::string PixelFormatToString(VideoCapturePixelFormat format);
93 static std::string PixelStorageToString(VideoPixelStorage storage);
95 // Returns the required buffer size to hold an image of a given
96 // VideoCaptureFormat with no padding and tightly packed.
97 size_t ImageAllocationSize() const;
99 // Checks that all values are in the expected range. All limits are specified
100 // in media::Limits.
101 bool IsValid() const;
103 bool operator==(const VideoCaptureFormat& other) const {
104 return frame_size == other.frame_size &&
105 frame_rate == other.frame_rate &&
106 pixel_format == other.pixel_format;
109 gfx::Size frame_size;
110 float frame_rate;
111 VideoCapturePixelFormat pixel_format;
112 VideoPixelStorage pixel_storage;
115 typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
117 // Parameters for starting video capture.
118 // This class is used by the client of a video capture device to specify the
119 // format of frames in which the client would like to have captured frames
120 // returned.
121 struct MEDIA_EXPORT VideoCaptureParams {
122 VideoCaptureParams();
124 bool operator==(const VideoCaptureParams& other) const {
125 return requested_format == other.requested_format &&
126 use_gpu_memory_buffers == other.use_gpu_memory_buffers &&
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;
136 // Indication to the Driver to try to use GpuMemoryBuffers.
137 bool use_gpu_memory_buffers;
140 } // namespace media
142 #endif // MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_