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 // GpuMemoryBuffer is an endianness-agnostic 32bpp pixel format until
53 // http://crbug.com/439520 is closed.
54 case PIXEL_FORMAT_GPUMEMORYBUFFER
:
55 result_frame_size
*= 4;
57 case PIXEL_FORMAT_MJPEG
:
58 case PIXEL_FORMAT_TEXTURE
:
59 result_frame_size
= 0;
61 default: // Sizes for the rest of the formats are unknown.
62 NOTREACHED() << "Unknown pixel format provided.";
65 return result_frame_size
;
68 std::string
VideoCaptureFormat::ToString() const {
69 return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s",
70 frame_size
.ToString().c_str(),
72 PixelFormatToString(pixel_format
).c_str());
75 std::string
VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format
) {
77 case PIXEL_FORMAT_UNKNOWN
:
79 case PIXEL_FORMAT_I420
:
81 case PIXEL_FORMAT_YUY2
:
83 case PIXEL_FORMAT_UYVY
:
85 case PIXEL_FORMAT_RGB24
:
87 case PIXEL_FORMAT_RGB32
:
89 case PIXEL_FORMAT_ARGB
:
91 case PIXEL_FORMAT_MJPEG
:
93 case PIXEL_FORMAT_NV12
:
95 case PIXEL_FORMAT_NV21
:
97 case PIXEL_FORMAT_YV12
:
99 case PIXEL_FORMAT_TEXTURE
:
101 case PIXEL_FORMAT_GPUMEMORYBUFFER
:
102 return "GPUMEMORYBUFFER";
103 case PIXEL_FORMAT_MAX
:
106 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format
;
110 VideoCaptureParams::VideoCaptureParams()
111 : resolution_change_policy(RESOLUTION_POLICY_FIXED
) {}