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"
10 #include "media/base/video_frame.h"
14 // This list is ordered by precedence of use.
15 static VideoPixelFormat
const kSupportedCapturePixelFormats
[] = {
28 VideoCaptureFormat::VideoCaptureFormat()
30 pixel_format(PIXEL_FORMAT_UNKNOWN
),
31 pixel_storage(PIXEL_STORAGE_CPU
) {
34 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size
& frame_size
,
36 VideoPixelFormat pixel_format
)
37 : frame_size(frame_size
),
38 frame_rate(frame_rate
),
39 pixel_format(pixel_format
),
40 pixel_storage(PIXEL_STORAGE_CPU
) {
43 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size
& frame_size
,
45 VideoPixelFormat pixel_format
,
46 VideoPixelStorage pixel_storage
)
47 : frame_size(frame_size
),
48 frame_rate(frame_rate
),
49 pixel_format(pixel_format
),
50 pixel_storage(pixel_storage
) {
53 bool VideoCaptureFormat::IsValid() const {
54 return (frame_size
.width() < media::limits::kMaxDimension
) &&
55 (frame_size
.height() < media::limits::kMaxDimension
) &&
56 (frame_size
.GetArea() >= 0) &&
57 (frame_size
.GetArea() < media::limits::kMaxCanvas
) &&
58 (frame_rate
>= 0.0f
) &&
59 (frame_rate
< media::limits::kMaxFramesPerSecond
) &&
60 (pixel_storage
!= PIXEL_STORAGE_TEXTURE
||
61 pixel_format
== PIXEL_FORMAT_ARGB
);
64 size_t VideoCaptureFormat::ImageAllocationSize() const {
65 return VideoFrame::AllocationSize(pixel_format
, frame_size
);
69 std::string
VideoCaptureFormat::ToString(const VideoCaptureFormat
& format
) {
70 return base::StringPrintf(
71 "(%s)@%.3ffps, pixel format: %s storage: %s.",
72 format
.frame_size
.ToString().c_str(), format
.frame_rate
,
73 VideoPixelFormatToString(format
.pixel_format
).c_str(),
74 PixelStorageToString(format
.pixel_storage
).c_str());
78 std::string
VideoCaptureFormat::PixelStorageToString(
79 VideoPixelStorage storage
) {
81 case PIXEL_STORAGE_CPU
:
83 case PIXEL_STORAGE_TEXTURE
:
85 case PIXEL_STORAGE_GPUMEMORYBUFFER
:
86 return "GPUMEMORYBUFFER";
88 NOTREACHED() << "Invalid VideoPixelStorage provided: "
89 << static_cast<int>(storage
);
94 bool VideoCaptureFormat::ComparePixelFormatPreference(
95 const VideoPixelFormat
& lhs
,
96 const VideoPixelFormat
& rhs
) {
97 const auto& format_lhs
= std::find(
98 kSupportedCapturePixelFormats
,
99 kSupportedCapturePixelFormats
+ arraysize(kSupportedCapturePixelFormats
),
101 const auto& format_rhs
= std::find(
102 kSupportedCapturePixelFormats
,
103 kSupportedCapturePixelFormats
+ arraysize(kSupportedCapturePixelFormats
),
105 return format_lhs
< format_rhs
;
108 VideoCaptureParams::VideoCaptureParams()
109 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION
),
110 power_line_frequency(PowerLineFrequency::FREQUENCY_DEFAULT
) {}