Delete unused downloads page asset.
[chromium-blink-merge.git] / media / base / video_capture_types.cc
blobf56935a04d5896bfb0b815c081afada67e0b113d
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"
11 namespace media {
13 VideoCaptureFormat::VideoCaptureFormat()
14 : frame_rate(0.0f),
15 pixel_format(VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN),
16 pixel_storage(PIXEL_STORAGE_CPU) {
19 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
20 float frame_rate,
21 VideoCapturePixelFormat pixel_format)
22 : frame_size(frame_size),
23 frame_rate(frame_rate),
24 pixel_format(pixel_format),
25 pixel_storage(PIXEL_STORAGE_CPU) {
28 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
29 float frame_rate,
30 VideoCapturePixelFormat pixel_format,
31 VideoPixelStorage pixel_storage)
32 : frame_size(frame_size),
33 frame_rate(frame_rate),
34 pixel_format(pixel_format),
35 pixel_storage(pixel_storage) {
38 bool VideoCaptureFormat::IsValid() const {
39 return (frame_size.width() < media::limits::kMaxDimension) &&
40 (frame_size.height() < media::limits::kMaxDimension) &&
41 (frame_size.GetArea() >= 0) &&
42 (frame_size.GetArea() < media::limits::kMaxCanvas) &&
43 (frame_rate >= 0.0f) &&
44 (frame_rate < media::limits::kMaxFramesPerSecond) &&
45 (pixel_storage != PIXEL_STORAGE_TEXTURE ||
46 pixel_format == VIDEO_CAPTURE_PIXEL_FORMAT_ARGB);
49 size_t VideoCaptureFormat::ImageAllocationSize() const {
50 size_t result_frame_size = frame_size.GetArea();
51 switch (pixel_format) {
52 case VIDEO_CAPTURE_PIXEL_FORMAT_I420:
53 case VIDEO_CAPTURE_PIXEL_FORMAT_YV12:
54 case VIDEO_CAPTURE_PIXEL_FORMAT_NV12:
55 case VIDEO_CAPTURE_PIXEL_FORMAT_NV21:
56 result_frame_size = result_frame_size * 3 / 2;
57 break;
58 case VIDEO_CAPTURE_PIXEL_FORMAT_UYVY:
59 case VIDEO_CAPTURE_PIXEL_FORMAT_YUY2:
60 result_frame_size *= 2;
61 break;
62 case VIDEO_CAPTURE_PIXEL_FORMAT_RGB24:
63 result_frame_size *= 3;
64 break;
65 case VIDEO_CAPTURE_PIXEL_FORMAT_RGB32:
66 case VIDEO_CAPTURE_PIXEL_FORMAT_ARGB:
67 result_frame_size *= 4;
68 break;
69 case VIDEO_CAPTURE_PIXEL_FORMAT_MJPEG:
70 result_frame_size = 0;
71 break;
72 default: // Sizes for the rest of the formats are unknown.
73 NOTREACHED() << "Unknown pixel format provided.";
74 break;
76 return result_frame_size;
79 //static
80 std::string VideoCaptureFormat::ToString(const VideoCaptureFormat& format) {
81 return base::StringPrintf("(%s)@%.3ffps, pixel format: %s storage: %s.",
82 format.frame_size.ToString().c_str(),
83 format.frame_rate,
84 PixelFormatToString(format.pixel_format).c_str(),
85 PixelStorageToString(format.pixel_storage).c_str());
88 // static
89 std::string VideoCaptureFormat::PixelFormatToString(
90 VideoCapturePixelFormat format) {
91 switch (format) {
92 case VIDEO_CAPTURE_PIXEL_FORMAT_UNKNOWN:
93 return "UNKNOWN";
94 case VIDEO_CAPTURE_PIXEL_FORMAT_I420:
95 return "I420";
96 case VIDEO_CAPTURE_PIXEL_FORMAT_YUY2:
97 return "YUY2";
98 case VIDEO_CAPTURE_PIXEL_FORMAT_UYVY:
99 return "UYVY";
100 case VIDEO_CAPTURE_PIXEL_FORMAT_RGB24:
101 return "RGB24";
102 case VIDEO_CAPTURE_PIXEL_FORMAT_RGB32:
103 return "RGB32";
104 case VIDEO_CAPTURE_PIXEL_FORMAT_ARGB:
105 return "ARGB";
106 case VIDEO_CAPTURE_PIXEL_FORMAT_MJPEG:
107 return "MJPEG";
108 case VIDEO_CAPTURE_PIXEL_FORMAT_NV12:
109 return "NV12";
110 case VIDEO_CAPTURE_PIXEL_FORMAT_NV21:
111 return "NV21";
112 case VIDEO_CAPTURE_PIXEL_FORMAT_YV12:
113 return "YV12";
115 NOTREACHED() << "Invalid VideoCapturePixelFormat provided: " << format;
116 return std::string();
119 // static
120 std::string VideoCaptureFormat::PixelStorageToString(
121 VideoPixelStorage storage) {
122 switch (storage) {
123 case PIXEL_STORAGE_CPU:
124 return "CPU";
125 case PIXEL_STORAGE_TEXTURE:
126 return "TEXTURE";
127 case PIXEL_STORAGE_GPUMEMORYBUFFER:
128 return "GPUMEMORYBUFFER";
130 NOTREACHED() << "Invalid VideoPixelStorage provided: "
131 << static_cast<int>(storage);
132 return std::string();
135 VideoCaptureParams::VideoCaptureParams()
136 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION),
137 power_line_frequency(PowerLineFrequency::FREQUENCY_DEFAULT) {}
139 } // namespace media