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 "media/base/media_export.h"
11 #include "ui/gfx/geometry/size.h"
15 // TODO(wjia): this type should be defined in a common place and
16 // shared with device manager.
17 typedef int VideoCaptureSessionId
;
19 // Color formats from camera. This list is sorted in order of preference.
20 enum VideoPixelFormat
{
31 PIXEL_FORMAT_TEXTURE
, // Capture format as a GL texture.
32 PIXEL_FORMAT_GPUMEMORYBUFFER
,
33 PIXEL_FORMAT_UNKNOWN
, // Color format not set.
37 // Policies for capture devices that have source content that varies in size.
38 // It is up to the implementation how the captured content will be transformed
39 // (e.g., scaling and/or letterboxing) in order to produce video frames that
40 // strictly adheree to one of these policies.
41 enum ResolutionChangePolicy
{
42 // Capture device outputs a fixed resolution all the time. The resolution of
43 // the first frame is the resolution for all frames.
44 RESOLUTION_POLICY_FIXED_RESOLUTION
,
46 // Capture device is allowed to output frames of varying resolutions. The
47 // width and height will not exceed the maximum dimensions specified. The
48 // aspect ratio of the frames will match the aspect ratio of the maximum
49 // dimensions as closely as possible.
50 RESOLUTION_POLICY_FIXED_ASPECT_RATIO
,
52 // Capture device is allowed to output frames of varying resolutions not
53 // exceeding the maximum dimensions specified.
54 RESOLUTION_POLICY_ANY_WITHIN_LIMIT
,
56 RESOLUTION_POLICY_LAST
,
59 // Some drivers use rational time per frame instead of float frame rate, this
60 // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
61 const int kFrameRatePrecision
= 10000;
63 // Video capture format specification.
64 // This class is used by the video capture device to specify the format of every
65 // frame captured and returned to a client. It is also used to specify a
66 // supported capture format by a device.
67 class MEDIA_EXPORT VideoCaptureFormat
{
70 VideoCaptureFormat(const gfx::Size
& frame_size
,
72 VideoPixelFormat pixel_format
);
74 std::string
ToString() const;
75 static std::string
PixelFormatToString(VideoPixelFormat format
);
77 // Returns the required buffer size to hold an image of a given
78 // VideoCaptureFormat with no padding and tightly packed.
79 size_t ImageAllocationSize() const;
81 // Checks that all values are in the expected range. All limits are specified
85 bool operator==(const VideoCaptureFormat
& other
) const {
86 return frame_size
== other
.frame_size
&&
87 frame_rate
== other
.frame_rate
&&
88 pixel_format
== other
.pixel_format
;
93 VideoPixelFormat pixel_format
;
96 typedef std::vector
<VideoCaptureFormat
> VideoCaptureFormats
;
98 // Parameters for starting video capture.
99 // This class is used by the client of a video capture device to specify the
100 // format of frames in which the client would like to have captured frames
102 class MEDIA_EXPORT VideoCaptureParams
{
104 VideoCaptureParams();
106 bool operator==(const VideoCaptureParams
& other
) const {
107 return requested_format
== other
.requested_format
&&
108 resolution_change_policy
== other
.resolution_change_policy
;
111 // Requests a resolution and format at which the capture will occur.
112 VideoCaptureFormat requested_format
;
114 // Policy for resolution change.
115 ResolutionChangePolicy resolution_change_policy
;
120 #endif // MEDIA_BASE_VIDEO_CAPTURE_TYPES_H_