1 // Copyright 2013 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 #include "media/base/video_capture_types.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
9 #include "media/base/limits.h"
13 VideoCaptureFormat::VideoCaptureFormat()
14 : frame_rate(0.0f
), pixel_format(PIXEL_FORMAT_UNKNOWN
) {}
16 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size
& frame_size
,
18 VideoPixelFormat pixel_format
)
19 : frame_size(frame_size
),
20 frame_rate(frame_rate
),
21 pixel_format(pixel_format
) {}
23 bool VideoCaptureFormat::IsValid() const {
24 return (frame_size
.width() < media::limits::kMaxDimension
) &&
25 (frame_size
.height() < media::limits::kMaxDimension
) &&
26 (frame_size
.GetArea() >= 0) &&
27 (frame_size
.GetArea() < media::limits::kMaxCanvas
) &&
28 (frame_rate
>= 0.0f
) &&
29 (frame_rate
< media::limits::kMaxFramesPerSecond
) &&
30 (pixel_format
>= 0) &&
31 (pixel_format
< PIXEL_FORMAT_MAX
);
34 size_t VideoCaptureFormat::ImageAllocationSize() const {
35 size_t result_frame_size
= frame_size
.GetArea();
36 switch (pixel_format
) {
37 case PIXEL_FORMAT_I420
:
38 case PIXEL_FORMAT_YV12
:
39 case PIXEL_FORMAT_NV12
:
40 case PIXEL_FORMAT_NV21
:
41 result_frame_size
= result_frame_size
* 3 / 2;
43 case PIXEL_FORMAT_UYVY
:
44 case PIXEL_FORMAT_YUY2
:
45 result_frame_size
*= 2;
47 case PIXEL_FORMAT_RGB24
:
48 result_frame_size
*= 3;
50 case PIXEL_FORMAT_RGB32
:
51 case PIXEL_FORMAT_ARGB
:
52 result_frame_size
*= 4;
54 case PIXEL_FORMAT_MJPEG
:
55 case PIXEL_FORMAT_TEXTURE
:
56 result_frame_size
= 0;
58 default: // Sizes for the rest of the formats are unknown.
59 NOTREACHED() << "Unknown pixel format provided.";
62 return result_frame_size
;
65 std::string
VideoCaptureFormat::ToString() const {
66 return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s",
67 frame_size
.ToString().c_str(),
69 PixelFormatToString(pixel_format
).c_str());
72 std::string
VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format
) {
74 case PIXEL_FORMAT_UNKNOWN
:
76 case PIXEL_FORMAT_I420
:
78 case PIXEL_FORMAT_YUY2
:
80 case PIXEL_FORMAT_UYVY
:
82 case PIXEL_FORMAT_RGB24
:
84 case PIXEL_FORMAT_RGB32
:
86 case PIXEL_FORMAT_ARGB
:
88 case PIXEL_FORMAT_MJPEG
:
90 case PIXEL_FORMAT_NV12
:
92 case PIXEL_FORMAT_NV21
:
94 case PIXEL_FORMAT_YV12
:
96 case PIXEL_FORMAT_TEXTURE
:
98 case PIXEL_FORMAT_MAX
:
101 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format
;
105 VideoCaptureParams::VideoCaptureParams()
106 : resolution_change_policy(RESOLUTION_POLICY_FIXED
) {}