Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / video / capture / video_capture_types.h
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.
4
5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_TYPES_H_
6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_TYPES_H_
7
8 #include <vector>
9
10 #include "media/base/media_export.h"
11 #include "ui/gfx/size.h"
12
13 namespace media {
14
15 // TODO(wjia): this type should be defined in a common place and
16 // shared with device manager.
17 typedef int VideoCaptureSessionId;
18
19 // Color formats from camera. This list is sorted in order of preference.
20 enum VideoPixelFormat {
21   PIXEL_FORMAT_I420,
22   PIXEL_FORMAT_YV12,
23   PIXEL_FORMAT_NV21,
24   PIXEL_FORMAT_UYVY,
25   PIXEL_FORMAT_YUY2,
26   PIXEL_FORMAT_RGB24,
27   PIXEL_FORMAT_ARGB,
28   PIXEL_FORMAT_MJPEG,
29   PIXEL_FORMAT_TEXTURE,  // Capture format as a GL texture.
30   PIXEL_FORMAT_UNKNOWN,  // Color format not set.
31   PIXEL_FORMAT_MAX,
32 };
33
34 // Policies for capture devices that has source content with dynamic resolution.
35 enum ResolutionChangePolicy {
36   // Capture device outputs a fixed resolution all the time. The resolution of
37   // the first frame is the resolution for all frames.
38   // It is implementation specific for the capture device to scale, letter-box
39   // and pillar-box. The only guarantee is that resolution will never change.
40   RESOLUTION_POLICY_FIXED,
41
42   // Capture device outputs frames with dynamic resolution. The width and height
43   // will not exceed the maximum dimensions specified. The typical scenario is
44   // the frames will have the same aspect ratio as the original content and
45   // scaled down to fit inside the limit.
46   RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT,
47
48   RESOLUTION_POLICY_LAST,
49 };
50
51 // Some drivers use rational time per frame instead of float frame rate, this
52 // constant k is used to convert between both: A fps -> [k/k*A] seconds/frame.
53 const int kFrameRatePrecision = 10000;
54
55 // Video capture format specification.
56 // This class is used by the video capture device to specify the format of every
57 // frame captured and returned to a client. It is also used to specify a
58 // supported capture format by a device.
59 class MEDIA_EXPORT VideoCaptureFormat {
60  public:
61   VideoCaptureFormat();
62   VideoCaptureFormat(const gfx::Size& frame_size,
63                      float frame_rate,
64                      VideoPixelFormat pixel_format);
65
66   std::string ToString() const;
67   static std::string PixelFormatToString(VideoPixelFormat format);
68
69   // Checks that all values are in the expected range. All limits are specified
70   // in media::Limits.
71   bool IsValid() const;
72
73   gfx::Size frame_size;
74   float frame_rate;
75   VideoPixelFormat pixel_format;
76 };
77
78 // Image capture format specification.
79 // This class is used by the video capture device to specify the format of a
80 // still image captured and returned to a client. A list of these is also
81 // provided when client queries supported formats for still image capture.
82 class MEDIA_EXPORT ImageCaptureFormat {
83  public:
84   ImageCaptureFormat();
85
86   ImageCaptureFormat(const gfx::Size& frame_size,
87                      VideoPixelFormat pixel_format);
88
89   gfx::Size frame_size;
90   VideoPixelFormat pixel_format;
91 };
92
93 typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
94
95 typedef std::vector<ImageCaptureFormat> ImageCaptureFormats;
96
97 // Parameters for starting video capture.
98 // This class is used by the client of a video capture device to specify the
99 // format of frames in which the client would like to have captured frames
100 // returned.
101 class MEDIA_EXPORT VideoCaptureParams {
102  public:
103   VideoCaptureParams();
104
105   // Requests a resolution and format at which the capture will occur.
106   VideoCaptureFormat requested_format;
107
108   // Policy for resolution change.
109   ResolutionChangePolicy resolution_change_policy;
110 };
111
112 }  // namespace media
113
114 #endif  // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_TYPES_H_