Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: media/base/video_capture_types.cc

Issue 2415703002: Move files video_capture*.* from media/base to media/capture (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_capture_types.h ('k') | media/base/video_capturer_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "media/base/video_capture_types.h"
6
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/strings/stringprintf.h"
10 #include "media/base/limits.h"
11 #include "media/base/video_frame.h"
12
13 namespace media {
14
15 // This list is ordered by precedence of use.
16 static VideoPixelFormat const kSupportedCapturePixelFormats[] = {
17 PIXEL_FORMAT_I420,
18 PIXEL_FORMAT_YV12,
19 PIXEL_FORMAT_NV12,
20 PIXEL_FORMAT_NV21,
21 PIXEL_FORMAT_UYVY,
22 PIXEL_FORMAT_YUY2,
23 PIXEL_FORMAT_RGB24,
24 PIXEL_FORMAT_RGB32,
25 PIXEL_FORMAT_ARGB,
26 PIXEL_FORMAT_MJPEG,
27 };
28
29 VideoCaptureFormat::VideoCaptureFormat()
30 : frame_rate(0.0f),
31 pixel_format(PIXEL_FORMAT_UNKNOWN),
32 pixel_storage(PIXEL_STORAGE_CPU) {
33 }
34
35 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
36 float frame_rate,
37 VideoPixelFormat pixel_format)
38 : frame_size(frame_size),
39 frame_rate(frame_rate),
40 pixel_format(pixel_format),
41 pixel_storage(PIXEL_STORAGE_CPU) {
42 }
43
44 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
45 float frame_rate,
46 VideoPixelFormat pixel_format,
47 VideoPixelStorage pixel_storage)
48 : frame_size(frame_size),
49 frame_rate(frame_rate),
50 pixel_format(pixel_format),
51 pixel_storage(pixel_storage) {
52 }
53
54 bool VideoCaptureFormat::IsValid() const {
55 return (frame_size.width() < media::limits::kMaxDimension) &&
56 (frame_size.height() < media::limits::kMaxDimension) &&
57 (frame_size.GetArea() >= 0) &&
58 (frame_size.GetArea() < media::limits::kMaxCanvas) &&
59 (frame_rate >= 0.0f) &&
60 (frame_rate < media::limits::kMaxFramesPerSecond) &&
61 (pixel_format >= PIXEL_FORMAT_UNKNOWN &&
62 pixel_format <= PIXEL_FORMAT_MAX);
63 }
64
65 size_t VideoCaptureFormat::ImageAllocationSize() const {
66 return VideoFrame::AllocationSize(pixel_format, frame_size);
67 }
68
69 //static
70 std::string VideoCaptureFormat::ToString(const VideoCaptureFormat& format) {
71 // Beware: This string is parsed by manager.js:parseVideoCaptureFormat_,
72 // take care when changing the formatting.
73 return base::StringPrintf(
74 "(%s)@%.3ffps, pixel format: %s, storage: %s",
75 format.frame_size.ToString().c_str(), format.frame_rate,
76 VideoPixelFormatToString(format.pixel_format).c_str(),
77 PixelStorageToString(format.pixel_storage).c_str());
78 }
79
80 // static
81 std::string VideoCaptureFormat::PixelStorageToString(
82 VideoPixelStorage storage) {
83 switch (storage) {
84 case PIXEL_STORAGE_CPU:
85 return "CPU";
86 }
87 NOTREACHED() << "Invalid VideoPixelStorage provided: "
88 << static_cast<int>(storage);
89 return std::string();
90 }
91
92 // static
93 bool VideoCaptureFormat::ComparePixelFormatPreference(
94 const VideoPixelFormat& lhs,
95 const VideoPixelFormat& rhs) {
96 auto* format_lhs = std::find(
97 kSupportedCapturePixelFormats,
98 kSupportedCapturePixelFormats + arraysize(kSupportedCapturePixelFormats),
99 lhs);
100 auto* format_rhs = std::find(
101 kSupportedCapturePixelFormats,
102 kSupportedCapturePixelFormats + arraysize(kSupportedCapturePixelFormats),
103 rhs);
104 return format_lhs < format_rhs;
105 }
106
107 VideoCaptureParams::VideoCaptureParams()
108 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION),
109 power_line_frequency(PowerLineFrequency::FREQUENCY_DEFAULT) {}
110
111 bool VideoCaptureParams::IsValid() const {
112 return requested_format.IsValid() &&
113 resolution_change_policy >= RESOLUTION_POLICY_FIXED_RESOLUTION &&
114 resolution_change_policy <= RESOLUTION_POLICY_LAST &&
115 power_line_frequency >= PowerLineFrequency::FREQUENCY_DEFAULT &&
116 power_line_frequency <= PowerLineFrequency::FREQUENCY_MAX;
117 }
118
119 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_capture_types.h ('k') | media/base/video_capturer_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698