Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / base / video_capture_types.cc
blob0bc6ae639511625fe34fa214aacb01fd65d860d9
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"
12 namespace media {
14 // This list is ordered by precedence of use.
15 static VideoPixelFormat const kSupportedCapturePixelFormats[] = {
16 PIXEL_FORMAT_I420,
17 PIXEL_FORMAT_YV12,
18 PIXEL_FORMAT_NV12,
19 PIXEL_FORMAT_NV21,
20 PIXEL_FORMAT_UYVY,
21 PIXEL_FORMAT_YUY2,
22 PIXEL_FORMAT_RGB24,
23 PIXEL_FORMAT_RGB32,
24 PIXEL_FORMAT_ARGB,
25 PIXEL_FORMAT_MJPEG,
28 VideoCaptureFormat::VideoCaptureFormat()
29 : frame_rate(0.0f),
30 pixel_format(PIXEL_FORMAT_UNKNOWN),
31 pixel_storage(PIXEL_STORAGE_CPU) {
34 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
35 float frame_rate,
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,
44 float frame_rate,
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);
68 //static
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());
77 // static
78 std::string VideoCaptureFormat::PixelStorageToString(
79 VideoPixelStorage storage) {
80 switch (storage) {
81 case PIXEL_STORAGE_CPU:
82 return "CPU";
83 case PIXEL_STORAGE_TEXTURE:
84 return "TEXTURE";
85 case PIXEL_STORAGE_GPUMEMORYBUFFER:
86 return "GPUMEMORYBUFFER";
88 NOTREACHED() << "Invalid VideoPixelStorage provided: "
89 << static_cast<int>(storage);
90 return std::string();
93 // static
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),
100 lhs);
101 const auto& format_rhs = std::find(
102 kSupportedCapturePixelFormats,
103 kSupportedCapturePixelFormats + arraysize(kSupportedCapturePixelFormats),
104 rhs);
105 return format_lhs < format_rhs;
108 VideoCaptureParams::VideoCaptureParams()
109 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION),
110 power_line_frequency(PowerLineFrequency::FREQUENCY_DEFAULT) {}
112 } // namespace media