OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/video_capture_types.h" | 5 #include "media/capture/video_capture_types.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 // This list is ordered by precedence of use. | 15 // This list is ordered by precedence of use. |
16 static VideoPixelFormat const kSupportedCapturePixelFormats[] = { | 16 static VideoPixelFormat const kSupportedCapturePixelFormats[] = { |
17 PIXEL_FORMAT_I420, | 17 PIXEL_FORMAT_I420, PIXEL_FORMAT_YV12, PIXEL_FORMAT_NV12, |
18 PIXEL_FORMAT_YV12, | 18 PIXEL_FORMAT_NV21, PIXEL_FORMAT_UYVY, PIXEL_FORMAT_YUY2, |
19 PIXEL_FORMAT_NV12, | 19 PIXEL_FORMAT_RGB24, PIXEL_FORMAT_RGB32, PIXEL_FORMAT_ARGB, |
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, | 20 PIXEL_FORMAT_MJPEG, |
27 }; | 21 }; |
28 | 22 |
29 VideoCaptureFormat::VideoCaptureFormat() | 23 VideoCaptureFormat::VideoCaptureFormat() |
30 : frame_rate(0.0f), | 24 : frame_rate(0.0f), |
31 pixel_format(PIXEL_FORMAT_UNKNOWN), | 25 pixel_format(PIXEL_FORMAT_UNKNOWN), |
32 pixel_storage(PIXEL_STORAGE_CPU) { | 26 pixel_storage(PIXEL_STORAGE_CPU) {} |
33 } | |
34 | 27 |
35 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size, | 28 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size, |
36 float frame_rate, | 29 float frame_rate, |
37 VideoPixelFormat pixel_format) | 30 VideoPixelFormat pixel_format) |
38 : frame_size(frame_size), | 31 : frame_size(frame_size), |
39 frame_rate(frame_rate), | 32 frame_rate(frame_rate), |
40 pixel_format(pixel_format), | 33 pixel_format(pixel_format), |
41 pixel_storage(PIXEL_STORAGE_CPU) { | 34 pixel_storage(PIXEL_STORAGE_CPU) {} |
42 } | |
43 | 35 |
44 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size, | 36 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size, |
45 float frame_rate, | 37 float frame_rate, |
46 VideoPixelFormat pixel_format, | 38 VideoPixelFormat pixel_format, |
47 VideoPixelStorage pixel_storage) | 39 VideoPixelStorage pixel_storage) |
48 : frame_size(frame_size), | 40 : frame_size(frame_size), |
49 frame_rate(frame_rate), | 41 frame_rate(frame_rate), |
50 pixel_format(pixel_format), | 42 pixel_format(pixel_format), |
51 pixel_storage(pixel_storage) { | 43 pixel_storage(pixel_storage) {} |
52 } | |
53 | 44 |
54 bool VideoCaptureFormat::IsValid() const { | 45 bool VideoCaptureFormat::IsValid() const { |
55 return (frame_size.width() < media::limits::kMaxDimension) && | 46 return (frame_size.width() < media::limits::kMaxDimension) && |
56 (frame_size.height() < media::limits::kMaxDimension) && | 47 (frame_size.height() < media::limits::kMaxDimension) && |
57 (frame_size.GetArea() >= 0) && | 48 (frame_size.GetArea() >= 0) && |
58 (frame_size.GetArea() < media::limits::kMaxCanvas) && | 49 (frame_size.GetArea() < media::limits::kMaxCanvas) && |
59 (frame_rate >= 0.0f) && | 50 (frame_rate >= 0.0f) && |
60 (frame_rate < media::limits::kMaxFramesPerSecond) && | 51 (frame_rate < media::limits::kMaxFramesPerSecond) && |
61 (pixel_format >= PIXEL_FORMAT_UNKNOWN && | 52 (pixel_format >= PIXEL_FORMAT_UNKNOWN && |
62 pixel_format <= PIXEL_FORMAT_MAX); | 53 pixel_format <= PIXEL_FORMAT_MAX); |
63 } | 54 } |
64 | 55 |
65 size_t VideoCaptureFormat::ImageAllocationSize() const { | 56 size_t VideoCaptureFormat::ImageAllocationSize() const { |
66 return VideoFrame::AllocationSize(pixel_format, frame_size); | 57 return VideoFrame::AllocationSize(pixel_format, frame_size); |
67 } | 58 } |
68 | 59 |
69 //static | 60 // static |
70 std::string VideoCaptureFormat::ToString(const VideoCaptureFormat& format) { | 61 std::string VideoCaptureFormat::ToString(const VideoCaptureFormat& format) { |
71 // Beware: This string is parsed by manager.js:parseVideoCaptureFormat_, | 62 // Beware: This string is parsed by manager.js:parseVideoCaptureFormat_, |
72 // take care when changing the formatting. | 63 // take care when changing the formatting. |
73 return base::StringPrintf( | 64 return base::StringPrintf( |
74 "(%s)@%.3ffps, pixel format: %s, storage: %s", | 65 "(%s)@%.3ffps, pixel format: %s, storage: %s", |
75 format.frame_size.ToString().c_str(), format.frame_rate, | 66 format.frame_size.ToString().c_str(), format.frame_rate, |
76 VideoPixelFormatToString(format.pixel_format).c_str(), | 67 VideoPixelFormatToString(format.pixel_format).c_str(), |
77 PixelStorageToString(format.pixel_storage).c_str()); | 68 PixelStorageToString(format.pixel_storage).c_str()); |
78 } | 69 } |
79 | 70 |
(...skipping 30 matching lines...) Expand all Loading... |
110 | 101 |
111 bool VideoCaptureParams::IsValid() const { | 102 bool VideoCaptureParams::IsValid() const { |
112 return requested_format.IsValid() && | 103 return requested_format.IsValid() && |
113 resolution_change_policy >= RESOLUTION_POLICY_FIXED_RESOLUTION && | 104 resolution_change_policy >= RESOLUTION_POLICY_FIXED_RESOLUTION && |
114 resolution_change_policy <= RESOLUTION_POLICY_LAST && | 105 resolution_change_policy <= RESOLUTION_POLICY_LAST && |
115 power_line_frequency >= PowerLineFrequency::FREQUENCY_DEFAULT && | 106 power_line_frequency >= PowerLineFrequency::FREQUENCY_DEFAULT && |
116 power_line_frequency <= PowerLineFrequency::FREQUENCY_MAX; | 107 power_line_frequency <= PowerLineFrequency::FREQUENCY_MAX; |
117 } | 108 } |
118 | 109 |
119 } // namespace media | 110 } // namespace media |
OLD | NEW |