Revert of Reland of crrev.com/1100173002 (Add a WinHeap dump provider to the memory...
[chromium-blink-merge.git] / media / base / video_capture_types.cc
blobcc5f8408f5ed111f073d7535c7b163f52566fc6c
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), pixel_format(PIXEL_FORMAT_UNKNOWN) {}
16 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
17 float frame_rate,
18 VideoPixelFormat pixel_format)
19 : frame_size(frame_size),
20 frame_rate(frame_rate),
21 pixel_format(pixel_format) {}
23 bool VideoCaptureFormat::IsValid() const {
24 return (frame_size.width() < media::limits::kMaxDimension) &&
25 (frame_size.height() < media::limits::kMaxDimension) &&
26 (frame_size.GetArea() >= 0) &&
27 (frame_size.GetArea() < media::limits::kMaxCanvas) &&
28 (frame_rate >= 0.0f) &&
29 (frame_rate < media::limits::kMaxFramesPerSecond) &&
30 (pixel_format >= 0) &&
31 (pixel_format < PIXEL_FORMAT_MAX);
34 size_t VideoCaptureFormat::ImageAllocationSize() const {
35 size_t result_frame_size = frame_size.GetArea();
36 switch (pixel_format) {
37 case PIXEL_FORMAT_I420:
38 case PIXEL_FORMAT_YV12:
39 case PIXEL_FORMAT_NV12:
40 case PIXEL_FORMAT_NV21:
41 result_frame_size = result_frame_size * 3 / 2;
42 break;
43 case PIXEL_FORMAT_UYVY:
44 case PIXEL_FORMAT_YUY2:
45 result_frame_size *= 2;
46 break;
47 case PIXEL_FORMAT_RGB24:
48 result_frame_size *= 3;
49 break;
50 case PIXEL_FORMAT_RGB32:
51 case PIXEL_FORMAT_ARGB:
52 // GpuMemoryBuffer is an endianness-agnostic 32bpp pixel format until
53 // http://crbug.com/439520 is closed.
54 case PIXEL_FORMAT_GPUMEMORYBUFFER:
55 result_frame_size *= 4;
56 break;
57 case PIXEL_FORMAT_MJPEG:
58 case PIXEL_FORMAT_TEXTURE:
59 result_frame_size = 0;
60 break;
61 default: // Sizes for the rest of the formats are unknown.
62 NOTREACHED() << "Unknown pixel format provided.";
63 break;
65 return result_frame_size;
68 std::string VideoCaptureFormat::ToString() const {
69 return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s",
70 frame_size.ToString().c_str(),
71 frame_rate,
72 PixelFormatToString(pixel_format).c_str());
75 std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) {
76 switch (format) {
77 case PIXEL_FORMAT_UNKNOWN:
78 return "UNKNOWN";
79 case PIXEL_FORMAT_I420:
80 return "I420";
81 case PIXEL_FORMAT_YUY2:
82 return "YUY2";
83 case PIXEL_FORMAT_UYVY:
84 return "UYVY";
85 case PIXEL_FORMAT_RGB24:
86 return "RGB24";
87 case PIXEL_FORMAT_RGB32:
88 return "RGB32";
89 case PIXEL_FORMAT_ARGB:
90 return "ARGB";
91 case PIXEL_FORMAT_MJPEG:
92 return "MJPEG";
93 case PIXEL_FORMAT_NV12:
94 return "NV12";
95 case PIXEL_FORMAT_NV21:
96 return "NV21";
97 case PIXEL_FORMAT_YV12:
98 return "YV12";
99 case PIXEL_FORMAT_TEXTURE:
100 return "TEXTURE";
101 case PIXEL_FORMAT_GPUMEMORYBUFFER:
102 return "GPUMEMORYBUFFER";
103 case PIXEL_FORMAT_MAX:
104 break;
106 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format;
107 return "";
110 VideoCaptureParams::VideoCaptureParams()
111 : resolution_change_policy(RESOLUTION_POLICY_FIXED) {}
112 } // namespace media